summaryrefslogtreecommitdiff
path: root/imdb-lookup
diff options
context:
space:
mode:
Diffstat (limited to 'imdb-lookup')
-rwxr-xr-ximdb-lookup/imdbinfo.py13
-rw-r--r--imdb-lookup/index.jinja2.html4
2 files changed, 13 insertions, 4 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 196b6ad..f5efe17 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -85,13 +85,18 @@ class TMDBCache(object):
keyContentType = "poster_{}_{}_content_type".format(format, poster_path)
url = "http://image.tmdb.org/t/p/{}/{}".format(format, poster_path)
if key not in self.db_images:
- r = requests.get(url)
- self.db_images[key] = r.content
- self.db_images[keyContentType] = r.headers['content-type']
+ try:
+ r = requests.get(url)
+ self.db_images[key] = r.content
+ self.db_images[keyContentType] = r.headers['content-type']
+ except:
+ return None
return (self.db_images[keyContentType], self.db_images[key])
def poster_base64(self, poster_path, format="w185"):
- contentType, data = self.poster(poster_path, format)
+ p = self.poster(poster_path, format)
+ if not p: return None
+ contentType, data = p
data64 = "".join(map(lambda c: isinstance(c,int) and chr(c) or c,
filter(lambda c: c!='\n', base64.encodestring(data))))
return "data:{};base64,{}".format(contentType, data64)
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index 42eed34..7271e91 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -14,7 +14,11 @@
<div style="clear: left; padding-top: 3em;">
<h2 style="">{{ info.title }}</h2>
<div style="width: 185px; float: left;">
+ {% if posterBase64 %}
<img src="{{ posterBase64 }}" />
+ {% else %}
+ <span> no image </span>
+ {% endif %}
</div>
<div style="">
<div style="font-size: 1.2em;">