Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

SpiffyTitles: Add Imdb API key #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SpiffyTitles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Queries the [OMDB API](http://www.omdbapi.com) to get additional information abo

`imdbHandlerEnabled` - Whether to show additional information about [IMDB](http://imdb.com) links

`imdbKey` - Omdb key used for imdb - Get one at [OMDBAPI](https://www.omdbapi.com/apikey.aspx)

`imdbTemplate` - This is the template used for [IMDB](http://imdb.com) links

Default value: `^ {{Title}} ({{Year}}, {{Country}}) - Rating: {{imdbRating}} :: {{Plot}}`
Expand Down
4 changes: 4 additions & 0 deletions SpiffyTitles/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def configure(advanced):
conf.registerGlobalValue(SpiffyTitles, 'youtubeDeveloperKey',
registry.String("", _("""Youtube developer key - required for Youtube handler."""), private=True))

# Omdb API
conf.registerGlobalValue(SpiffyTitles, 'imdbKey',
registry.String("", _("""Omdb API key - required for Imdb handler."""), private=True))

# Link cache lifetime
conf.registerGlobalValue(SpiffyTitles, 'linkCacheLifetimeInSeconds',
registry.Integer(60, _("""Link cache lifetime in seconds""")))
Expand Down
7 changes: 6 additions & 1 deletion SpiffyTitles/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,14 +833,19 @@ def handler_imdb(self, url, info, channel):

return self.handler_default(url, channel)

imdb_key = self.registryValue("imdbKey")
if not imdb_key:
log.info("SpiffyTitles: no Imdb key set! Check https://www.omdbapi.com/apikey.aspx .")
return None

# Don't care about query strings
if "?" in url:
url = url.split("?")[0]

# We can only accommodate a specific format of URL here
if "/title/" in url:
imdb_id = url.split("/title/")[1].rstrip("/")
omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json&tomatoes=true" % (imdb_id)
omdb_url = "http://www.omdbapi.com/?i=%s&apikey=%s&plot=short&r=json&tomatoes=true" % (imdb_id, imdb_key)

try:
request = requests.get(omdb_url, timeout=10, headers=headers)
Expand Down