sigma67 / spotify_to_ytmusic

Clone a Spotify playlist to YouTube Music
MIT License
791 stars 65 forks source link

Request contains an invalid argument #15

Closed demesm closed 3 years ago

demesm commented 3 years ago

Trying to transfer any playlist results in this error:

❯ python3 YouTube.py "https://open.spotify.com/playlist/04TqDTuVBKg9OjPPezjmcE?si=YB7XVWHCTgm4umw-f64IUg" requested from 100 requested from 200 requested from 300 requested from 400 requested from 500 requested from 600 requested from 700 requested from 800 requested from 900 requested from 1000 requested from 1100 requested from 1200 10 searched 20 searched 30 searched 40 searched 50 searched 60 searched 70 searched 80 searched 90 searched 100 searched 110 searched 120 searched 130 searched 140 searched 150 searched 160 searched 170 searched 180 searched 190 searched 200 searched 210 searched 220 searched 230 searched 240 searched 250 searched 260 searched 270 searched 280 searched 290 searched 300 searched 310 searched 320 searched 330 searched 340 searched 350 searched 360 searched 370 searched 380 searched 390 searched 400 searched 410 searched 420 searched 430 searched 440 searched 450 searched 460 searched 470 searched 480 searched 490 searched 500 searched 510 searched 520 searched 530 searched 540 searched 550 searched 560 searched 570 searched 580 searched 590 searched 600 searched 610 searched 620 searched 630 searched 640 searched 650 searched 660 searched 670 searched 680 searched 690 searched 700 searched 710 searched 720 searched 730 searched 740 searched 750 searched 760 searched 770 searched 780 searched 790 searched 800 searched 810 searched 820 searched 830 searched 840 searched 850 searched 860 searched 870 searched 880 searched

[youtube] 890 searched 900 searched 910 searched 920 searched 930 searched 940 searched 950 searched 960 searched 970 searched 980 searched 990 searched 1000 searched 1010 searched 1020 searched 1030 searched 1040 searched 1050 searched 1060 searched 1070 searched 1080 searched 1090 searched 1100 searched 1110 searched 1120 searched 1130 searched 1140 searched 1150 searched 1160 searched 1170 searched 1180 searched 1190 searched 1200 searched 1210 searched 1220 searched 1230 searched Traceback (most recent call last): File "YouTube.py", line 190, in main() File "YouTube.py", line 182, in main playlistId = ytmusic.create_playlist(name, info, 'PUBLIC' if args.public else 'PRIVATE') File "YouTube.py", line 19, in create_playlist return self.api.create_playlist(name, info, privacy, video_ids=tracks) File "/home/scott/.local/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 145, in create_playlist response = self._send_request(endpoint, body) File "/home/scott/.local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 129, in _send_request raise Exception(message + error) Exception: Server returned HTTP 400: Bad Request. Request contains an invalid argument.

I used firefox to copy the headers, also tried with chrome

sigma67 commented 3 years ago

Can you try with a smaller playlist? Or does the error only occur with the large playlist?

Most likely something is wrong with your headers, though.

demesm commented 3 years ago

Happens with any size playlist

sigma67 commented 3 years ago

There is likely some invalid data in your headers. Can you post the keys of your headers_auth.json? (no need to send the values)

If you want you can also send me the file to ytmusicapi@gmail.com and I can try to figure it out for you

demesm commented 3 years ago

From chrome raw (deleted values)

accept: / accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9 authorization: content-length: 747 content-type: application/json cookie: origin: https://music.youtube.com referer: https://music.youtube.com/ sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90" sec-ch-ua-mobile: ?0 sec-fetch-dest: empty sec-fetch-mode: cors sec-fetch-site: same-origin user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 x-client-data: x-goog-authuser: 0 x-goog-pageid: undefined x-goog-visitor-id: x-origin: https://music.youtube.com x-youtube-ad-signals: x-youtube-client-name: x-youtube-client-version: x-youtube-device: cbr=Chrome&cbrver=90.0.4430.93&ceng=WebKit&cengver=537.36&cos=Windows&cosver=10.0&cplatform=DESKTOP x-youtube-identity-token: x-youtube-page-cl: x-youtube-page-label: x-youtube-time-zone: America/New_York x-youtube-utc-offset: -240

From FF - I have tried w/ and w/o the POST

POST /youtubei/v1/browse?ctoken=...FDNX30 HTTP/1.1 Host: music.youtube.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0 Accept: / Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Content-Type: application/json Content-Length: 731 X-Goog-Visitor-Id: X-Goog-AuthUser: 0 X-Goog-PageId: undefined x-origin: https://music.youtube.com X-YouTube-Client-Name: 67 X-YouTube-Client-Version: 0.1 X-YouTube-Device: cbr=Firefox&cbrver=88.0&ceng=Gecko&cengver=88.0&cos=Windows&cosver=10.0&cplatform=DESKTOP X-Youtube-Identity-Token: X-YouTube-Page-CL: 371 X-YouTube-Page-Label: youtube.music.web.client_20210503_00_RC01 X-YouTube-Utc-Offset: -240 X-YouTube-Time-Zone: America/New_York X-YouTube-Ad-Signals: Origin: https://music.youtube.com Authorization: Referer: https://music.youtube.com/ Connection: keep-alive Cookie:

demesm commented 3 years ago

This is what ends up in the settings field after running Setup.py, I have split it for easier reading

{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0" "Accept": "/" "Accept-Language": "en-US en;q=0.5" "Content-Type": "application/json" "X-Goog-AuthUser": "0" "origin": "https://music.youtube.com" "X-Goog-Visitor-Id": "WWRDeEFjhvD" "Cookie": "VISITOR_INFO1_LIVE=I; _gcl_au=1.1.206.162; PREF=volume=100&library_tab_browse_id=FEmusic_liked_playlists; SID=9QfsOeS9DkvZa9vp6h77uAqkFfbeKjHp3i2HFLT9SmDtK2SP_dDo9-gd0U8bSwJNJ1Bicg.; Secure-3PSID=9QfsOeS9DkvZa9vp6h77uAqkFfbeKjHp3i2HFLT9SmDtK2SPsvB7-mOQ1Q_o2tYsU2dW1g.; HSID=AyYOvhyEQOuZWhwj9; SSID=A6a-iQ7keBC48zC4M; APISID=Lqz_HMlNJAj8ZdWL/Anz9f0Xy-ezQ3CKCh; SAPISID=yA1Mr8R1m3Y42A-6/ADxMYmFCByhGdMA83; Secure-3PAPISID=-6/; LOGIN_INFO=QrNgY; __Secure-3PSIDCC=16iGvg; YSC=I"}

sigma67 commented 3 years ago

Your headers_auth mostly seems correct (contains all necessary keys), but you truncated something at the end I think. That might be why it's not working

demesm commented 3 years ago

I removed all random stuff from in between for github, its unchanged when running it

demesm commented 3 years ago

Your headers_auth mostly seems correct (contains all necessary keys), but you truncated something at the end I think. That might be why it's not working

So, I tracked it to the create_playlist() function using the console.

I went to do it manually in chrome to see what, if anything was missing - it turns out when you create your first playlist (I just swapped over to YTM), it prompts you to create a channel.

You have to have already done this to utilize the api, works fine after this :)