]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/bannedvideo.py
[ie/mlbtv] Fix extraction (#10296)
[yt-dlp.git] / yt_dlp / extractor / bannedvideo.py
index 8f8f5ef5f2ef22504d3a56c08fb9f80261e0d32c..46f2978f7fbd317b468051b997df2ab0e03bb6c6 100644 (file)
@@ -1,14 +1,12 @@
-from __future__ import unicode_literals
-
 import json
 
 from .common import InfoExtractor
 from ..utils import (
-    try_get,
-    int_or_none,
-    url_or_none,
     float_or_none,
+    int_or_none,
+    try_get,
     unified_timestamp,
+    url_or_none,
 )
 
 
@@ -25,7 +23,7 @@ class BannedVideoIE(InfoExtractor):
             'description': 'md5:560d96f02abbebe6c6b78b47465f6b28',
             'upload_date': '20200324',
             'timestamp': 1585087895,
-        }
+        },
     }]
 
     _GRAPHQL_GETMETADATA_QUERY = '''
@@ -86,32 +84,27 @@ class BannedVideoIE(InfoExtractor):
         'GetCommentReplies': _GRAPHQL_GETCOMMENTSREPLIES_QUERY,
     }
 
-    def _call_api(self, video_id, id, operation, note):
+    def _call_api(self, video_id, id_var, operation, note):
         return self._download_json(
             'https://api.infowarsmedia.com/graphql', video_id, note=note,
             headers={
-                'Content-Type': 'application/json; charset=utf-8'
+                'Content-Type': 'application/json; charset=utf-8',
             }, data=json.dumps({
-                'variables': {'id': id},
+                'variables': {'id': id_var},
                 'operationName': operation,
-                'query': self._GRAPHQL_QUERIES[operation]
+                'query': self._GRAPHQL_QUERIES[operation],
             }).encode('utf8')).get('data')
 
-    def _extract_comments(self, video_id, comments, comment_data):
+    def _get_comments(self, video_id, comments, comment_data):
+        yield from comments
         for comment in comment_data.copy():
             comment_id = comment.get('_id')
             if comment.get('replyCount') > 0:
                 reply_json = self._call_api(
                     video_id, comment_id, 'GetCommentReplies',
                     f'Downloading replies for comment {comment_id}')
-                comments.extend(
-                    self._parse_comment(reply, comment_id)
-                    for reply in reply_json.get('getCommentReplies'))
-
-        return {
-            'comments': comments,
-            'comment_count': len(comments),
-        }
+                for reply in reply_json.get('getCommentReplies'):
+                    yield self._parse_comment(reply, comment_id)
 
     @staticmethod
     def _parse_comment(comment_data, parent):
@@ -142,7 +135,6 @@ def _real_extract(self, url):
             formats.extend(self._extract_m3u8_formats(
                 video_info.get('streamUrl'), video_id, 'mp4',
                 entry_protocol='m3u8_native', m3u8_id='hls', live=True))
-        self._sort_formats(formats)
 
         return {
             'id': video_id,
@@ -159,7 +151,5 @@ def _real_extract(self, url):
             'tags': [tag.get('name') for tag in video_info.get('tags')],
             'availability': self._availability(is_unlisted=video_info.get('unlisted')),
             'comments': comments,
-            '__post_extractor': (
-                (lambda: self._extract_comments(video_id, comments, video_json.get('getVideoComments')))
-                if self.get_param('getcomments') else None)
+            '__post_extractor': self.extract_comments(video_id, comments, video_json.get('getVideoComments')),
         }