From 0d47caaedd0e98ba3aa7c3b633fc534039b54016 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sun, 14 May 2017 00:06:58 +1000 Subject: [PATCH 01/14] Extra attempts at resolving the poster errors. --- Contents/Code/__init__.py | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 373d83c..2456386 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -93,17 +93,9 @@ def Update(self, metadata, media, lang, force, movie): metadata.genres = tags - if len(series['art']['banner']): - for art in series['art']['banner']: - metadata.banner[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) - - if len(series['art']['thumb']): - for art in series['art']['thumb']: - metadata.posters[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) - - if len(series['art']['fanart']): - for art in series['art']['fanart']: - metadata.art[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + self.metadata_add(metadata.banner, series['art']['banner']) + self.metadata_add(metadata.posters, series['art']['thumb']) + self.metadata_add(metadata.art, series['art']['fanart']) ### Generate general content ratings. ### VERY rough approximation to: https://www.healthychildren.org/English/family-life/Media/Pages/TV-Ratings-A-Guide-for-Parents.aspx @@ -155,6 +147,35 @@ def Update(self, metadata, media, lang, force, movie): for art in series['art']['thumb']: episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + def metadata_add(self, meta, images): + valid = list() + + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + + for key in meta.keys(): + Log("DEBUG :: [metadata_add] :: Current key found: %s" % key) + + for art in images: + if (art not in meta): + Log("[metadata_add] :: Adding metadata %s (index %d)" % (art['url'], art['index'])) + meta[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + valid.append(art['url']) + + meta.validate_keys(valid) + + for key in meta.keys(): + Log("DEBUG :: [metadata_add] :: Current key found: %s" % key) + if (key not in valid): + del meta[key] + Log("DEBUG :: [metadata_add] :: deleting key: %s" % key) + + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") + Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") def try_get(arr, idx, default=""): try: From 997699f0629cbaed636b15938d7a87a9da04a851 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sun, 14 May 2017 00:19:03 +1000 Subject: [PATCH 02/14] Fix typo --- Contents/Code/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 2456386..a6f981d 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -93,7 +93,7 @@ def Update(self, metadata, media, lang, force, movie): metadata.genres = tags - self.metadata_add(metadata.banner, series['art']['banner']) + self.metadata_add(metadata.banners, series['art']['banner']) self.metadata_add(metadata.posters, series['art']['thumb']) self.metadata_add(metadata.art, series['art']['fanart']) From 554103e63d4b79b8119ad84d9ac51d4eec56b0e2 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Tue, 25 Jul 2017 01:50:24 +1000 Subject: [PATCH 03/14] Update code to respect allpics =1 --- Contents/Code/__init__.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index a6f981d..b191c04 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -1,6 +1,13 @@ -import os, re, time, string, thread, threading, urllib, copy -from lxml import etree +import os +import re +import time +import string +import thread +import threading +import urllib +import copy from datetime import datetime +from lxml import etree import tags as TagBlacklist API_KEY = '' @@ -71,7 +78,7 @@ def Update(self, metadata, media, lang, force, movie): # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv # episode_data = HttpReq("api/ep/getbyfilename?apikey=%s&filename=%s" % (GetApiKey(), urllib.quote(media.filename))) - series = HttpReq("api/serie?id=%s&level=3" % aid) + series = HttpReq("api/serie?id=%s&level=3&allpics=1" % aid) # build metadata on the TV show. metadata.summary = try_get(series, 'summary') @@ -150,32 +157,16 @@ def Update(self, metadata, media, lang, force, movie): def metadata_add(self, meta, images): valid = list() - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - - for key in meta.keys(): - Log("DEBUG :: [metadata_add] :: Current key found: %s" % key) - for art in images: - if (art not in meta): - Log("[metadata_add] :: Adding metadata %s (index %d)" % (art['url'], art['index'])) - meta[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) - valid.append(art['url']) + Log("[metadata_add] :: Adding metadata %s (index %d)" % (art['url'], art['index'])) + meta[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + valid.append(art['url']) meta.validate_keys(valid) for key in meta.keys(): - Log("DEBUG :: [metadata_add] :: Current key found: %s" % key) if (key not in valid): del meta[key] - Log("DEBUG :: [metadata_add] :: deleting key: %s" % key) - - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") - Log.Debug("DEBUG :: [metadata_add] :: BLOCKING OUT") def try_get(arr, idx, default=""): try: From ec33a4b5285cb2ab6ba1710da5ad8f35db8b3b02 Mon Sep 17 00:00:00 2001 From: Kingsley Date: Fri, 4 Aug 2017 09:17:18 +0100 Subject: [PATCH 04/14] Support relative URLs. --- Contents/Code/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index b191c04..ffba624 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -152,14 +152,14 @@ def Update(self, metadata, media, lang, force, movie): if len(series['art']['thumb']): for art in series['art']['thumb']: - episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) def metadata_add(self, meta, images): valid = list() for art in images: Log("[metadata_add] :: Adding metadata %s (index %d)" % (art['url'], art['index'])) - meta[art['url']] = Proxy.Media(HTTP.Request(art['url']).content, art['index']) + meta[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) valid.append(art['url']) meta.validate_keys(valid) From 6f9230db957aee78407dfac9baff2db6f687d73c Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sun, 13 Aug 2017 02:06:35 +1000 Subject: [PATCH 05/14] Fix up episode metadata not being provided --- Contents/Code/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index ffba624..0f537e0 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -134,7 +134,7 @@ def Update(self, metadata, media, lang, force, movie): if not movie: for ep in series['eps']: - if ep['eptype'] != 1: + if ep['eptype'] != "Episode": continue season = 1 @@ -147,7 +147,7 @@ def Update(self, metadata, media, lang, force, movie): episodeObj.title = ep['name'] episodeObj.summary = ep['summary'] - if ep['air'] != '1/01/0001 12:00:00 AM': + if ep['air'] != '1/01/0001 12:00:00 AM' and ep['air'] != '0001-01-01': episodeObj.originally_available_at = datetime.strptime(ep['air'], "%d/%m/%Y %H:%M:%S %p").date() if len(series['art']['thumb']): From 90d0c2a26a68936333056ccacd02ad4cacbbf2e3 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sun, 13 Aug 2017 02:08:38 +1000 Subject: [PATCH 06/14] Change the thumbnails that you can use the one provided by shoko --- Contents/Code/__init__.py | 2 +- Contents/DefaultPrefs.json | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 0f537e0..8ad4eb8 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -150,7 +150,7 @@ def Update(self, metadata, media, lang, force, movie): if ep['air'] != '1/01/0001 12:00:00 AM' and ep['air'] != '0001-01-01': episodeObj.originally_available_at = datetime.strptime(ep['air'], "%d/%m/%Y %H:%M:%S %p").date() - if len(series['art']['thumb']): + if len(series['art']['thumb']) and Prefs['customThumbs']: for art in series['art']['thumb']: episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index 92c7cda..d8c9ec4 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -74,5 +74,12 @@ "label": "Hide any miscellaneous tags.", "type": "bool", "default": true + }, + + { + "id": "customThumbs", + "label": "Use shoko's thumbnails", + "type": "bool", + "default": false } -] \ No newline at end of file +] From 51f26a7ed871e2f6aaf0dd6c5a30a44380a409d1 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Mon, 14 Aug 2017 02:10:36 +1000 Subject: [PATCH 07/14] Add theme support --- Contents/Code/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 8ad4eb8..de2bd75 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -154,6 +154,10 @@ def Update(self, metadata, media, lang, force, movie): for art in series['art']['thumb']: episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) + links = HttpReq("api/links/serie?id=%d" % aid) + for tvdbid in links["tvdb"]: + metadata.themes[tvdbid] = Proxy.Media("http://tvthemes.plexapp.com/{tvdb}.mp3".format(tvdb=tvdbid)) + def metadata_add(self, meta, images): valid = list() From 125e4caebf0743847e97f859d2bb2c1641ceb0d2 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Mon, 14 Aug 2017 02:25:49 +1000 Subject: [PATCH 08/14] Fix typo --- Contents/Code/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index de2bd75..8d39583 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -154,7 +154,7 @@ def Update(self, metadata, media, lang, force, movie): for art in series['art']['thumb']: episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) - links = HttpReq("api/links/serie?id=%d" % aid) + links = HttpReq("api/links/serie?id=%s" % aid) for tvdbid in links["tvdb"]: metadata.themes[tvdbid] = Proxy.Media("http://tvthemes.plexapp.com/{tvdb}.mp3".format(tvdb=tvdbid)) From 5c4e04990d28cd702e4462d2a18ae9a25923442f Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Tue, 15 Aug 2017 00:41:36 +1000 Subject: [PATCH 09/14] Cache cache go away~ --- Contents/Code/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 8d39583..ff3a97c 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -21,6 +21,7 @@ def ValidatePrefs(): def Start(): Log("Shoko metata agent started") HTTP.Headers['Accept'] = 'application/json' + HTTP.CacheTime = 0 #cache, can you please go away, typically we will be requesting LOCALLY. HTTP.CacheTime ValidatePrefs() From 76c69d9ba09e0f7ddf059e1d88b4dce2e0e6d5af Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Tue, 15 Aug 2017 00:57:00 +1000 Subject: [PATCH 10/14] Fix up theme music --- Contents/Code/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index ff3a97c..236bcac 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -13,6 +13,9 @@ API_KEY = '' PLEX_HOST = '' +#this is from https://github.com/plexinc-agents/PlexThemeMusic.bundle/blob/master/Contents/Code/__init__.py +THEME_URL = 'http://tvthemes.plexapp.com/%s.mp3' + def ValidatePrefs(): pass @@ -156,8 +159,15 @@ def Update(self, metadata, media, lang, force, movie): episodeObj.thumbs[art['url']] = Proxy.Media(HTTP.Request("http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url'])).content, art['index']) links = HttpReq("api/links/serie?id=%s" % aid) - for tvdbid in links["tvdb"]: - metadata.themes[tvdbid] = Proxy.Media("http://tvthemes.plexapp.com/{tvdb}.mp3".format(tvdb=tvdbid)) + + #adapted from: https://github.com/plexinc-agents/PlexThemeMusic.bundle/blob/fb5c77a60c925dcfd60e75a945244e07ee009e7c/Contents/Code/__init__.py#L41-L45 + for tid in links["tvdb"]: + if THEME_URL % tid not in metadata.themes: + try: + metadata.themes[THEME_URL % tid] = Proxy.Media(HTTP.Request(THEME_URL % tid)) + Log("added: %s" % THEME_URL % tid) + except: + Log("error adding music, probably not found") def metadata_add(self, meta, images): valid = list() From 7bf468dddf1f3fd43bdd90b91f08a55db7c8c73d Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Tue, 15 Aug 2017 00:59:10 +1000 Subject: [PATCH 11/14] Make it optional --- Contents/Code/__init__.py | 15 ++++++++------- Contents/DefaultPrefs.json | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 236bcac..e526a6c 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -161,13 +161,14 @@ def Update(self, metadata, media, lang, force, movie): links = HttpReq("api/links/serie?id=%s" % aid) #adapted from: https://github.com/plexinc-agents/PlexThemeMusic.bundle/blob/fb5c77a60c925dcfd60e75a945244e07ee009e7c/Contents/Code/__init__.py#L41-L45 - for tid in links["tvdb"]: - if THEME_URL % tid not in metadata.themes: - try: - metadata.themes[THEME_URL % tid] = Proxy.Media(HTTP.Request(THEME_URL % tid)) - Log("added: %s" % THEME_URL % tid) - except: - Log("error adding music, probably not found") + if Prefs["themeMusic"]: + for tid in links["tvdb"]: + if THEME_URL % tid not in metadata.themes: + try: + metadata.themes[THEME_URL % tid] = Proxy.Media(HTTP.Request(THEME_URL % tid)) + Log("added: %s" % THEME_URL % tid) + except: + Log("error adding music, probably not found") def metadata_add(self, meta, images): valid = list() diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index d8c9ec4..3f0f268 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -81,5 +81,12 @@ "label": "Use shoko's thumbnails", "type": "bool", "default": false + }, + + { + "id": "themeMusic", + "label": "Grab theme music the same way plex theme music would", + "type": "bool", + "default": true } ] From ef21191423f06d7802d76a99df104982a018e143 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sun, 20 Aug 2017 23:36:48 +1000 Subject: [PATCH 12/14] Fix year throwing errors on scan also add logging. --- .../Resources/Series/Shoko Series Scanner.py | 83 ++++++++++++------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/Contents/Resources/Series/Shoko Series Scanner.py b/Contents/Resources/Series/Shoko Series Scanner.py index 6f4878a..2775a84 100644 --- a/Contents/Resources/Series/Shoko Series Scanner.py +++ b/Contents/Resources/Series/Shoko Series Scanner.py @@ -13,17 +13,42 @@ API_KEY = '' -def log(methodName, message, *args): - ''' - Create a log message given the message and arguments - ''' - logMsg = message - # Replace the arguments in the string - if args: - logMsg = message % args - - logMsg = methodName + ' :: ' + logMsg - print logMsg +### Log + LOG_PATH calculated once for all calls ### +import logging, logging.handlers # +RootLogger = logging.getLogger('main') +RootHandler = None +RootFormatting = logging.Formatter('%(message)s') #%(asctime)-15s %(levelname)s - +RootLogger.setLevel(logging.DEBUG) +Log = RootLogger + +FileListLogger = logging.getLogger('FileListLogger') +FileListHandler = None +FileListFormatting = logging.Formatter('%(message)s') +FileListLogger.setLevel(logging.DEBUG) +LogFileList = FileListLogger.info + +def set_logging(instance, filename): + global RootLogger, RootHandler, RootFormatting, FileListLogger, FileListHandler, FileListFormatting + logger, handler, formatting, backup_count = [RootLogger, RootHandler, RootFormatting, 9] if instance=="Root" else [FileListLogger, FileListHandler, FileListFormatting, 1] + if handler: logger.removeHandler(handler) + handler = logging.handlers.RotatingFileHandler(os.path.join(LOG_PATH, filename), maxBytes=10*1024*1024, backupCount=backup_count) #handler = logging.FileHandler(os.path.join(LOG_PATH, filename), mode) + #handler.setFormatter(formatting) + handler.setLevel(logging.DEBUG) + logger.addHandler(handler) + if instance=="Root": RootHandler = handler + else: FileListHandler = handler + +### Check config files on boot up then create library variables ### #platform = xxx if callable(getattr(sys,'platform')) else "" +import inspect +LOG_PATH = os.path.abspath(os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), "..", "..", "Logs")) +if not os.path.isdir(LOG_PATH): + path_location = { 'Windows': '%LOCALAPPDATA%\\Plex Media Server', + 'MacOSX': '$HOME/Library/Application Support/Plex Media Server', + 'Linux': '$PLEX_HOME/Library/Application Support/Plex Media Server' } + try: path = os.path.expandvars(path_location[Platform.OS.lower()] if Platform.OS.lower() in path_location else '~') # Platform.OS: Windows, MacOSX, or Linux + except: pass #os.makedirs(LOG_PATH) # User folder on MacOS-X +LOG_FILE_LIBRARY = LOG_FILE = 'Shoko Metadata Scanner.log' # Log filename library will include the library name, LOG_FILE not and serve as reference +set_logging("Root", LOG_FILE_LIBRARY) def HttpPost(url, postdata): @@ -34,7 +59,7 @@ def HttpPost(url, postdata): def HttpReq(url, authenticate=True): - log('HttpReq' ,"Requesting: %s", url) + Log.info("Requesting: %s", url) api_string = '' if authenticate: api_string = '&apikey=%s' % GetApiKey() @@ -52,7 +77,7 @@ def GetApiKey(): data = '{"user":"%s", "pass":"%s", "device":"%s"}' % ( Prefs['Username'], Prefs['Password'] if Prefs['Password'] != None else '', 'Shoko Series Scanner For Plex') resp = HttpPost('api/auth', data)['apikey'] - log('GetApiKey', "Got API KEY: %s", resp) + Log.info( "Got API KEY: %s", resp) API_KEY = resp return resp @@ -60,18 +85,18 @@ def GetApiKey(): def Scan(path, files, mediaList, subdirs, language=None, root=None): - log('Scan', 'path: %s', path) - log('Scan', 'files: %s', files) - log('Scan', 'mediaList: %s', mediaList) - log('Scan', 'subdirs: %s', subdirs) - log('Scan', 'language: %s', language) - log('Scan', 'root: %s', root) + Log.debug('path: %s', path) + Log.debug('files: %s', files) + Log.debug('mediaList: %s', mediaList) + Log.debug('subdirs: %s', subdirs) + Log.debug('language: %s', language) + Log.info('root: %s', root) # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) for idx, file in enumerate(files): - log('Scan', 'file: %s', file) + Log.info('file: %s', file) # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv episode_data = HttpReq("api/ep/getbyfilename?filename=%s" % (urllib.quote(os.path.basename(file)))) @@ -80,7 +105,7 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None): series_data = HttpReq("api/serie/fromep?id=%d&nocast=1¬ag=1" % episode_data['id']) showTitle = series_data['name'].encode("utf-8") #no idea why I need to do this. - log('Scan', 'show title: %s', showTitle) + Log.info('show title: %s', showTitle) seasonNumber = 0 seasonStr = try_get(episode_data, 'season', None) @@ -93,28 +118,28 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None): if seasonNumber <= 0 and Prefs['IncludeOther'] == False: break #Ignore this by choice. - log('Scan', 'season number: %s', seasonNumber) + Log.info('season number: %s', seasonNumber) - seasonYear = episode_data['year'] - log('Scan', 'season year: %s', seasonYear) + seasonYear = try_get(episode_data, 'year', 0) + Log.info('season year: %s', seasonYear) episodeNumber = int(episode_data['epnumber']) if episode_data['eptype'] != 'Episode': episodeNumber = str("%s%d" % (episode_data['eptype'][0], episode_data['epnumber'])) - log('Scan', 'episode number: %s', episodeNumber) + Log.info('episode number: %s', episodeNumber) episodeTitle = episode_data['name'].encode("utf-8") - log('Scan', 'episode title: %s', episodeTitle) + Log.info('episode title: %s', episodeTitle) vid = Media.Episode(showTitle, int(seasonNumber), episodeNumber , episodeTitle, int(seasonYear)) - log('Scan', 'vid: %s', vid) + Log.info('vid: %s', vid) vid.parts.append(file) mediaList.append(vid) - log('Scan', 'stack media') + Log.info('stack media') Stack.Scan(path, files, mediaList, subdirs) - log('Scan', 'media list %s', mediaList) + Log.debug('media list %s', mediaList) def try_get(arr, idx, default=""): From b920d15f4ae461c751b9f3cf49925e48f9a22590 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Mon, 21 Aug 2017 00:10:02 +1000 Subject: [PATCH 13/14] Remove data that could potentially throw an error, as well as attempt to log exceptions --- .../Resources/Series/Shoko Series Scanner.py | 107 +++++++++--------- 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/Contents/Resources/Series/Shoko Series Scanner.py b/Contents/Resources/Series/Shoko Series Scanner.py index 2775a84..e56bf95 100644 --- a/Contents/Resources/Series/Shoko Series Scanner.py +++ b/Contents/Resources/Series/Shoko Series Scanner.py @@ -85,61 +85,58 @@ def GetApiKey(): def Scan(path, files, mediaList, subdirs, language=None, root=None): - Log.debug('path: %s', path) - Log.debug('files: %s', files) - Log.debug('mediaList: %s', mediaList) - Log.debug('subdirs: %s', subdirs) - Log.debug('language: %s', language) - Log.info('root: %s', root) - - # Scan for video files. - VideoFiles.Scan(path, files, mediaList, subdirs, root) - - for idx, file in enumerate(files): - Log.info('file: %s', file) - # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv - - episode_data = HttpReq("api/ep/getbyfilename?filename=%s" % (urllib.quote(os.path.basename(file)))) - if len(episode_data) == 0: break - if (try_get(episode_data, "code", 200) == 404): break - - series_data = HttpReq("api/serie/fromep?id=%d&nocast=1¬ag=1" % episode_data['id']) - showTitle = series_data['name'].encode("utf-8") #no idea why I need to do this. - Log.info('show title: %s', showTitle) - - seasonNumber = 0 - seasonStr = try_get(episode_data, 'season', None) - if seasonStr == None: - if episode_data['eptype'] == 'Episode': seasonNumber = 1 - if episode_data['eptype'] == 'Credits': seasonNumber = -1 #season -1 for OP/ED - else: - seasonNumber = seasonStr.split('x')[0] - - if seasonNumber <= 0 and Prefs['IncludeOther'] == False: break #Ignore this by choice. - - - Log.info('season number: %s', seasonNumber) - - seasonYear = try_get(episode_data, 'year', 0) - Log.info('season year: %s', seasonYear) - - episodeNumber = int(episode_data['epnumber']) - if episode_data['eptype'] != 'Episode': - episodeNumber = str("%s%d" % (episode_data['eptype'][0], episode_data['epnumber'])) - - Log.info('episode number: %s', episodeNumber) - - episodeTitle = episode_data['name'].encode("utf-8") - Log.info('episode title: %s', episodeTitle) - - vid = Media.Episode(showTitle, int(seasonNumber), episodeNumber , episodeTitle, int(seasonYear)) - Log.info('vid: %s', vid) - vid.parts.append(file) - mediaList.append(vid) - - Log.info('stack media') - Stack.Scan(path, files, mediaList, subdirs) - Log.debug('media list %s', mediaList) + try: + Log.debug('path: %s', path) + Log.debug('files: %s', files) + Log.debug('mediaList: %s', mediaList) + Log.debug('subdirs: %s', subdirs) + Log.debug('language: %s', language) + Log.info('root: %s', root) + + # Scan for video files. + VideoFiles.Scan(path, files, mediaList, subdirs, root) + + for idx, file in enumerate(files): + Log.info('file: %s', file) + # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv + + episode_data = HttpReq("api/ep/getbyfilename?filename=%s" % (urllib.quote(os.path.basename(file)))) + if len(episode_data) == 0: break + if (try_get(episode_data, "code", 200) == 404): break + + series_data = HttpReq("api/serie/fromep?id=%d&nocast=1¬ag=1" % episode_data['id']) + showTitle = series_data['name'].encode("utf-8") #no idea why I need to do this. + Log.info('show title: %s', showTitle) + + seasonNumber = 0 + seasonStr = try_get(episode_data, 'season', None) + if seasonStr == None: + if episode_data['eptype'] == 'Episode': seasonNumber = 1 + if episode_data['eptype'] == 'Credits': seasonNumber = -1 #season -1 for OP/ED + else: + seasonNumber = seasonStr.split('x')[0] + + if seasonNumber <= 0 and Prefs['IncludeOther'] == False: break #Ignore this by choice. + + + Log.info('season number: %s', seasonNumber) + + episodeNumber = int(episode_data['epnumber']) + if episode_data['eptype'] != 'Episode': + episodeNumber = str("%s%d" % (episode_data['eptype'][0], episode_data['epnumber'])) + + Log.info('episode number: %s', episodeNumber) + + vid = Media.Episode(showTitle, int(seasonNumber), episodeNumber) + Log.info('vid: %s', vid) + vid.parts.append(file) + mediaList.append(vid) + + Log.info('stack media') + Stack.Scan(path, files, mediaList, subdirs) + Log.debug('media list %s', mediaList) + except Exception as e: + Log.error("Error in Scan: '%s'" % e) def try_get(arr, idx, default=""): From 9a924e20486497035c947de3c3e553bb9283ac3f Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Mon, 21 Aug 2017 00:14:52 +1000 Subject: [PATCH 14/14] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5e8b3e..fcce8db 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,6 @@ Naming episodes/series works best with [This format](https://support.plex.tv/hc/ # Plans -I do plan to in the long term to add things such as scrobbling to this plugin +~~I do plan to in the long term to add things such as scrobbling to this plugin~~ - This has been added to Shoko, via webhooks -Another future plan is in regards to syncing watched status between shoko and plex. +~~Another future plan is in regards to syncing watched status between shoko and plex.~~ - This can be done inside shoko. via webhook or manual plex linking.