diff --git a/resources/lib/playlists/kodi_pl.py b/resources/lib/playlists/kodi_pl.py index a2e01a20..ef654c25 100644 --- a/resources/lib/playlists/kodi_pl.py +++ b/resources/lib/playlists/kodi_pl.py @@ -5,6 +5,7 @@ Create and delete playlists on the Kodi side of things """ from __future__ import absolute_import, division, unicode_literals from logging import getLogger +import re from .common import Playlist, PlaylistError from . import db, pms @@ -16,6 +17,8 @@ LOG = getLogger('PLEX.playlists.kodi_pl') ############################################################################### +REGEX_FILE_NUMBERING = re.compile(r'''_(\d+)\.\w+$''') + def create(plex_id): """ @@ -43,18 +46,15 @@ def create(plex_id): '%s.m3u' % name) while path_ops.exists(path) or db.get_playlist(path=path): # In case the Plex playlist names are not unique - occurance = utils.REGEX_FILE_NUMBERING.search(path) + occurance = REGEX_FILE_NUMBERING.search(path) if not occurance: path = path_ops.path.join(v.PLAYLIST_PATH, playlist.kodi_type, '%s_01.m3u' % name[:min(len(name), 248)]) else: - occurance = int(occurance.group(1)) + 1 - path = path_ops.path.join(v.PLAYLIST_PATH, - playlist.kodi_type, - '%s_%02d.m3u' % (name[:min(len(name), - 248)], - occurance)) + number = int(occurance.group(1)) + 1 + basename = re.sub(REGEX_FILE_NUMBERING, '', path) + path = '%s_%02d.m3u' % (basename, number) LOG.debug('Kodi playlist path: %s', path) playlist.kodi_path = path xml_playlist = pms.get_playlist(plex_id) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index f22b9876..62bd4f4a 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -38,7 +38,6 @@ REGEX_PLEX_ID = re.compile(r'''plex_id=(\d+)''') # Return the numbers at the end of an url like '.../.../XXXX' REGEX_END_DIGITS = re.compile(r'''/(.+)/(\d+)$''') REGEX_PLEX_DIRECT = re.compile(r'''\.plex\.direct:\d+$''') -REGEX_FILE_NUMBERING = re.compile(r'''_(\d+)\.\w+$''') # Plex API REGEX_IMDB = re.compile(r'''/(tt\d+)''') REGEX_TVDB = re.compile(r'''thetvdb:\/\/(.+?)\?''')