Skip to content

Commit

Permalink
Add a summary sanatizer based off HAMA
Browse files Browse the repository at this point in the history
  • Loading branch information
Cazzar committed May 5, 2019
1 parent 5f508ac commit ec4d960
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit ec4d960

Please sign in to comment.