From 23ac39a8606a15e7987ca0a366b17d536e878217 Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 31 Jan 2020 21:07:27 +0100 Subject: [PATCH] Fix DirectPaths when a video's folder name is identical to a video's filename (you will need to manually reset the Kodi database) --- resources/lib/itemtypes/movies.py | 4 ++-- resources/lib/itemtypes/music.py | 4 ++-- resources/lib/itemtypes/tvshows.py | 4 ++-- resources/lib/utils.py | 9 +++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/resources/lib/itemtypes/movies.py b/resources/lib/itemtypes/movies.py index 8f6f0263..971da6e6 100644 --- a/resources/lib/itemtypes/movies.py +++ b/resources/lib/itemtypes/movies.py @@ -5,7 +5,7 @@ from logging import getLogger from .common import ItemBase from ..plex_api import API -from .. import app, variables as v, plex_functions as PF +from .. import app, variables as v, plex_functions as PF, utils LOG = getLogger('PLEX.movies') @@ -54,7 +54,7 @@ class Movie(ItemBase): else: # Network share filename = playurl.rsplit("/", 1)[1] - path = playurl.replace(filename, "") + path = utils.rreplace(playurl, filename, "", 1) kodi_pathid = self.kodidb.add_path(path, content='movies', scraper='metadata.local') diff --git a/resources/lib/itemtypes/music.py b/resources/lib/itemtypes/music.py index f609829a..15b98bfa 100644 --- a/resources/lib/itemtypes/music.py +++ b/resources/lib/itemtypes/music.py @@ -7,7 +7,7 @@ from .common import ItemBase from ..plex_api import API from ..plex_db import PlexDB, PLEXDB_LOCK from ..kodi_db import KodiMusicDB, KODIDB_LOCK -from .. import plex_functions as PF, db, timing, app, variables as v +from .. import plex_functions as PF, db, timing, app, variables as v, utils LOG = getLogger('PLEX.music') @@ -539,7 +539,7 @@ class Song(MusicMixin, ItemBase): else: # Network share filename = playurl.rsplit("/", 1)[1] - path = playurl.replace(filename, "") + path = utils.rreplace(playurl, filename, "", 1) if do_indirect: # Plex works a bit differently path = "%s%s" % (app.CONN.server, xml[0][0].get('key')) diff --git a/resources/lib/itemtypes/tvshows.py b/resources/lib/itemtypes/tvshows.py index 4a61091d..50c25e49 100644 --- a/resources/lib/itemtypes/tvshows.py +++ b/resources/lib/itemtypes/tvshows.py @@ -5,7 +5,7 @@ from logging import getLogger from .common import ItemBase, process_path from ..plex_api import API -from .. import plex_functions as PF, app, variables as v +from .. import plex_functions as PF, app, variables as v, utils LOG = getLogger('PLEX.tvshows') @@ -434,7 +434,7 @@ class Episode(TvShowMixin, ItemBase): else: # Network share filename = playurl.rsplit("/", 1)[1] - path = playurl.replace(filename, "") + path = utils.rreplace(playurl, filename, "", 1) parent_path_id = self.kodidb.parent_path_id(path) kodi_pathid = self.kodidb.add_path(path, id_parent_path=parent_path_id) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 3bf26dc2..2da4a378 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -249,6 +249,15 @@ def ERROR(txt='', hide_tb=False, notify=False, cancel_sync=False): return short +def rreplace(s, old, new, occurrence=-1): + """ + Replaces the string old [str, unicode] with new from the RIGHT given a + string s. + """ + li = s.rsplit(old, occurrence) + return new.join(li) + + class AttributeDict(dict): """ Turns an etree xml response's xml.attrib into an object with attributes