add gzip encoding, ignore some headers that might break requests
This commit is contained in:
parent
650f0a220d
commit
f9d317bd0d
4 changed files with 13 additions and 6 deletions
|
|
@ -48,11 +48,13 @@ def prepare_order_params(order):
|
|||
|
||||
def initialize_headers():
|
||||
return {
|
||||
"User-Agent": USER_AGENT,
|
||||
"Accept": "*/*",
|
||||
"Content-Type": "application/json",
|
||||
"user-agent": USER_AGENT,
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"content-type": "application/json",
|
||||
"content-encoding": "gzip",
|
||||
"origin": YTM_DOMAIN,
|
||||
"X-Goog-AuthUser": "0"
|
||||
"x-goog-authuser": "0"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ class UploadsMixin:
|
|||
upload_url = "https://upload.youtube.com/upload/usermusic/http?authuser=0"
|
||||
filesize = os.path.getsize(filepath)
|
||||
body = ("filename=" + ntpath.basename(filepath)).encode('utf-8')
|
||||
headers.pop('content-encoding', None)
|
||||
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8'
|
||||
headers['X-Goog-Upload-Command'] = 'start'
|
||||
headers['X-Goog-Upload-Header-Content-Length'] = str(filesize)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def setup(filepath=None, headers_raw=None):
|
|||
header = content.split(': ')
|
||||
if len(header) == 1: # nothing was split
|
||||
continue
|
||||
user_headers[header[0]] = ': '.join(header[1:])
|
||||
user_headers[header[0].lower()] = ': '.join(header[1:])
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("Error parsing your input, please try again. Full error: " + str(e))
|
||||
|
|
@ -37,6 +37,10 @@ def setup(filepath=None, headers_raw=None):
|
|||
+ ". Please try a different request (such as /browse) and make sure you are logged in."
|
||||
)
|
||||
|
||||
ignore_headers = {"host", "content-length", "accept-encoding"}
|
||||
for i in ignore_headers:
|
||||
user_headers.pop(i, None)
|
||||
|
||||
headers = initialize_headers()
|
||||
headers.update(user_headers)
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi
|
|||
else: # no authentication
|
||||
self.headers = initialize_headers()
|
||||
|
||||
if 'X-Goog-Visitor-Id' not in self.headers:
|
||||
if 'x-goog-visitor-id' not in self.headers:
|
||||
self.headers.update(get_visitor_id(self._send_get_request))
|
||||
|
||||
# prepare context
|
||||
|
|
|
|||
Loading…
Reference in a new issue