Fix upload metadata and file types (fixes #1)
This commit is contained in:
parent
38129fc759
commit
ec3c41c210
1 changed files with 4 additions and 9 deletions
|
|
@ -449,28 +449,23 @@ class YTMusic:
|
||||||
headers = self.headers
|
headers = self.headers
|
||||||
upload_url = "https://upload.youtube.com/upload/usermusic/http?authuser=0"
|
upload_url = "https://upload.youtube.com/upload/usermusic/http?authuser=0"
|
||||||
file = open(filepath, 'rb')
|
file = open(filepath, 'rb')
|
||||||
req = requests.Request('POST', upload_url,
|
filesize = os.path.getsize(filepath)
|
||||||
files={'file': file},
|
|
||||||
headers=headers)
|
|
||||||
prepped = req.prepare()
|
|
||||||
filesize = prepped.headers['content-length']
|
|
||||||
|
|
||||||
body = "filename=" + ntpath.basename(filepath)
|
body = "filename=" + ntpath.basename(filepath)
|
||||||
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8'
|
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8'
|
||||||
headers['X-Goog-Upload-Command'] = 'start'
|
headers['X-Goog-Upload-Command'] = 'start'
|
||||||
headers['X-Goog-Upload-Header-Content-Length'] = filesize
|
headers['X-Goog-Upload-Header-Content-Length'] = str(filesize)
|
||||||
headers['X-Goog-Upload-Protocol'] = 'resumable'
|
headers['X-Goog-Upload-Protocol'] = 'resumable'
|
||||||
response = requests.post(upload_url, data=body, headers=headers)
|
response = requests.post(upload_url, data=body, headers=headers)
|
||||||
headers['X-Goog-Upload-Command'] = 'upload, finalize'
|
headers['X-Goog-Upload-Command'] = 'upload, finalize'
|
||||||
headers['X-Goog-Upload-Offset'] = '0'
|
headers['X-Goog-Upload-Offset'] = '0'
|
||||||
upload_url = response.headers['X-Goog-Upload-URL']
|
upload_url = response.headers['X-Goog-Upload-URL']
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
response = requests.post(upload_url, files={'file': file}, headers=headers)
|
response = requests.post(upload_url, data=file, headers=headers)
|
||||||
file.close()
|
file.close()
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return 'STATUS_SUCCEEDED'
|
return 'STATUS_SUCCEEDED'
|
||||||
else:
|
else:
|
||||||
return response.content
|
return response
|
||||||
|
|
||||||
def delete_uploaded_song(self, uploaded_song):
|
def delete_uploaded_song(self, uploaded_song):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue