]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/crackle.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / crackle.py
index db4962c422f73c676c20bd1715a5b6c9247faf08..c4ceba94085c5dd8b986c6942f44040a5974e18c 100644 (file)
@@ -1,14 +1,12 @@
-# coding: utf-8
-from __future__ import unicode_literals, division
-
 import hashlib
 import hmac
 import re
 import time
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError
+from ..networking.exceptions import HTTPError
 from ..utils import (
+    ExtractorError,
     determine_ext,
     float_or_none,
     int_or_none,
@@ -16,7 +14,6 @@
     parse_age_limit,
     parse_duration,
     url_or_none,
-    ExtractorError
 )
 
 
@@ -48,7 +45,7 @@ class CrackleIE(InfoExtractor):
             'skip_download': True,
         },
         'expected_warnings': [
-            'Trying with a list of known countries'
+            'Trying with a list of known countries',
         ],
     }, {
         'url': 'https://www.sonycrackle.com/thanksgiving/2510064',
@@ -92,7 +89,7 @@ def _real_extract(self, url):
         for num, country in enumerate(countries):
             if num == 1:  # start hard-coded list
                 self.report_warning('%s. Trying with a list of known countries' % (
-                    'Unable to obtain video formats from %s API' % geo_bypass_country if geo_bypass_country
+                    f'Unable to obtain video formats from {geo_bypass_country} API' if geo_bypass_country
                     else 'No country code was given using --geo-bypass-country'))
             elif num == num_countries:  # end of list
                 geo_info = self._download_json(
@@ -102,28 +99,28 @@ def _real_extract(self, url):
                 country = geo_info.get('CountryCode')
                 if country is None:
                     continue
-                self.to_screen('%s identified country as %s' % (self.IE_NAME, country))
+                self.to_screen(f'{self.IE_NAME} identified country as {country}')
                 if country in countries:
-                    self.to_screen('Downloading from %s API was already attempted. Skipping...' % country)
+                    self.to_screen(f'Downloading from {country} API was already attempted. Skipping...')
                     continue
 
             if country is None:
                 continue
             try:
                 media = self._download_json(
-                    'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s?disableProtocols=true' % (video_id, country),
-                    video_id, note='Downloading media JSON from %s API' % country,
+                    f'https://web-api-us.crackle.com/Service.svc/details/media/{video_id}/{country}?disableProtocols=true',
+                    video_id, note=f'Downloading media JSON from {country} API',
                     errnote='Unable to download media JSON')
             except ExtractorError as e:
                 # 401 means geo restriction, trying next country
-                if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
+                if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                     continue
                 raise
 
             status = media.get('status')
             if status.get('messageCode') != '0':
                 raise ExtractorError(
-                    '%s said: %s %s - %s' % (
+                    '{} said: {} {} - {}'.format(
                         self.IE_NAME, status.get('messageCodeDescription'), status.get('messageCode'), status.get('message')),
                     expected=True)
 
@@ -180,7 +177,6 @@ def _real_extract(self, url):
                 })
         if not formats and has_drm:
             self.report_drm(video_id)
-        self._sort_formats(formats)
 
         description = media.get('Description')
         duration = int_or_none(media.get(