]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/gaia.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / gaia.py
index e9527758fa24b764951d536805c548d9e6351a97..c84386f2cb3aefd651e9d77e5bbce06be4aa1b96 100644 (file)
@@ -1,8 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import re
-
 from .common import InfoExtractor
 from ..compat import (
     compat_str,
@@ -57,26 +52,24 @@ class GaiaIE(InfoExtractor):
     def _real_initialize(self):
         auth = self._get_cookies('https://www.gaia.com/').get('auth')
         if auth:
-            auth = self._parse_json(
-                compat_urllib_parse_unquote(auth.value),
-                None, fatal=False)
-        if not auth:
-            username, password = self._get_login_info()
-            if username is None:
-                return
-            auth = self._download_json(
-                'https://auth.gaia.com/v1/login',
-                None, data=urlencode_postdata({
-                    'username': username,
-                    'password': password
-                }))
-            if auth.get('success') is False:
-                raise ExtractorError(', '.join(auth['messages']), expected=True)
-        if auth:
+            auth = self._parse_json(compat_urllib_parse_unquote(auth.value), None, fatal=False)
             self._jwt = auth.get('jwt')
 
+    def _perform_login(self, username, password):
+        if self._jwt:
+            return
+        auth = self._download_json(
+            'https://auth.gaia.com/v1/login',
+            None, data=urlencode_postdata({
+                'username': username,
+                'password': password
+            }))
+        if auth.get('success') is False:
+            raise ExtractorError(', '.join(auth['messages']), expected=True)
+        self._jwt = auth.get('jwt')
+
     def _real_extract(self, url):
-        display_id, vtype = re.search(self._VALID_URL, url).groups()
+        display_id, vtype = self._match_valid_url(url).groups()
         node_id = self._download_json(
             'https://brooklyn.gaia.com/pathinfo', display_id, query={
                 'path': 'video/' + display_id,
@@ -95,7 +88,6 @@ def _real_extract(self, url):
             media_id, headers=headers)
         formats = self._extract_m3u8_formats(
             media['mediaUrls']['bcHLS'], media_id, 'mp4')
-        self._sort_formats(formats)
 
         subtitles = {}
         text_tracks = media.get('textTracks', {})