mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-02-03 17:20:13 +09:00
Compare commits
15 Commits
509aa12046
...
af6edd0bbf
Author | SHA1 | Date | |
---|---|---|---|
|
af6edd0bbf | ||
|
1036478d13 | ||
|
00ad2b8ca1 | ||
|
ab7c61ca29 | ||
|
176fc2cb00 | ||
|
1a57b3c03f | ||
|
c68a4ae679 | ||
|
a58f3e7777 | ||
|
fb4126a18c | ||
|
2ab47fa3a8 | ||
|
09cace68c2 | ||
|
66f48768b0 | ||
|
ea4b8b6747 | ||
|
2e6682d80e | ||
|
8fb38341ae |
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
InfoExtractor,
|
InfoExtractor,
|
||||||
@ -28,6 +30,7 @@ from ..utils import (
|
|||||||
update_url_query,
|
update_url_query,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlhandle_detect_ext,
|
urlhandle_detect_ext,
|
||||||
|
sanitized_Request,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -309,7 +312,81 @@ class SoundcloudIE(InfoExtractor):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'YUKXoArFcqrlQn9tfNHvvyfnDISj04zk'
|
self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or "T5R4kgWS2PRf6lzLyIravUMnKlbIxQag" # 'EXLwg5lHTO2dslU5EePe3xkw0m1h86Cd' # 'YUKXoArFcqrlQn9tfNHvvyfnDISj04zk'
|
||||||
|
self._login()
|
||||||
|
|
||||||
|
_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
|
||||||
|
_API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
|
||||||
|
_API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
|
||||||
|
_access_token = None
|
||||||
|
_HEADERS = {}
|
||||||
|
_NETRC_MACHINE = 'soundcloud'
|
||||||
|
|
||||||
|
def _login(self):
|
||||||
|
username, password = self._get_login_info()
|
||||||
|
if username is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
def genDevId():
|
||||||
|
def genNumBlock():
|
||||||
|
return ''.join([str(random.randrange(10)) for i in range(6)])
|
||||||
|
return '-'.join([genNumBlock() for i in range(4)])
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
'client_id': self._CLIENT_ID,
|
||||||
|
'recaptcha_pubkey': 'null',
|
||||||
|
'recaptcha_response': 'null',
|
||||||
|
'credentials': {
|
||||||
|
'identifier': username,
|
||||||
|
'password': password
|
||||||
|
},
|
||||||
|
'signature': self.sign(username, password, self._CLIENT_ID),
|
||||||
|
'device_id': genDevId(),
|
||||||
|
'user_agent': self._USER_AGENT
|
||||||
|
}
|
||||||
|
|
||||||
|
query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
|
||||||
|
login = sanitized_Request(self._API_AUTH_URL_PW % query, json.dumps(payload).encode('utf-8'))
|
||||||
|
response = self._download_json(login, None)
|
||||||
|
self._access_token = response.get('session').get('access_token')
|
||||||
|
if not self._access_token:
|
||||||
|
self.report_warning('Unable to get access token, login may has failed')
|
||||||
|
else:
|
||||||
|
self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
|
||||||
|
|
||||||
|
# signature generation
|
||||||
|
def sign(self, user, pw, clid):
|
||||||
|
a = 33
|
||||||
|
i = 1
|
||||||
|
s = 440123
|
||||||
|
w = 117
|
||||||
|
u = 1800000
|
||||||
|
l = 1042
|
||||||
|
b = 37
|
||||||
|
k = 37
|
||||||
|
c = 5
|
||||||
|
n = "0763ed7314c69015fd4a0dc16bbf4b90" # _KEY
|
||||||
|
y = "8" # _REV
|
||||||
|
r = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" # _USER_AGENT
|
||||||
|
e = user # _USERNAME
|
||||||
|
t = clid # _CLIENT_ID
|
||||||
|
|
||||||
|
d = '-'.join([str(mInt) for mInt in [a, i, s, w, u, l, b, k]])
|
||||||
|
p = n + y + d + r + e + t + d + n
|
||||||
|
h = p
|
||||||
|
|
||||||
|
m = 8011470
|
||||||
|
f = 0
|
||||||
|
|
||||||
|
for f in range(f, len(h)):
|
||||||
|
m = (m >> 1) + ((1 & m) << 23)
|
||||||
|
m += ord(h[f])
|
||||||
|
m &= 16777215
|
||||||
|
|
||||||
|
# c is not even needed
|
||||||
|
out = str(y) + ':' + str(d) + ':' + format(m, 'x') + ':' + str(c)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _resolv_url(cls, url):
|
def _resolv_url(cls, url):
|
||||||
@ -389,7 +466,7 @@ class SoundcloudIE(InfoExtractor):
|
|||||||
if not format_url:
|
if not format_url:
|
||||||
continue
|
continue
|
||||||
stream = self._download_json(
|
stream = self._download_json(
|
||||||
format_url, track_id, query=query, fatal=False)
|
format_url, track_id, query=query, fatal=False, headers=self._HEADERS)
|
||||||
if not isinstance(stream, dict):
|
if not isinstance(stream, dict):
|
||||||
continue
|
continue
|
||||||
stream_url = url_or_none(stream.get('url'))
|
stream_url = url_or_none(stream.get('url'))
|
||||||
@ -487,7 +564,7 @@ class SoundcloudIE(InfoExtractor):
|
|||||||
info_json_url = self._resolv_url(self._BASE_URL + resolve_title)
|
info_json_url = self._resolv_url(self._BASE_URL + resolve_title)
|
||||||
|
|
||||||
info = self._download_json(
|
info = self._download_json(
|
||||||
info_json_url, full_title, 'Downloading info JSON', query=query)
|
info_json_url, full_title, 'Downloading info JSON', query=query, headers=self._HEADERS)
|
||||||
|
|
||||||
return self._extract_info_dict(info, full_title, token)
|
return self._extract_info_dict(info, full_title, token)
|
||||||
|
|
||||||
@ -503,7 +580,7 @@ class SoundcloudPlaylistBaseIE(SoundcloudIE):
|
|||||||
'ids': ','.join([compat_str(t['id']) for t in tracks]),
|
'ids': ','.join([compat_str(t['id']) for t in tracks]),
|
||||||
'playlistId': playlist_id,
|
'playlistId': playlist_id,
|
||||||
'playlistSecretToken': token,
|
'playlistSecretToken': token,
|
||||||
})
|
}, headers=self._HEADERS)
|
||||||
entries = []
|
entries = []
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
track_id = str_or_none(track.get('id'))
|
track_id = str_or_none(track.get('id'))
|
||||||
@ -547,7 +624,7 @@ class SoundcloudSetIE(SoundcloudPlaylistBaseIE):
|
|||||||
full_title += '/' + token
|
full_title += '/' + token
|
||||||
|
|
||||||
info = self._download_json(self._resolv_url(
|
info = self._download_json(self._resolv_url(
|
||||||
self._BASE_URL + full_title), full_title)
|
self._BASE_URL + full_title), full_title, headers=self._HEADERS)
|
||||||
|
|
||||||
if 'errors' in info:
|
if 'errors' in info:
|
||||||
msgs = (compat_str(err['error_message']) for err in info['errors'])
|
msgs = (compat_str(err['error_message']) for err in info['errors'])
|
||||||
@ -574,7 +651,7 @@ class SoundcloudPagedPlaylistBaseIE(SoundcloudIE):
|
|||||||
for i in itertools.count():
|
for i in itertools.count():
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
next_href, playlist_id,
|
next_href, playlist_id,
|
||||||
'Downloading track page %s' % (i + 1), query=query)
|
'Downloading track page %s' % (i + 1), query=query, headers=self._HEADERS)
|
||||||
|
|
||||||
collection = response['collection']
|
collection = response['collection']
|
||||||
|
|
||||||
@ -696,7 +773,7 @@ class SoundcloudUserIE(SoundcloudPagedPlaylistBaseIE):
|
|||||||
|
|
||||||
user = self._download_json(
|
user = self._download_json(
|
||||||
self._resolv_url(self._BASE_URL + uploader),
|
self._resolv_url(self._BASE_URL + uploader),
|
||||||
uploader, 'Downloading user info')
|
uploader, 'Downloading user info', headers=self._HEADERS)
|
||||||
|
|
||||||
resource = mobj.group('rsrc') or 'all'
|
resource = mobj.group('rsrc') or 'all'
|
||||||
|
|
||||||
@ -721,7 +798,7 @@ class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
track_name = self._match_id(url)
|
track_name = self._match_id(url)
|
||||||
|
|
||||||
track = self._download_json(self._resolv_url(url), track_name)
|
track = self._download_json(self._resolv_url(url), track_name, headers=self._HEADERS)
|
||||||
track_id = self._search_regex(
|
track_id = self._search_regex(
|
||||||
r'soundcloud:track-stations:(\d+)', track['id'], 'track id')
|
r'soundcloud:track-stations:(\d+)', track['id'], 'track id')
|
||||||
|
|
||||||
@ -754,7 +831,7 @@ class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE):
|
|||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
self._API_V2_BASE + 'playlists/' + playlist_id,
|
self._API_V2_BASE + 'playlists/' + playlist_id,
|
||||||
playlist_id, 'Downloading playlist', query=query)
|
playlist_id, 'Downloading playlist', query=query, headers=self._HEADERS)
|
||||||
|
|
||||||
return self._extract_set(data, token)
|
return self._extract_set(data, token)
|
||||||
|
|
||||||
@ -791,7 +868,7 @@ class SoundcloudSearchIE(SearchInfoExtractor, SoundcloudIE):
|
|||||||
for i in itertools.count(1):
|
for i in itertools.count(1):
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
next_url, collection_id, 'Downloading page {0}'.format(i),
|
next_url, collection_id, 'Downloading page {0}'.format(i),
|
||||||
'Unable to download API page')
|
'Unable to download API page', headers=self._HEADERS)
|
||||||
|
|
||||||
collection = response.get('collection', [])
|
collection = response.get('collection', [])
|
||||||
if not collection:
|
if not collection:
|
||||||
|
@ -9,6 +9,7 @@ import json
|
|||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ from ..utils import (
|
|||||||
|
|
||||||
class YoutubeBaseInfoExtractor(InfoExtractor):
|
class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||||
"""Provide base functions for Youtube extractors"""
|
"""Provide base functions for Youtube extractors"""
|
||||||
|
|
||||||
_LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
|
_LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
|
||||||
_TWOFACTOR_URL = 'https://accounts.google.com/signin/challenge'
|
_TWOFACTOR_URL = 'https://accounts.google.com/signin/challenge'
|
||||||
|
|
||||||
@ -138,7 +140,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
[2, 1, None, 1,
|
[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',
|
'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],
|
None, [], 4],
|
||||||
1, [None, None, []], None, None, None, True
|
1, [None, None, []], None, None, None, True,
|
||||||
],
|
],
|
||||||
username,
|
username,
|
||||||
]
|
]
|
||||||
@ -160,7 +162,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
None, 1, None, [1, None, None, None, [password, None, True]],
|
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],
|
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(
|
challenge_results = req(
|
||||||
@ -213,7 +215,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
user_hash, None, 2, None,
|
user_hash, None, 2, None,
|
||||||
[
|
[
|
||||||
9, None, None, None, None, None, None, None,
|
9, None, None, None, None, None, None, None,
|
||||||
[None, tfa_code, True, 2]
|
[None, tfa_code, True, 2],
|
||||||
]]
|
]]
|
||||||
|
|
||||||
tfa_results = req(
|
tfa_results = req(
|
||||||
@ -284,7 +286,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
'client': {
|
'client': {
|
||||||
'clientName': 'WEB',
|
'clientName': 'WEB',
|
||||||
'clientVersion': '2.20201021.03.00',
|
'clientVersion': '2.20201021.03.00',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +387,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
'client': {
|
'client': {
|
||||||
'clientName': 'WEB',
|
'clientName': 'WEB',
|
||||||
'clientVersion': '2.20201021.03.00',
|
'clientVersion': '2.20201021.03.00',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
'query': query,
|
'query': query,
|
||||||
}
|
}
|
||||||
@ -462,7 +464,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
# (HTML, videodetails, metadata, renderers)
|
# (HTML, videodetails, metadata, renderers)
|
||||||
'name': ('content', 'author', (('ownerChannelName', None), 'title'), ['text']),
|
'name': ('content', 'author', (('ownerChannelName', None), 'title'), ['text']),
|
||||||
'url': ('href', 'ownerProfileUrl', 'vanityChannelUrl',
|
'url': ('href', 'ownerProfileUrl', 'vanityChannelUrl',
|
||||||
['navigationEndpoint', 'browseEndpoint', 'canonicalBaseUrl'])
|
['navigationEndpoint', 'browseEndpoint', 'canonicalBaseUrl']),
|
||||||
}
|
}
|
||||||
if any((videodetails, metadata, renderers)):
|
if any((videodetails, metadata, renderers)):
|
||||||
result = (
|
result = (
|
||||||
@ -671,7 +673,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
|
'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
|
||||||
'description': '',
|
'description': '',
|
||||||
'uploader': '8KVIDEO',
|
'uploader': '8KVIDEO',
|
||||||
'title': 'UHDTV TEST 8K VIDEO.mp4'
|
'title': 'UHDTV TEST 8K VIDEO.mp4',
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'youtube_include_dash_manifest': True,
|
'youtube_include_dash_manifest': True,
|
||||||
@ -711,7 +713,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
'uploader_url': r're:https?://(?:www\.)?youtube\.com/@theamazingatheist',
|
'uploader_url': r're:https?://(?:www\.)?youtube\.com/@theamazingatheist',
|
||||||
'title': 'Burning Everyone\'s Koran',
|
'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',
|
'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
|
# Age-gated videos
|
||||||
{
|
{
|
||||||
@ -839,7 +841,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
},
|
},
|
||||||
'expected_warnings': [
|
'expected_warnings': [
|
||||||
'DASH manifest missing',
|
'DASH manifest missing',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
# Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
|
# 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.
|
# cpn generation algorithm is reverse engineered from base.js.
|
||||||
# In fact it works even with dummy cpn.
|
# In fact it works even with dummy cpn.
|
||||||
CPN_ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
|
CPN_ALPHABET = string.ascii_letters + string.digits + '-_'
|
||||||
cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(0, 16))
|
cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(16))
|
||||||
|
|
||||||
# more consistent results setting it to right before the end
|
# more consistent results setting it to right before the end
|
||||||
qs = parse_qs(playback_url)
|
qs = parse_qs(playback_url)
|
||||||
@ -1881,8 +1883,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
mobj = re.match(cls._VALID_URL, url, re.VERBOSE)
|
mobj = re.match(cls._VALID_URL, url, re.VERBOSE)
|
||||||
if mobj is None:
|
if mobj is None:
|
||||||
raise ExtractorError('Invalid URL: %s' % url)
|
raise ExtractorError('Invalid URL: %s' % url)
|
||||||
video_id = mobj.group(2)
|
return mobj.group(2)
|
||||||
return video_id
|
|
||||||
|
|
||||||
def _extract_chapters_from_json(self, data, video_id, duration):
|
def _extract_chapters_from_json(self, data, video_id, duration):
|
||||||
chapters_list = try_get(
|
chapters_list = try_get(
|
||||||
@ -1951,7 +1952,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
pb_context = {'html5Preference': 'HTML5_PREF_WANTS'}
|
pb_context = {'html5Preference': 'HTML5_PREF_WANTS'}
|
||||||
|
|
||||||
player_url = self._extract_player_url(webpage)
|
player_url = self._extract_player_url(webpage)
|
||||||
ytcfg = self._extract_ytcfg(video_id, webpage)
|
ytcfg = self._extract_ytcfg(video_id, webpage or '')
|
||||||
sts = self._extract_signature_timestamp(video_id, player_url, ytcfg)
|
sts = self._extract_signature_timestamp(video_id, player_url, ytcfg)
|
||||||
if sts:
|
if sts:
|
||||||
pb_context['signatureTimestamp'] = sts
|
pb_context['signatureTimestamp'] = sts
|
||||||
@ -2035,7 +2036,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
headers = {
|
headers = {
|
||||||
'X-YouTube-Client-Name': '85',
|
'X-YouTube-Client-Name': '85',
|
||||||
'X-YouTube-Client-Version': '2.0',
|
'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)
|
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)])
|
return ''.join([r['text'] for r in runs if isinstance(r.get('text'), compat_str)])
|
||||||
|
|
||||||
search_meta = (
|
search_meta = (
|
||||||
lambda x: self._html_search_meta(x, webpage, default=None)) \
|
(lambda x: self._html_search_meta(x, webpage, default=None))
|
||||||
if webpage else lambda x: None
|
if webpage else lambda _: None)
|
||||||
|
|
||||||
video_details = player_response.get('videoDetails') or {}
|
video_details = player_response.get('videoDetails') or {}
|
||||||
microformat = try_get(
|
microformat = try_get(
|
||||||
@ -2137,7 +2138,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
def build_fragments(f):
|
def build_fragments(f):
|
||||||
return LazyList({
|
return LazyList({
|
||||||
'url': update_url_query(f['url'], {
|
'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))
|
} for range_start in range(0, f['filesize'], CHUNK_SIZE))
|
||||||
|
|
||||||
@ -2236,7 +2237,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
'protocol': 'http_dash_segments',
|
'protocol': 'http_dash_segments',
|
||||||
'fragments': build_fragments(dct),
|
'fragments': build_fragments(dct),
|
||||||
} if dct['filesize'] else {
|
} 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)
|
formats.append(dct)
|
||||||
@ -2414,9 +2415,9 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
'is_live': is_live,
|
'is_live': is_live,
|
||||||
}
|
}
|
||||||
|
|
||||||
pctr = try_get(
|
pctr = traverse_obj(
|
||||||
player_response,
|
player_response,
|
||||||
lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict)
|
('captions', 'playerCaptionsTracklistRenderer', T(dict)))
|
||||||
if pctr:
|
if pctr:
|
||||||
def process_language(container, base_url, lang_code, query):
|
def process_language(container, base_url, lang_code, query):
|
||||||
lang_subs = []
|
lang_subs = []
|
||||||
@ -2430,9 +2431,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
})
|
})
|
||||||
container[lang_code] = lang_subs
|
container[lang_code] = lang_subs
|
||||||
|
|
||||||
|
def process_subtitles():
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for caption_track in (pctr.get('captionTracks') or []):
|
for caption_track in traverse_obj(pctr, (
|
||||||
base_url = caption_track.get('baseUrl')
|
'captionTracks', lambda _, v: v.get('baseUrl'))):
|
||||||
|
base_url = self._yt_urljoin(caption_track['baseUrl'])
|
||||||
if not base_url:
|
if not base_url:
|
||||||
continue
|
continue
|
||||||
if caption_track.get('kind') != 'asr':
|
if caption_track.get('kind') != 'asr':
|
||||||
@ -2443,18 +2446,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
subtitles, base_url, lang_code, {})
|
subtitles, base_url, lang_code, {})
|
||||||
continue
|
continue
|
||||||
automatic_captions = {}
|
automatic_captions = {}
|
||||||
for translation_language in (pctr.get('translationLanguages') or []):
|
for translation_language in traverse_obj(pctr, (
|
||||||
translation_language_code = translation_language.get('languageCode')
|
'translationLanguages', lambda _, v: v.get('languageCode'))):
|
||||||
if not translation_language_code:
|
translation_language_code = translation_language['languageCode']
|
||||||
continue
|
|
||||||
process_language(
|
process_language(
|
||||||
automatic_captions, base_url, translation_language_code,
|
automatic_captions, base_url, translation_language_code,
|
||||||
{'tlang': translation_language_code})
|
{'tlang': translation_language_code})
|
||||||
info['automatic_captions'] = automatic_captions
|
info['automatic_captions'] = automatic_captions
|
||||||
info['subtitles'] = subtitles
|
info['subtitles'] = subtitles
|
||||||
|
|
||||||
|
process_subtitles()
|
||||||
|
|
||||||
parsed_url = compat_urllib_parse_urlparse(url)
|
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)
|
query = compat_parse_qs(component)
|
||||||
for k, v in query.items():
|
for k, v in query.items():
|
||||||
for d_k, s_ks in [('start', ('start', 't')), ('end', ('end',))]:
|
for d_k, s_ks in [('start', ('start', 't')), ('end', ('end',))]:
|
||||||
@ -2684,7 +2688,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
'title': 'Super Cooper Shorts - Shorts',
|
'title': 'Super Cooper Shorts - Shorts',
|
||||||
'uploader': 'Super Cooper Shorts',
|
'uploader': 'Super Cooper Shorts',
|
||||||
'uploader_id': '@SuperCooperShorts',
|
'uploader_id': '@SuperCooperShorts',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
# Channel that does not have a Shorts tab. Test should just download videos on Home tab instead
|
# Channel that does not have a Shorts tab. Test should just download videos on Home tab instead
|
||||||
'url': 'https://www.youtube.com/@emergencyawesome/shorts',
|
'url': 'https://www.youtube.com/@emergencyawesome/shorts',
|
||||||
@ -2738,7 +2742,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
'description': 'md5:609399d937ea957b0f53cbffb747a14c',
|
'description': 'md5:609399d937ea957b0f53cbffb747a14c',
|
||||||
'uploader': 'ThirstForScience',
|
'uploader': 'ThirstForScience',
|
||||||
'uploader_id': '@ThirstForScience',
|
'uploader_id': '@ThirstForScience',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
|
'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
@ -3037,7 +3041,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
'uploader': '3Blue1Brown',
|
'uploader': '3Blue1Brown',
|
||||||
'uploader_id': '@3blue1brown',
|
'uploader_id': '@3blue1brown',
|
||||||
'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
|
'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
|
||||||
}
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -3335,7 +3339,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
|||||||
'client': {
|
'client': {
|
||||||
'clientName': 'WEB',
|
'clientName': 'WEB',
|
||||||
'clientVersion': client_version,
|
'clientVersion': client_version,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
visitor_data = try_get(context, lambda x: x['client']['visitorData'], compat_str)
|
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
|
headers['x-goog-visitor-id'] = visitor_data
|
||||||
data['continuation'] = continuation['continuation']
|
data['continuation'] = continuation['continuation']
|
||||||
data['clickTracking'] = {
|
data['clickTracking'] = {
|
||||||
'clickTrackingParams': continuation['itct']
|
'clickTrackingParams': continuation['itct'],
|
||||||
}
|
}
|
||||||
count = 0
|
count = 0
|
||||||
retries = 3
|
retries = 3
|
||||||
@ -3613,7 +3617,7 @@ class YoutubePlaylistIE(InfoExtractor):
|
|||||||
'uploader': 'milan',
|
'uploader': 'milan',
|
||||||
'uploader_id': '@milan5503',
|
'uploader_id': '@milan5503',
|
||||||
'channel_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
|
'channel_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
|
'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
|
||||||
'playlist_mincount': 455,
|
'playlist_mincount': 455,
|
||||||
@ -3623,7 +3627,7 @@ class YoutubePlaylistIE(InfoExtractor):
|
|||||||
'uploader': 'LBK',
|
'uploader': 'LBK',
|
||||||
'uploader_id': '@music_king',
|
'uploader_id': '@music_king',
|
||||||
'channel_id': 'UC21nz3_MesPLqtDqwdvnoxA',
|
'channel_id': 'UC21nz3_MesPLqtDqwdvnoxA',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
|
'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
@ -3734,7 +3738,7 @@ class YoutubeSearchIE(SearchInfoExtractor, YoutubeBaseInfoExtractor):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'youtube-dl test video',
|
'id': 'youtube-dl test video',
|
||||||
'title': 'youtube-dl test video',
|
'title': 'youtube-dl test video',
|
||||||
}
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _get_n_results(self, query, n):
|
def _get_n_results(self, query, n):
|
||||||
@ -3754,7 +3758,7 @@ class YoutubeSearchDateIE(YoutubeSearchIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'youtube-dl test video',
|
'id': 'youtube-dl test video',
|
||||||
'title': 'youtube-dl test video',
|
'title': 'youtube-dl test video',
|
||||||
}
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
@ -3769,7 +3773,7 @@ class YoutubeSearchURLIE(YoutubeBaseInfoExtractor):
|
|||||||
'id': 'youtube-dl test video',
|
'id': 'youtube-dl test video',
|
||||||
'title': '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',
|
'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
@ -3785,6 +3789,7 @@ class YoutubeSearchURLIE(YoutubeBaseInfoExtractor):
|
|||||||
class YoutubeFeedsInfoExtractor(YoutubeTabIE):
|
class YoutubeFeedsInfoExtractor(YoutubeTabIE):
|
||||||
"""
|
"""
|
||||||
Base class for feed extractors
|
Base class for feed extractors
|
||||||
|
|
||||||
Subclasses must define the _FEED_NAME property.
|
Subclasses must define the _FEED_NAME property.
|
||||||
"""
|
"""
|
||||||
_LOGIN_REQUIRED = True
|
_LOGIN_REQUIRED = True
|
||||||
|
Loading…
Reference in New Issue
Block a user