use v1/next instead of searching for the continuation index

This commit is contained in:
diogo 2021-07-19 12:09:17 +03:00 committed by Samantaz Fox
parent 6176da3cbb
commit 84124b837d
No known key found for this signature in database
GPG Key ID: F42821059186176E
1 changed files with 6 additions and 13 deletions

View File

@ -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