]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/imggaming.py
[ie/crunchyroll] Fix stream extraction (#10005)
[yt-dlp.git] / yt_dlp / extractor / imggaming.py
index bae74b290802f69d3b8f49e44cd6d62d7a9842f2..a40aa21763e2ae705ca184d972afcdad4204df69 100644 (file)
@@ -1,10 +1,7 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import json
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError
+from ..networking.exceptions import HTTPError
 from ..utils import (
     ExtractorError,
     int_or_none,
@@ -21,25 +18,26 @@ class ImgGamingBaseIE(InfoExtractor):
     _REALM = None
     _VALID_URL_TEMPL = r'https?://(?P<domain>%s)/(?P<type>live|playlist|video)/(?P<id>\d+)(?:\?.*?\bplaylistId=(?P<playlist_id>\d+))?'
 
-    def _real_initialize(self):
+    def _initialize_pre_login(self):
         self._HEADERS = {
             'Realm': 'dce.' + self._REALM,
             'x-api-key': self._API_KEY,
         }
 
-        email, password = self._get_login_info()
-        if email is None:
-            self.raise_login_required()
-
+    def _perform_login(self, username, password):
         p_headers = self._HEADERS.copy()
         p_headers['Content-Type'] = 'application/json'
         self._HEADERS['Authorization'] = 'Bearer ' + self._download_json(
             self._API_BASE + 'login',
             None, 'Logging in', data=json.dumps({
-                'id': email,
+                'id': username,
                 'secret': password,
             }).encode(), headers=p_headers)['authorisationToken']
 
+    def _real_initialize(self):
+        if not self._HEADERS.get('Authorization'):
+            self.raise_login_required(method='password')
+
     def _call_api(self, path, media_id):
         return self._download_json(
             self._API_BASE + path + media_id, media_id, headers=self._HEADERS)
@@ -54,9 +52,9 @@ def _extract_dve_api_url(self, media_id, media_type):
             return self._call_api(
                 stream_path, media_id)['playerUrlCallback']
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
+            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
                 raise ExtractorError(
-                    self._parse_json(e.cause.read().decode(), media_id)['messages'][0],
+                    self._parse_json(e.cause.response.read().decode(), media_id)['messages'][0],
                     expected=True)
             raise
 
@@ -96,7 +94,7 @@ def _real_extract(self, url):
                 continue
             if proto == 'hls':
                 m3u8_formats = self._extract_m3u8_formats(
-                    media_url, media_id, 'mp4', 'm3u8' if is_live else 'm3u8_native',
+                    media_url, media_id, 'mp4', live=is_live,
                     m3u8_id='hls', fatal=False, headers=self._MANIFEST_HEADERS)
                 for f in m3u8_formats:
                     f.setdefault('http_headers', {}).update(self._MANIFEST_HEADERS)
@@ -105,7 +103,6 @@ def _real_extract(self, url):
                 formats.extend(self._extract_mpd_formats(
                     media_url, media_id, mpd_id='dash', fatal=False,
                     headers=self._MANIFEST_HEADERS))
-        self._sort_formats(formats)
 
         subtitles = {}
         for subtitle in video_data.get('subtitles', []):