summaryrefslogtreecommitdiff
path: root/imdb-lookup
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-12-08 23:49:07 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-12-08 23:49:07 +0100
commita6ff2d8166723026b3db0092399fe6f694fa0750 (patch)
tree11a8482fbe52efe4390f149e06ae5de78f59d08f /imdb-lookup
parente16f2428ad410645db1a640d4a56d63df74efd4a (diff)
downloadscripts-a6ff2d8166723026b3db0092399fe6f694fa0750.tar.gz
scripts-a6ff2d8166723026b3db0092399fe6f694fa0750.zip
more data!
Diffstat (limited to 'imdb-lookup')
-rwxr-xr-ximdb-lookup/imdbinfo.py12
-rw-r--r--imdb-lookup/index.jinja2.html83
2 files changed, 72 insertions, 23 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 5c88fc1..eeea947 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -167,6 +167,18 @@ class TMDBCache(object):
key = "imdb_maindetails_{}".format(movie_id)
return self._cache(key, do_request)
+ def omdb_movie(self, movie_id):
+ def do_request():
+ BASE_URI="http://www.omdbapi.com/"
+ params={'i':movie_id, 'plot':'short', 'r':'json', 'tomatoes':'true'}
+ r = requests.get(BASE_URI, params=params)
+ assert r.status_code == 200, "Request must return status-code 200"
+ data = json.loads(r.text)
+ assert data is not None and data['Response'] == 'True', "Data must not be empty"
+ return data
+ key = "omdb_{}".format(movie_id)
+ return self._cache(key, do_request)
+
def weight_rating(infos):
""" add 'rating' to all infos"""
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index 21c263f..a3cf411 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -18,16 +18,17 @@
background-color: #EFAAAA;
height: 150px;
}
- .td1, .td2, .td3, .td4 {
+ .td1, .td2, .td3, .td4, .td5 {
width: 1em;
font-size: 18pt;
- padding: 5px;
+ padding: 2px;
vertical-align: top;
}
.td1 .on { color: #ffd700; }
.td2 .on { color: blue; }
- .td1, .td2 .off { color: gray; }
- .td1 .num, .td2 .num { font-size: 12pt; color: gray; }
+ .td3 .on { color: red; }
+ .td4 .on { color: black; }
+ .td1 .off, .td2 .off, .td3 .off, .td4 .off, .td5 .off{ color: #c0c0c0; }
.poster {
margin: 10px;
width: 185px;
@@ -40,11 +41,19 @@
vertical-align: top;
}
.info table td { padding: .2em; }
- .details { padding: 1em; }
+ .details { padding: 0.5em; }
.files {
list-style: none;
padding-left: 0px;
- font-size: 0.9em;
+ font-size: 0.7em;
+ margin: 0px;
+ }
+ .imdbid {
+ font-family: monospace;
+ padding: 3px;
+ background-color: #f0f0f0;
+ border: 1px solid #e0e0e0;
+ border-radius: 4px;
}
.files li:before { margin: 0 1em; content: '▶'; }
.headline { font-size: 0.9em; color: 3e3e3e; }
@@ -56,39 +65,59 @@
color: #ccc;
font-style: italic;
}
+ .rated {
+ border: 1px solid black;
+ border-radius: 5px;
+ font-size:0.7em;
+ padding: 2px;
+ }
</style>
</head>
<body>
{% for (path, imdb_id) in input %}
{% set info = tmdbcache.infos(imdb_id) %}</h2>
{% if info %}
- {% set age = gmtime.tm_year - int(info['release_date'].split('-')[0]) %}
+ {% set year = int(info['release_date'].split('-')[0]) %}
+ {% set age = gmtime.tm_year - year %}
{% set centuries = int(age / 10) %}
{% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %}
{% set local_title = tmdbcache.alternative_title(imdb_id, "DE") %}
{% set imdb_data = tmdbcache.imdb_movie(imdb_id)['data'] %}
+ {% set omdb_data = tmdbcache.omdb_movie(imdb_id) %}
{% set votes = imdb_data['num_votes'] %}
{% set popularity = int( 9*(1 - (1+math.exp(-1))/(1+math.exp(votes/70000.0 -1 ))) + 1 ) %}
+ {% set fresh = (omdb_data.tomatoMeter != 'N/A') and int(omdb_data.tomatoMeter) or None %}
+ {% set userMeter = (omdb_data.tomatoUserMeter != 'N/A') and int(omdb_data.tomatoUserMeter) or None %}
<div class="box">
<table>
<tr>
{% if "vote_average" in info.keys() %}
- <td class="td1" title="TMDB Rating">
- <span class="off">{{ " ".join(["☆"] * (10-int(info["vote_average"]))) }}</span>
- <span class="on">{{ " ".join(["★"] * int(info["vote_average"])) }}</span>
- <span class="num">{{info["vote_average"]}}</span>
- </td>
- <td class="td2" title="IMDB Rating">
+ <td class="td1" title="IMDB Rating: {{imdb_data.rating}}">
<span class="off">{{ " ".join(["☆"] * (10-int(imdb_data["rating"]))) }}</span>
<span class="on">{{ " ".join(["★"] * int(imdb_data["rating"])) }}</span>
- <span class="num">{{imdb_data["rating"]}}</span>
</td>
- <td class="td3" title="IMDB Popularity">
+ {% if userMeter %}
+ <td class="td2" title="Rotten tomatoes user rating: {{userMeter}}%">
+ <span class="off">{{ " ".join(["☆"] * (10-int(userMeter/10))) }}</span>
+ <span class="on">{{ " ".join(["★"] * int(userMeter/10)) }}</span>
+ </td>
+ {% else %}
+ <td class="td2"></td>
+ {% endif %}
+ {% if fresh %}
+ <td class="td3" title="Rotten tomatoes: {{fresh}}% fresh">
+ <span class="off">{{ " ".join(["☆"] * (10-int(fresh/10))) }}</span>
+ <span class="on">{{ " ".join(["★"] * int(fresh/10)) }}</span>
+ </td>
+ {% else %}
+ <td class="td3"></td>
+ {% endif %}
+ <td class="td4" title="IMDB Popularity: {{votes}} votes">
<span class="off">{{ " ".join(["☆"] * (10-popularity)) }}</span>
<span class="on">{{ " ".join(["★"] * popularity) }}</span>
</td>
- <td class="td4" title="Centuries since release">
- <span class="off">{{ " ".join(["&nbsp;&nbsp;"] * (9-centuries)) }}</span>
+ <td class="td5" title="Centuries since release">
+ <span class="off">{{ " ".join(["⌚"] * (9-centuries)) }}</span>
<span class="on">{{ " ".join(["⌚"] * (centuries + 1)) }}</span>
</td>
{% endif %}
@@ -109,7 +138,10 @@
</div>
<div class="headline">
by {{ imdb_data["directors_summary"] | join(", ", attribute="name.name") }},
- runtime {{ info['runtime'] }} min.
+ runtime {{ info['runtime'] }} min, {{year}}
+ {% if omdb_data.Rated != 'N/A' %}
+ <span class="rated">{{omdb_data.Rated}}</span>
+ {% endif %}
</div>
<div class="headline">
Starring: {{ imdb_data["cast_summary"] | join(", ", attribute="name.name") }}
@@ -119,14 +151,17 @@
<table class="details">
{% if 'homepage' in info and info['homepage'] %}
<tr>
- <td style="font-style: italic">Homepage</td>
- <td><a href="{{ info['homepage'] }}">{{ info['homepage'] }}</a></td>
+ <td colspan="2">
+ ➜ <a href="{{ info['homepage'] }}">{{ info['homepage'] }}</a>
+ </td>
</tr>
- {% endif %}
+ {% elif omdb_data.Website != "N/A" %}
<tr>
- <td style="font-style: italic">Release</td>
- <td>{{ info['release_date'] }} {% if age > 0 %} &ensp;({{ age }} year{% if age > 1 %}s{% endif %} &ensp; old){% endif %}</td>
+ <td colspan="2">
+ ➜ <a href="{{ omdb_data.Website }}">{{ omdb_data.Website }}</a>
+ </td>
</tr>
+ {% endif %}
<tr>
<td colspan="2">
➜ <a href="http://www.themoviedb.org/movie/{{ info.id }}" rel="noreferrer">themoviedb.org</a>
@@ -136,6 +171,8 @@
➜ <a href="http://letterboxd.com/tmdb/{{ info.id }}" rel="noreferrer">letterboxd.com</a>
&ensp;
➜ <a href="http://www.ofdb.de/view.php?page=suchergebnis&Kat=IMDb&SText={{ info.imdb_id }}" rel="noreferrer">ofdb.db</a>
+ &ensp;
+ ➜ <span class="imdbid">{{ info.imdb_id }}</span>
</td>
</tr>
</table>