unfuck playlists

This commit is contained in:
706f6f7079646f6f646f6f 2021-10-08 11:40:35 +02:00
parent 21e29411af
commit 204bfe2587
2 changed files with 11 additions and 5 deletions

View File

@ -439,15 +439,21 @@ def get_playlist_videos(db, playlist, offset, locale = nil, continuation = nil)
else else
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)
offset = (offset / 100).to_i64 * 100_i64 normalized_offset = (offset / 100).to_i64 * 100_i64
ctoken = produce_playlist_continuation(playlist.id, offset) ctoken = produce_playlist_continuation(playlist.id, normalized_offset)
initial_data = YoutubeAPI.browse(ctoken) initial_data = YoutubeAPI.browse(ctoken)
else else
initial_data = YoutubeAPI.browse("VL" + playlist.id, params: "") initial_data = YoutubeAPI.browse("VL" + playlist.id, params: "")
end end
return extract_playlist_videos(initial_data) videos = extract_playlist_videos(initial_data)
until videos.empty? || videos[0].index == offset
videos.shift
end
return videos
end end
end end
@ -524,7 +530,7 @@ def template_playlist(playlist)
playlist["videos"].as_a.each do |video| playlist["videos"].as_a.each do |video|
html += <<-END_HTML html += <<-END_HTML
<li class="pure-menu-item"> <li class="pure-menu-item">
<a href="/watch?v=#{video["videoId"]}&list=#{playlist["playlistId"]}"> <a href="/watch?v=#{video["videoId"]}&list=#{playlist["playlistId"]}&index=#{video.["index"]}">
<div class="thumbnail"> <div class="thumbnail">
<img class="thumbnail" src="/vi/#{video["videoId"]}/mqdefault.jpg"> <img class="thumbnail" src="/vi/#{video["videoId"]}/mqdefault.jpg">
<p class="length">#{recode_length_seconds(video["lengthSeconds"].as_i)}</p> <p class="length">#{recode_length_seconds(video["lengthSeconds"].as_i)}</p>

View File

@ -48,7 +48,7 @@
<p dir="auto"><b><%= HTML.escape(item.author) %></b></p> <p dir="auto"><b><%= HTML.escape(item.author) %></b></p>
</a> </a>
<% when PlaylistVideo %> <% when PlaylistVideo %>
<a style="width:100%" href="/watch?v=<%= item.id %>&list=<%= item.plid %>"> <a style="width:100%" href="/watch?v=<%= item.id %>&list=<%= item.plid %>&index=<%= item.index %>">
<% if !env.get("preferences").as(Preferences).thin_mode %> <% if !env.get("preferences").as(Preferences).thin_mode %>
<div class="thumbnail"> <div class="thumbnail">
<img class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg"/> <img class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg"/>