linsomniac / spotify_to_ytmusic

Copy playlists and liked music from Spotify to YTMusic
Creative Commons Zero v1.0 Universal
1.72k stars 106 forks source link

Failing if Spotify Playlist contains Unicode characters #12

Closed JorgWashingmache closed 7 months ago

JorgWashingmache commented 8 months ago

Snímek obrazovky 2024-01-15 191329 IDK what this is, hope you can help me

linsomniac commented 8 months ago

This is probably a unicode decoding issue, could you try running this command and pasting the output:

python3 -c "print(repr(open('playlists.json', 'r').read()[520:620]))"

In the directory where your playlist.json file is.

I probably just need to open it with an encoding.

Thanks!

JorgWashingmache commented 8 months ago

image

linsomniac commented 8 months ago

I wasn't able to reproduce this, but I've pushed a code change that specifies a utf-8 encoding for the playlists.json file, and can also take the argument "--spotify-playlists-encoding" argument to change it. I think doing it in UTF-8 is going to solve it. Please give it a shot and let me know.

Vercety87 commented 8 months ago

Hi @linsomniac ,

First of all, a huge thanks for your work. It's amazing !

Got the same problem so I tried with --spotify-playlists-encoding=UTF-8.

The script started normally, but after maybe 20 minutes, it started to show me this :

ERROR: (Retrying) Server returned HTTP 400: Bad Request.
This functionality is not available right now. Please try again later. in 160 seconds

Don't know if I made something wrong.

Edit : it ended up with :

Looking up playlist '': id=None
Traceback (most recent call last):
  File "/opt/homebrew/bin/s2yt_copy_all_playlists", line 8, in <module>
    sys.exit(copy_all_playlists())
             ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/spotify2ytmusic/cli.py", line 286, in copy_all_playlists
    dst_pl_id = yt.create_playlist(title=pl_name, description=pl_name)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/ytmusicapi/mixins/playlists.py", line 240, in create_playlist
    response = self._send_request(endpoint, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/ytmusicapi/ytmusic.py", line 238, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 400: Bad Request.
Request contains an invalid argument.
python3 -c "print(repr(open('playlists.json', 'r').read()[520:620]))"
'", "DO", "DE", "EC", "EE", "SV", "FI", "FR", "GR", "GT", "HN", "HK", "HU", "IS", "IE", "IT", "LV", "'
linsomniac commented 8 months ago

@Vercety87 Your issue looks like something addressed over in #2 and the user there was able to work around it by slowing down the rate of interaction with YTMusic. Try adding the argument "--track-sleep 3" (which worked for the user over in #2 ) and you can try adjusting that up or down. The default is 0.1 seconds.

linsomniac commented 8 months ago

Looking a little deeper into this, I see that this is happening on the "create_playlist". Have you tried running the program a few times, does it always have that "yt.create_playlist" line in it, or is it failing at different points in the run.

It is safe to re-run the programs, it should not add duplicates. Definitely try the "--track-sleep 3" though. That will slow it way down, but may end up getting it to work.

linsomniac commented 8 months ago

Other calls to YTMusic were wrapped in retries with slowdown, but the create playlist call was not. I just pushed a code update that does that. That should help with @Vercety87 's problem, you may want to use a --track-sleep with it as well though.

Vercety87 commented 8 months ago

Thanks, just updated on my computer. Trying again with track-sleep, I'll let you know when it is done.

Vercety87 commented 8 months ago

Hi @linsomniac , got this error now :

`Playlist done!

Looking up playlist 'Test': id=None ERROR: (Retrying) maximum recursion depth exceeded in comparison in 5 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 10 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 20 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 40 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 80 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 160 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 320 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 640 seconds ERROR: (Retrying) maximum recursion depth exceeded in comparison in 1280 seconds`

This playlist had no title at the begining. I add one manually on the JSON, but now can't go futher because of the missing ID

linsomniac commented 8 months ago

I've pushed a new version that will give me some more diagnostics information. Please run it and let me know the output.

Vercety87 commented 8 months ago

Thank you, here the result :

output.txt

linsomniac commented 8 months ago

Ok, I think I've got it, thank you for that!

Vercety87 commented 8 months ago

Looks like it did the job.

Re run the script all night, ended up with an error this morning but as I already edited my playlist.json. I will redo the test from scratch today. Thanks.

@linsomniac it's all good. No more errors on my original playlist.json. Thanks