Fix numbering of already existing playlist files

This commit is contained in:
croneter 2018-09-23 16:03:50 +02:00
parent 5fabaf6a8e
commit c6e1a7029a
2 changed files with 7 additions and 8 deletions

View file

@ -5,6 +5,7 @@ Create and delete playlists on the Kodi side of things
""" """
from __future__ import absolute_import, division, unicode_literals from __future__ import absolute_import, division, unicode_literals
from logging import getLogger from logging import getLogger
import re
from .common import Playlist, PlaylistError from .common import Playlist, PlaylistError
from . import db, pms 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): def create(plex_id):
""" """
@ -43,18 +46,15 @@ def create(plex_id):
'%s.m3u' % name) '%s.m3u' % name)
while path_ops.exists(path) or db.get_playlist(path=path): while path_ops.exists(path) or db.get_playlist(path=path):
# In case the Plex playlist names are not unique # 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: if not occurance:
path = path_ops.path.join(v.PLAYLIST_PATH, path = path_ops.path.join(v.PLAYLIST_PATH,
playlist.kodi_type, playlist.kodi_type,
'%s_01.m3u' % name[:min(len(name), 248)]) '%s_01.m3u' % name[:min(len(name), 248)])
else: else:
occurance = int(occurance.group(1)) + 1 number = int(occurance.group(1)) + 1
path = path_ops.path.join(v.PLAYLIST_PATH, basename = re.sub(REGEX_FILE_NUMBERING, '', path)
playlist.kodi_type, path = '%s_%02d.m3u' % (basename, number)
'%s_%02d.m3u' % (name[:min(len(name),
248)],
occurance))
LOG.debug('Kodi playlist path: %s', path) LOG.debug('Kodi playlist path: %s', path)
playlist.kodi_path = path playlist.kodi_path = path
xml_playlist = pms.get_playlist(plex_id) xml_playlist = pms.get_playlist(plex_id)

View file

@ -38,7 +38,6 @@ REGEX_PLEX_ID = re.compile(r'''plex_id=(\d+)''')
# Return the numbers at the end of an url like '.../.../XXXX' # Return the numbers at the end of an url like '.../.../XXXX'
REGEX_END_DIGITS = re.compile(r'''/(.+)/(\d+)$''') REGEX_END_DIGITS = re.compile(r'''/(.+)/(\d+)$''')
REGEX_PLEX_DIRECT = re.compile(r'''\.plex\.direct:\d+$''') REGEX_PLEX_DIRECT = re.compile(r'''\.plex\.direct:\d+$''')
REGEX_FILE_NUMBERING = re.compile(r'''_(\d+)\.\w+$''')
# Plex API # Plex API
REGEX_IMDB = re.compile(r'''/(tt\d+)''') REGEX_IMDB = re.compile(r'''/(tt\d+)''')
REGEX_TVDB = re.compile(r'''thetvdb:\/\/(.+?)\?''') REGEX_TVDB = re.compile(r'''thetvdb:\/\/(.+?)\?''')