From 60a233c93157f4832f237b31b3676e27f5c8ada1 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 4 Apr 2019 02:08:35 +1100 Subject: [PATCH 01/10] Make the link sanitization work a little better --- 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 bb727f0..6795582 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -15,7 +15,7 @@ #this is from https://github.com/plexinc-agents/PlexThemeMusic.bundle/blob/master/Contents/Code/__init__.py THEME_URL = 'http://tvthemes.plexapp.com/%s.mp3' -LINK_REGEX = r"https?:\/\/\w+.\w+(?:\/?\w+)? \[([\w ]+)\]" +LINK_REGEX = r"https?:\/\/\w+.\w+(?:\/?\w+)? \[([^\]]+)\]" def ValidatePrefs(): pass From c823ef700ebea05ccab3c82befa56fd2932ce23f Mon Sep 17 00:00:00 2001 From: da3dsoul Date: Fri, 5 Apr 2019 03:22:52 -0400 Subject: [PATCH 02/10] Add Mature to the MPAA list --- Contents/Code/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 428d2f1..98afc3b 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -154,6 +154,9 @@ def Update(self, metadata, media, lang, force, movie): if 'Seinen' in tags: metadata.content_rating = 'TV-MA' + if 'Mature' in tags: + metadata.content_rating = 'TV-MA' + if '18 Restricted' in tags: metadata.content_rating = 'TV-R' From a7fdc0675e517c78d33e2c3aed88153ebc9e6668 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sat, 4 May 2019 17:21:20 +1000 Subject: [PATCH 03/10] Update for an issue with "ismovie" --- Contents/Resources/Movies/Shoko Movie Scanner.py | 4 ++-- Contents/Resources/Series/Shoko Series Scanner.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Contents/Resources/Movies/Shoko Movie Scanner.py b/Contents/Resources/Movies/Shoko Movie Scanner.py index 4517498..b6731a8 100644 --- a/Contents/Resources/Movies/Shoko Movie Scanner.py +++ b/Contents/Resources/Movies/Shoko Movie Scanner.py @@ -97,7 +97,7 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None): if seasonNumber <= 0 and Prefs['IncludeOther'] == False: continue #Ignore this by choice. - if (series_data["ismovie"] == 0 or seasonNumber <= 0): + if (try_get(series_data, "ismovie", 0) == 0 or seasonNumber <= 0): continue vid = Media.Movie(showTitle, int(seasonYear)) log('Scan', 'vid: %s', vid) @@ -113,4 +113,4 @@ def try_get(arr, idx, default=""): try: return arr[idx] except: - return default \ No newline at end of file + return default diff --git a/Contents/Resources/Series/Shoko Series Scanner.py b/Contents/Resources/Series/Shoko Series Scanner.py index eb9ef1e..55d3635 100644 --- a/Contents/Resources/Series/Shoko Series Scanner.py +++ b/Contents/Resources/Series/Shoko Series Scanner.py @@ -130,7 +130,7 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None): if seasonNumber <= 0 and Prefs['IncludeOther'] == False: continue #Ignore this by choice. - if (series_data["ismovie"] == 1 and seasonNumber >= 1): continue # Ignore movies in preference for Shoko Movie Scanner, but keep specials as Plex sees specials as duplicate + if (try_get(series_data, "ismovie", 0) == 1 and seasonNumber >= 1): continue # Ignore movies in preference for Shoko Movie Scanner, but keep specials as Plex sees specials as duplicate Log.info('season number: %s', seasonNumber) episodeNumber = int(episode_data['epnumber']) Log.info('episode number: %s', episodeNumber) From 5f508ac89bafcaa9b753512066c672c648028ef2 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Sat, 4 May 2019 23:11:30 +1000 Subject: [PATCH 04/10] Fix up an error when certain image types don't exist --- Contents/Code/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 4618449..1baaf46 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -118,9 +118,9 @@ def Update(self, metadata, media, lang, force, movie): metadata.genres = tags - self.metadata_add(metadata.banners, series['art']['banner']) - self.metadata_add(metadata.posters, series['art']['thumb']) - self.metadata_add(metadata.art, series['art']['fanart']) + self.metadata_add(metadata.banners, try_get(series['art'], 'banner', [])) + self.metadata_add(metadata.posters, try_get(series['art'], 'thumb', [])) + self.metadata_add(metadata.art, try_get(series['art'], 'fanart', [])) groupinfo = HttpReq("api/serie/groups?id=%s&level=2" % aid); collections = [] From ec4d960c91d1ef19742fb67a8f325a4cf1302542 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Mon, 6 May 2019 01:16:41 +1000 Subject: [PATCH 05/10] Add a summary sanatizer based off HAMA Source: https://github.com/ZeroQI/Hama.bundle/blob/1ce898cfc5e90665a2274eaa32b744914d5876fc/Contents/Code/AniDB.py#L390-L396 --- Contents/Code/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 1baaf46..e3cf756 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -104,7 +104,8 @@ def Update(self, metadata, media, lang, force, movie): series = HttpReq("api/serie?id=%s&level=3&allpics=1&tagfilter=%d" % (aid, flags)) # build metadata on the TV show. - metadata.summary = re.sub(LINK_REGEX, r'\1', try_get(series, 'summary')) + #metadata.summary = re.sub(LINK_REGEX, r'\1', try_get(series, 'summary')) + metadata.summary = summary_sanitizer(try_get(series, 'summary')) metadata.title = series['name'] metadata.rating = float(series['rating']) year = try_get(series, "year", None) @@ -193,7 +194,7 @@ def Update(self, metadata, media, lang, force, movie): episodeObj = metadata.seasons[season].episodes[ep['epnumber']] episodeObj.title = ep['name'] if (ep['summary'] != "Episode Overview not Available"): - episodeObj.summary = ep['summary'] + episodeObj.summary = summary_sanitizer(ep['summary']) Log("" + str(ep['epnumber']) + ": " + ep['summary']) if ep['air'] != '1/01/0001 12:00:00 AM' and ep['air'] != '0001-01-01': @@ -236,6 +237,13 @@ def metadata_add(self, meta, images): if (key not in valid): del meta[key] +def summary_sanitizer(summary): + summary = re.sub(LINK_REGEX, r'\1', summary) # Replace links + summary = re.sub(r'^(\*|--|~) .*', "", summary, flags=re.MULTILINE) # Remove the line if it starts with ('* ' / '-- ' / '~ ') + summary = re.sub(r'\n(Source|Note|Summary):.*', "", summary, flags=re.DOTALL) # Remove all lines after this is seen + summary = re.sub(r'\n\n+', r'\n\n', summary, flags=re.DOTALL) # Condense multiple empty lines + return summary.strip(" \n") + def try_get(arr, idx, default=""): try: return arr[idx] From 34ce13f61018112dcf4bd4dccf17b4e8a67ac701 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 16 May 2019 01:27:26 +1000 Subject: [PATCH 06/10] Fix up some images not being passed properly from plex. Also further ignore the new plex_404.png --- Contents/Code/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index e3cf756..0914d9a 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -222,14 +222,19 @@ def metadata_add(self, meta, images): try: if 'support/plex_404.png' in art['url']: continue + if 'Static/plex_404.png' in art['url']: + continue if ':' in art['url']: urlparts = urllib.parse.urlparse(art['url']) art['url'] = art['url'].replace("{scheme}://{host}:{port}/".format(scheme=urlparts.scheme, host=urlparts.hostname, port=urlparts.port), '') - Log("[metadata_add] :: Adding metadata %s (index %d)" % (art['url'], 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']) + url = "http://{host}:{port}{relativeURL}".format(host=Prefs['Hostname'], port=Prefs['Port'], relativeURL=art['url']) + idx = try_get(art, 'index', 0) + Log("[metadata_add] :: Adding metadata %s (index %d)" % (url, idx)) + meta[art['url']] = Proxy.Media(HTTP.Request(url).content, idx) valid.append(art['url']) - except: + except Exception as e: Log("[metadata_add] :: Invalid URL given (%s), skipping" % art['url']) + Log(e) meta.validate_keys(valid) From 6bd085ddfb0b0cdd09b8438f01b436e1153b15a6 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 16 May 2019 01:35:23 +1000 Subject: [PATCH 07/10] Fix an error on if there is no tags --- 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 0914d9a..f4b8e0a 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -114,7 +114,7 @@ def Update(self, metadata, media, lang, force, movie): # metadata.year = int(year) tags = [] - for tag in series['tags']: + for tag in try_get(series, 'tags', []): tags.append(tag) metadata.genres = tags From c4572cc71c4b330c6de7f84380ec5035f43810e0 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 16 May 2019 01:38:10 +1000 Subject: [PATCH 08/10] Fix an error with Roles too... --- 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 f4b8e0a..4138648 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -167,7 +167,7 @@ def Update(self, metadata, media, lang, force, movie): metadata.originally_available_at = datetime.strptime(series['air'], "%Y-%m-%d").date() metadata.roles.clear() - for role in series['roles']: + for role in try_get(series, 'roles', []): meta_role = metadata.roles.new() Log(role['character']) meta_role.name = role['staff'] From c1fb229d9785e445a74e967c23a385e4d5cc4519 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 16 May 2019 01:48:06 +1000 Subject: [PATCH 09/10] Fix an issue with Air dates not being existant. Also split the Synopsis cleanups into it's own prefs. --- Contents/Code/__init__.py | 17 +++++++++++------ Contents/DefaultPrefs.json | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 4138648..054876c 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -163,8 +163,9 @@ def Update(self, metadata, media, lang, force, movie): Log('Assumed tv rating to be: %s' % metadata.content_rating) - if series['air'] != '1/01/0001 12:00:00 AM' and series['air'] != '0001-01-01': - metadata.originally_available_at = datetime.strptime(series['air'], "%Y-%m-%d").date() + airdate = try_get(series, 'air', '1/01/0001 12:00:00 AM') + if airdate != '1/01/0001 12:00:00 AM' and airdate != '0001-01-01': + metadata.originally_available_at = datetime.strptime(airdate, "%Y-%m-%d").date() metadata.roles.clear() for role in try_get(series, 'roles', []): @@ -243,10 +244,14 @@ def metadata_add(self, meta, images): del meta[key] def summary_sanitizer(summary): - summary = re.sub(LINK_REGEX, r'\1', summary) # Replace links - summary = re.sub(r'^(\*|--|~) .*', "", summary, flags=re.MULTILINE) # Remove the line if it starts with ('* ' / '-- ' / '~ ') - summary = re.sub(r'\n(Source|Note|Summary):.*', "", summary, flags=re.DOTALL) # Remove all lines after this is seen - summary = re.sub(r'\n\n+', r'\n\n', summary, flags=re.DOTALL) # Condense multiple empty lines + if Prefs["synposisCleanLinks"]: + summary = re.sub(LINK_REGEX, r'\1', summary) # Replace links + if Prefs["synposisCleanMiscLines"]: + summary = re.sub(r'^(\*|--|~) .*', "", summary, flags=re.MULTILINE) # Remove the line if it starts with ('* ' / '-- ' / '~ ') + if Prefs["synposisRemoveSummary"]: + summary = re.sub(r'\n(Source|Note|Summary):.*', "", summary, flags=re.DOTALL) # Remove all lines after this is seen + if Prefs["synposisCleanMultiEmptyLines"]: + summary = re.sub(r'\n\n+', r'\n\n', summary, flags=re.DOTALL) # Condense multiple empty lines return summary.strip(" \n") def try_get(arr, idx, default=""): diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index 3f0f268..9b24868 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -88,5 +88,33 @@ "label": "Grab theme music the same way plex theme music would", "type": "bool", "default": true + }, + + { + "id": "synposisCleanLinks", + "label": "Synopsis: Remove links.", + "type": "bool", + "default": true + }, + + { + "id": "synposisCleanMiscLines", + "label": "Synopsis: Remove the line if it starts with ('* ' / '-- ' / '~ ').", + "type": "bool", + "default": true + }, + + { + "id": "synposisRemoveSummary", + "label": "Synopsis: Remove anything after Source, Note or Summary.", + "type": "bool", + "default": true + }, + + { + "id": "synposisCleanMultiEmptyLines", + "label": "Synopsis: Collapse excessive empty lines..", + "type": "bool", + "default": true } ] From 71873963d2306d38d50e9faa35bd29e3c1dbe6a8 Mon Sep 17 00:00:00 2001 From: Cayde Dixon Date: Thu, 16 May 2019 01:50:13 +1000 Subject: [PATCH 10/10] Forgot a bit with airdate. --- Contents/Code/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 054876c..97036ba 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -198,8 +198,10 @@ def Update(self, metadata, media, lang, force, movie): episodeObj.summary = summary_sanitizer(ep['summary']) Log("" + str(ep['epnumber']) + ": " + ep['summary']) - if ep['air'] != '1/01/0001 12:00:00 AM' and ep['air'] != '0001-01-01': - episodeObj.originally_available_at = datetime.strptime(ep['air'], "%Y-%m-%d").date() + airdate = try_get(ep, 'air', '1/01/0001 12:00:00 AM') + + if airdate != '1/01/0001 12:00:00 AM' and airdate != '0001-01-01': + episodeObj.originally_available_at = datetime.strptime(airdate, "%Y-%m-%d").date() if len(ep['art']['thumb']) and Prefs['customThumbs']: self.metadata_add(episodeObj.thumbs, ep['art']['thumb'])