use CaseInsensitiveDict for headers

This commit is contained in:
sigma67 2021-12-12 20:55:31 +01:00
commit 0cefc97d87
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
2 changed files with 5 additions and 5 deletions

View file

@ -203,7 +203,7 @@ class UploadsMixin:
+ ', '.join(supported_filetypes)) + ', '.join(supported_filetypes))
headers = self.headers.copy() headers = self.headers.copy()
upload_url = "https://upload.youtube.com/upload/usermusic/http?authuser=%s" % headers['X-Goog-AuthUser'] upload_url = "https://upload.youtube.com/upload/usermusic/http?authuser=%s" % headers['x-goog-authuser']
filesize = os.path.getsize(filepath) filesize = os.path.getsize(filepath)
body = ("filename=" + ntpath.basename(filepath)).encode('utf-8') body = ("filename=" + ntpath.basename(filepath)).encode('utf-8')
headers.pop('content-encoding', None) headers.pop('content-encoding', None)

View file

@ -1,6 +1,7 @@
import requests import requests
import gettext import gettext
import os import os
from requests.structures import CaseInsensitiveDict
from functools import partial from functools import partial
from contextlib import suppress from contextlib import suppress
from typing import Dict from typing import Dict
@ -74,15 +75,14 @@ class YTMusic(BrowsingMixin, WatchMixin, ExploreMixin, LibraryMixin, PlaylistsMi
self.proxies = proxies self.proxies = proxies
# prepare headers # prepare headers
self.headers = {}
if auth: if auth:
try: try:
if os.path.isfile(auth): if os.path.isfile(auth):
file = auth file = auth
with open(file) as json_file: with open(file) as json_file:
self.headers = json.load(json_file) self.headers = CaseInsensitiveDict(json.load(json_file))
else: else:
self.headers = json.loads(auth) self.headers = CaseInsensitiveDict(json.loads(auth))
except Exception as e: except Exception as e:
print( print(
@ -120,7 +120,7 @@ class YTMusic(BrowsingMixin, WatchMixin, ExploreMixin, LibraryMixin, PlaylistsMi
# verify authentication credentials work # verify authentication credentials work
if auth: if auth:
try: try:
cookie = self.headers.get('cookie', self.headers.get('Cookie')) cookie = self.headers.get('cookie')
self.sapisid = sapisid_from_cookie(cookie) self.sapisid = sapisid_from_cookie(cookie)
except KeyError: except KeyError:
raise Exception("Your cookie is missing the required value __Secure-3PAPISID") raise Exception("Your cookie is missing the required value __Secure-3PAPISID")