SpiffyTitles/IMDB: fix meta/tomato scores

This commit is contained in:
oddluck 2020-02-23 23:06:01 +00:00
parent 1d23fe8bbf
commit c7479a9421
5 changed files with 31 additions and 6 deletions

BIN
IMDB/.plugin.py.swp Normal file

Binary file not shown.

View File

@ -28,7 +28,7 @@ def configure(advanced):
IMDB = conf.registerPlugin('IMDB') IMDB = conf.registerPlugin('IMDB')
conf.registerGlobalValue(IMDB, 'template', conf.registerGlobalValue(IMDB, 'template',
registry.String("\x02\x031,8 IMDb \x0F\x02 | $title ($year, $country, [$rated], $genre, $runtime) | IMDB: $imdbRating MC: $metascore% | http://imdb.com/title/$imdbID | $plot | Director: $director | Writer: $writer | Actors: $actors", _("""Template for the output of a search query."""))) registry.String("\x02\x031,8 IMDb \x0F\x02 | $title ($year, $country, [$rated], $genre, $runtime) | IMDB: $imdbRating | MC: $metascore | RT: $tomatoMeter | http://imdb.com/title/$imdbID | $plot | Director: $director | Writer: $writer | Actors: $actors", _("""Template for the output of a search query.""")))
# alternative template: # alternative template:
# $title ($year - $director) :: [i:$imdbRating r:$tomatoMeter m:$metascore] $plot :: http://imdb.com/title/$imdbID # $title ($year - $director) :: [i:$imdbRating r:$tomatoMeter m:$metascore] $plot :: http://imdb.com/title/$imdbID

View File

@ -78,6 +78,8 @@ class IMDB(callbacks.Plugin):
if not_found or unknown_error: if not_found or unknown_error:
self.log.info("IMDB: OMDB error for %s" % (omdb_url)) self.log.info("IMDB: OMDB error for %s" % (omdb_url))
else: else:
meta = None
tomato = None
imdb_template = self.registryValue("template") imdb_template = self.registryValue("template")
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
imdb_template = imdb_template.decode("utf-8") imdb_template = imdb_template.decode("utf-8")
@ -88,8 +90,19 @@ class IMDB(callbacks.Plugin):
imdb_template = imdb_template.replace("$plot", response["Plot"]) imdb_template = imdb_template.replace("$plot", response["Plot"])
imdb_template = imdb_template.replace("$imdbID", response["imdbID"]) imdb_template = imdb_template.replace("$imdbID", response["imdbID"])
imdb_template = imdb_template.replace("$imdbRating", response["imdbRating"]) imdb_template = imdb_template.replace("$imdbRating", response["imdbRating"])
imdb_template = imdb_template.replace("$tomatoMeter", response["tomatoMeter"]) for rating in response["Ratings"]:
imdb_template = imdb_template.replace("$metascore", response["Metascore"]) if rating["Source"] == "Rotten Tomatoes":
tomato = rating["Value"]
if rating["Source"] == "Metacritic":
meta = "{0}%".format(rating["Value"].split('/')[0])
if meta:
imdb_template = imdb_template.replace("$metascore", meta)
else:
imdb_template = imdb_template.replace("$metascore", "N/A")
if tomato:
imdb_template = imdb_template.replace("$tomatoMeter", tomato)
else:
imdb_template = imdb_template.replace("$tomatoMeter", "N/A")
imdb_template = imdb_template.replace("$released",response["Released"]) imdb_template = imdb_template.replace("$released",response["Released"])
imdb_template = imdb_template.replace("$genre",response["Genre"]) imdb_template = imdb_template.replace("$genre",response["Genre"])
imdb_template = imdb_template.replace("$released",response["Released"]) imdb_template = imdb_template.replace("$released",response["Released"])
@ -98,6 +111,11 @@ class IMDB(callbacks.Plugin):
imdb_template = imdb_template.replace("$rated",response["Rated"]) imdb_template = imdb_template.replace("$rated",response["Rated"])
imdb_template = imdb_template.replace("$runtime",response["Runtime"]) imdb_template = imdb_template.replace("$runtime",response["Runtime"])
imdb_template = imdb_template.replace("$writer",response["Writer"]) imdb_template = imdb_template.replace("$writer",response["Writer"])
imdb_template = imdb_template.replace("$votes",response["imdbVotes"])
imdb_template = imdb_template.replace("$boxOffice",response["BoxOffice"])
imdb_template = imdb_template.replace("$production",response["Production"])
imdb_template = imdb_template.replace("$website",response["Website"])
imdb_template = imdb_template.replace("$poster",response["Poster"])
result = imdb_template result = imdb_template
else: else:

View File

@ -270,7 +270,7 @@ conf.registerChannelValue(SpiffyTitles.imdb, 'logo',
# IMDB template # IMDB template
conf.registerChannelValue(SpiffyTitles.imdb, 'template', conf.registerChannelValue(SpiffyTitles.imdb, 'template',
registry.String("^ {{imdb_logo}} :: {{title}} ({{year}}, {{country}}, [{{rated}}], {{genre}}, {{runtime}}) :: IMDB: {{imdb_rating}} MC: {{metascore}} :: {{plot}}", _("""IMDB title template"""))) registry.String("^ {{imdb_logo}} :: {{title}} ({{year}}, {{country}}, [{{rated}}], {{genre}}, {{runtime}}) :: IMDB: {{imdb_rating}} | MC: {{metascore}} | RT: {{tomatoMeter}} :: {{plot}}", _("""IMDB title template""")))

View File

@ -1100,6 +1100,13 @@ class SpiffyTitles(callbacks.Plugin):
if not_found or unknown_error: if not_found or unknown_error:
log.debug("SpiffyTitles: OMDB error for %s" % (omdb_url)) log.debug("SpiffyTitles: OMDB error for %s" % (omdb_url))
else: else:
meta = "N/A"
tomato = "N/A"
for rating in response["Ratings"]:
if rating["Source"] == "Rotten Tomatoes":
tomato = rating["Value"]
if rating["Source"] == "Metacritic":
meta = "{0}%".format(rating["Value"].split('/')[0])
template_vars = { template_vars = {
"title": response["Title"], "title": response["Title"],
"year": response["Year"], "year": response["Year"],
@ -1108,8 +1115,8 @@ class SpiffyTitles(callbacks.Plugin):
"plot": response["Plot"], "plot": response["Plot"],
"imdb_id": response["imdbID"], "imdb_id": response["imdbID"],
"imdb_rating": response["imdbRating"], "imdb_rating": response["imdbRating"],
"tomatoMeter": response["tomatoMeter"], "tomatoMeter": tomato,
"metascore": response["Metascore"], "metascore": meta,
"released": response["Released"], "released": response["Released"],
"genre": response["Genre"], "genre": response["Genre"],
"awards": response["Awards"], "awards": response["Awards"],