fix cases when high offset video from playlist has no offset in url

This commit is contained in:
diogo 2021-07-17 01:48:33 +02:00 committed by Samantaz Fox
parent 7eba7fbcc7
commit 440105976f
No known key found for this signature in database
GPG key ID: F42821059186176E

View file

@ -439,7 +439,7 @@ def get_playlist_videos(db, playlist, offset, locale = nil, continuation = nil)
else else
videos = [] of PlaylistVideo videos = [] of PlaylistVideo
until videos.size >= 50 || videos.size == playlist.video_count until videos.size >= 50 || videos.size == playlist.video_count || offset >= playlist.video_count
if offset >= 100 if offset >= 100
# Normalize offset to match youtube's behavior (100 videos chunck per request) # Normalize offset to match youtube's behavior (100 videos chunck per request)
normalized_offset = (offset / 100).to_i64 * 100_i64 normalized_offset = (offset / 100).to_i64 * 100_i64
@ -454,18 +454,24 @@ def get_playlist_videos(db, playlist, offset, locale = nil, continuation = nil)
if continuation if continuation
until videos[0].id == continuation until videos[0].id == continuation
videos.shift videos.shift
if videos.size == 0
break
end end
elsif end
else
until videos[0].index == offset until videos[0].index == offset
videos.shift videos.shift
if videos.size == 0
break
end
end end
end end
if offset == 0 if videos.size > 0 && offset == 0
offset = videos[0].index offset = videos[0].index
end end
offset += 50 offset += 100
end end
return videos return videos