From 84124b837db306c9bd5575fd6f87c413baed1e5b Mon Sep 17 00:00:00 2001 From: diogo Date: Mon, 19 Jul 2021 12:09:17 +0300 Subject: [PATCH] use v1/next instead of searching for the continuation index --- src/invidious/playlists.cr | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 20128462..b17ff9ef 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -437,6 +437,12 @@ def get_playlist_videos(db, playlist, offset, locale = nil, continuation = nil) db.query_all("SELECT * FROM playlist_videos WHERE plid = $1 ORDER BY array_position($2, index) LIMIT 100 OFFSET $3", playlist.id, playlist.index, offset, as: PlaylistVideo) else + + if continuation + initial_data = request_youtube_api_next(continuation, playlist.id) + offset = initial_data["contents"]["twoColumnWatchNextResults"]["playlist"]["playlist"]["currentIndex"].as_i + end + videos = [] of PlaylistVideo until videos.size >= 100 || videos.size == playlist.video_count || offset >= playlist.video_count @@ -445,19 +451,6 @@ def get_playlist_videos(db, playlist, offset, locale = nil, continuation = nil) initial_data = request_youtube_api_browse(ctoken) videos += extract_playlist_videos(initial_data) - if continuation - until videos[0].id == continuation - videos.shift - if videos.size == 0 - break - end - end - end - - if videos.size > 0 && offset == 0 - offset = videos[0].index - end - offset += 100 end