Fix incorrect path joining for UNC paths - Use direct full path to movie file from Radarr #2842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orpath_replace_reverse_movie
, the incorrect slash in front of the file name was still there, and would cause the search to fail. Because inbazarr/subtitles/refinders/database.py
, when this line compares the paths, the forward slash (which would appar inTableMovies.path
but notpath
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:
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.