From 0217522df6b39cd488faa6e4710d0ad1b8ff4b00 Mon Sep 17 00:00:00 2001 From: Audrey <45548254+tntmod54321@users.noreply.github.com> Date: Sat, 2 Nov 2024 08:36:45 -0400 Subject: [PATCH] add video metadata fallback api call, fix linter errors --- yt_dlp/extractor/bannedvideo.py | 35 ++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/yt_dlp/extractor/bannedvideo.py b/yt_dlp/extractor/bannedvideo.py index 0726f42b91..929cabbaf9 100644 --- a/yt_dlp/extractor/bannedvideo.py +++ b/yt_dlp/extractor/bannedvideo.py @@ -50,6 +50,28 @@ class BannedVideoBaseIE(InfoExtractor): } }''' + _GRAPHQL_GETMETADATA_FALLBACK_QUERY = ''' +query GetVideo($id: String!) { + getVideo(id: $id) { + ...DisplayVideoFields streamUrl directUrl liked disliked audio unlisted live tags { + _id name __typename + } + sale { + _id text textSale description url videoUpload { + cloudflareVideoUID __typename + } + __typename + } + __typename + } +} +fragment DisplayVideoFields on Video { + _id title summary playCount likeCount angerCount largeImage embedUrl published videoDuration channel { + _id title avatar __typename + } + createdAt __typename +}''' + _GRAPHQL_GETCOMMENTSREPLIES_QUERY = ''' query GetCommentReplies($id: String!) { getCommentReplies(id: $id, limit: 999999, offset: 0) { @@ -114,6 +136,7 @@ class BannedVideoBaseIE(InfoExtractor): _GRAPHQL_QUERIES = { 'GetVideoAndComments': _GRAPHQL_GETMETADATA_QUERY, + 'GetVideo': _GRAPHQL_GETMETADATA_FALLBACK_QUERY, 'GetCommentReplies': _GRAPHQL_GETCOMMENTSREPLIES_QUERY, 'GetChannel': _GRAPHQL_GETCHANNEL_QUERY, 'GetChannelVideos': _GRAPHQL_GETCHANNELVIDEOS_QUERY, @@ -195,9 +218,11 @@ def _parse_comment(comment_data, parent): def _real_extract(self, url): video_id = self._match_id(url) video_json = self._call_api(video_id, 'GetVideoAndComments', 'Downloading video metadata') + if not video_json: + video_json = self._call_api(video_id, 'GetVideo', 'Downloading video metadata (fallback)') video_info = video_json['getVideo'] is_live = video_info.get('live') - comments = [self._parse_comment(comment, 'root') for comment in video_json.get('getVideoComments')] + comments = [self._parse_comment(comment, 'root') for comment in video_json.get('getVideoComments', [])] formats = [{ 'format_id': 'direct', @@ -257,8 +282,8 @@ def _real_extract(self, url): channel_id = channel_info['_id'] return self.playlist_result( - [self.url_result(f'https://banned.video/watch?id={id}', url_transparent=True) - for id in self._paginate(channel_id, 'GetChannelVideos')], + [self.url_result(f'https://banned.video/watch?id={vid}', url_transparent=True) + for vid in self._paginate(channel_id, 'GetChannelVideos')], channel_id, channel_info['title'], channel_info.get('summary'), thumbnail=channel_info.get('coverImage')) @@ -288,6 +313,6 @@ def _real_extract(self, url): playlist_info = self._call_api(playlist_id, 'GetPlaylist', 'Downloading playlist metadata')['getPlaylist'] return self.playlist_result( - [self.url_result(f'https://banned.video/watch?id={id}', url_transparent=True) - for id in self._paginate(playlist_id, 'GetPlaylistVideos')], playlist_id, + [self.url_result(f'https://banned.video/watch?id={vid}', url_transparent=True) + for vid in self._paginate(playlist_id, 'GetPlaylistVideos')], playlist_id, playlist_info['title'], playlist_info.get('summary'))