mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Refactor code, update namespaces
This commit is contained in:
@@ -8,11 +8,11 @@ using System.Xml.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services;
|
||||
using Podsync.Services.Builder;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Feed.Internal;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Rss;
|
||||
using Podsync.Services.Rss.Feed;
|
||||
using Podsync.Services.Rss.Feed.Internal;
|
||||
using Podsync.Services.Storage;
|
||||
using Shared;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Podsync.Controllers
|
||||
Provider = linkInfo.Provider,
|
||||
LinkType = linkInfo.LinkType,
|
||||
Id = linkInfo.Id,
|
||||
Quality = request.Quality ?? ResolveType.VideoHigh,
|
||||
Quality = request.Quality ?? ResolveFormat.VideoHigh,
|
||||
PageSize = request.PageSize ?? Constants.DefaultPageSize
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Podsync.Controllers
|
||||
var enablePatreonFeatures = User.EnablePatreonFeatures();
|
||||
if (!enablePatreonFeatures)
|
||||
{
|
||||
feed.Quality = ResolveType.VideoHigh;
|
||||
feed.Quality = ResolveFormat.VideoHigh;
|
||||
feed.PageSize = Constants.DefaultPageSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Podsync.Services
|
||||
{
|
||||
public const int DefaultPageSize = 50;
|
||||
|
||||
public const ResolveType DefaultFormat = ResolveType.VideoHigh;
|
||||
public const ResolveFormat DefaultFormat = ResolveFormat.VideoHigh;
|
||||
|
||||
public static class Patreon
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Podsync.Services
|
||||
[Url]
|
||||
public string Url { get; set; }
|
||||
|
||||
public ResolveType? Quality { get; set; }
|
||||
public ResolveFormat? Quality { get; set; }
|
||||
|
||||
[Range(50, 150)]
|
||||
public int? PageSize { get; set; }
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace Podsync.Services.Resolver
|
||||
{
|
||||
string Version { get; }
|
||||
|
||||
Task<Uri> Resolve(Uri videoUrl, ResolveType resolveType = ResolveType.VideoHigh);
|
||||
Task<Uri> Resolve(Uri videoUrl, ResolveFormat format = ResolveFormat.VideoHigh);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Podsync.Services.Resolver
|
||||
{
|
||||
public enum ResolveType
|
||||
public enum ResolveFormat
|
||||
{
|
||||
VideoHigh = 0,
|
||||
VideoLow,
|
||||
@@ -36,9 +36,9 @@ namespace Podsync.Services.Resolver
|
||||
public string Version { get; }
|
||||
|
||||
|
||||
public async Task<Uri> Resolve(Uri videoUrl, ResolveType resolveType)
|
||||
public async Task<Uri> Resolve(Uri videoUrl, ResolveFormat resolveFormat)
|
||||
{
|
||||
var format = SelectFormat(resolveType);
|
||||
var format = SelectFormat(resolveFormat);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -52,20 +52,20 @@ namespace Podsync.Services.Resolver
|
||||
}
|
||||
}
|
||||
|
||||
private static string SelectFormat(ResolveType resolveType)
|
||||
private static string SelectFormat(ResolveFormat format)
|
||||
{
|
||||
switch (resolveType)
|
||||
switch (format)
|
||||
{
|
||||
case ResolveType.VideoHigh:
|
||||
case ResolveFormat.VideoHigh:
|
||||
return "best[ext=mp4]";
|
||||
case ResolveType.VideoLow:
|
||||
case ResolveFormat.VideoLow:
|
||||
return "worst[ext=mp4]";
|
||||
case ResolveType.AudioHigh:
|
||||
case ResolveFormat.AudioHigh:
|
||||
return "bestaudio[ext=m4a]/worstaudio[ext=m4a]";
|
||||
case ResolveType.AudioLow:
|
||||
case ResolveFormat.AudioLow:
|
||||
return "worstaudio[ext=m4a]/bestaudio[ext=m4a]";
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(resolveType), "Unsupported format", null);
|
||||
throw new ArgumentOutOfRangeException(nameof(format), "Unsupported format", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,11 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Storage;
|
||||
using Shared;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
namespace Podsync.Services.Rss
|
||||
{
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class CompositeRssBuilder : RssBuilderBase
|
||||
@@ -35,7 +34,7 @@ namespace Podsync.Services.Builder
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override Task<Rss> Query(FeedMetadata feed)
|
||||
public override Task<Feed.Rss> Query(FeedMetadata feed)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using Shared;
|
||||
|
||||
namespace Podsync.Services.Feed
|
||||
namespace Podsync.Services.Rss.Feed
|
||||
{
|
||||
[XmlRoot("channel")]
|
||||
public class Channel : IXmlSerializable
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Podsync.Services.Feed.Internal
|
||||
namespace Podsync.Services.Rss.Feed.Internal
|
||||
{
|
||||
public class Utf8StringWriter : StringWriter
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Podsync.Services.Feed
|
||||
namespace Podsync.Services.Rss.Feed
|
||||
{
|
||||
[XmlRoot("item")]
|
||||
public class Item : IXmlSerializable
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Podsync.Services.Feed
|
||||
namespace Podsync.Services.Rss.Feed
|
||||
{
|
||||
public static class Namespaces
|
||||
{
|
||||
@@ -6,7 +6,7 @@ using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using Shared;
|
||||
|
||||
namespace Podsync.Services.Feed
|
||||
namespace Podsync.Services.Rss.Feed
|
||||
{
|
||||
[XmlRoot("rss")]
|
||||
public class Rss : IXmlSerializable
|
||||
@@ -1,16 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Storage;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
namespace Podsync.Services.Rss
|
||||
{
|
||||
public interface IRssBuilder
|
||||
{
|
||||
Provider Provider { get; }
|
||||
|
||||
Task<Rss> Query(string feedId);
|
||||
Task<Feed.Rss> Query(string feedId);
|
||||
|
||||
Task<Rss> Query(FeedMetadata metadata);
|
||||
Task<Feed.Rss> Query(FeedMetadata metadata);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Storage;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
namespace Podsync.Services.Rss
|
||||
{
|
||||
public abstract class RssBuilderBase : IRssBuilder
|
||||
{
|
||||
@@ -16,13 +15,13 @@ namespace Podsync.Services.Builder
|
||||
|
||||
public abstract Provider Provider { get; }
|
||||
|
||||
public async Task<Rss> Query(string feedId)
|
||||
public async Task<Feed.Rss> Query(string feedId)
|
||||
{
|
||||
var metadata = await _storageService.Load(feedId);
|
||||
|
||||
return await Query(metadata);
|
||||
}
|
||||
|
||||
public abstract Task<Rss> Query(FeedMetadata metadata);
|
||||
public abstract Task<Feed.Rss> Query(FeedMetadata metadata);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Rss.Feed;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.Vimeo;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
namespace Podsync.Services.Rss
|
||||
{
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class VimeoRssBuilder : RssBuilderBase
|
||||
@@ -21,7 +21,7 @@ namespace Podsync.Services.Builder
|
||||
|
||||
public override Provider Provider { get; } = Provider.Vimeo;
|
||||
|
||||
public override async Task<Rss> Query(FeedMetadata metadata)
|
||||
public override async Task<Feed.Rss> Query(FeedMetadata metadata)
|
||||
{
|
||||
var linkType = metadata.LinkType;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Podsync.Services.Builder
|
||||
throw new NotSupportedException("URL type is not supported");
|
||||
}
|
||||
|
||||
var rss = new Rss
|
||||
var rss = new Feed.Rss
|
||||
{
|
||||
Channels = new[] { channel }
|
||||
};
|
||||
@@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Rss.Feed;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.YouTube;
|
||||
using Channel = Podsync.Services.Feed.Channel;
|
||||
using Channel = Podsync.Services.Rss.Feed.Channel;
|
||||
using Video = Podsync.Services.Videos.YouTube.Video;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
namespace Podsync.Services.Rss
|
||||
{
|
||||
public class YouTubeRssBuilder : RssBuilderBase
|
||||
{
|
||||
@@ -22,7 +22,7 @@ namespace Podsync.Services.Builder
|
||||
|
||||
public override Provider Provider { get; } = Provider.YouTube;
|
||||
|
||||
public override async Task<Rss> Query(FeedMetadata metadata)
|
||||
public override async Task<Feed.Rss> Query(FeedMetadata metadata)
|
||||
{
|
||||
if (metadata.Provider != Provider.YouTube)
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Podsync.Services.Builder
|
||||
|
||||
channel.Items = videos.Select(youtubeVideo => MakeItem(youtubeVideo, metadata)).ToArray();
|
||||
|
||||
var rss = new Rss
|
||||
var rss = new Feed.Rss
|
||||
{
|
||||
Channels = new[] { channel }
|
||||
};
|
||||
@@ -117,14 +117,14 @@ namespace Podsync.Services.Builder
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetContentType(ResolveType resolveType)
|
||||
private static string GetContentType(ResolveFormat format)
|
||||
{
|
||||
if (resolveType == ResolveType.VideoHigh || resolveType == ResolveType.VideoLow)
|
||||
if (format == ResolveFormat.VideoHigh || format == ResolveFormat.VideoLow)
|
||||
{
|
||||
return "video/mp4";
|
||||
}
|
||||
|
||||
if (resolveType == ResolveType.AudioHigh || resolveType == ResolveType.AudioLow)
|
||||
if (format == ResolveFormat.AudioHigh || format == ResolveFormat.AudioLow)
|
||||
{
|
||||
return "audio/mp4";
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace Podsync.Services.Storage
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
public ResolveType Quality { get; set; }
|
||||
public ResolveFormat Quality { get; set; }
|
||||
|
||||
public int PageSize { get; set; }
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services;
|
||||
using Podsync.Services.Builder;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Patreon;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Rss;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.Vimeo;
|
||||
using Podsync.Services.Videos.YouTube;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Podsync.Tests.Controllers
|
||||
[InlineData("http://youtube.com", null, 0)]
|
||||
[InlineData("http://youtube.com", null, 25)]
|
||||
[InlineData("http://youtube.com", null, 151)]
|
||||
public async Task ValidateCreateTest(string url, ResolveType? quality, int? pageSize)
|
||||
public async Task ValidateCreateTest(string url, ResolveFormat? quality, int? pageSize)
|
||||
{
|
||||
var feed = new CreateFeedRequest
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace Podsync.Tests.Controllers
|
||||
var feed = new CreateFeedRequest
|
||||
{
|
||||
Url = "https://www.youtube.com/channel/UCKy1dAqELo0zrOtPkf0eTMw",
|
||||
Quality = ResolveType.AudioLow,
|
||||
Quality = ResolveFormat.AudioLow,
|
||||
};
|
||||
|
||||
var response = await Client.PostAsync("/feed/create", MakeHttpContent(feed));
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Podsync.Tests.Services.Patreon
|
||||
|
||||
private Tokens Tokens => Configuration.CreatorTokens;
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Run manually with access token")]
|
||||
public async Task FetchProfileTest()
|
||||
{
|
||||
var user = await _api.FetchUserAndPledges(Tokens);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Podsync.Tests.Services.Resolver
|
||||
[Fact]
|
||||
public async Task ResolveOutputTest()
|
||||
{
|
||||
var downloadUrl = await _resolver.Resolve(new Uri("https://www.youtube.com/watch?v=-csRxRj_zcw&t=45s"), ResolveType.AudioHigh);
|
||||
var downloadUrl = await _resolver.Resolve(new Uri("https://www.youtube.com/watch?v=-csRxRj_zcw&t=45s"), ResolveFormat.AudioHigh);
|
||||
Assert.True(downloadUrl.IsAbsoluteUri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Rss.Feed;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Services.Feed
|
||||
namespace Podsync.Tests.Services.Rss.Feed
|
||||
{
|
||||
public class FeedSerializationTests
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace Podsync.Tests.Services.Feed
|
||||
[Fact]
|
||||
public void SerializeFeedTest()
|
||||
{
|
||||
var feed = new Rss();
|
||||
var feed = new Podsync.Services.Rss.Feed.Rss();
|
||||
|
||||
var item = new Item
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace Podsync.Tests.Services.Feed
|
||||
channel
|
||||
};
|
||||
|
||||
var serializer = new XmlSerializer(typeof(Rss));
|
||||
var serializer = new XmlSerializer(typeof(Podsync.Services.Rss.Feed.Rss));
|
||||
|
||||
string body;
|
||||
using (var writer = new StringWriter())
|
||||
@@ -2,13 +2,13 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Podsync.Services.Builder;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Rss;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.Vimeo;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Services.Builder
|
||||
namespace Podsync.Tests.Services.Rss
|
||||
{
|
||||
public class VimeoRssBuilderTests : TestBase
|
||||
{
|
||||
@@ -2,13 +2,13 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Podsync.Services.Builder;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Rss;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.YouTube;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Services.Builder
|
||||
namespace Podsync.Tests.Services.Rss
|
||||
{
|
||||
public class YouTubeRssBuilderTests : TestBase
|
||||
{
|
||||
Reference in New Issue
Block a user