mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:25:56 -04:00
playlist starts at the offset
This commit is contained in:
parent
e3054ccdd2
commit
d9bfb3d305
@ -437,17 +437,38 @@ 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",
|
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)
|
playlist.id, playlist.index, offset, as: PlaylistVideo)
|
||||||
else
|
else
|
||||||
if offset >= 100
|
videos = [] of PlaylistVideo
|
||||||
# Normalize offset to match youtube's behavior (100 videos chunck per request)
|
|
||||||
offset = (offset / 100).to_i64 * 100_i64
|
|
||||||
|
|
||||||
ctoken = produce_playlist_continuation(playlist.id, offset)
|
until videos.size >= 50 || videos.size == playlist.video_count
|
||||||
initial_data = YoutubeAPI.browse(ctoken)
|
if offset >= 100
|
||||||
else
|
# Normalize offset to match youtube's behavior (100 videos chunck per request)
|
||||||
initial_data = YoutubeAPI.browse("VL" + playlist.id, params: "")
|
normalized_offset = (offset / 100).to_i64 * 100_i64
|
||||||
|
ctoken = produce_playlist_continuation(playlist.id, normalized_offset)
|
||||||
|
initial_data = request_youtube_api_browse(ctoken)
|
||||||
|
else
|
||||||
|
initial_data = request_youtube_api_browse("VL" + playlist.id, params: "")
|
||||||
|
end
|
||||||
|
|
||||||
|
videos += extract_playlist_videos(initial_data)
|
||||||
|
|
||||||
|
if continuation
|
||||||
|
until videos[0].id == continuation
|
||||||
|
videos.shift
|
||||||
|
end
|
||||||
|
elsif
|
||||||
|
until videos[0].index == offset
|
||||||
|
videos.shift
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if offset == 0
|
||||||
|
offset = videos[0].index
|
||||||
|
end
|
||||||
|
|
||||||
|
offset += 50
|
||||||
end
|
end
|
||||||
|
|
||||||
return extract_playlist_videos(initial_data)
|
return videos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user