From 32ddb6cb7803d51c6862eea676f280673b6c8c8e Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Wed, 16 Mar 2016 12:26:31 +0100 Subject: [PATCH] Custom smb path substitutions for direct paths --- README.md | 3 +- resources/language/English/strings.xml | 13 +++++- resources/language/German/strings.xml | 14 ++++++- resources/lib/initialsetup.py | 26 ++++++++++-- resources/lib/itemtypes.py | 57 ++++++++++++++++---------- resources/lib/userclient.py | 16 +++++++- resources/settings.xml | 8 ++++ 7 files changed, 107 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 36507321..b8f43358 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ Currently these features are working: **Known Issues:** - **Plex Music:** You must have a static IP address for your Plex media server if you plan to use Plex Music features. This is due to the way Kodi works and cannot be helped. --**Plex updates:** PlexKodiConnect continuously polls the Plex Media Server for changes. If something on the PMS has changed, this change is synced to Kodi. Hence if you rescan your entire library, a long PlexKodiConnect re-sync is triggered. +- **Plex updates:** PlexKodiConnect continuously polls the Plex Media Server for changes. If something on the PMS has changed, this change is synced to Kodi. Hence if you rescan your entire library, a long PlexKodiConnect re-sync is triggered. +- **Direct Paths:** If you use direct paths, your sync will be slower **What could be in the pipeline?** - Watch Later diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 30b1fe8b..9527dbcc 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -375,9 +375,18 @@ Add network credentials to allow Kodi access to your content? Note: Skipping this step may generate a message during the initial scan of your content if Kodi can't locate your content. Kodi can't locate file: Please verify the path. You may need to verify your network credentials in the add-on settings or use different Plex paths. Stop syncing? - Shall we transform Plex paths from e.g. \\myNas\mymovie.mkv to smb://myNas/mymovie.mkv? (recommended) - Replace Plex paths \\myNas with SMB paths smb://myNas + Transform Plex UNC library paths \\myNas\mymovie.mkv automatically to smb paths, smb://myNas/mymovie.mkv? (recommended) + Replace Plex UNC paths \\myNas with smb://myNas + Replace Plex paths /volume1/media or \\myserver\media with custom SMB paths smb://NAS/mystuff + Original Plex MOVIE path to replace: + Replace Plex MOVIE with: + Original Plex TV SHOWS path to replace: + Replace Plex TV SHOWS with: + Original Plex MUSIC path to replace: + Replace Plex MUSIC with: + Go a step further and complete replace all original Plex library paths (/volume1/media) with custom SMB paths (smb://NAS/MyStuff)? + Please enter your custom smb paths in the settings under "Sync Options" and then restart Kodi Switch Plex Home User diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index 8ee6ba0f..009e9279 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -311,8 +311,18 @@ Möchten Sie nun Netzwerk Zugangsdaten eingeben? Wenn Sie diesen Schritt überspringen, wird möglicherweise die Synchronisierung Ihrer Bibliothek fehlschlagen, wenn Kodi nicht auf Ihre Medien zugreifen kann. Kodi kann die folgende Datei nicht finden: Bitte verifizieren Sie den Pfad. Möglichweise müssen Sie in den Addon Einstellungen die Netzwerk Zugangsdaten korrekt eingeben, oder Plex muss andere Pfade nutzen. Soll Sync gestoppt werden? - Sollen alle Plex Pfade \\meinNAS\meinFilm.mkv durch smb://meinNAS/meinFilm.mkv ersetzt werden? (empfohlen) - Plex Pfade \\meinNAS durch SMB Pfade smb://meinNAS ersetzen + Sollen alle Plex UNC Pfade \\meinNAS\meinFilm.mkv automatisch durch SMB Pfade smb://meinNAS/meinFilm.mkv ersetzt werden? (empfohlen) + Plex UNC Pfade \\meinNAS durch smb://meinNAS ersetzen + + Benutzerdefinierte smb Pfade für z.B. /volume1/media erstellen + Ursprünglicher Plex Pfad für FILME: + Plex FILM Pfade ersetzen durch: + Ursprünglicher Plex Pfad für TV SERIEN: + Plex TV SERIEN Pfade ersetzen durch: + Ursprünglicher Plex Pfad für MUSIK: + Plex MUSIK Pfade ersetzen durch: + Sollen sogar sämtliche Plex Pfade wie /volume1/Hans/medien durch benutzerdefinierte smb Pfade wie smb://NAS/Filme ersetzt werden? + Bitte geben Sie Ihre benutzerdefinierten SMB Pfade nun in den Einstellungen unter Sync Optionen ein. Starten Sie dann Kodi neu. Plex Home Benutzer wechseln diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 29270369..a61f0194 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -234,6 +234,7 @@ class InitialSetup(): if forcePlexTV: return + goToSettings = False # Direct paths (\\NAS\mymovie.mkv) or addon (http)? if dialog.yesno(heading=self.addonName, line1=string(39027), @@ -247,6 +248,21 @@ class InitialSetup(): if dialog.yesno(heading=self.addonName, line1=string(39033)): self.logMsg("User chose to replace paths with smb", 1) + else: + utils.settings('replaceSMB', value="false") + + # complete replace all original Plex library paths with custom SMB + if dialog.yesno(heading=self.addonName, + line1=string(39043)): + self.logMsg("User chose custom smb paths", 1) + utils.settings('remapSMB', value="true") + # Please enter your custom smb paths in the settings under + # "Sync Options" and then restart Kodi + dialog.ok(heading=self.addonName, + line1=string(39044)) + goToSettings = True + # Don't start anything because we need these paths first! + utils.window('emby_serverStatus', value="Stop") # Go to network credentials? if dialog.yesno(heading=self.addonName, @@ -260,8 +276,12 @@ class InitialSetup(): self.logMsg("User opted to disable Plex music library.", 1) utils.settings('enableMusic', value="false") - # Open Settings page now? - if dialog.yesno(heading=self.addonName, - line1=string(39017)): + if goToSettings: xbmc.executebuiltin( 'Addon.OpenSettings(plugin.video.plexkodiconnect)') + else: + # Open Settings page now? + if dialog.yesno(heading=self.addonName, + line1=string(39017)): + xbmc.executebuiltin( + 'Addon.OpenSettings(plugin.video.plexkodiconnect)') diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index cce00347..a4ebdddf 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -41,6 +41,8 @@ class Items(object): else False self.replaceSMB = True if utils.window('replaceSMB') == 'true' \ else False + self.remapSMB = True if utils.window('remapSMB') == 'true' \ + else False # self.music_enabled = utils.settings('enableMusic') == "true" # self.contentmsg = utils.settings('newContent') == "true" @@ -88,6 +90,28 @@ class Items(object): line2=string(39032)) return resp + def validatePlayurl(self, playurl, typus): + """ + If False is returned, itemtypes should return with False (stop sync) + + typus: 'movie', 'tv', 'music' + """ + if self.remapSMB: + playurl = playurl.replace(utils.window('remapSMB%sOrg' % typus), + utils.window('remapSMB%sNew' % typus)) + # There might be backslashes left over: + playurl = playurl.replace('\\', '/') + elif self.replaceSMB: + if playurl.startswith('\\\\'): + playurl = 'smb:' + playurl.replace('\\', '/') + if (utils.window('emby_pathverified') != "true" and + not xbmcvfs.exists(playurl.encode('utf-8'))): + # Validate the path is correct with user intervention + if self.askToValidate(playurl): + utils.window('emby_shouldStop', value="true") + playurl = False + return playurl + def itemsbyId(self, items, process, pdialog=None): # Process items by itemid. Process can be added, update, userdata, remove emby = self.emby @@ -423,16 +447,9 @@ class Movies(Items): # Something went wrong, trying to use non-direct paths doIndirect = True else: - if self.replaceSMB: - if playurl.startswith('\\\\'): - playurl = playurl.replace('\\', '/') - playurl = 'smb:' + playurl - if (utils.window('emby_pathverified') != "true" and - not xbmcvfs.exists(playurl.encode('utf-8'))): - # Validate the path is correct with user intervention - if self.askToValidate(playurl): - utils.window('emby_shouldStop', value="true") - return False + playurl = self.validatePlayurl(playurl, 'movie') + if playurl is False: + return False if "\\" in playurl: # Local path filename = playurl.rsplit("\\", 1)[1] @@ -1037,10 +1054,9 @@ class TVShows(Items): # Something went wrong, trying to use non-direct paths doIndirect = True else: - if self.replaceSMB: - if playurl.startswith('\\\\'): - playurl = playurl.replace('\\', '/') - playurl = 'smb:' + playurl + playurl = self.validatePlayurl(playurl, 'tv') + if playurl is False: + return False if "\\" in playurl: # Local path path = "%s\\" % playurl @@ -1341,10 +1357,9 @@ class TVShows(Items): # Something went wrong, trying to use non-direct paths doIndirect = True else: - if self.replaceSMB: - if playurl.startswith('\\\\'): - playurl = playurl.replace('\\', '/') - playurl = 'smb:' + playurl + playurl = self.validatePlayurl(playurl, 'tv') + if playurl is False: + return False if (utils.window('emby_pathverified') != "true" and not xbmcvfs.exists(playurl.encode('utf-8'))): # Validate the path is correct with user intervention @@ -2100,9 +2115,9 @@ class Music(Items): # Something went wrong, trying to use non-direct paths doIndirect = True else: - if self.replaceSMB: - playurl = playurl.replace('\\', '/') - playurl = 'smb:' + playurl + playurl = self.validatePlayurl(playurl, 'music') + if playurl is False: + return False if (utils.window('emby_pathverified') != "true" and not xbmcvfs.exists(playurl.encode('utf-8'))): # Validate the path is correct with user intervention diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index 19731fe6..f8de8380 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -203,11 +203,25 @@ class UserClient(threading.Thread): window('plex_machineIdentifier', value=self.machineIdentifier) window('plex_servername', value=self.servername) window('plex_authenticated', value='true') - # self.directpath + window('useDirectPaths', value='true' if utils.settings('useDirectPaths') == "1" else 'false') window('replaceSMB', value='true' if utils.settings('replaceSMB') == "true" else 'false') + window('remapSMB', value='true' + if utils.settings('remapSMB') == "true" else 'false') + if window('remapSMB') == 'true': + items = ('movie', 'tv', 'music') + for item in items: + # Normalize! Get rid of potential (back)slashes at the end + org = settings('remapSMB%sOrg' % item) + new = settings('remapSMB%sNew' % item) + if org.endswith('\\') or org.endswith('/'): + org = org[:-1] + if new.endswith('\\') or new.endswith('/'): + new = new[:-1] + window('remapSMB%sOrg' % item, value=org) + window('remapSMB%sNew' % item, value=new) # Set DownloadUtils values doUtils.setUsername(username) diff --git a/resources/settings.xml b/resources/settings.xml index d7666ab7..3012f1fd 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -61,6 +61,14 @@ + + + + + + + +