mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-25 20:55:52 +01:00
Author: colethedj
This commit is contained in:
parent
0181adefc6
commit
1974e99f4b
@ -301,12 +301,22 @@ def _real_initialize(self):
|
|||||||
_YT_INITIAL_BOUNDARY_RE = r'(?:var\s+meta|</script|\n)'
|
_YT_INITIAL_BOUNDARY_RE = r'(?:var\s+meta|</script|\n)'
|
||||||
|
|
||||||
def _generate_sapisidhash_header(self):
|
def _generate_sapisidhash_header(self):
|
||||||
sapisid_cookie = self._get_cookies('https://www.youtube.com').get('SAPISID')
|
# Sometimes SAPISID cookie isn't present but __Secure-3PAPISID is.
|
||||||
|
# See: https://github.com/yt-dlp/yt-dlp/issues/393
|
||||||
|
yt_cookies = self._get_cookies('https://www.youtube.com')
|
||||||
|
sapisid_cookie = dict_get(
|
||||||
|
yt_cookies, ('__Secure-3PAPISID', 'SAPISID'))
|
||||||
if sapisid_cookie is None:
|
if sapisid_cookie is None:
|
||||||
return
|
return
|
||||||
time_now = round(time.time())
|
time_now = round(time.time())
|
||||||
sapisidhash = hashlib.sha1((str(time_now) + " " + sapisid_cookie.value + " " + "https://www.youtube.com").encode("utf-8")).hexdigest()
|
# SAPISID cookie is required if not already present
|
||||||
return "SAPISIDHASH %s_%s" % (time_now, sapisidhash)
|
if not yt_cookies.get('SAPISID'):
|
||||||
|
self._set_cookie(
|
||||||
|
'.youtube.com', 'SAPISID', sapisid_cookie.value, secure=True, expire_time=time_now + 3600)
|
||||||
|
# SAPISIDHASH algorithm from https://stackoverflow.com/a/32065323
|
||||||
|
sapisidhash = hashlib.sha1(
|
||||||
|
f'{time_now} {sapisid_cookie.value} https://www.youtube.com'.encode('utf-8')).hexdigest()
|
||||||
|
return f'SAPISIDHASH {time_now}_{sapisidhash}'
|
||||||
|
|
||||||
def _call_api(self, ep, query, video_id, fatal=True, headers=None,
|
def _call_api(self, ep, query, video_id, fatal=True, headers=None,
|
||||||
note='Downloading API JSON', errnote='Unable to download API page',
|
note='Downloading API JSON', errnote='Unable to download API page',
|
||||||
|
Loading…
Reference in New Issue
Block a user