mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-08-22 01:51:36 +00:00
Compare commits
13 Commits
dd1c8fdaeb
...
4539d51b34
Author | SHA1 | Date | |
---|---|---|---|
|
4539d51b34 | ||
|
1036478d13 | ||
|
00ad2b8ca1 | ||
|
ab7c61ca29 | ||
|
ea4948068d | ||
|
eff6cd4c24 | ||
|
0a99e9f59d | ||
|
04a7c7a849 | ||
|
dc80f50f7e | ||
|
1ce8590329 | ||
|
0235e627b9 | ||
|
3ee378c099 | ||
|
6abc344f22 |
@ -1,16 +1,23 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import (
|
||||
compat_b64decode,
|
||||
compat_kwargs,
|
||||
compat_str,
|
||||
compat_urllib_parse_urlparse,
|
||||
)
|
||||
from ..utils import (
|
||||
clean_html,
|
||||
dict_get,
|
||||
ExtractorError,
|
||||
get_element_by_class,
|
||||
int_or_none,
|
||||
parse_iso8601,
|
||||
str_or_none,
|
||||
strip_or_none,
|
||||
try_get,
|
||||
url_or_none,
|
||||
urlencode_postdata,
|
||||
@ -22,6 +29,42 @@ class PlatziBaseIE(InfoExtractor):
|
||||
_LOGIN_URL = 'https://platzi.com/login/'
|
||||
_NETRC_MACHINE = 'platzi'
|
||||
|
||||
def _raise_extractor_error(self, video_id, reason, expected=True):
|
||||
raise ExtractorError('[%s] %s: %s' % (self.IE_NAME, video_id, reason), expected=expected)
|
||||
|
||||
def _download_webpage(self, url_or_request, video_id, *args, **kwargs):
|
||||
# CF likes Connection: keep-alive and so disfavours Py2
|
||||
# retry on 403 may get in
|
||||
kwargs['expected_status'] = 403
|
||||
# header parameters required fpor Py3 to breach site's CF fence w/o 403
|
||||
headers = kwargs.get('headers') or {}
|
||||
new_hdrs = {}
|
||||
if 'User-Agent' not in headers:
|
||||
headers['User-Agent'] = 'Mozilla/5.0' # (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.0.0 Safari/537.36'
|
||||
kwargs['headers'] = new_hdrs = headers
|
||||
if new_hdrs:
|
||||
kwargs = compat_kwargs(kwargs)
|
||||
for _ in range(2):
|
||||
x = super(PlatziBaseIE, self)._download_webpage_handle(url_or_request, video_id, *args, **kwargs)
|
||||
if x is False:
|
||||
return x
|
||||
if x[1].getcode() != 403:
|
||||
break
|
||||
kwargs.pop('expected_status', None)
|
||||
note = kwargs.pop('note', '')
|
||||
kwargs['note'] = (note or 'Downloading webpage') + ' - retrying'
|
||||
kwargs = compat_kwargs(kwargs)
|
||||
path = compat_urllib_parse_urlparse(x[1].geturl())
|
||||
if path == '/':
|
||||
self._raise_extractor_error(video_id, 'Redirected to home page: content expired?')
|
||||
elif path == '/login':
|
||||
self.raise_login_required()
|
||||
else:
|
||||
errs = clean_html(get_element_by_class('Errorpage-text', x[0]))
|
||||
if errs:
|
||||
self._raise_extractor_error(video_id, errs)
|
||||
return x[0]
|
||||
|
||||
def _real_initialize(self):
|
||||
self._login()
|
||||
|
||||
@ -75,6 +118,26 @@ class PlatziIE(PlatziBaseIE):
|
||||
'''
|
||||
|
||||
_TESTS = [{
|
||||
'url': 'https://platzi.com/clases/1927-intro-selenium/29383-bienvenida-al-curso',
|
||||
'md5': '0af120f1ffd18a2246f19099d52b83e2',
|
||||
'info_dict': {
|
||||
'id': '29383',
|
||||
'ext': 'mp4',
|
||||
'title': 'Por qué aprender Selenium y qué verás',
|
||||
'description': 'md5:bbe91d2760052ca4054a3149a6580436',
|
||||
'timestamp': 1627400390,
|
||||
'upload_date': '20210727',
|
||||
'creator': 'Héctor Vega',
|
||||
'series': 'Curso de Introducción a Selenium con Python',
|
||||
'duration': 11700,
|
||||
'categories': list,
|
||||
},
|
||||
'params': {
|
||||
'format': 'bestvideo',
|
||||
# 'skip_download': True,
|
||||
},
|
||||
'expected_warnings': ['HTTP Error 401']
|
||||
}, {
|
||||
'url': 'https://platzi.com/clases/1311-next-js/12074-creando-nuestra-primera-pagina/',
|
||||
'md5': '8f56448241005b561c10f11a595b37e3',
|
||||
'info_dict': {
|
||||
@ -84,7 +147,7 @@ class PlatziIE(PlatziBaseIE):
|
||||
'description': 'md5:4c866e45034fc76412fbf6e60ae008bc',
|
||||
'duration': 420,
|
||||
},
|
||||
'skip': 'Requires platzi account credentials',
|
||||
'skip': 'Content expired',
|
||||
}, {
|
||||
'url': 'https://courses.platzi.com/classes/1367-communication-codestream/13430-background/',
|
||||
'info_dict': {
|
||||
@ -94,10 +157,7 @@ class PlatziIE(PlatziBaseIE):
|
||||
'description': 'md5:49c83c09404b15e6e71defaf87f6b305',
|
||||
'duration': 360,
|
||||
},
|
||||
'skip': 'Requires platzi account credentials',
|
||||
'params': {
|
||||
'skip_download': True,
|
||||
},
|
||||
'skip': 'Content expired',
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
@ -105,50 +165,60 @@ class PlatziIE(PlatziBaseIE):
|
||||
|
||||
webpage = self._download_webpage(url, lecture_id)
|
||||
|
||||
data = self._parse_json(
|
||||
data_preloaded_state = self._parse_json(
|
||||
self._search_regex(
|
||||
# client_data may contain "};" so that we have to try more
|
||||
# strict regex first
|
||||
(r'client_data\s*=\s*({.+?})\s*;\s*\n',
|
||||
r'client_data\s*=\s*({.+?})\s*;'),
|
||||
webpage, 'client data'),
|
||||
(r'window\s*.\s*__PRELOADED_STATE__\s*=\s*({.*?});?\s*</script'), webpage, 'client data'),
|
||||
lecture_id)
|
||||
|
||||
material = data['initialState']['material']
|
||||
desc = material['description']
|
||||
title = desc['title']
|
||||
video_player = try_get(data_preloaded_state, lambda x: x['videoPlayer'], dict) or {}
|
||||
title = strip_or_none(video_player.get('name')) or self._og_search_title(webpage)
|
||||
servers = try_get(video_player, lambda x: x['video']['servers'], dict) or {}
|
||||
if not servers and try_get(video_player, lambda x: x['blockedInfo']['blocked']):
|
||||
why = video_player['blockedInfo'].get('type') or 'unspecified'
|
||||
if why == 'unlogged':
|
||||
self.raise_login_required()
|
||||
self._raise_extractor_error(lecture_id, 'All video formats blocked because ' + why)
|
||||
|
||||
formats = []
|
||||
for server_id, server in material['videos'].items():
|
||||
if not isinstance(server, dict):
|
||||
headers = {'Referer': url}
|
||||
extractions = {
|
||||
'hls': lambda x: formats.extend(self._extract_m3u8_formats(
|
||||
server_json[x], lecture_id, 'mp4',
|
||||
entry_protocol='m3u8_native', m3u8_id='hls',
|
||||
note='Downloading %s m3u8 information' % (server_json.get('id', x), ),
|
||||
headers=headers, fatal=False)),
|
||||
'dash': lambda x: formats.extend(self._extract_mpd_formats(
|
||||
server_json[x], lecture_id, mpd_id='dash',
|
||||
note='Downloading %s MPD manifest' % (server_json.get('id', x), ),
|
||||
headers=headers, fatal=False)),
|
||||
}
|
||||
for server, server_json in servers.items():
|
||||
if not isinstance(server_json, dict):
|
||||
continue
|
||||
for format_id in ('hls', 'dash'):
|
||||
format_url = url_or_none(server.get(format_id))
|
||||
if not format_url:
|
||||
continue
|
||||
if format_id == 'hls':
|
||||
formats.extend(self._extract_m3u8_formats(
|
||||
format_url, lecture_id, 'mp4',
|
||||
entry_protocol='m3u8_native', m3u8_id=format_id,
|
||||
note='Downloading %s m3u8 information' % server_id,
|
||||
fatal=False))
|
||||
elif format_id == 'dash':
|
||||
formats.extend(self._extract_mpd_formats(
|
||||
format_url, lecture_id, mpd_id=format_id,
|
||||
note='Downloading %s MPD manifest' % server_id,
|
||||
fatal=False))
|
||||
for fmt in server_json.keys():
|
||||
extraction = extractions.get(fmt)
|
||||
if callable(extraction):
|
||||
extraction(fmt)
|
||||
self._sort_formats(formats)
|
||||
for f in formats:
|
||||
f.setdefault('http_headers', {})['Referer'] = headers['Referer']
|
||||
|
||||
content = str_or_none(desc.get('content'))
|
||||
description = (clean_html(compat_b64decode(content).decode('utf-8'))
|
||||
if content else None)
|
||||
duration = int_or_none(material.get('duration'), invscale=60)
|
||||
def categories():
|
||||
cat = strip_or_none(video_player.get('courseCategory'))
|
||||
if cat:
|
||||
return [cat]
|
||||
|
||||
return {
|
||||
'id': lecture_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'duration': duration,
|
||||
'description': clean_html(video_player.get('courseDescription')) or self._og_search_description(webpage),
|
||||
'duration': int_or_none(video_player.get('duration'), invscale=60),
|
||||
'thumbnail': url_or_none(video_player.get('thumbnail')) or self._og_search_thumbnail(webpage),
|
||||
'timestamp': parse_iso8601(dict_get(video_player, ('dateModified', 'datePublished'))),
|
||||
'creator': strip_or_none(video_player.get('teacherName')) or clean_html(get_element_by_class('TeacherDetails-name', webpage)),
|
||||
'comment_count': int_or_none(video_player.get('commentsNumber')),
|
||||
'categories': categories(),
|
||||
'series': strip_or_none(video_player.get('courseTitle')) or None,
|
||||
'formats': formats,
|
||||
}
|
||||
|
||||
@ -157,17 +227,35 @@ class PlatziCourseIE(PlatziBaseIE):
|
||||
_VALID_URL = r'''(?x)
|
||||
https?://
|
||||
(?:
|
||||
platzi\.com/clases| # es version
|
||||
courses\.platzi\.com/classes # en version
|
||||
(?P<clas>
|
||||
platzi\.com/clases| # es version
|
||||
courses\.platzi\.com/classes # en version
|
||||
)|
|
||||
platzi\.com(?:/(?P<curs>cursos))?
|
||||
)/(?P<id>[^/?\#&]+)
|
||||
'''
|
||||
_TESTS = [{
|
||||
'url': 'https://platzi.com/web-angular/',
|
||||
'info_dict': {
|
||||
'id': 'web-angular',
|
||||
'title': 'Frontend con Angular',
|
||||
},
|
||||
'playlist_count': 9,
|
||||
}, {
|
||||
'url': 'https://platzi.com/cursos/angular/',
|
||||
'info_dict': {
|
||||
'id': '2478',
|
||||
'title': 'Curso de Fundamentos de Angular',
|
||||
},
|
||||
'playlist_count': 21,
|
||||
}, {
|
||||
'url': 'https://platzi.com/clases/next-js/',
|
||||
'info_dict': {
|
||||
'id': '1311',
|
||||
'title': 'Curso de Next.js',
|
||||
},
|
||||
'playlist_count': 22,
|
||||
'skip': 'Oops (updating page)',
|
||||
}, {
|
||||
'url': 'https://courses.platzi.com/classes/communication-codestream/',
|
||||
'info_dict': {
|
||||
@ -175,23 +263,62 @@ class PlatziCourseIE(PlatziBaseIE):
|
||||
'title': 'Codestream Course',
|
||||
},
|
||||
'playlist_count': 14,
|
||||
'skip': 'Content expired',
|
||||
}]
|
||||
|
||||
@classmethod
|
||||
def _match_valid_url(cls, url):
|
||||
return re.match(cls._VALID_URL, url)
|
||||
|
||||
@classmethod
|
||||
def suitable(cls, url):
|
||||
return False if PlatziIE.suitable(url) else super(PlatziCourseIE, cls).suitable(url)
|
||||
|
||||
def __extract_things(self, webpage, thing_id, thing_pattern):
|
||||
return self.playlist_from_matches(
|
||||
re.finditer(thing_pattern, webpage),
|
||||
playlist_id=thing_id,
|
||||
playlist_title=self._og_search_title(webpage, default=None),
|
||||
getter=lambda m: urljoin('https://platzi.com', m.group('path')))
|
||||
|
||||
def _extract_classes(self, webpage, course_id):
|
||||
display_id = course_id
|
||||
course_id = self._search_regex(
|
||||
r'''(["'])courseId\1\s*:\s*(?P<id>\d+)''',
|
||||
webpage, 'course id', group='id', fatal=False) or course_id
|
||||
return self.__extract_things(
|
||||
webpage, course_id,
|
||||
r'''<a\b[^>]+\bhref\s*=\s*['"]?(?P<path>/clases/\d+-%s/[^/]+)'''
|
||||
% (display_id, ))
|
||||
|
||||
def _extract_categories(self, webpage, cat_id):
|
||||
return self.__extract_things(
|
||||
webpage, cat_id,
|
||||
r'''<a\b[^>]+\bhref\s*=\s*['"]?(?P<path>/cursos/[^/]+)''')
|
||||
|
||||
def _real_extract(self, url):
|
||||
course_name = self._match_id(url)
|
||||
|
||||
webpage = self._download_webpage(url, course_name)
|
||||
m = self._match_valid_url(url)
|
||||
classes, courses, this_id = m.group('clas', 'curs', 'id')
|
||||
|
||||
props = self._parse_json(
|
||||
self._search_regex(r'data\s*=\s*({.+?})\s*;', webpage, 'data'),
|
||||
course_name)['initialProps']
|
||||
webpage = self._download_webpage(url, this_id)
|
||||
|
||||
if courses:
|
||||
return self._extract_classes(webpage, this_id)
|
||||
|
||||
if not classes:
|
||||
return self._extract_categories(webpage, this_id)
|
||||
|
||||
# this branch now seems always to give "Oops" pages
|
||||
course_name = this_id
|
||||
|
||||
initialData = self._search_regex(
|
||||
(r'window.initialData\s*=\s*({.+?})\s*;\s*\n', r'window.initialData\s*=\s*({.+?})\s*;'),
|
||||
webpage, 'initialData')
|
||||
props = self._parse_json(initialData, course_name, default={})
|
||||
props = try_get(props, lambda x: x['initialProps'], dict) or {}
|
||||
entries = []
|
||||
for chapter_num, chapter in enumerate(props['concepts'], 1):
|
||||
for chapter_num, chapter in enumerate(props.get('concepts') or [], 1):
|
||||
if not isinstance(chapter, dict):
|
||||
continue
|
||||
materials = chapter.get('materials')
|
||||
@ -221,4 +348,8 @@ class PlatziCourseIE(PlatziBaseIE):
|
||||
course_id = compat_str(try_get(props, lambda x: x['course']['id']))
|
||||
course_title = try_get(props, lambda x: x['course']['name'], compat_str)
|
||||
|
||||
return self.playlist_result(entries, course_id, course_title)
|
||||
result = self.playlist_result(entries, course_id, course_title)
|
||||
desc = clean_html(get_element_by_class('RouteDescription-content', webpage))
|
||||
if desc:
|
||||
result['description'] = desc
|
||||
return result
|
||||
|
@ -9,6 +9,7 @@ import json
|
||||
import os.path
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import time
|
||||
import traceback
|
||||
|
||||
@ -67,6 +68,7 @@ from ..utils import (
|
||||
|
||||
class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
"""Provide base functions for Youtube extractors"""
|
||||
|
||||
_LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
|
||||
_TWOFACTOR_URL = 'https://accounts.google.com/signin/challenge'
|
||||
|
||||
@ -138,7 +140,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
[2, 1, None, 1,
|
||||
'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
|
||||
None, [], 4],
|
||||
1, [None, None, []], None, None, None, True
|
||||
1, [None, None, []], None, None, None, True,
|
||||
],
|
||||
username,
|
||||
]
|
||||
@ -160,7 +162,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
None, 1, None, [1, None, None, None, [password, None, True]],
|
||||
[
|
||||
None, None, [2, 1, None, 1, 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4],
|
||||
1, [None, None, []], None, None, None, True
|
||||
1, [None, None, []], None, None, None, True,
|
||||
]]
|
||||
|
||||
challenge_results = req(
|
||||
@ -213,7 +215,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
user_hash, None, 2, None,
|
||||
[
|
||||
9, None, None, None, None, None, None, None,
|
||||
[None, tfa_code, True, 2]
|
||||
[None, tfa_code, True, 2],
|
||||
]]
|
||||
|
||||
tfa_results = req(
|
||||
@ -284,7 +286,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'client': {
|
||||
'clientName': 'WEB',
|
||||
'clientVersion': '2.20201021.03.00',
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -385,7 +387,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'client': {
|
||||
'clientName': 'WEB',
|
||||
'clientVersion': '2.20201021.03.00',
|
||||
}
|
||||
},
|
||||
},
|
||||
'query': query,
|
||||
}
|
||||
@ -462,7 +464,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
# (HTML, videodetails, metadata, renderers)
|
||||
'name': ('content', 'author', (('ownerChannelName', None), 'title'), ['text']),
|
||||
'url': ('href', 'ownerProfileUrl', 'vanityChannelUrl',
|
||||
['navigationEndpoint', 'browseEndpoint', 'canonicalBaseUrl'])
|
||||
['navigationEndpoint', 'browseEndpoint', 'canonicalBaseUrl']),
|
||||
}
|
||||
if any((videodetails, metadata, renderers)):
|
||||
result = (
|
||||
@ -671,7 +673,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
|
||||
'description': '',
|
||||
'uploader': '8KVIDEO',
|
||||
'title': 'UHDTV TEST 8K VIDEO.mp4'
|
||||
'title': 'UHDTV TEST 8K VIDEO.mp4',
|
||||
},
|
||||
'params': {
|
||||
'youtube_include_dash_manifest': True,
|
||||
@ -711,7 +713,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'uploader_url': r're:https?://(?:www\.)?youtube\.com/@theamazingatheist',
|
||||
'title': 'Burning Everyone\'s Koran',
|
||||
'description': 'SUBSCRIBE: http://www.youtube.com/saturninefilms \r\n\r\nEven Obama has taken a stand against freedom on this issue: http://www.huffingtonpost.com/2010/09/09/obama-gma-interview-quran_n_710282.html',
|
||||
}
|
||||
},
|
||||
},
|
||||
# Age-gated videos
|
||||
{
|
||||
@ -839,7 +841,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
},
|
||||
'expected_warnings': [
|
||||
'DASH manifest missing',
|
||||
]
|
||||
],
|
||||
},
|
||||
# Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
|
||||
{
|
||||
@ -1820,8 +1822,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
|
||||
# cpn generation algorithm is reverse engineered from base.js.
|
||||
# In fact it works even with dummy cpn.
|
||||
CPN_ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
|
||||
cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(0, 16))
|
||||
CPN_ALPHABET = string.ascii_letters + string.digits + '-_'
|
||||
cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(16))
|
||||
|
||||
# more consistent results setting it to right before the end
|
||||
qs = parse_qs(playback_url)
|
||||
@ -1881,8 +1883,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
mobj = re.match(cls._VALID_URL, url, re.VERBOSE)
|
||||
if mobj is None:
|
||||
raise ExtractorError('Invalid URL: %s' % url)
|
||||
video_id = mobj.group(2)
|
||||
return video_id
|
||||
return mobj.group(2)
|
||||
|
||||
def _extract_chapters_from_json(self, data, video_id, duration):
|
||||
chapters_list = try_get(
|
||||
@ -2035,7 +2036,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
headers = {
|
||||
'X-YouTube-Client-Name': '85',
|
||||
'X-YouTube-Client-Version': '2.0',
|
||||
'Origin': 'https://www.youtube.com'
|
||||
'Origin': 'https://www.youtube.com',
|
||||
}
|
||||
|
||||
video_info = self._call_api('player', query, video_id, fatal=False, headers=headers)
|
||||
@ -2064,8 +2065,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
return ''.join([r['text'] for r in runs if isinstance(r.get('text'), compat_str)])
|
||||
|
||||
search_meta = (
|
||||
lambda x: self._html_search_meta(x, webpage, default=None)) \
|
||||
if webpage else lambda x: None
|
||||
(lambda x: self._html_search_meta(x, webpage, default=None))
|
||||
if webpage else lambda _: None)
|
||||
|
||||
video_details = player_response.get('videoDetails') or {}
|
||||
microformat = try_get(
|
||||
@ -2137,7 +2138,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
def build_fragments(f):
|
||||
return LazyList({
|
||||
'url': update_url_query(f['url'], {
|
||||
'range': '{0}-{1}'.format(range_start, min(range_start + CHUNK_SIZE - 1, f['filesize']))
|
||||
'range': '{0}-{1}'.format(range_start, min(range_start + CHUNK_SIZE - 1, f['filesize'])),
|
||||
})
|
||||
} for range_start in range(0, f['filesize'], CHUNK_SIZE))
|
||||
|
||||
@ -2236,7 +2237,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'protocol': 'http_dash_segments',
|
||||
'fragments': build_fragments(dct),
|
||||
} if dct['filesize'] else {
|
||||
'downloader_options': {'http_chunk_size': CHUNK_SIZE} # No longer useful?
|
||||
'downloader_options': {'http_chunk_size': CHUNK_SIZE}, # No longer useful?
|
||||
})
|
||||
|
||||
formats.append(dct)
|
||||
@ -2414,9 +2415,9 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'is_live': is_live,
|
||||
}
|
||||
|
||||
pctr = try_get(
|
||||
pctr = traverse_obj(
|
||||
player_response,
|
||||
lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict)
|
||||
('captions', 'playerCaptionsTracklistRenderer', T(dict)))
|
||||
if pctr:
|
||||
def process_language(container, base_url, lang_code, query):
|
||||
lang_subs = []
|
||||
@ -2430,31 +2431,34 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
})
|
||||
container[lang_code] = lang_subs
|
||||
|
||||
subtitles = {}
|
||||
for caption_track in (pctr.get('captionTracks') or []):
|
||||
base_url = caption_track.get('baseUrl')
|
||||
if not base_url:
|
||||
continue
|
||||
if caption_track.get('kind') != 'asr':
|
||||
lang_code = caption_track.get('languageCode')
|
||||
if not lang_code:
|
||||
def process_subtitles():
|
||||
subtitles = {}
|
||||
for caption_track in traverse_obj(pctr, (
|
||||
'captionTracks', lambda _, v: v.get('baseUrl'))):
|
||||
base_url = self._yt_urljoin(caption_track['baseUrl'])
|
||||
if not base_url:
|
||||
continue
|
||||
process_language(
|
||||
subtitles, base_url, lang_code, {})
|
||||
continue
|
||||
automatic_captions = {}
|
||||
for translation_language in (pctr.get('translationLanguages') or []):
|
||||
translation_language_code = translation_language.get('languageCode')
|
||||
if not translation_language_code:
|
||||
if caption_track.get('kind') != 'asr':
|
||||
lang_code = caption_track.get('languageCode')
|
||||
if not lang_code:
|
||||
continue
|
||||
process_language(
|
||||
subtitles, base_url, lang_code, {})
|
||||
continue
|
||||
process_language(
|
||||
automatic_captions, base_url, translation_language_code,
|
||||
{'tlang': translation_language_code})
|
||||
info['automatic_captions'] = automatic_captions
|
||||
info['subtitles'] = subtitles
|
||||
automatic_captions = {}
|
||||
for translation_language in traverse_obj(pctr, (
|
||||
'translationLanguages', lambda _, v: v.get('languageCode'))):
|
||||
translation_language_code = translation_language['languageCode']
|
||||
process_language(
|
||||
automatic_captions, base_url, translation_language_code,
|
||||
{'tlang': translation_language_code})
|
||||
info['automatic_captions'] = automatic_captions
|
||||
info['subtitles'] = subtitles
|
||||
|
||||
process_subtitles()
|
||||
|
||||
parsed_url = compat_urllib_parse_urlparse(url)
|
||||
for component in [parsed_url.fragment, parsed_url.query]:
|
||||
for component in (parsed_url.fragment, parsed_url.query):
|
||||
query = compat_parse_qs(component)
|
||||
for k, v in query.items():
|
||||
for d_k, s_ks in [('start', ('start', 't')), ('end', ('end',))]:
|
||||
@ -2684,7 +2688,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||
'title': 'Super Cooper Shorts - Shorts',
|
||||
'uploader': 'Super Cooper Shorts',
|
||||
'uploader_id': '@SuperCooperShorts',
|
||||
}
|
||||
},
|
||||
}, {
|
||||
# Channel that does not have a Shorts tab. Test should just download videos on Home tab instead
|
||||
'url': 'https://www.youtube.com/@emergencyawesome/shorts',
|
||||
@ -2738,7 +2742,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||
'description': 'md5:609399d937ea957b0f53cbffb747a14c',
|
||||
'uploader': 'ThirstForScience',
|
||||
'uploader_id': '@ThirstForScience',
|
||||
}
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
|
||||
'only_matching': True,
|
||||
@ -3037,7 +3041,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||
'uploader': '3Blue1Brown',
|
||||
'uploader_id': '@3blue1brown',
|
||||
'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
|
||||
}
|
||||
},
|
||||
}]
|
||||
|
||||
@classmethod
|
||||
@ -3335,7 +3339,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||
'client': {
|
||||
'clientName': 'WEB',
|
||||
'clientVersion': client_version,
|
||||
}
|
||||
},
|
||||
}
|
||||
visitor_data = try_get(context, lambda x: x['client']['visitorData'], compat_str)
|
||||
|
||||
@ -3354,7 +3358,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||
headers['x-goog-visitor-id'] = visitor_data
|
||||
data['continuation'] = continuation['continuation']
|
||||
data['clickTracking'] = {
|
||||
'clickTrackingParams': continuation['itct']
|
||||
'clickTrackingParams': continuation['itct'],
|
||||
}
|
||||
count = 0
|
||||
retries = 3
|
||||
@ -3613,7 +3617,7 @@ class YoutubePlaylistIE(InfoExtractor):
|
||||
'uploader': 'milan',
|
||||
'uploader_id': '@milan5503',
|
||||
'channel_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
|
||||
}
|
||||
},
|
||||
}, {
|
||||
'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
|
||||
'playlist_mincount': 455,
|
||||
@ -3623,7 +3627,7 @@ class YoutubePlaylistIE(InfoExtractor):
|
||||
'uploader': 'LBK',
|
||||
'uploader_id': '@music_king',
|
||||
'channel_id': 'UC21nz3_MesPLqtDqwdvnoxA',
|
||||
}
|
||||
},
|
||||
}, {
|
||||
'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
|
||||
'only_matching': True,
|
||||
@ -3734,7 +3738,7 @@ class YoutubeSearchIE(SearchInfoExtractor, YoutubeBaseInfoExtractor):
|
||||
'info_dict': {
|
||||
'id': 'youtube-dl test video',
|
||||
'title': 'youtube-dl test video',
|
||||
}
|
||||
},
|
||||
}]
|
||||
|
||||
def _get_n_results(self, query, n):
|
||||
@ -3754,7 +3758,7 @@ class YoutubeSearchDateIE(YoutubeSearchIE):
|
||||
'info_dict': {
|
||||
'id': 'youtube-dl test video',
|
||||
'title': 'youtube-dl test video',
|
||||
}
|
||||
},
|
||||
}]
|
||||
|
||||
|
||||
@ -3769,7 +3773,7 @@ class YoutubeSearchURLIE(YoutubeBaseInfoExtractor):
|
||||
'id': 'youtube-dl test video',
|
||||
'title': 'youtube-dl test video',
|
||||
},
|
||||
'params': {'playlistend': 5}
|
||||
'params': {'playlistend': 5},
|
||||
}, {
|
||||
'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
|
||||
'only_matching': True,
|
||||
@ -3785,6 +3789,7 @@ class YoutubeSearchURLIE(YoutubeBaseInfoExtractor):
|
||||
class YoutubeFeedsInfoExtractor(YoutubeTabIE):
|
||||
"""
|
||||
Base class for feed extractors
|
||||
|
||||
Subclasses must define the _FEED_NAME property.
|
||||
"""
|
||||
_LOGIN_REQUIRED = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user