]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/gab.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / gab.py
index 9ba0b1ca1998a9e669301f314eb9fc87da703339..024628e1ca0ba3ea4d95e55f5b448e80f02ef118 100644 (file)
@@ -1,6 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import re
 
 from .common import InfoExtractor
@@ -10,7 +7,7 @@
     parse_codecs,
     parse_duration,
     str_to_int,
-    unified_timestamp
+    unified_timestamp,
 )
 
 
@@ -22,33 +19,32 @@ class GabTVIE(InfoExtractor):
             'id': '61217eacea5665de450d0488',
             'ext': 'mp4',
             'title': 'WHY WAS AMERICA IN AFGHANISTAN - AMERICA FIRST AGAINST AMERICAN OLIGARCHY',
-            'description': None,
             'uploader': 'Wurzelroot',
             'uploader_id': '608fb0a85738fd1974984f7d',
             'thumbnail': 'https://tv.gab.com/image/61217eacea5665de450d0488',
-        }
+        },
     }]
 
     def _real_extract(self, url):
-        id = self._match_id(url).split('-')[-1]
-        webpage = self._download_webpage(url, id)
+        video_id = self._match_id(url).split('-')[-1]
+        webpage = self._download_webpage(url, video_id)
         channel_id = self._search_regex(r'data-channel-id=\"(?P<channel_id>[^\"]+)', webpage, 'channel_id')
         channel_name = self._search_regex(r'data-channel-name=\"(?P<channel_id>[^\"]+)', webpage, 'channel_name')
         title = self._search_regex(r'data-episode-title=\"(?P<channel_id>[^\"]+)', webpage, 'title')
         view_key = self._search_regex(r'data-view-key=\"(?P<channel_id>[^\"]+)', webpage, 'view_key')
         description = clean_html(
             self._html_search_regex(self._meta_regex('description'), webpage, 'description', group='content')) or None
-        available_resolutions = re.findall(r'<a\ data-episode-id=\"%s\"\ data-resolution=\"(?P<resolution>[^\"]+)' % id,
-                                           webpage)
+        available_resolutions = re.findall(
+            rf'<a\ data-episode-id=\"{video_id}\"\ data-resolution=\"(?P<resolution>[^\"]+)', webpage)
 
         formats = []
         for resolution in available_resolutions:
             frmt = {
-                'url': f'https://tv.gab.com/media/{id}?viewKey={view_key}&r={resolution}',
+                'url': f'https://tv.gab.com/media/{video_id}?viewKey={view_key}&r={resolution}',
                 'format_id': resolution,
                 'vcodec': 'h264',
                 'acodec': 'aac',
-                'ext': 'mp4'
+                'ext': 'mp4',
             }
             if 'audio-' in resolution:
                 frmt['abr'] = str_to_int(resolution.replace('audio-', ''))
@@ -57,16 +53,15 @@ def _real_extract(self, url):
             else:
                 frmt['height'] = str_to_int(resolution.replace('p', ''))
             formats.append(frmt)
-        self._sort_formats(formats)
 
         return {
-            'id': id,
+            'id': video_id,
             'title': title,
             'formats': formats,
             'description': description,
             'uploader': channel_name,
             'uploader_id': channel_id,
-            'thumbnail': f'https://tv.gab.com/image/{id}',
+            'thumbnail': f'https://tv.gab.com/image/{video_id}',
         }
 
 
@@ -84,7 +79,7 @@ class GabIE(InfoExtractor):
             'description': 'md5:204055fafd5e1a519f5d6db953567ca3',
             'timestamp': 1635192289,
             'upload_date': '20211025',
-        }
+        },
     }, {
         'url': 'https://gab.com/TheLonelyProud/posts/107045884469287653',
         'md5': 'f9cefcfdff6418e392611a828d47839d',
@@ -96,7 +91,7 @@ class GabIE(InfoExtractor):
             'timestamp': 1633390571,
             'upload_date': '20211004',
             'uploader': 'TheLonelyProud',
-        }
+        },
     }]
 
     def _real_extract(self, url):
@@ -123,8 +118,6 @@ def _real_extract(self, url):
             } for url, f in ((media.get('url'), metadata.get('original') or {}),
                              (media.get('source_mp4'), metadata.get('playable') or {})) if url]
 
-            self._sort_formats(formats)
-
             author = json_data.get('account') or {}
             entries.append({
                 'id': f'{post_id}-{idx}',