1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Add pagination support

This commit is contained in:
Maksym Pavlenko
2017-01-13 19:43:45 -08:00
parent f69da18a54
commit eeb3e3ac7d
8 changed files with 79 additions and 55 deletions

View File

@@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc;
using Podsync.Helpers;
using Podsync.Services;
using Podsync.Services.Links;
using Podsync.Services.Resolver;
using Podsync.Services.Rss;
using Podsync.Services.Rss.Contracts;
using Podsync.Services.Storage;
@@ -47,7 +46,7 @@ namespace Podsync.Controllers
Provider = linkInfo.Provider,
LinkType = linkInfo.LinkType,
Id = linkInfo.Id,
Quality = request.Quality ?? ResolveFormat.VideoHigh,
Quality = request.Quality ?? Constants.DefaultFormat,
PageSize = request.PageSize ?? Constants.DefaultPageSize
};
@@ -59,7 +58,8 @@ namespace Podsync.Controllers
}
else
{
feed.Quality = ResolveFormat.VideoHigh;
feed.Quality = Constants.DefaultFormat;
feed.PageSize = Constants.DefaultPageSize;
}
var feedId = await _feedService.Create(feed);

View File

@@ -50,10 +50,10 @@ namespace Podsync.Services.Rss.Builders
}
// Get video ids from this playlist
var ids = await _youTube.GetPlaylistItemIds(new PlaylistItemsQuery { PlaylistId = channel.Guid });
var ids = await _youTube.GetPlaylistItemIds(new PlaylistItemsQuery { PlaylistId = channel.Guid, Count = metadata.PageSize });
// Get video descriptions
var videos = await _youTube.GetVideos(new VideoQuery { Id = string.Join(",", ids) });
var videos = await _youTube.GetVideos(new VideoQuery { Ids = ids });
channel.Items = videos.Select(youtubeVideo => MakeItem(youtubeVideo, metadata)).ToArray();

View File

@@ -24,8 +24,6 @@ namespace Podsync.Services.Rss
throw new ArgumentException("Only YouTube supports audio feeds");
}
metadata.PageSize = Constants.DefaultPageSize;
return _storageService.Save(metadata);
}

View File

@@ -1,9 +1,9 @@
namespace Podsync.Services.Videos.YouTube
using System.Collections.Generic;
namespace Podsync.Services.Videos.YouTube
{
public struct VideoQuery
{
public string Id { get; set; }
public int? Count { get; set; }
public ICollection<string> Ids { get; set; }
}
}

View File

@@ -71,17 +71,18 @@ namespace Podsync.Services.Videos.YouTube
{
var request = _youtube.Videos.List("id,snippet,contentDetails");
request.Id = query.Id;
var totalCount = query.Ids.Count;
var pageIndex = 0;
return AggregatePages<Video>(query.Count, async (list, token, pageSize) =>
return AggregatePages<Video>(totalCount, async (list, token, pageSize) =>
{
request.MaxResults = pageSize;
request.PageToken = token;
request.Id = string.Join(",", query.Ids.Skip(pageIndex * MaxResults).Take(pageSize));
pageIndex++;
var response = await request.ExecuteAsync();
response.Items.Select(ConvertVideo).AddTo(list);
return response.NextPageToken;
return list.Count == totalCount ? null : true.ToString();
});
}

View File

@@ -54,15 +54,16 @@
aria-hidden="true"
title="This features are available for patrons only. You may support us and unlock this features"></i>
}
<span class="@(!enableFeatures ? "locked" : "")">
<span id="control-panel">
Selected format <a class="selected-option" id="video-format">video</a> <a id="audio-format">audio</a>,
quality <a class="selected-option" id="best-quality">best</a> <a id="worst-quality">worst</a>,
</span>
<span id="control-panel" class="@(!enableFeatures ? "locked" : "")">
Selected format <a class="selected-option" id="video-format">video</a> <a id="audio-format">audio</a>,
quality <a class="selected-option" id="best-quality">best</a> <a id="worst-quality">worst</a>,
</span>
<span class="locked" style="text-decoration: line-through">
<i class="fa fa-question-circle master-tooltip" title="Still under development. We will keep you updated via Patreon's news feed" aria-hidden="true"></i>
episode count <a class="selected-option">50</a> <a>100</a> <a>150</a>
<span id="page-controls">
episode count <a class="selected-option">50</a> <a>100</a> <a>150</a>
</span>
</span>
</p>
</div>

View File

@@ -52,26 +52,29 @@ $(function () {
Tooltips
*/
$(document).on('mouseenter', 'i', function() {
var title = $(this).attr('title');
if (!title) {
return;
}
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip"></p>').text(title).appendTo('body').fadeIn('fast');
});
if (!isMobile()) {
$(document).on('mouseenter', 'i', function () {
var title = $(this).attr('title');
if (!title) {
return;
}
$(document).on('mouseleave', 'i', function() {
var text = $(this).data('tipText');
$(this).attr('title', text);
$('.tooltip').remove();
});
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip"></p>').text(title).appendTo('body').fadeIn('fast');
});
$(document).on('mousemove', 'i', function(e) {
var x = e.pageX + 10;
var y = e.pageY + 5;
$('.tooltip').css({ top: y, left: x });
});
$(document).on('mouseleave', 'i', function () {
var text = $(this).data('tipText');
$(this).attr('title', text);
$('.tooltip').remove();
});
$(document).on('mousemove', 'i', function (e) {
var x = e.pageX + 10;
var y = e.pageY + 5;
$('.tooltip').css({ top: y, left: x });
});
}
/*
Control panel
@@ -112,6 +115,28 @@ $(function () {
}
}
function pageSwitch(evt) {
if (isLocked()) {
return;
}
$('#page-controls > a').removeClass('selected-option');
$(evt.target).addClass('selected-option');
getPageCount();
}
function getPageCount() {
try {
var text = $('#page-controls > a.selected-option').text();
return parseInt(text);
} catch (e) {
return 50;
}
}
$('#page-controls > a').click(pageSwitch);
/* Modal */
function closeModal() {
@@ -156,13 +181,21 @@ $(function () {
}
}
$('body').on('keydown', function (e) {
// ESC
if ($('#modal').is(':visible') && e.keyCode === 27) {
$('#close-modal').click();
}
e.stopPropagation();
});
/*
Attach handlers
*/
$('#get-link').click(function(e) {
var url = $('#url-input').val();
createFeed({ url: url, quality: getQuality() }, displayLink);
createFeed({ url: url, quality: getQuality(), pageSize: getPageCount() }, displayLink);
e.preventDefault();
});
@@ -175,19 +208,11 @@ $(function () {
$('#video-format, #audio-format').click(formatSwith);
$('#best-quality, #worst-quality').click(qualitySwitch);
$('#close-modal').click(closeModal);
$('#modal-copy').click(copyLink);
if (!canCopy()) {
$('#modal-copy').hide();
}
$('body').on('keydown', function (e) {
// ESC
if ($('#modal').is(':visible') && e.keyCode === 27) {
$('#close-modal').click();
}
e.stopPropagation();
});
});

View File

@@ -89,11 +89,10 @@ namespace Podsync.Tests.Services.Videos.YouTube
{
var query = new VideoQuery
{
Id = "OlYH4gDi0Sk,kkcKnWrCZ7k"
Ids = new[] { "OlYH4gDi0Sk,kkcKnWrCZ7k" }
};
var response = await _client.GetVideos(query);
var list = response as IList<Video> ?? response.ToList();
var list = await _client.GetVideos(query);
Assert.Equal(2, list.Count);