]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/limelight.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / limelight.py
index 369141d6797b967dcb3ffdacd569697f094c5f28..1ff091ddb7d6ea19e8bdccdaca58b353d4075e3f 100644 (file)
@@ -1,18 +1,15 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import re
 
 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,
     smuggle_url,
     try_get,
     unsmuggle_url,
-    ExtractorError,
 )
 
 
@@ -20,7 +17,7 @@ class LimelightBaseIE(InfoExtractor):
     _PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
 
     @classmethod
-    def _extract_urls(cls, webpage, source_url):
+    def _extract_embed_urls(cls, url, webpage):
         lm = {
             'Media': 'media',
             'Channel': 'channel',
@@ -28,7 +25,7 @@ def _extract_urls(cls, webpage, source_url):
         }
 
         def smuggle(url):
-            return smuggle_url(url, {'source_url': source_url})
+            return smuggle_url(url, {'source_url': url})
 
         entries = []
         for kind, video_id in re.findall(
@@ -72,8 +69,8 @@ def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
                 item_id, 'Downloading PlaylistService %s JSON' % method,
                 fatal=fatal, headers=headers)
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
-                error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission']
+            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
+                error = self._parse_json(e.cause.response.read().decode(), item_id)['detail']['contentAccessPermission']
                 if error == 'CountryDisabled':
                     self.raise_geo_restricted()
                 raise ExtractorError(error, expected=True)
@@ -182,8 +179,6 @@ def _extract_info(self, pc, mobile, i, referer):
                     'ext': ext,
                 })
 
-        self._sort_formats(formats)
-
         subtitles = {}
         for flag in mobile_item.get('flags'):
             if flag == 'ClosedCaptions':
@@ -194,7 +189,7 @@ def _extract_info(self, pc, mobile, i, referer):
                     cc_url = cc.get('webvttFileUrl')
                     if not cc_url:
                         continue
-                    lang = cc.get('languageCode') or self._search_regex(r'/[a-z]{2}\.vtt', cc_url, 'lang', default='en')
+                    lang = cc.get('languageCode') or self._search_regex(r'/([a-z]{2})\.vtt', cc_url, 'lang', default='en')
                     subtitles.setdefault(lang, []).append({
                         'url': cc_url,
                     })