get x-goog-visitor-id dynamically to avoid errors caused by its expiry
removed headers.json all headers provided by user are now used in the headers file created by setup.py instead of only required headers
This commit is contained in:
parent
391eb3f4aa
commit
048f17989a
7 changed files with 169 additions and 149 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import re
|
||||
import json
|
||||
from http.cookies import SimpleCookie
|
||||
from hashlib import sha1
|
||||
import time
|
||||
from functools import wraps
|
||||
import locale
|
||||
from ytmusicapi.constants import *
|
||||
|
||||
|
||||
def prepare_browse_endpoint(type, browseId):
|
||||
|
|
@ -44,6 +46,26 @@ def prepare_order_params(order):
|
|||
return order_params[orders.index(order)]
|
||||
|
||||
|
||||
def initialize_headers():
|
||||
return {
|
||||
"User-Agent": USER_AGENT,
|
||||
"Accept": "*/*",
|
||||
"Content-Type": "application/json",
|
||||
"origin": YTM_DOMAIN,
|
||||
"X-Goog-AuthUser": "0"
|
||||
}
|
||||
|
||||
|
||||
def get_visitor_id(request_func):
|
||||
response = request_func(YTM_DOMAIN)
|
||||
matches = re.findall(r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;', response)
|
||||
visitor_id = ""
|
||||
if len(matches) > 0:
|
||||
ytcfg = json.loads(matches[0])
|
||||
visitor_id = ytcfg.get('VISITOR_DATA')
|
||||
return {'X-Goog-Visitor-Id': visitor_id}
|
||||
|
||||
|
||||
def html_to_txt(html_text):
|
||||
tags = re.findall("<[^>]+>", html_text)
|
||||
for tag in tags:
|
||||
|
|
|
|||
Loading…
Reference in a new issue