Allow to only sync specific Plex or Kodi playlists
This commit is contained in:
parent
016208f18f
commit
1eed16dd52
6 changed files with 95 additions and 11 deletions
|
@ -113,11 +113,21 @@ msgctxt "#30020"
|
||||||
msgid "Sync Plex playlists"
|
msgid "Sync Plex playlists"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
# PKC settings sync options
|
||||||
|
msgctxt "#30021"
|
||||||
|
msgid "Only sync specific Plex playlists to Kodi"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
# PKC settings category
|
# PKC settings category
|
||||||
msgctxt "#30022"
|
msgctxt "#30022"
|
||||||
msgid "Advanced"
|
msgid "Advanced"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
# PKC settings sync options
|
||||||
|
msgctxt "#30023"
|
||||||
|
msgid "Only sync specific Kodi playlists to Plex"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgctxt "#30024"
|
msgctxt "#30024"
|
||||||
msgid "Username"
|
msgid "Username"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -126,6 +136,16 @@ msgctxt "#30025"
|
||||||
msgid "Display message if PMS goes offline"
|
msgid "Display message if PMS goes offline"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
# PKC settings sync options
|
||||||
|
msgctxt "#30026"
|
||||||
|
msgid "Prefix in Plex playlist name to trigger sync"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
# PKC settings sync options
|
||||||
|
msgctxt "#30027"
|
||||||
|
msgid "Prefix in Kodi playlist name to trigger sync"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgctxt "#30030"
|
msgctxt "#30030"
|
||||||
msgid "Port Number"
|
msgid "Port Number"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -48,7 +48,9 @@ STATE_SETTINGS = {
|
||||||
'forceReloadSkinOnPlaybackStop': 'FORCE_RELOAD_SKIN',
|
'forceReloadSkinOnPlaybackStop': 'FORCE_RELOAD_SKIN',
|
||||||
'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER',
|
'fetch_pms_item_number': 'FETCH_PMS_ITEM_NUMBER',
|
||||||
'imageSyncNotifications': 'IMAGE_SYNC_NOTIFICATIONS',
|
'imageSyncNotifications': 'IMAGE_SYNC_NOTIFICATIONS',
|
||||||
'enablePlaylistSync': 'SYNC_PLAYLISTS'
|
'enablePlaylistSync': 'SYNC_PLAYLISTS',
|
||||||
|
'syncSpecificPlexPlaylists': 'SYNC_SPECIFIC_PLEX_PLAYLISTS',
|
||||||
|
'syncSpecificKodiPlaylists': 'SYNC_SPECIFIC_KODI_PLAYLISTS'
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -63,8 +63,16 @@ def delete_plex_playlist(playlist):
|
||||||
entry in the Plex playlist table.
|
entry in the Plex playlist table.
|
||||||
Returns None or raises PL.PlaylistError
|
Returns None or raises PL.PlaylistError
|
||||||
"""
|
"""
|
||||||
LOG.debug('Deleting playlist from PMS: %s', playlist)
|
if (state.SYNC_SPECIFIC_KODI_PLAYLISTS and
|
||||||
PL.delete_playlist_from_pms(playlist)
|
not sync_kodi_playlist(playlist.kodi_path)):
|
||||||
|
# We might have already synced this playlist BEFORE user chose to only
|
||||||
|
# sync specific playlists. Let's NOT delete all those playlists.
|
||||||
|
# However, delete it from our database of synced playlists.
|
||||||
|
LOG.debug('Not deleting playlist since user chose not to sync: %s',
|
||||||
|
playlist)
|
||||||
|
else:
|
||||||
|
LOG.debug('Deleting playlist from PMS: %s', playlist)
|
||||||
|
PL.delete_playlist_from_pms(playlist)
|
||||||
update_plex_table(playlist, delete=True)
|
update_plex_table(playlist, delete=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,12 +84,20 @@ def create_kodi_playlist(plex_id=None, updated_at=None):
|
||||||
created in any case (not replaced). Thus make sure that the "same" playlist
|
created in any case (not replaced). Thus make sure that the "same" playlist
|
||||||
is deleted from both disk and the Plex database.
|
is deleted from both disk and the Plex database.
|
||||||
Returns the playlist or raises PL.PlaylistError
|
Returns the playlist or raises PL.PlaylistError
|
||||||
|
|
||||||
|
Be aware that user settings will be checked whether this Plex playlist
|
||||||
|
should actually indeed be synced
|
||||||
"""
|
"""
|
||||||
xml = PL.get_PMS_playlist(PL.Playlist_Object(), playlist_id=plex_id)
|
xml = PL.get_PMS_playlist(PL.Playlist_Object(), playlist_id=plex_id)
|
||||||
if xml is None:
|
if xml is None:
|
||||||
LOG.error('Could not get Plex playlist %s', plex_id)
|
LOG.error('Could not get Plex playlist %s', plex_id)
|
||||||
raise PL.PlaylistError('Could not get Plex playlist %s' % plex_id)
|
raise PL.PlaylistError('Could not get Plex playlist %s' % plex_id)
|
||||||
api = API(xml)
|
api = API(xml)
|
||||||
|
if state.SYNC_SPECIFIC_PLEX_PLAYLISTS:
|
||||||
|
prefix = utils.settings('syncSpecificPlexPlaylistsPrefix')
|
||||||
|
if api.title() and not api.title().startswith(prefix):
|
||||||
|
LOG.debug('User chose to not sync playlist %s', api.title())
|
||||||
|
return
|
||||||
playlist = PL.Playlist_Object()
|
playlist = PL.Playlist_Object()
|
||||||
playlist.id = api.plex_id()
|
playlist.id = api.plex_id()
|
||||||
playlist.type = v.KODI_PLAYLIST_TYPE_FROM_PLEX[api.playlist_type()]
|
playlist.type = v.KODI_PLAYLIST_TYPE_FROM_PLEX[api.playlist_type()]
|
||||||
|
@ -122,14 +138,17 @@ def delete_kodi_playlist(playlist):
|
||||||
the Plex playlist table.
|
the Plex playlist table.
|
||||||
Returns None or raises PL.PlaylistError
|
Returns None or raises PL.PlaylistError
|
||||||
"""
|
"""
|
||||||
try:
|
if not sync_kodi_playlist(playlist.kodi_path):
|
||||||
path_ops.remove(playlist.kodi_path)
|
LOG.debug('Do not delete since we should not sync playlist %s',
|
||||||
except (OSError, IOError) as err:
|
playlist)
|
||||||
LOG.error('Could not delete Kodi playlist file %s. Error:\n %s: %s',
|
|
||||||
playlist, err.errno, err.strerror)
|
|
||||||
raise PL.PlaylistError('Could not delete %s' % playlist.kodi_path)
|
|
||||||
else:
|
else:
|
||||||
update_plex_table(playlist, delete=True)
|
try:
|
||||||
|
path_ops.remove(playlist.kodi_path)
|
||||||
|
except (OSError, IOError) as err:
|
||||||
|
LOG.error('Could not delete Kodi playlist file %s. Error:\n%s: %s',
|
||||||
|
playlist, err.errno, err.strerror)
|
||||||
|
raise PL.PlaylistError('Could not delete %s' % playlist.kodi_path)
|
||||||
|
update_plex_table(playlist, delete=True)
|
||||||
|
|
||||||
|
|
||||||
def update_plex_table(playlist, delete=False):
|
def update_plex_table(playlist, delete=False):
|
||||||
|
@ -382,6 +401,8 @@ def _full_sync():
|
||||||
if extension not in SUPPORTED_FILETYPES:
|
if extension not in SUPPORTED_FILETYPES:
|
||||||
continue
|
continue
|
||||||
path = path_ops.path.join(root, file)
|
path = path_ops.path.join(root, file)
|
||||||
|
if not sync_kodi_playlist(path):
|
||||||
|
continue
|
||||||
kodi_hash = utils.generate_file_md5(path)
|
kodi_hash = utils.generate_file_md5(path)
|
||||||
playlist = playlist_object_from_db(kodi_hash=kodi_hash)
|
playlist = playlist_object_from_db(kodi_hash=kodi_hash)
|
||||||
playlist_2 = playlist_object_from_db(path=path)
|
playlist_2 = playlist_object_from_db(path=path)
|
||||||
|
@ -417,6 +438,25 @@ def _full_sync():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def sync_kodi_playlist(path):
|
||||||
|
"""
|
||||||
|
Returns True if we should sync this Kodi playlist with path [unicode] to
|
||||||
|
Plex based on the playlist file name and the user settings, False otherwise
|
||||||
|
"""
|
||||||
|
if not state.SYNC_SPECIFIC_KODI_PLAYLISTS:
|
||||||
|
return True
|
||||||
|
playlist = PL.Playlist_Object()
|
||||||
|
try:
|
||||||
|
playlist.kodi_path = path
|
||||||
|
except PL.PlaylistError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
prefix = utils.settings('syncSpecificKodiPlaylistsPrefix')
|
||||||
|
if playlist.kodi_filename.startswith(prefix):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class PlaylistEventhandler(FileSystemEventHandler):
|
class PlaylistEventhandler(FileSystemEventHandler):
|
||||||
"""
|
"""
|
||||||
PKC eventhandler to monitor Kodi playlists safed to disk
|
PKC eventhandler to monitor Kodi playlists safed to disk
|
||||||
|
@ -444,6 +484,10 @@ class PlaylistEventhandler(FileSystemEventHandler):
|
||||||
if (not state.ENABLE_MUSIC and
|
if (not state.ENABLE_MUSIC and
|
||||||
event.src_path.startswith(v.PLAYLIST_PATH_MUSIC)):
|
event.src_path.startswith(v.PLAYLIST_PATH_MUSIC)):
|
||||||
return
|
return
|
||||||
|
path = event.dest_path if event.event_type == EVENT_TYPE_MOVED \
|
||||||
|
else event.src_path
|
||||||
|
if not sync_kodi_playlist(path):
|
||||||
|
return
|
||||||
_method_map = {
|
_method_map = {
|
||||||
EVENT_TYPE_MODIFIED: self.on_modified,
|
EVENT_TYPE_MODIFIED: self.on_modified,
|
||||||
EVENT_TYPE_MOVED: self.on_moved,
|
EVENT_TYPE_MOVED: self.on_moved,
|
||||||
|
|
|
@ -57,6 +57,14 @@ class Service():
|
||||||
utils.settings('syncThreadNumber'))
|
utils.settings('syncThreadNumber'))
|
||||||
LOG.info('Playlist m3u encoding: %s', v.M3U_ENCODING)
|
LOG.info('Playlist m3u encoding: %s', v.M3U_ENCODING)
|
||||||
LOG.info("Full sys.argv received: %s", sys.argv)
|
LOG.info("Full sys.argv received: %s", sys.argv)
|
||||||
|
LOG.info('Synching only specific Kodi playlists: %s',
|
||||||
|
utils.settings('syncSpecificKodiPlaylists') == 'true')
|
||||||
|
LOG.info('Kodi playlist prefix: %s',
|
||||||
|
utils.settings('syncSpecificKodiPlaylistsPrefix'))
|
||||||
|
LOG.info('Synching only specific Plex playlists: %s',
|
||||||
|
utils.settings('syncSpecificPlexPlaylistsPrefix') == 'true')
|
||||||
|
LOG.info('Play playlist prefix: %s',
|
||||||
|
utils.settings('syncSpecificPlexPlaylistsPrefix'))
|
||||||
self.monitor = xbmc.Monitor()
|
self.monitor = xbmc.Monitor()
|
||||||
# Load/Reset PKC entirely - important for user/Kodi profile switch
|
# Load/Reset PKC entirely - important for user/Kodi profile switch
|
||||||
initialsetup.reload_pkc()
|
initialsetup.reload_pkc()
|
||||||
|
|
|
@ -55,6 +55,10 @@ SYNC_DIALOG = True
|
||||||
IMAGE_SYNC_NOTIFICATIONS = True
|
IMAGE_SYNC_NOTIFICATIONS = True
|
||||||
# Sync playlists from Plex to Kodi and vice-versa?
|
# Sync playlists from Plex to Kodi and vice-versa?
|
||||||
SYNC_PLAYLISTS = True
|
SYNC_PLAYLISTS = True
|
||||||
|
# Only sync specific Plex playlists to Kodi?
|
||||||
|
SYNC_SPECIFIC_PLEX_PLAYLISTS = False
|
||||||
|
# Only sync specific Kodi playlists to Plex?
|
||||||
|
SYNC_SPECIFIC_KODI_PLAYLISTS = False
|
||||||
# Is synching of Plex music enabled?
|
# Is synching of Plex music enabled?
|
||||||
ENABLE_MUSIC = True
|
ENABLE_MUSIC = True
|
||||||
# How often shall we sync?
|
# How often shall we sync?
|
||||||
|
|
|
@ -57,12 +57,18 @@
|
||||||
<category label="30506"><!-- Sync Options -->
|
<category label="30506"><!-- Sync Options -->
|
||||||
<setting type="lsep" label="30537" /><!-- Restart if you make changes -->
|
<setting type="lsep" label="30537" /><!-- Restart if you make changes -->
|
||||||
<setting type="sep" />
|
<setting type="sep" />
|
||||||
<setting id="enablePlaylistSync" type="bool" label="30020" default="true" visible="true"/><!-- Sync Plex playlists -->
|
|
||||||
<setting id="fullSyncInterval" type="number" label="39053" default="60" option="int" />
|
<setting id="fullSyncInterval" type="number" label="39053" default="60" option="int" />
|
||||||
<setting id="dbSyncScreensaver" type="bool" label="39062" default="false" /><!--Sync when screensaver is deactivated-->
|
<setting id="dbSyncScreensaver" type="bool" label="39062" default="false" /><!--Sync when screensaver is deactivated-->
|
||||||
<setting id="dbSyncIndicator" label="30507" type="bool" default="true" /><!-- show syncing progress -->
|
<setting id="dbSyncIndicator" label="30507" type="bool" default="true" /><!-- show syncing progress -->
|
||||||
<setting id="syncThreadNumber" type="slider" label="39003" default="10" option="int" range="1,1,20"/><!-- Number of simultaneous download threads -->
|
<setting id="syncThreadNumber" type="slider" label="39003" default="10" option="int" range="1,1,20"/><!-- Number of simultaneous download threads -->
|
||||||
<setting id="limitindex" type="number" label="30515" default="200" option="int" /><!-- Maximum items to request from the server at once -->
|
<setting id="limitindex" type="number" label="30515" default="200" option="int" /><!-- Maximum items to request from the server at once -->
|
||||||
|
<setting type="lsep" label="$LOCALIZE[136]" /><!-- Playlists -->
|
||||||
|
<setting type="sep" />
|
||||||
|
<setting id="enablePlaylistSync" type="bool" label="30020" default="true" visible="true"/><!-- Sync Plex playlists -->
|
||||||
|
<setting id="syncSpecificKodiPlaylists" type="bool" label="30023" default="false" visible="true"/><!-- Only sync specific Kodi playlists to Plex -->
|
||||||
|
<setting id="syncSpecificKodiPlaylistsPrefix" type="text" label="30027" default="sync_" visible="eq(-1,true)"/><!-- Prefix in Kodi playlist name to trigger sync -->
|
||||||
|
<setting id="syncSpecificPlexPlaylists" type="bool" label="30021" default="false" visible="true"/><!-- Only sync specific Plex playlists to Kodi -->
|
||||||
|
<setting id="syncSpecificPlexPlaylistsPrefix" type="text" label="30026" default="sync_" visible="eq(-1,true)" /><!-- Prefix in Plex playlist name to trigger sync -->
|
||||||
<setting type="sep" />
|
<setting type="sep" />
|
||||||
<setting type="lsep" label="39052" /><!-- Background Sync -->
|
<setting type="lsep" label="39052" /><!-- Background Sync -->
|
||||||
<setting id="enableBackgroundSync" type="bool" label="39026" default="true" visible="true"/>
|
<setting id="enableBackgroundSync" type="bool" label="39026" default="true" visible="true"/>
|
||||||
|
|
Loading…
Reference in a new issue