summaryrefslogtreecommitdiff
path: root/imdb-lookup
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-11-22 22:50:12 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-11-22 22:50:12 +0100
commit85ed124b5d9a189d2eceb512c545f57b29e428de (patch)
treed85264a515a9f8fc31c1928d02645c06ddd5e0e5 /imdb-lookup
parentc08d2b4a03f89c6fe5384474febb2e2f93a25ee2 (diff)
downloadscripts-85ed124b5d9a189d2eceb512c545f57b29e428de.tar.gz
scripts-85ed124b5d9a189d2eceb512c545f57b29e428de.zip
links to movies sites
Diffstat (limited to 'imdb-lookup')
-rwxr-xr-ximdb-lookup/imdbinfo.py30
-rw-r--r--imdb-lookup/index.jinja2.html189
2 files changed, 136 insertions, 83 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 7b23356..caf00a4 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -6,15 +6,16 @@ import sys
import re
import dbm
import json
+import time
import base64
import argparse
import math
import logging
-from StringIO import StringIO
-try:
- from urllib.parse import quote as urlencode
-except:
- from urllib import quote as urlencode
+try: from StringIO import StringIO
+except: from io import StringIO
+
+try: from urllib.parse import quote as urlencode
+except: from urllib import quote as urlencode
try:
from PIL import Image
@@ -112,7 +113,16 @@ class TMDBCache(object):
data64 = "".join(map(lambda c: isinstance(c,int) and chr(c) or c,
filter(lambda c: c!='\n', base64.encodestring(buf.getvalue()))))
return "data:{};base64,{}".format(contentType, data64)
-
+
+
+def weight_rating(infos):
+ """ add 'rating' to all infos"""
+ maxvotes = max(map(lambda i: i["vote_count"], infos))
+ for info in infos:
+ f = math.sin(math.pi * ( info["vote_average"]/10.0 ) )
+ d = (float(info["vote_count"]) / maxvotes) - 0.5
+ info['rating'] = info["vote_average"] + 2 * d * f
+ return infos
class Protector(object):
def __init__(self, child):
@@ -161,11 +171,8 @@ def do_rating(args, imdb_ids):
with TMDBCache() as tmdbcache:
infos = list(filter(lambda i: "vote_average" in i and "vote_count" in i,
map(lambda fid: tmdbcache.infos(fid[1]), imdb_ids)))
- maxvotes = max(map(lambda i: i["vote_count"], infos))
+ weight_rating(infos)
for info in infos:
- f = math.sin(math.pi * ( info["vote_average"]/10.0 ) )
- d = (float(info["vote_count"]) / maxvotes) - 0.5
- info['rating'] = info["vote_average"] + 2 * d * f
print(u"{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info))
@@ -183,9 +190,8 @@ def do_index(args, imdb_ids):
template_file = os.path.join(os.path.dirname(__file__), "index.jinja2.html")
template = Template(open(template_file, "rb").read().decode('utf-8'))
with TMDBCache() as tmdbcache:
- #infos = list(map(tmdbcache.infos, imdb_ids))
- #posters = list(map(asBase64, map(tmdbcache.poster, map(lambda info: info['poster_path'], infos))))
mapping = {
+ 'gmtime' : time.gmtime(),
'input' : imdb_ids,
'tmdbcache' : Protector(tmdbcache),
'title' : 'Movie overview',
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index 019e937..b318b83 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -2,75 +2,122 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>{{title}}</title>
- <style>
- .box {
- margin: 2em 5em auto;
- border-radius: 5px;
- border: 2px solid gray;
- box-shadow: 0px 0px 30px 0px gray;
- background-color: #fafafa;
- clear: both;
- }
- .td1 {
- width: 1em;
- font-size: 18pt;
- padding: 5px;
- }
- .td2 {
- margin: 10px;
- width: 185px;
- float: left;
- min-height: 200px;
- box-shadow: 0px 0px 5px 0px gray;
- }
- .td3 { padding-left: 2em; }
- .td3 table td { padding: .2em; }
- </style>
- </head>
- <body>
- {% for (filename, imdb_id) in input %}
- {% set info = tmdbcache.infos(imdb_id) %}</h2>
- {% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %}
- {% if info %}
- <div class="box">
- <table>
- <tr>
- {% if "vote_average" in info.keys() %}
- <td class="td1">
- <span style="color:gray;">{{ " ".join(["☆"] * (10-int(info["vote_average"]))) }}</span>
- <span style="color: #ffd700;">{{ " ".join(["★"] * int(info["vote_average"])) }}</span>
- </td>
- {% endif %}
- <td class="td2">
- {% if posterBase64 %}
- <a href="{{urlencode(filename)}}"><img src="{{ posterBase64 }}" /></a>
- {% else %}
- <span> no image </span>
- {% endif %}
- </td>
- <td class="td3">
- <div style="font-size: 2em;">{{ info.title }}</div>
- <div style="font-size: 1.2em;">{{ info.overview }}</div>
- <table style="padding: 2em;">
- {% for (key, value) in info.items() %}
- {% if key in ['runtime','adult','homepage','release_date','original_title'] %}
- <tr>
- <td style="font-style: italic;">{{ key }}</td>
- <td>{{ value }}</td>
- </tr>
- {% endif %}
- {% endfor %}
- </table>
- </td>
- </tr>
- </table>
- </div>
- {% else %}
- <span>No infos for {{filename}} {{imdb_id}}</span>
- {% endif %}
- {% endfor %}
- </body>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>{{title}}</title>
+ <style>
+ .box {
+ margin: 2em 5em auto;
+ border-radius: 5px;
+ box-shadow: 0px 0px 30px 0px gray;
+ background-color: #fafafa;
+ clear: both;
+ }
+ .error {
+ background-color: #EFAAAA;
+ }
+ .td1, .td2, .td3 {
+ width: 1em;
+ font-size: 18pt;
+ padding: 5px;
+ }
+ .td1 .on { color: #ffd700; }
+ .td2 .on { color: blue; }
+ .td1, .td2 .off { color: gray; }
+ .poster {
+ margin: 10px;
+ width: 185px;
+ float: left;
+ min-height: 200px;
+ box-shadow: 0px 0px 5px 0px gray;
+ }
+ .infos {
+ padding-left: 2em;
+ vertical-align: top;
+ }
+ .infos table td { padding: .2em; }
+ </style>
+ </head>
+ <body>
+ {% for (filename, 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 centuries = int(age / 10) %}
+ {% set posterBase64 = tmdbcache.poster_base64(info['poster_path']) %}
+ <div class="box">
+ <table>
+ <tr>
+ {% if "vote_average" in info.keys() %}
+ <td class="td1">
+ <span class="off">{{ " ".join(["☆"] * (10-int(info["vote_average"]))) }}</span>
+ <span class="on">{{ " ".join(["★"] * int(info["vote_average"])) }}</span>
+ </td>
+ <td class="td2">
+ <span class="off">{{ " ".join(["☆"] * (10-int(info["popularity"]*10))) }}</span>
+ <span class="on">{{ " ".join(["★"] * int(info["popularity"]*10)) }}</span>
+ </td>
+ <td class="td3">
+ <span class="off">{{ " ".join(["&nbsp;&nbsp;"] * (10-centuries)) }}</span>
+ <span class="on">{{ " ".join(["⌚"] * centuries) }}</span>
+ </td>
+ {% endif %}
+ <td class="poster">
+ {% if posterBase64 %}
+ <a href="{{urlencode(filename)}}"><img src="{{ posterBase64 }}" /></a>
+ {% else %}
+ <span> no image </span>
+ {% endif %}
+ </td>
+ <td class="infos">
+ <div style="font-size: 2em;">
+ {{ info.title }}
+ {% if info.title != info.original_title %}
+ &ensp;({{ info.original_title }})
+ {% endif %}
+ </div>
+ <div>{{ info.overview }}</div>
+ <table style="padding: 2em;">
+ {% if 'runtime' in info %}
+ <tr>
+ <td style="font-style: italic">Runtime</td>
+ <td>{{ info['runtime'] }}</td>
+ </tr>
+ {% endif %}
+ {% if 'homepage' in info %}
+ <tr>
+ <td style="font-style: italic">Homepage</td>
+ <td><a href="{{ info['homepage'] }}">{{ info['homepage'] }}</a></td>
+ </tr>
+ {% endif %}
+ <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>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <a href="http://www.themoviedb.org/movie/{{ info.id }}" rel="noreferrer">→ themoviedb.org</a>
+ &ensp;
+ <a href="http://www.imdb.com/title/{{ info.imdb_id }}" rel="noreferrer">→ imdb.com</a>
+ &ensp;
+ <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>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </div>
+ {% else %}
+ <div class="box error">
+ No infos for {{filename}} {{imdb_id}}
+ </div>
+ {% endif %}
+ {% endfor %}
+ </body>
</html>
+<!--
+vim: tabstop=1 expandtab shiftwidth=1 softtabstop=1:
+-->