mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Improve resolve service API
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace Podsync.Services.Resolver
|
||||
{
|
||||
public enum FileType
|
||||
{
|
||||
Video,
|
||||
Audio
|
||||
}
|
||||
}
|
@@ -5,6 +5,6 @@ namespace Podsync.Services.Resolver
|
||||
{
|
||||
public interface IResolverService
|
||||
{
|
||||
Task<Uri> Resolve(Uri videoUrl, FileType fileType = FileType.Video, Quality quality = Quality.High);
|
||||
Task<Uri> Resolve(Uri videoUrl, ResolveType resolveType = ResolveType.VideoHigh);
|
||||
}
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
namespace Podsync.Services.Resolver
|
||||
{
|
||||
public enum Quality
|
||||
{
|
||||
High,
|
||||
Low
|
||||
}
|
||||
}
|
10
src/Podsync/Services/Resolver/ResolveType.cs
Normal file
10
src/Podsync/Services/Resolver/ResolveType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Podsync.Services.Resolver
|
||||
{
|
||||
public enum ResolveType
|
||||
{
|
||||
VideoHigh,
|
||||
VideoLow,
|
||||
AudioHigh,
|
||||
AudioLow
|
||||
}
|
||||
}
|
@@ -8,13 +8,14 @@ namespace Podsync.Services.Resolver
|
||||
{
|
||||
private static readonly int WaitTimeout = (int)TimeSpan.FromSeconds(5).TotalMilliseconds;
|
||||
|
||||
public async Task<Uri> Resolve(Uri videoUrl, FileType fileType, Quality quality)
|
||||
public async Task<Uri> Resolve(Uri videoUrl, ResolveType resolveType)
|
||||
{
|
||||
var format = SelectFormat(fileType, quality);
|
||||
var format = SelectFormat(resolveType);
|
||||
|
||||
using (var proc = new Process())
|
||||
{
|
||||
var startInfo = proc.StartInfo;
|
||||
|
||||
startInfo.FileName = "youtube-dl";
|
||||
startInfo.Arguments = $"-f {format} -g {videoUrl}";
|
||||
|
||||
@@ -44,34 +45,21 @@ namespace Podsync.Services.Resolver
|
||||
}
|
||||
}
|
||||
|
||||
private static string SelectFormat(FileType fileType, Quality quality)
|
||||
private static string SelectFormat(ResolveType resolveType)
|
||||
{
|
||||
if (fileType == FileType.Video)
|
||||
switch (resolveType)
|
||||
{
|
||||
if (quality == Quality.High)
|
||||
{
|
||||
case ResolveType.VideoHigh:
|
||||
return "bestvideo";
|
||||
}
|
||||
|
||||
if (quality == Quality.Low)
|
||||
{
|
||||
case ResolveType.VideoLow:
|
||||
return "worstvideo";
|
||||
}
|
||||
}
|
||||
else if (fileType == FileType.Audio)
|
||||
{
|
||||
if (quality == Quality.High)
|
||||
{
|
||||
case ResolveType.AudioHigh:
|
||||
return "bestaudio";
|
||||
}
|
||||
|
||||
if (quality == Quality.Low)
|
||||
{
|
||||
case ResolveType.AudioLow:
|
||||
return "worstaudio";
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(resolveType), "Unsupported format", null);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unsupported format");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user