diff --git a/resources/lib/kodi_db/__init__.py b/resources/lib/kodi_db/__init__.py index 4778d422..70e79bf9 100644 --- a/resources/lib/kodi_db/__init__.py +++ b/resources/lib/kodi_db/__init__.py @@ -22,12 +22,9 @@ def kodiid_from_filename(path, kodi_type=None, db_type=None): """ kodi_id = None path = utils.try_decode(path) - try: - filename = path.rsplit('/', 1)[1] - path = path.rsplit('/', 1)[0] + '/' - except IndexError: - filename = path.rsplit('\\', 1)[1] - path = path.rsplit('\\', 1)[0] + '\\' + path, filename = path_ops.path.split(path) + # Make sure path ends in either '/' or '\' + path = path_ops.path.join(path, '') if kodi_type == v.KODI_TYPE_SONG or db_type == 'music': with KodiMusicDB(lock=False) as kodidb: try: diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index a76d6529..96fd6cfd 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -372,19 +372,15 @@ def verify_kodi_item(plex_id, kodi_item): raise PlaylistError LOG.debug('Starting research for Kodi id since we didnt get one: %s', kodi_item) - kodi_id, _ = kodiid_from_filename(kodi_item['file'], - v.KODI_TYPE_MOVIE) - kodi_item['type'] = v.KODI_TYPE_MOVIE - if kodi_id is None: - kodi_id, _ = kodiid_from_filename(kodi_item['file'], - v.KODI_TYPE_EPISODE) - kodi_item['type'] = v.KODI_TYPE_EPISODE - if kodi_id is None: - kodi_id, _ = kodiid_from_filename(kodi_item['file'], - v.KODI_TYPE_SONG) - kodi_item['type'] = v.KODI_TYPE_SONG + # Try the VIDEO DB first - will find both movies and episodes + kodi_id, kodi_type = kodiid_from_filename(kodi_item['file'], + db_type='video') + if not kodi_id: + # No movie or episode found - try MUSIC DB now for songs + kodi_id, kodi_type = kodiid_from_filename(kodi_item['file'], + db_type='music') kodi_item['id'] = kodi_id - kodi_item['type'] = None if kodi_id is None else kodi_item['type'] + kodi_item['type'] = None if kodi_id is None else kodi_type LOG.debug('Research results for kodi_item: %s', kodi_item) return kodi_item