Upgrade yt_dlp and download script

This commit is contained in:
2025-05-02 16:11:08 -05:00
parent 3a2e8eeb08
commit d68d9ce4f9
1194 changed files with 60099 additions and 44436 deletions

View File

@@ -1,12 +1,8 @@
import json
import re
import urllib.parse
from .common import InfoExtractor
from ..compat import (
compat_parse_qs,
compat_urlparse,
)
from ..utils import (
ExtractorError,
update_url_query,
@@ -35,9 +31,9 @@ class SafariBaseIE(InfoExtractor):
return
redirect_url = urlh.url
parsed_url = compat_urlparse.urlparse(redirect_url)
qs = compat_parse_qs(parsed_url.query)
next_uri = compat_urlparse.urljoin(
parsed_url = urllib.parse.urlparse(redirect_url)
qs = urllib.parse.parse_qs(parsed_url.query)
next_uri = urllib.parse.urljoin(
'https://api.oreilly.com', qs['next'][0])
auth, urlh = self._download_json_handle(
@@ -55,7 +51,7 @@ class SafariBaseIE(InfoExtractor):
if (not auth.get('logged_in') and not auth.get('redirect_uri')
and credentials):
raise ExtractorError(
'Unable to login: %s' % credentials, expected=True)
f'Unable to login: {credentials}', expected=True)
# oreilly serves two same instances of the following cookies
# in Set-Cookie header and expects first one to be actually set
@@ -63,7 +59,7 @@ class SafariBaseIE(InfoExtractor):
self._apply_first_set_cookie_header(urlh, cookie)
_, urlh = self._download_webpage_handle(
auth.get('redirect_uri') or next_uri, None, 'Completing login',)
auth.get('redirect_uri') or next_uri, None, 'Completing login')
if is_logged(urlh):
self.LOGGED_IN = True
@@ -125,7 +121,7 @@ class SafariIE(SafariBaseIE):
partner_id = self._PARTNER_ID
ui_id = self._UICONF_ID
else:
video_id = '%s-%s' % (mobj.group('course_id'), mobj.group('part'))
video_id = '{}-{}'.format(mobj.group('course_id'), mobj.group('part'))
webpage, urlh = self._download_webpage_handle(url, video_id)
@@ -145,14 +141,14 @@ class SafariIE(SafariBaseIE):
group='id')
query = {
'wid': '_%s' % partner_id,
'wid': f'_{partner_id}',
'uiconf_id': ui_id,
'flashvars[referenceId]': reference_id,
}
if self.LOGGED_IN:
kaltura_session = self._download_json(
'%s/player/kaltura_session/?reference_id=%s' % (self._API_BASE, reference_id),
f'{self._API_BASE}/player/kaltura_session/?reference_id={reference_id}',
video_id, 'Downloading kaltura session JSON',
'Unable to download kaltura session JSON', fatal=False,
headers={'Accept': 'application/json'})
@@ -181,7 +177,7 @@ class SafariApiIE(SafariBaseIE):
def _real_extract(self, url):
mobj = self._match_valid_url(url)
part = self._download_json(
url, '%s/%s' % (mobj.group('course_id'), mobj.group('part')),
url, '{}/{}'.format(mobj.group('course_id'), mobj.group('part')),
'Downloading part JSON')
web_url = part['web_url']
if 'library/view' in web_url:
@@ -237,18 +233,18 @@ class SafariCourseIE(SafariBaseIE):
@classmethod
def suitable(cls, url):
return (False if SafariIE.suitable(url) or SafariApiIE.suitable(url)
else super(SafariCourseIE, cls).suitable(url))
else super().suitable(url))
def _real_extract(self, url):
course_id = self._match_id(url)
course_json = self._download_json(
'%s/book/%s/?override_format=%s' % (self._API_BASE, course_id, self._API_FORMAT),
f'{self._API_BASE}/book/{course_id}/?override_format={self._API_FORMAT}',
course_id, 'Downloading course JSON')
if 'chapters' not in course_json:
raise ExtractorError(
'No chapters found for course %s' % course_id, expected=True)
f'No chapters found for course {course_id}', expected=True)
entries = [
self.url_result(chapter, SafariApiIE.ie_key())