sdaqo / anipy-cli

Little tool in python to watch and download anime from the terminal (the better way to watch anime). Also applicable as an API
https://sdaqo.github.io/anipy-cli
GNU General Public License v3.0
263 stars 39 forks source link

Invalid Format for Directories #177

Closed yamiOnEstrogen closed 3 months ago

yamiOnEstrogen commented 3 months ago

Describe the bug Directories can not be created with some special characters in Linux, and other Operating Systems.

To Reproduce Steps to reproduce the behavior:

  1. Run the command anipi-cli --download --ffpmeg (--ffpmeg is not required)
  2. Search for D4DJ: First Mix
  3. See error

Expected behavior Program should automatically replace these characters with a replacer. For example _, -, etc

Info anipy-cli 3.1.2 using Python 3.10.12

Platform

sdaqo commented 3 months ago

Can you please give me the whole error. All characters shown here are valid linux file/path name characters, we already filter out the only invalid character '/'

yamiOnEstrogen commented 3 months ago

Of course!

***Download Mode***
Downloads are stored in: /media/d/Plex_2
? Search Anime: D4DJ First Mix
? Select Show: 1. YU: D4DJ: First Mix (S/D)
? Want to watch in dub? Yes
Hint: you can set a default in the config with `preferred_type`!
? Input Episode Range(s) from episodes 1 to 13: 1-13
> Downloading Episode 1 of D4DJ: First Mix (dub)
Traceback (most recent call last):
  File "/home/d/.local/bin/anipy-cli", line 8, in <module>
    sys.exit(run_cli())
  File "/home/d/.local/pipx/venvs/anipy-cli/lib/python3.10/site-packages/anipy_cli/cli.py", line 60, in run_cli
    cli_class(options=args).run()
  File "/home/d/.local/pipx/venvs/anipy-cli/lib/python3.10/site-packages/anipy_cli/clis/base_cli.py", line 31, in run
    ret = func()
  File "/home/d/.local/pipx/venvs/anipy-cli/lib/python3.10/site-packages/anipy_cli/clis/download_cli.py", line 97, in process
    downloader.download(
  File "/home/d/.local/pipx/venvs/anipy-cli/lib/python3.10/site-packages/anipy_api/download.py", line 274, in download
    download_path.parent.mkdir(parents=True, exist_ok=True)
  File "/usr/lib/python3.10/pathlib.py", line 1175, in mkdir
    self._accessor.mkdir(self, mode)
OSError: [Errno 22] Invalid argument: '/media/d/Plex_2/D4DJ: First Mix'
sdaqo commented 3 months ago

Does this only happen with this specific anime? Are you able to run mkdir '/media/d/Plex_2/D4DJ: First Mix'?

And, is /media/d/Plex_2 perhaps network storage or a ntfs filesystem? ":" is a invalid character on windows filesystems (well, sometimes it is, windows is a little weird), this may cause issues as you are running from a linux machine and the program only filters the windows characters out if you are on a windows machine.

yamiOnEstrogen commented 3 months ago

Are you able to run mkdir '/media/d/Plex_2/D4DJ: First Mix'?

No, I get the following error: mkdir: cannot create directory ‘D4DJ: First Mix’: Invalid argument

And, is /media/d/Plex_2 perhaps network storage or a ntfs filesystem?

Yes it is a ntfs, the only reason it is, because formatting into Fat32 or Ext4 will cause permission issues with Plex, with how it lives at /media

image

sdaqo commented 3 months ago

Ok so that is the problem. So I do not really want to implement code to detect a ntfs file system, because that is normally windows only. I could in theory also replace the bad characters on every system but some (linux) users might like to keep those in their filenames. I have two options for you:

  1. Convert to ext4 and fix permissions on your drive

I do not know if you already saw this plex forum post: https://forums.plex.tv/t/using-ext-ntfs-or-other-format-drives-internal-or-external-on-linux/198544

It says here:

F. Correct (set) Linux file permissions (ext4 drives only)

Drives are now mounted. Verify PMS can read them.
NTFS drives do not require permissions to be set for Linux because they use a different mechanism.
We will only address the ext4 formatted drive.

[chuck@lizum ~]$ su
Password:

# change the default permissions to owner='rwx', everyone else to 'r-x' 
#  'x' means to traverse the directory to subdirectories & files
[root@lizum chuck]# find /usb/media3 -type d -exec chmod 755 {} \;

# change the default permissions to owner= 'rw-',  everyone else 'r-only'
[root@lizum chuck]# find /usb/media3 -type f -exec chmod 644 {} \;

If you do not have a backup drive big enough you may want to get gparted and shrink the ntfs partition, convert empty space to a ext4 partition, copy some files over, shrink ntfs partition further and repeat that until all files are moved.

  1. Or you write yourself some script that replaces the bad characters and moves the files automatically Here is a list of disallowed characters for windows:
    < (less than)
    > (greater than)
    : (colon - sometimes works, but is actually NTFS Alternate Data Streams)
    " (double quote)
    / (forward slash)
    \ (backslash)
    | (vertical bar or pipe)
    ? (question mark)
    * (asterisk)

Also you may want to read this to know actually how bad the windows implementation is: https://stackoverflow.com/a/1976050/15207740 (maybe this convinces you to switch back to ext4 :)

yamiOnEstrogen commented 3 months ago

Hello! Thank you! I fixed the issue. I do have a suggestion.

On the OSError: [Errno 22] Invalid argument: (...) error show a error that states that the error could have been caused by a ntfs drive.

sdaqo commented 3 months ago

well you are right about that, I will look into it