mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Implement Vimeo RSS builder
This commit is contained in:
@@ -22,8 +22,6 @@ namespace Podsync.Controllers
|
||||
[HandleException]
|
||||
public class FeedController : Controller
|
||||
{
|
||||
private const int DefaultPageSize = 50;
|
||||
|
||||
private readonly XmlSerializer _serializer = new XmlSerializer(typeof(Rss));
|
||||
|
||||
private readonly IRssBuilder _rssBuilder;
|
||||
@@ -52,7 +50,7 @@ namespace Podsync.Controllers
|
||||
LinkType = linkInfo.LinkType,
|
||||
Id = linkInfo.Id,
|
||||
Quality = request.Quality ?? ResolveType.VideoHigh,
|
||||
PageSize = request.PageSize ?? DefaultPageSize
|
||||
PageSize = request.PageSize ?? Constants.DefaultPageSize
|
||||
};
|
||||
|
||||
// Check if user eligible for Patreon features
|
||||
@@ -60,7 +58,7 @@ namespace Podsync.Controllers
|
||||
if (!enablePatreonFeatures)
|
||||
{
|
||||
feed.Quality = ResolveType.VideoHigh;
|
||||
feed.PageSize = DefaultPageSize;
|
||||
feed.PageSize = Constants.DefaultPageSize;
|
||||
}
|
||||
|
||||
var feedId = await _storageService.Save(feed);
|
||||
|
@@ -7,13 +7,16 @@ using Shared;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
{
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class CompositeRssBuilder : RssBuilderBase
|
||||
{
|
||||
private readonly YouTubeRssBuilder _youTubeBuilder;
|
||||
private readonly VimeoRssBuilder _vimeoBuilder;
|
||||
|
||||
public CompositeRssBuilder(IServiceProvider serviceProvider, IStorageService storageService) : base(storageService)
|
||||
{
|
||||
_youTubeBuilder = serviceProvider.CreateInstance<YouTubeRssBuilder>();
|
||||
_vimeoBuilder = serviceProvider.CreateInstance<VimeoRssBuilder>();
|
||||
}
|
||||
|
||||
public override Provider Provider
|
||||
@@ -28,6 +31,11 @@ namespace Podsync.Services.Builder
|
||||
return _youTubeBuilder.Query(baseUrl, feedId, feed);
|
||||
}
|
||||
|
||||
if (feed.Provider == Provider.Vimeo)
|
||||
{
|
||||
return _vimeoBuilder.Query(baseUrl, feedId, feed);
|
||||
}
|
||||
|
||||
throw new NotSupportedException("Not supported provider");
|
||||
}
|
||||
}
|
||||
|
@@ -8,8 +8,6 @@ namespace Podsync.Services.Builder
|
||||
{
|
||||
public abstract class RssBuilderBase : IRssBuilder
|
||||
{
|
||||
protected static readonly string DefaultItunesCategory = "TV & Film";
|
||||
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
protected RssBuilderBase(IStorageService storageService)
|
||||
|
116
src/Podsync/Services/Builder/VimeoRssBuilder.cs
Normal file
116
src/Podsync/Services/Builder/VimeoRssBuilder.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services.Feed;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.Vimeo;
|
||||
|
||||
namespace Podsync.Services.Builder
|
||||
{
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class VimeoRssBuilder : RssBuilderBase
|
||||
{
|
||||
private readonly IVimeoClient _client;
|
||||
|
||||
public VimeoRssBuilder(IStorageService storageService, IVimeoClient client) : base(storageService)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public override Provider Provider { get; } = Provider.Vimeo;
|
||||
|
||||
public override async Task<Rss> Query(Uri baseUrl, string feedId, FeedMetadata metadata)
|
||||
{
|
||||
var linkType = metadata.LinkType;
|
||||
|
||||
var id = metadata.Id;
|
||||
|
||||
var pageSize = metadata.PageSize;
|
||||
if (pageSize == 0)
|
||||
{
|
||||
pageSize = Constants.DefaultPageSize;
|
||||
}
|
||||
|
||||
Channel channel = null;
|
||||
if (linkType == LinkType.Channel)
|
||||
{
|
||||
channel = CreateChannel(await _client.Channel(id));
|
||||
channel.Items = CreateItems(await _client.ChannelVideos(id, pageSize));
|
||||
}
|
||||
else if (linkType == LinkType.Group)
|
||||
{
|
||||
channel = CreateChannel(await _client.Group(id));
|
||||
channel.Items = CreateItems(await _client.GroupVideos(id, pageSize));
|
||||
}
|
||||
else if (linkType == LinkType.User)
|
||||
{
|
||||
channel = CreateChannel(await _client.User(id));
|
||||
channel.Items = CreateItems(await _client.UserVideos(id, pageSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("URL type is not supported");
|
||||
}
|
||||
|
||||
var rss = new Rss
|
||||
{
|
||||
Channels = new[] { channel }
|
||||
};
|
||||
|
||||
return rss;
|
||||
}
|
||||
|
||||
private static Channel CreateChannel(Group group)
|
||||
{
|
||||
return new Channel
|
||||
{
|
||||
Title = group.Name,
|
||||
Description = group.Description,
|
||||
Link = group.Link,
|
||||
PubDate = group.CreatedAt,
|
||||
Image = group.Thumbnail,
|
||||
Thumbnail = group.Thumbnail,
|
||||
Guid = group.Link.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
private static Channel CreateChannel(User user)
|
||||
{
|
||||
return new Channel
|
||||
{
|
||||
Title = user.Name,
|
||||
Description = user.Bio,
|
||||
Link = user.Link,
|
||||
PubDate = user.CreatedAt,
|
||||
Image = user.Thumbnail,
|
||||
Thumbnail = user.Thumbnail,
|
||||
Guid = user.Link.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
private static Item CreateItem(Video video)
|
||||
{
|
||||
return new Item
|
||||
{
|
||||
Title = video.Title,
|
||||
Description = video.Description,
|
||||
PubDate = video.CreatedAt,
|
||||
Link = video.Link,
|
||||
Duration = video.Duration,
|
||||
Content = new MediaContent
|
||||
{
|
||||
Length = video.Size,
|
||||
MediaType = "video/mp4",
|
||||
Url = null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<Item> CreateItems(IEnumerable<Video> videos)
|
||||
{
|
||||
return videos.Select(CreateItem);
|
||||
}
|
||||
}
|
||||
}
|
@@ -96,11 +96,9 @@ namespace Podsync.Services.Builder
|
||||
Title = item.Title,
|
||||
Description = item.Description,
|
||||
Link = item.Link,
|
||||
LastBuildDate = DateTime.Now,
|
||||
PubDate = item.PublishedAt,
|
||||
Image = item.Thumbnail,
|
||||
Thumbnail = item.Thumbnail,
|
||||
Category = DefaultItunesCategory
|
||||
};
|
||||
}
|
||||
|
||||
|
7
src/Podsync/Services/Constants.cs
Normal file
7
src/Podsync/Services/Constants.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Podsync.Services
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const int DefaultPageSize = 50;
|
||||
}
|
||||
}
|
@@ -12,10 +12,13 @@ namespace Podsync.Services.Feed
|
||||
public class Channel : IXmlSerializable
|
||||
{
|
||||
private const string PodsyncGeneratorName = "Podsync Generator";
|
||||
private static readonly string DefaultItunesCategory = "TV & Film";
|
||||
|
||||
public Channel()
|
||||
{
|
||||
Items = Enumerable.Empty<Item>();
|
||||
Category = DefaultItunesCategory;
|
||||
LastBuildDate = DateTime.Now;
|
||||
}
|
||||
|
||||
public string Guid { get; set; }
|
||||
|
65
test/Podsync.Tests/Services/Builder/VimeoRssBuilderTests.cs
Normal file
65
test/Podsync.Tests/Services/Builder/VimeoRssBuilderTests.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Podsync.Services.Builder;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Storage;
|
||||
using Podsync.Services.Videos.Vimeo;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Services.Builder
|
||||
{
|
||||
public class VimeoRssBuilderTests : TestBase
|
||||
{
|
||||
private readonly Mock<IStorageService> _storageService = new Mock<IStorageService>();
|
||||
|
||||
private readonly VimeoRssBuilder _builder;
|
||||
|
||||
public VimeoRssBuilderTests()
|
||||
{
|
||||
_builder = new VimeoRssBuilder(_storageService.Object, new VimeoClient(Options));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LinkType.Channel, "staffpicks")]
|
||||
[InlineData(LinkType.Group, "motion")]
|
||||
[InlineData(LinkType.User, "motionarray")]
|
||||
public async Task BuildRssTest(LinkType linkType, string id)
|
||||
{
|
||||
var feed = new FeedMetadata
|
||||
{
|
||||
Provider = Provider.YouTube,
|
||||
LinkType = linkType,
|
||||
Id = id
|
||||
};
|
||||
|
||||
var feedId = DateTime.UtcNow.Ticks.ToString();
|
||||
|
||||
_storageService.Setup(x => x.Load(feedId)).ReturnsAsync(feed);
|
||||
|
||||
var rss = await _builder.Query(new Uri("http://localhost:2020"), feedId);
|
||||
|
||||
Assert.NotEmpty(rss.Channels);
|
||||
|
||||
var channel = rss.Channels.Single();
|
||||
|
||||
Assert.NotNull(channel.Title);
|
||||
Assert.NotNull(channel.Description);
|
||||
Assert.NotNull(channel.Image);
|
||||
Assert.NotNull(channel.Guid);
|
||||
Assert.NotEmpty(channel.Items);
|
||||
|
||||
foreach (var item in channel.Items)
|
||||
{
|
||||
Assert.NotNull(item.Title);
|
||||
Assert.NotNull(item.Link);
|
||||
Assert.True(item.Duration.TotalSeconds > 0);
|
||||
Assert.NotNull(item.Content);
|
||||
Assert.True(item.Content.Length > 0);
|
||||
Assert.NotNull(item.Content.MediaType);
|
||||
Assert.NotNull(item.PubDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user