bazarr icon indicating copy to clipboard operation
bazarr copied to clipboard

Incorrect Escape Sequence In File Paths for Radarr and Sonarr

Open Teagan42 opened this issue 4 months ago • 2 comments

Describe the bug Bazarr uses / to escape (space) in the folder name where media is stored. This appears to be due to these replace statements: https://github.com/morpheus65535/bazarr/blob/d6b74c908353c5051e188565e01b686a7017c3e9/bazarr/utilities/path_mappings.py#L49 https://github.com/morpheus65535/bazarr/blob/d6b74c908353c5051e188565e01b686a7017c3e9/bazarr/utilities/path_mappings.py#L67 https://github.com/morpheus65535/bazarr/blob/d6b74c908353c5051e188565e01b686a7017c3e9/bazarr/utilities/path_mappings.py#L85

                if path_mapping[1] in path:
                   path = path.replace(path_mapping[1], path_mapping[0])
                   if path.startswith('\\\\') or re.match(r'^[a-zA-Z]:\\', path):
                       path = path.replace('/', '\\')
                    elif path.startswith('/'):
                       path = path.replace('\\', '/')
                    break

We have the path mapping defined as /library/movies/ -> /movies/ /library/tv/ -> /tv/

This causes the interpreter to enter the if block. The path is then mutated to /movies/... or /tv/... and as the path mappings force tailing slashes, this ensures that the path now starts with /, causing the interpreter to enter the elif block. Python's str.replace(old, new) replaces all instances of old with new, so strings that were properly escaped are now "escaped" with the path delimiter /.

Bazarr now believes movies like The Big Short is in the folder /movies/The/ Big/ Short/.

Example: Path mapping in Bazarr: Radarr: /library/movies/ Bazarr: /movies/ image Sonarr: /library/tv/ Bazarr: /tv/ image

(Note: when I attempt to leave the trailing slash off, it will map /library/ to /)

Radarr has Road Trip path: /library/movies/Road\ Trip\ (2005)/ ![image](https://github.com/user-attachments/assets/eb8b76f8-111b-4b82-a633-e8880ec8797e) Bazarr imported path: /movies/Road/ Trip/ (2005)/` image

Radarr has Mary Poppins path: /library/movies/Mary\ Poppins\ (1964)/ ![image](https://github.com/user-attachments/assets/90b09fd3-38a5-4f28-9ace-8388b11a32aa) Bazarr imported path: /movies/Mary/ Poppins/ (1965)/` image

To Reproduce Steps to reproduce the behavior:

  1. Deploy Radarr or Sonarr with library mounts that contain the mounts defined in Bazarrr container
  2. Have media separated into folders by the title of the media, some of which contain spaces
  3. Create appropriate path mappings in the Radarr and Sonarr settings page
  4. Sync the libraries into Bazarr
  5. Go to a movie or tv show that contains spaces and search for subtitles
  6. See Error 500 File not found error image

Expected behavior Folders that are mapped between the services respect proper escape sequences for their platform

Screenshots Included above

Software (please complete the following information):

  • Bazarr: v1.4.5 (image: linuxserver/bazarr:1.4.5)
  • Radarr version 5.10.4.9218 (image: linuxserver/radarr:5.10.1)
  • Sonarr version 4.0.9.2386 (image: linuxserver/sonarr:4.0.9)
  • OS: Ubuntu 22.04

Additional context Add any other context about the problem here.

Teagan42 avatar Oct 12 '24 00:10 Teagan42