1
0
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:
Maksym Pavlenko
2016-11-07 14:08:10 -08:00
parent be36998a16
commit 2842cd68d3
5 changed files with 22 additions and 40 deletions

View File

@@ -1,8 +0,0 @@
namespace Podsync.Services.Resolver
{
public enum FileType
{
Video,
Audio
}
}

View File

@@ -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);
}
}

View File

@@ -1,8 +0,0 @@
namespace Podsync.Services.Resolver
{
public enum Quality
{
High,
Low
}
}

View File

@@ -0,0 +1,10 @@
namespace Podsync.Services.Resolver
{
public enum ResolveType
{
VideoHigh,
VideoLow,
AudioHigh,
AudioLow
}
}

View File

@@ -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");
}
}
}