aome510 / spotify-player

A Spotify player in the terminal with full feature parity
MIT License
3.36k stars 146 forks source link

OS error: file name too long #506

Closed masoniis closed 1 month ago

masoniis commented 1 month ago

Describe the bug When playing a song from a playlist that contains very long authors or song name, spotify_player runs into problems attempting to save files that have names which exceed the (mac) OS length limit for writing.

To Reproduce On MacOS sonoma, play a song from an album such as this one. I did this on a separate chrome spotify client, before trying to launch the terminal. Now that the song is active, the terminal will produce this output:

$ spotify_player
Error: Failed to initialize the Spotify data

Caused by:
    File name too long (os error 63)

Expected behaviour The CLI doesn't attempt to write files which have names that exceed the mac limit. Perhaps they should be clipped, or encoded, etc.

Log and backtrace No backtrace necessary, (my backtrace is entirely empty, this is my first launch of spotify_player). Here is the relevant log context:

2024-07-14T17:17:50.192136Z  INFO spotify_player::streaming: Initializing a new integrated player with device_id=c563f912-f32a-42fe-b29e-b6c585ea8eda
2024-07-14T17:17:50.192260Z  INFO spotify_player::streaming: Starting an integrated Spotify player using librespot's spirc protocol
2024-07-14T17:17:50.542336Z  INFO spotify_player::client: Retrieving image from url: https://i.scdn.co/image/ab67616d0000b273bfd2db0a9adc1f642860d277
2024-07-14T17:17:50.714032Z  INFO spotify_player::client: Saving the retrieved image into /Users/user/.cache/spotify-player/image/Love Songs - Piano Transcriptions Without Words-Angela Hewitt, Franz Liszt, Robert Schumann, Franz Schubert, Richard Strauss, Christoph Willibald Gluck, Gottfried Heinrich Stölzel, Gustav Mahler, Edvard Grieg, Gabriel Fauré, Manuel de Falla, George Gershwin, Percy Grainger-cover.jpg

It's clear from above what is causing the long file error.

Environment

lodenrogue commented 1 month ago

It seems the max length for MacOS file names is 255 characters. [1]

Do all titles have a - before artist names? Maybe we can truncate there?

I think the main concern is having potential file name conflicts. I'm not familiar enough with this player to know how it handles this or whether that even matters.

[1] APFS: https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits

aome510 commented 1 month ago

Do all titles have a - before artist names? Maybe we can truncate there?

I think the main concern is having potential file name conflicts. I'm not familiar enough with this player to know how it handles this or whether that even matters.

Yeah, we can truncate and the main concern is file name conflict. One simple way to fix this issue to only include first artist's name instead of all artists.

thebrrt commented 1 month ago

It seems the max length for MacOS file names is 255 characters. [1]

Do all titles have a - before artist names? Maybe we can truncate there?

I think the main concern is having potential file name conflicts. I'm not familiar enough with this player to know how it handles this or whether that even matters.

[1] APFS: https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits

What about saving as some kind of UUID? I noticed someone mentioned this issue where they were thinking of using the album ID as a hash, but at that point, you might as well just use the album ID

If the concern is that it'd make it hard for users to look up songs in their files, maybe the solution is to include a command line argument that parses the files and returns the right file names? Maybe a local database to store the right file names and associate them with their IDs?

514