chazlarson / Media-Scripts

MIT License
114 stars 24 forks source link

Issue with Windows Character Naming Restrictions Causing Directory Skipping and Errors #39

Open DireKangaroo opened 7 months ago

DireKangaroo commented 7 months ago

I have an issue where media names on Plex containing restricted characters on Windows systems result in skipping creating those directories and triggering errors. The script continues to run in the background but no longer shows progress.

Example 1; Is a smart collection ending with ?

File "C:\Plex\Media-Scripts-main\Plex\grab-all-posters.py", line 1384, in <module>
    result = future.result() # blocks
             ^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Plex\Media-Scripts-main\Plex\grab-all-posters.py", line 655, in process_the_thing     
    p.mkdir(parents=True, exist_ok=True)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\pathlib.py", line 1116, in mkdir
    os.mkdir(self, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'assets\\Movies\\Collections\\What should I watch?'

Example 2; Normal plex collection with : in de middle of it:

File "C:\Plex\Media-Scripts-main\Plex\grab-all-posters.py", line 1384, in <module>
    result = future.result() # blocks
             ^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Plex\Media-Scripts-main\Plex\grab-all-posters.py", line 655, in process_the_thing     
    p.mkdir(parents=True, exist_ok=True)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\pathlib.py", line 1116, in mkdir
    os.mkdir(self, mode)
NotADirectoryError: [WinError 267] The directory name is invalid: 'assets\\Movies\\Collections\\Demon Slayer: Kimetsu no Yaiba Collection'

Impact: The presence of restricted Windows characters such as ?, *, <, >, |, ", and : in directory names causes to skip those, leading to incomplete processing of files. While the script continues execution, the skipped directories are not handled as intended.

I also have certain items on plex that contain a / such as the V/H/S Collection. For the movies themselves these are replaced by +, but multiple subdirectories are created for the collection itself.

Steps to Reproduce:

  1. Attempt to process directories with names containing restricted characters (?, *, <, >, |, ", :) using script on a Windows system.
  2. Observe the script skipping these directories and generating errors in the output or logs.

Proposed Solution In the arr applications, the : is replaced with -. It's possible that a similar approach could be implemented here. However, I'm uncertain about how pmm manages this, as I've only just begun with pmm.

chazlarson commented 4 months ago

I've made changes in this area; can you give this a try and see if it's still an issue? I have no Windows machines available to test.