Skip to content

Commit

Permalink
Set content-type: application/rss+xml
Browse files Browse the repository at this point in the history
  • Loading branch information
i3arnon committed Nov 6, 2020
1 parent 7c65a91 commit c6a89c3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 49 deletions.
111 changes: 63 additions & 48 deletions src/Service/YoutubeFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,32 @@ public async Task<SyndicationFeedFormatter> GetUserFeedAsync(
int maxLength,
bool isPopular)
{
var baseAddress = GetBaseAddress();

var channel =
await GetChannelAsync(userId) ??
await FindChannelAsync(userId);
var arguments = new Arguments(
channel.ContentDetails.RelatedPlaylists.Uploads,
encoding,
maxLength,
isPopular);

var feed = new ItunesFeed(
GetTitle(channel.Snippet.Title, arguments),
channel.Snippet.Description,
new Uri(string.Format(_channelUrlFormat, channel.Id)))
{
ImageUrl = new Uri(channel.Snippet.Thumbnails.Medium.Url),
Items = await GenerateItemsAsync(
baseAddress,
channel.Snippet.PublishedAt.GetValueOrDefault(),
arguments),
};
return await GetFeedFormatterAsync(GetFeedAsync);

return feed.GetRss20Formatter();
async Task<ItunesFeed> GetFeedAsync(string baseAddress)
{
var channel =
await GetChannelAsync(userId) ??
await FindChannelAsync(userId);

var arguments = new Arguments(
channel.ContentDetails.RelatedPlaylists.Uploads,
encoding,
maxLength,
isPopular);

return new ItunesFeed(
GetTitle(channel.Snippet.Title, arguments),
channel.Snippet.Description,
new Uri(string.Format(_channelUrlFormat, channel.Id)))
{
ImageUrl = new Uri(channel.Snippet.Thumbnails.Medium.Url),
Items = await GenerateItemsAsync(
baseAddress,
channel.Snippet.PublishedAt.GetValueOrDefault(),
arguments)
};
}

async Task<Channel> GetChannelAsync(string id)
{
Expand Down Expand Up @@ -102,33 +104,35 @@ public async Task<SyndicationFeedFormatter> GetPlaylistFeedAsync(
int maxLength,
bool isPopular)
{
var baseAddress = GetBaseAddress();
return await GetFeedFormatterAsync(GetFeedAsync);

var arguments = new Arguments(
playlistId,
encoding,
maxLength,
isPopular);

var playlistRequest = _youtubeService.Playlists.List("snippet");
playlistRequest.Id = playlistId;
playlistRequest.MaxResults = 1;

var playlist = (await playlistRequest.ExecuteAsync()).Items.First();

var feed = new ItunesFeed(
GetTitle(playlist.Snippet.Title, arguments),
playlist.Snippet.Description,
new Uri(string.Format(_playlistUrlFormat, playlist.Id)))
async Task<ItunesFeed> GetFeedAsync(string baseAddress)
{
ImageUrl = new Uri(playlist.Snippet.Thumbnails.Medium.Url),
Items = await GenerateItemsAsync(
baseAddress,
playlist.Snippet.PublishedAt.GetValueOrDefault(),
arguments),
};

return feed.GetRss20Formatter();
var arguments =
new Arguments(
playlistId,
encoding,
maxLength,
isPopular);

var playlistRequest = _youtubeService.Playlists.List("snippet");
playlistRequest.Id = playlistId;
playlistRequest.MaxResults = 1;

var playlist = (await playlistRequest.ExecuteAsync()).Items.First();

return new ItunesFeed(
GetTitle(playlist.Snippet.Title, arguments),
playlist.Snippet.Description,
new Uri(string.Format(_playlistUrlFormat, playlist.Id)))
{
ImageUrl = new Uri(playlist.Snippet.Thumbnails.Medium.Url),
Items = await GenerateItemsAsync(
baseAddress,
playlist.Snippet.PublishedAt.GetValueOrDefault(),
arguments)
};
}
}

public async Task GetVideoAsync(string videoId, string encoding)
Expand Down Expand Up @@ -170,6 +174,17 @@ async Task<string> GetAudioUriAsync()
}
}

private async Task<SyndicationFeedFormatter> GetFeedFormatterAsync(Func<string, Task<ItunesFeed>> getFeedAsync)
{
var transportAddress = OperationContext.Current.IncomingMessageProperties.Via;
var baseAddress = $"http://{transportAddress.DnsSafeHost}:{transportAddress.Port}/FeedService";

WebOperationContext.Current.OutgoingResponse.ContentType = "application/rss+xml; charset=utf-8";

var feed = await getFeedAsync(baseAddress);
return feed.GetRss20Formatter();
}

private async Task GetContentAsync(Func<Task<string>> getContentUriAsync)
{
var context = WebOperationContext.Current;
Expand Down
2 changes: 1 addition & 1 deletion src/YouCast/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<Button
x:Name="YoucastLink"
Style="{StaticResource LinkButton}"
Click="YoucastLink_OnClick" Content="YouCast v2.16."/>
Click="YoucastLink_OnClick" Content="YouCast v2.17."/>
<Label VerticalAlignment="Center" Content="Made by"/>
<Button
x:Name="TwitterLink"
Expand Down

0 comments on commit c6a89c3

Please sign in to comment.