]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/dropbox.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / dropbox.py
index ec86d7ad2447759076bb1ed1f16f4324291a5f13..51b40df428c71ec850cae6458241951347977ba7 100644 (file)
@@ -1,9 +1,9 @@
 import base64
 import os.path
 import re
+import urllib.parse
 
 from .common import InfoExtractor
-from ..compat import compat_urllib_parse_unquote
 from ..utils import (
     ExtractorError,
     update_url_query,
@@ -19,8 +19,8 @@ class DropboxIE(InfoExtractor):
             'info_dict': {
                 'id': 'nelirfsxnmcfbfh',
                 'ext': 'mp4',
-                'title': 'youtube-dl test video \'ä"BaW_jenozKc'
-            }
+                'title': 'youtube-dl test video \'ä"BaW_jenozKc',
+            },
         }, {
             'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh',
             'only_matching': True,
@@ -40,7 +40,7 @@ def _real_extract(self, url):
         mobj = self._match_valid_url(url)
         video_id = mobj.group('id')
         webpage = self._download_webpage(url, video_id)
-        fn = compat_urllib_parse_unquote(url_basename(url))
+        fn = urllib.parse.unquote(url_basename(url))
         title = os.path.splitext(fn)[0]
 
         password = self.get_param('videopassword')
@@ -51,7 +51,7 @@ def _real_extract(self, url):
                 content_id = self._search_regex(r'content_id=(.*?)["\']', webpage, 'content_id')
                 payload = f'is_xhr=true&t={self._get_cookies("https://www.dropbox.com").get("t").value}&content_id={content_id}&password={password}&url={url}'
                 response = self._download_json(
-                    'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password', data=payload.encode('UTF-8'),
+                    'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password', data=payload.encode(),
                     headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'})
 
                 if response.get('status') != 'authed':
@@ -65,12 +65,14 @@ def _real_extract(self, url):
         formats, subtitles, has_anonymous_download = [], {}, False
         for encoded in reversed(re.findall(r'registerStreamedPrefetch\s*\(\s*"[\w/+=]+"\s*,\s*"([\w/+=]+)"', webpage)):
             decoded = base64.b64decode(encoded).decode('utf-8', 'ignore')
+            if not has_anonymous_download:
+                has_anonymous_download = self._search_regex(
+                    r'(anonymous:\tanonymous)', decoded, 'anonymous', default=False)
             transcode_url = self._search_regex(
-                r'\n\x03(https://[^\x12\x03\n]+\.m3u8)', decoded, 'transcode url', default=None)
+                r'\n.(https://[^\x03\x08\x12\n]+\.m3u8)', decoded, 'transcode url', default=None)
             if not transcode_url:
                 continue
-            formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id)
-            has_anonymous_download = self._search_regex(r'(anonymous:\tanonymous)', decoded, 'anonymous', default=False)
+            formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id, 'mp4')
             break
 
         # downloads enabled we can get the original file
@@ -79,12 +81,12 @@ def _real_extract(self, url):
                 'url': update_url_query(url, {'dl': '1'}),
                 'format_id': 'original',
                 'format_note': 'Original',
-                'quality': 1
+                'quality': 1,
             })
 
         return {
             'id': video_id,
             'title': title,
             'formats': formats,
-            'subtitles': subtitles
+            'subtitles': subtitles,
         }