From b45e3476c8e158103649563cd0506f57011dabdd Mon Sep 17 00:00:00 2001 From: Astound Date: Mon, 22 Jan 2024 05:39:11 +0800 Subject: 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 --- youtube/playlist.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'youtube/playlist.py') 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'] -- cgit v1.2.3