add gzip encoding, ignore some headers that might break requests

This commit is contained in:
sigma67 2021-04-28 16:27:57 +02:00
commit f9d317bd0d
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
4 changed files with 13 additions and 6 deletions

View file

@ -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"
}

View file

@ -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)

View file

@ -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)

View file

@ -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