]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/toggle.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / toggle.py
index 1e2a2d819c3990db8fcf3252a143f710014acb61..de2e03f178c5834d47736c2156aa7b334e162584 100644 (file)
@@ -1,13 +1,9 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import json
 import re
 
 from .common import InfoExtractor
 from ..utils import (
     determine_ext,
-    ExtractorError,
     float_or_none,
     int_or_none,
     parse_iso8601,
@@ -30,7 +26,7 @@ class ToggleIE(InfoExtractor):
         },
         'params': {
             'skip_download': 'm3u8 download',
-        }
+        },
     }, {
         'note': 'DRM-protected video',
         'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413',
@@ -44,7 +40,7 @@ class ToggleIE(InfoExtractor):
         },
         'params': {
             'skip_download': 'DRM-protected wvm download',
-        }
+        },
     }, {
         # this also tests correct video id extraction
         'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay',
@@ -60,7 +56,7 @@ class ToggleIE(InfoExtractor):
         'params': {
             'skip_download': 'DRM-protected wvm download',
         },
-        'skip': 'm3u8 links are geo-restricted'
+        'skip': 'm3u8 links are geo-restricted',
     }, {
         'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
         'only_matching': True,
@@ -96,14 +92,14 @@ def _real_extract(self, url):
                     'LocaleLanguage': '',
                     'LocaleCountry': '',
                     'LocaleDevice': '',
-                    'LocaleUserState': 0
+                    'LocaleUserState': 0,
                 },
                 'Platform': 0,
                 'SiteGuid': 0,
                 'DomainID': '0',
                 'UDID': '',
                 'ApiUser': self._API_USER,
-                'ApiPass': self._API_PASS
+                'ApiPass': self._API_PASS,
             },
             'MediaID': video_id,
             'mediaType': 0,
@@ -111,7 +107,7 @@ def _real_extract(self, url):
 
         info = self._download_json(
             'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
-            video_id, 'Downloading video info json', data=json.dumps(params).encode('utf-8'))
+            video_id, 'Downloading video info json', data=json.dumps(params).encode())
 
         title = info['MediaName']
 
@@ -126,8 +122,8 @@ def _real_extract(self, url):
             if ext == 'm3u8':
                 m3u8_formats = self._extract_m3u8_formats(
                     video_url, video_id, ext='mp4', m3u8_id=vid_format,
-                    note='Downloading %s m3u8 information' % vid_format,
-                    errnote='Failed to download %s m3u8 information' % vid_format,
+                    note=f'Downloading {vid_format} m3u8 information',
+                    errnote=f'Failed to download {vid_format} m3u8 information',
                     fatal=False)
                 for f in m3u8_formats:
                     # Apple FairPlay Streaming
@@ -137,14 +133,14 @@ def _real_extract(self, url):
             elif ext == 'mpd':
                 formats.extend(self._extract_mpd_formats(
                     video_url, video_id, mpd_id=vid_format,
-                    note='Downloading %s MPD manifest' % vid_format,
-                    errnote='Failed to download %s MPD manifest' % vid_format,
+                    note=f'Downloading {vid_format} MPD manifest',
+                    errnote=f'Failed to download {vid_format} MPD manifest',
                     fatal=False))
             elif ext == 'ism':
                 formats.extend(self._extract_ism_formats(
                     video_url, video_id, ism_id=vid_format,
-                    note='Downloading %s ISM manifest' % vid_format,
-                    errnote='Failed to download %s ISM manifest' % vid_format,
+                    note=f'Downloading {vid_format} ISM manifest',
+                    errnote=f'Failed to download {vid_format} ISM manifest',
                     fatal=False))
             elif ext == 'mp4':
                 formats.append({
@@ -154,13 +150,10 @@ def _real_extract(self, url):
                 })
         if not formats:
             for meta in (info.get('Metas') or []):
-                if (not self._downloader.params.get('allow_unplayable_formats')
+                if (not self.get_param('allow_unplayable_formats')
                         and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'):
-                    raise ExtractorError(
-                        'This video is DRM protected.', expected=True)
-            # Most likely because geo-blocked
-            raise ExtractorError('No downloadable videos found', expected=True)
-        self._sort_formats(formats)
+                    self.report_drm(video_id)
+            # Most likely because geo-blocked if no formats and no DRM
 
         thumbnails = []
         for picture in info.get('Pictures', []):