]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/mixcloud.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / mixcloud.py
index b8ccd0ab4c7d4581d786ecd6ed76d36c6432197b..fb5a08ca286bca6b88b4b023c55a53809dd4435d 100644 (file)
@@ -1,18 +1,14 @@
-from __future__ import unicode_literals
-
 import itertools
-import re
 
 from .common import InfoExtractor
 from ..compat import (
     compat_b64decode,
-    compat_chr,
     compat_ord,
     compat_str,
     compat_urllib_parse_unquote,
-    compat_zip
 )
 from ..utils import (
+    ExtractorError,
     int_or_none,
     parse_iso8601,
     strip_or_none,
@@ -75,11 +71,11 @@ class MixcloudIE(MixcloudBaseIE):
     def _decrypt_xor_cipher(key, ciphertext):
         """Encrypt/Decrypt XOR cipher. Both ways are possible because it's XOR."""
         return ''.join([
-            compat_chr(compat_ord(ch) ^ compat_ord(k))
-            for ch, k in compat_zip(ciphertext, itertools.cycle(key))])
+            chr(compat_ord(ch) ^ compat_ord(k))
+            for ch, k in zip(ciphertext, itertools.cycle(key))])
 
     def _real_extract(self, url):
-        username, slug = re.match(self._VALID_URL, url).groups()
+        username, slug = self._match_valid_url(url).groups()
         username, slug = compat_urllib_parse_unquote(username), compat_urllib_parse_unquote(slug)
         track_id = '%s_%s' % (username, slug)
 
@@ -126,7 +122,20 @@ def _real_extract(self, url):
       tag {
         name
       }
-    }''', track_id, username, slug)
+    }
+    restrictedReason
+    id''', track_id, username, slug)
+
+        if not cloudcast:
+            raise ExtractorError('Track not found', expected=True)
+
+        reason = cloudcast.get('restrictedReason')
+        if reason == 'tracklist':
+            raise ExtractorError('Track unavailable in your country due to licensing restrictions', expected=True)
+        elif reason == 'repeat_play':
+            raise ExtractorError('You have reached your play limit for this track', expected=True)
+        elif reason:
+            raise ExtractorError('Track is restricted', expected=True)
 
         title = cloudcast['name']
 
@@ -150,6 +159,7 @@ def _real_extract(self, url):
                 formats.append({
                     'format_id': 'http',
                     'url': decrypted,
+                    'vcodec': 'none',
                     'downloader_options': {
                         # Mixcloud starts throttling at >~5M
                         'http_chunk_size': 5242880,
@@ -159,8 +169,6 @@ def _real_extract(self, url):
         if not formats and cloudcast.get('isExclusive'):
             self.raise_login_required(metadata_available=True)
 
-        self._sort_formats(formats)
-
         comments = []
         for edge in (try_get(cloudcast, lambda x: x['comments']['edges']) or []):
             node = edge.get('node') or {}
@@ -214,7 +222,7 @@ def _get_playlist_title(self, title, slug):
         return title
 
     def _real_extract(self, url):
-        username, slug = re.match(self._VALID_URL, url).groups()
+        username, slug = self._match_valid_url(url).groups()
         username = compat_urllib_parse_unquote(username)
         if not slug:
             slug = 'uploads'