diff options
author | Astound <kirito@disroot.org> | 2024-01-22 05:39:11 +0800 |
---|---|---|
committer | Astound <kirito@disroot.org> | 2024-01-22 05:39:11 +0800 |
commit | b45e3476c8e158103649563cd0506f57011dabdd (patch) | |
tree | 2cc8126655a58ecb4228a78b84218fd0f79da536 /youtube/playlist.py | |
parent | d591956baafa6a16b956f814b69ecbf1f5e23aba (diff) | |
download | yt-local-b45e3476c8e158103649563cd0506f57011dabdd.tar.lz yt-local-b45e3476c8e158103649563cd0506f57011dabdd.tar.xz yt-local-b45e3476c8e158103649563cd0506f57011dabdd.zip |
channels: Use the UU playlist to get videos by default
This will be much less likely to break moving forward since
YouTube rarely changes the playlist api
Videos page now includes shorts and streams in the video lsit
Also include an option to filter out shorts on the videos page
Diffstat (limited to 'youtube/playlist.py')
-rw-r--r-- | youtube/playlist.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/youtube/playlist.py b/youtube/playlist.py index 7eb4d22..a2ff80f 100644 --- a/youtube/playlist.py +++ b/youtube/playlist.py @@ -47,23 +47,25 @@ def playlist_first_page(playlist_id, report_text="Retrieved playlist", use_mobil return content -def get_videos(playlist_id, page, use_mobile=False): +def get_videos(playlist_id, page, include_shorts=True, use_mobile=False): # mobile requests return 20 videos per page if use_mobile: - url = "https://m.youtube.com/playlist?ctoken=" - url += playlist_ctoken(playlist_id, (int(page)-1)*20) + "&pbj=1" - content = util.fetch_url( - url, util.mobile_xhr_headers, - report_text="Retrieved playlist", debug_name='playlist_videos' - ) + page_size = 20 + headers = util.mobile_xhr_headers # desktop requests return 100 videos per page else: - url = "https://www.youtube.com/playlist?ctoken=" - url += playlist_ctoken(playlist_id, (int(page)-1)*100) + "&pbj=1" - content = util.fetch_url( - url, util.desktop_xhr_headers, - report_text="Retrieved playlist", debug_name='playlist_videos' - ) + page_size = 100 + headers = util.desktop_xhr_headers + + url = "https://m.youtube.com/playlist?ctoken=" + url += playlist_ctoken(playlist_id, (int(page)-1)*page_size, + include_shorts=include_shorts) + url += "&pbj=1" + content = util.fetch_url( + url, headers, report_text="Retrieved playlist", + debug_name='playlist_videos' + ) + info = json.loads(content.decode('utf-8')) return info @@ -117,7 +119,7 @@ def get_playlist_page(): 'playlist.html', header_playlist_names=local_playlist.get_playlist_names(), video_list=info.get('items', []), - num_pages = math.ceil(video_count/100), + num_pages=math.ceil(video_count/100), parameters_dictionary=request.args, **info['metadata'] |