channel: use YT API to fetch playlist items

This commit is contained in:
Samantaz Fox 2022-11-11 00:44:24 +01:00
parent 8e8ca4fcc5
commit c5ee2bfc0f
No known key found for this signature in database
GPG Key ID: F42821059186176E
1 changed files with 21 additions and 19 deletions

View File

@ -1,28 +1,30 @@
def fetch_channel_playlists(ucid, author, continuation, sort_by) def fetch_channel_playlists(ucid, author, continuation, sort_by)
if continuation if continuation
response_json = YoutubeAPI.browse(continuation) initial_data = YoutubeAPI.browse(continuation)
items, continuation = extract_items(response_json, author, ucid)
else else
url = "/channel/#{ucid}/playlists?flow=list&view=1" params =
case sort_by case sort_by
when "last", "last_added" when "last", "last_added"
# # Equivalent to "&sort=lad"
# {"2:string": "playlists", "3:varint": 4, "4:varint": 1, "6:varint": 1}
"EglwbGF5bGlzdHMYBCABMAE%3D"
when "oldest", "oldest_created" when "oldest", "oldest_created"
url += "&sort=da" # formerly "&sort=da"
# Not available anymore :c or maybe ??
# {"2:string": "playlists", "3:varint": 2, "4:varint": 1, "6:varint": 1}
"EglwbGF5bGlzdHMYAiABMAE%3D"
# {"2:string": "playlists", "3:varint": 1, "4:varint": 1, "6:varint": 1}
# "EglwbGF5bGlzdHMYASABMAE%3D"
when "newest", "newest_created" when "newest", "newest_created"
url += "&sort=dd" # Formerly "&sort=dd"
else nil # Ignore # {"2:string": "playlists", "3:varint": 3, "4:varint": 1, "6:varint": 1}
"EglwbGF5bGlzdHMYAyABMAE%3D"
end end
response = YT_POOL.client &.get(url) initial_data = YoutubeAPI.browse(ucid, params: params || "")
initial_data = extract_initial_data(response.body)
return [] of SearchItem, nil if !initial_data
items, continuation = extract_items(initial_data, author, ucid)
end end
return items, continuation return extract_items(initial_data, ucid, author)
end end
# ## NOTE: DEPRECATED # ## NOTE: DEPRECATED