]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/zattoo.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / zattoo.py
index 22620c0a324d94c37816f134bf1a3209abcd3ca5..161804b604cef88560e6e7d4734011fb09b0b6b4 100644 (file)
@@ -1,8 +1,8 @@
 import re
-from uuid import uuid4
+import uuid
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError, compat_str
+from ..networking.exceptions import HTTPError
 from ..utils import (
     ExtractorError,
     int_or_none,
@@ -26,17 +26,17 @@ def _real_initialize(self):
     def _perform_login(self, username, password):
         try:
             data = self._download_json(
-                '%s/zapi/v2/account/login' % self._host_url(), None, 'Logging in',
+                f'{self._host_url()}/zapi/v2/account/login', None, 'Logging in',
                 data=urlencode_postdata({
                     'login': username,
                     'password': password,
                     'remember': 'true',
                 }), headers={
-                    'Referer': '%s/login' % self._host_url(),
+                    'Referer': f'{self._host_url()}/login',
                     'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                 })
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
+            if isinstance(e.cause, HTTPError) and e.cause.status == 400:
                 raise ExtractorError(
                     'Unable to login: incorrect username and/or password',
                     expected=True)
@@ -50,9 +50,9 @@ def _initialize_pre_login(self):
 
         # Will setup appropriate cookies
         self._request_webpage(
-            '%s/zapi/v3/session/hello' % self._host_url(), None,
+            f'{self._host_url()}/zapi/v3/session/hello', None,
             'Opening session', data=urlencode_postdata({
-                'uuid': compat_str(uuid4()),
+                'uuid': str(uuid.uuid4()),
                 'lang': 'en',
                 'app_version': '1.8.2',
                 'format': 'json',
@@ -71,8 +71,7 @@ def _extract_video_id_from_recording(self, recid):
 
     def _extract_cid(self, video_id, channel_name):
         channel_groups = self._download_json(
-            '%s/zapi/v2/cached/channels/%s' % (self._host_url(),
-                                               self._power_guide_hash),
+            f'{self._host_url()}/zapi/v2/cached/channels/{self._power_guide_hash}',
             video_id, 'Downloading channel list',
             query={'details': False})['channel_groups']
         channel_list = []
@@ -89,8 +88,7 @@ def _extract_cid(self, video_id, channel_name):
 
     def _extract_cid_and_video_info(self, video_id):
         data = self._download_json(
-            '%s/zapi/v2/cached/program/power_details/%s' % (
-                self._host_url(), self._power_guide_hash),
+            f'{self._host_url()}/zapi/v2/cached/program/power_details/{self._power_guide_hash}',
             video_id,
             'Downloading video information',
             query={
@@ -112,7 +110,7 @@ def _extract_cid_and_video_info(self, video_id):
             'season_number': int_or_none(p.get('s_no')),
             'release_year': int_or_none(p.get('year')),
             'categories': try_get(p, lambda x: x['c'], list),
-            'tags': try_get(p, lambda x: x['g'], list)
+            'tags': try_get(p, lambda x: x['g'], list),
         }
 
         return cid, info_dict
@@ -122,7 +120,7 @@ def _extract_ondemand_info(self, ondemand_id):
         @returns    (ondemand_token, ondemand_type, info_dict)
         """
         data = self._download_json(
-            '%s/zapi/vod/movies/%s' % (self._host_url(), ondemand_id),
+            f'{self._host_url()}/zapi/vod/movies/{ondemand_id}',
             ondemand_id, 'Downloading ondemand information')
         info_dict = {
             'id': ondemand_id,
@@ -143,18 +141,18 @@ def _extract_formats(self, cid, video_id, record_id=None, ondemand_id=None, onde
 
         if is_live:
             postdata_common.update({'timeshift': 10800})
-            url = '%s/zapi/watch/live/%s' % (self._host_url(), cid)
+            url = f'{self._host_url()}/zapi/watch/live/{cid}'
         elif record_id:
-            url = '%s/zapi/watch/recording/%s' % (self._host_url(), record_id)
+            url = f'{self._host_url()}/zapi/watch/recording/{record_id}'
         elif ondemand_id:
             postdata_common.update({
                 'teasable_id': ondemand_id,
                 'term_token': ondemand_termtoken,
-                'teasable_type': ondemand_type
+                'teasable_type': ondemand_type,
             })
-            url = '%s/zapi/watch/vod/video' % self._host_url()
+            url = f'{self._host_url()}/zapi/watch/vod/video'
         else:
-            url = '%s/zapi/v3/watch/replay/%s/%s' % (self._host_url(), cid, video_id)
+            url = f'{self._host_url()}/zapi/v3/watch/replay/{cid}/{video_id}'
         formats = []
         subtitles = {}
         for stream_type in ('dash', 'hls7'):
@@ -162,7 +160,7 @@ def _extract_formats(self, cid, video_id, record_id=None, ondemand_id=None, onde
             postdata['stream_type'] = stream_type
 
             data = self._download_json(
-                url, video_id, 'Downloading %s formats' % stream_type.upper(),
+                url, video_id, f'Downloading {stream_type.upper()} formats',
                 data=urlencode_postdata(postdata), fatal=False)
             if not data:
                 continue
@@ -217,7 +215,7 @@ def _extract_live(self, channel_name):
             'title': channel_name,
             'is_live': True,
             'formats': formats,
-            'subtitles': subtitles
+            'subtitles': subtitles,
         }
 
     def _extract_record(self, record_id):
@@ -266,9 +264,9 @@ class ZattooIE(ZattooBaseIE):
             'release_year': 2022,
             'episode': 'Folge 1655',
             'categories': 'count:1',
-            'tags': 'count:2'
+            'tags': 'count:2',
         },
-        'params': {'skip_download': 'm3u8'}
+        'params': {'skip_download': 'm3u8'},
     }, {
         'url': 'https://zattoo.com/program/daserste/210177916',
         'only_matching': True,
@@ -321,7 +319,7 @@ class ZattooRecordingsIE(ZattooBaseIE):
 class NetPlusTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = 'netplus'
     _HOST = 'netplus.tv'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class NetPlusTVIE(NetPlusTVBaseIE):
@@ -457,7 +455,7 @@ class WalyTVRecordingsIE(WalyTVBaseIE):
 class BBVTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = 'bbvtv'
     _HOST = 'bbv-tv.net'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class BBVTVIE(BBVTVBaseIE):
@@ -503,7 +501,7 @@ class BBVTVRecordingsIE(BBVTVBaseIE):
 class VTXTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = 'vtxtv'
     _HOST = 'vtxtv.ch'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class VTXTVIE(VTXTVBaseIE):
@@ -594,7 +592,7 @@ class GlattvisionTVRecordingsIE(GlattvisionTVBaseIE):
 class SAKTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = 'saktv'
     _HOST = 'saktv.ch'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class SAKTVIE(SAKTVBaseIE):
@@ -685,7 +683,7 @@ class EWETVRecordingsIE(EWETVBaseIE):
 class QuantumTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = 'quantumtv'
     _HOST = 'quantum-tv.com'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class QuantumTVIE(QuantumTVBaseIE):
@@ -776,7 +774,7 @@ class OsnatelTVRecordingsIE(OsnatelTVBaseIE):
 class EinsUndEinsTVBaseIE(ZattooPlatformBaseIE):
     _NETRC_MACHINE = '1und1tv'
     _HOST = '1und1.tv'
-    _API_HOST = 'www.%s' % _HOST
+    _API_HOST = f'www.{_HOST}'
 
 
 class EinsUndEinsTVIE(EinsUndEinsTVBaseIE):