audible-cli icon indicating copy to clipboard operation
audible-cli copied to clipboard

Can't donwload files if title or subtitle is too long

Open vcalv opened this issue 1 year ago • 6 comments

I've just come across an audiobook where the filename for the aaxc file is well over the usual limit (256 bytes).

Most filesystems, and the linux internals, usually have a maximum length for a filename (full path).

The limit is usually 256 bytes.

Apparently it's not difficult for the automatically generated filename to exceed that.

Once that happens, every file operations fails with [Errno 36] File name too long.

This is a very low level error, not easy to circumvent.

two options here:

  • Truncate automatic filenames to a specifiable maximum length
  • Allow the user to specify the filename or template, either on the command line or config

As it stands there are definitely audiobooks not downloadable as of now.

Thank you.

vcalv avatar Dec 09 '24 20:12 vcalv

my pull request (https://github.com/mkb79/audible-cli/pull/216) implements truncating the base-filename at 230 bytes and adds --filename-mode asin_only which allows the user to use only the asin as the base-filename.

devvythelopper avatar Dec 14 '24 12:12 devvythelopper

@devvythelopper Thank you for your pr. It looks fine, but I will try it out first for drawbacks. My planned solution was to check the maximum name length like this solution. Now I have to decide, which way is the best.

mkb79 avatar Dec 14 '24 12:12 mkb79

The problem with the other solution is, that it might cut off the suffixes -annotations.json (and you'd have to code around that). Also depending on how you implemented writing to files, you might have to touch a multitude of places in your code.

The problem with my solution is, that it does not check for actual filesystem limits. I suppose one should add os.statvfs(file_parent_path).f_namemax to my solution and substract some 25 bytes (UTF-8 characters can take up to 4 bytes and most filesystems limit to number of bytes, not to number of characters).

devvythelopper avatar Dec 15 '24 14:12 devvythelopper

there is one drawback I've thought of btw:

say a user successfully has downloaded an audiobook that has a very long filename, say 235 bytes. Adding your extensions the filenames may be between 240 and 250 bytes. if we cut the filenames off now at 230, this audiobook will be redownloaded if the user specifies --all. What you could do to mitigate this is to not use 230 bytes but actually look at all your suffixes, and look which is the longest. Then take os.statvfs(file_parent_path).f_namemax - max_suffix_length as the byte length limit. Any book already successfully downloaded does not have a filename longer than this.

Or you leave my PR as it is now for simplicity's sake, and you'll be safe if in the future some longer suffixes might be added. I personally would leave it as it is now. It's good enough and users will adjust.

devvythelopper avatar Dec 16 '24 11:12 devvythelopper

I believe I’m experiencing the same issue.

Executing: .\audible\audible.exe --profile livia -v error download --overwrite --output-dir ".\assets\audiobooks\Harry Potter und der Orden des Phönix - Gesprochen von Rufus Beck - J.K. Rowling" --asin "B01M0PQY17" --aax-fallback --timeout 600 --pdf --cover --cover-size 900 --ignore-podcasts
Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_2_Harry_Potter_5-LC_128_44100_stereo.aax:   0%| | 0.00/60
Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_3_Harry_Potter_5-LC_128_44100_stereo.aax:   0%| | 0.00/61
Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_1_Harry_Potter_5-LC_128_44100_stereo.aax:   0%| | 0.00/61
error: [Errno 2] No such file or directory: 'C:\\Workspace\\Audible\\assets\\audiobooks\\Harry Potter und der Orden des Ph�nix - Gesprochen von Rufus Beck - J.K. Rowling\\Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_2_Harry_Potter_5-LC_128_44100_stereo.tmp' error: [Errno 2] No such file or directory: 'C:\\Workspace\\Audible\\assets\\audiobooks\\Harry Potter und der Orden des Ph�nix - Gesprochen von Rufus Beck - J.K. Rowling\\Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_3_Harry_Potter_5-LC_128_44100_stereo.tmp' error: [Errno 2] No such file or directory: 'C:\\Workspace\\Audible\\assets\\audiobooks\\Harry Potter und der Orden des Ph�nix - Gesprochen von Rufus Beck - J.K. Rowling\\Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_Harry_Potter_und_der_Orden_des_Phonix_-_Gesprochen_von_Rufus_Beck_-_Teil_1_Harry_Potter_5-LC_128_44100_stereo.tmp' The download ended with the following result: New cover files: 1

Given the length of the path, I suspect it might be causing the crash at some point. Having a solution for this would be greatly appreciated.

That said, the tool is amazing—I managed to download 244 books without any issues! Thank you so much for your hard work and effort in creating such an incredible tool!

rewisch avatar Jan 28 '25 11:01 rewisch

@mkb79 when will you merge this into the main branch (if at all?)... I'm still using my branch at this point...

devvythelopper avatar Mar 28 '25 16:03 devvythelopper