Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect path joining for UNC paths - Use direct full path to movie file from Radarr #2842

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

ThioJoe
Copy link

@ThioJoe ThioJoe commented Feb 3, 2025

Context

I was using the docker container and had to use path mapping, and couldn't get it to show any subtitle search results for any movies.

I have my video files on a NAS, so I have the paths looking like this in Sonarr/Radarr, where the files use a UNC path:
\\192.168.1.xxx\path\to\show\season\episode.mkv
\\192.168.1.xxx\path\to\WhateverMoviesFolder\movie.mkv

Non-Root Cause

Turns out that the file paths Bazarr was using after fetching the info from Radarr was not correct. For example, parsed_movie.path after escaping would end up being \\\\192.168.1.xxx\\path\\to\\WhateverMoviesFolder/movie.mkv (Note the forward slash).

And even after the path went through path_replace_movie or path_replace_reverse_movie, the incorrect slash in front of the file name was still there, and would cause the search to fail. Because in bazarr/subtitles/refinders/database.py, when this line compares the paths, the forward slash (which would appar in TableMovies.path but not path for some reason), would not match and cause it to fail to find what movie was being searched, therefore not ever getting any results.
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path))) \

Root Cause

In the parser that gets the movie info from the Radarr API (bazarr/radarr/sync/parser.py), even though Radarr was correctly returning the info in these two properties:

  • movie["path"]\\\\192.168.1.xxx\\path\\to\\WhateverMoviesFolder
  • movie['movieFile']['relativePath']movie.mkv

...Apparently os.path.join doesn't recognize the UNC path with the extra escaped slashes (or maybe it wouldn't recognize a UNC path regardless, not sure), and so this line ends up causing that incorrect path with the forward slash I mentioned above:
'path': os.path.join(movie["path"], movie['movieFile']['relativePath']),

You can see this here, I just added a Watch in VSCode on the after/before with the fix:

image

Solution (This pull request)

Fortunately the Radarr API also has a property that returns the complete path to the video file all in one, so we can use that instead of getting the separate parts and joining them, so we can do this:
movie['movieFile']['path']\\\\192.168.1.xxx\\path\\to\\WhateverMoviesFolder\\movie.mkv

(See the screenshot in the previous section for result)


Extra Note:

This appears to only be an issue with the info from Radarr, not Sonarr. parser.py for Sonarr already appears to use the equivalent to direct path so it already gets the correct full path:
'path': episode['episodeFile']['path'],

So there is even precedent for this pull request's change since that's how the Sonarr parser works.

Instead of os.path.join which incorrectly uses forward slash when combining UNC network path with the filename.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant