summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-12-09 23:04:51 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-12-09 23:04:51 +0100
commita4657a5aff417e0a03d6794c59725ddad0875ced (patch)
tree7bb10306002e6d575f920f6a8223d3b198774539
parent7cf4924c983d62fef25cf5eeaf4647f7220d818d (diff)
downloadscripts-a4657a5aff417e0a03d6794c59725ddad0875ced.tar.gz
scripts-a4657a5aff417e0a03d6794c59725ddad0875ced.zip
more compact
-rwxr-xr-ximdb-lookup/imdbinfo.py20
-rw-r--r--imdb-lookup/index.jinja2.html65
2 files changed, 47 insertions, 38 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index eeea947..4290dac 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -17,7 +17,7 @@ from io import BytesIO
from urllib.parse import quote as urlencode
try:
- from PIL import Image
+ from PIL import Image, ImageFilter
import tmdbsimple as tmdb
import requests
except ImportError as e:
@@ -126,12 +126,11 @@ class TMDBCache(object):
return None
contentType, data = p
image = Image.open(BytesIO(data))
+ image = image.filter(ImageFilter.GaussianBlur(radius=1))
buf = BytesIO()
- image.save(buf, "JPEG", quality=10, optimize=True)
- data64 = base64.encodestring(buf.getvalue())
- data64 = "".join(map(lambda c: isinstance(c, int) and chr(c) or c,
- filter(lambda c: c != '\n', data64)))
- return "data:{};base64,{}".format(contentType, data64)
+ image.save(buf, "JPEG", quality=15, optimize=True)
+ data64 = base64.encodestring(buf.getvalue()).translate(None, b'\n')
+ return "data:{};base64,{}".format("image/jpeg", data64.decode())
def _imdb_request(self, path, query):
# see also https://github.com/richardasaurus/imdb-pie
@@ -287,10 +286,6 @@ def do_index(args, imdb_ids):
if sum(map(curfile.endswith, valid_extensions)):
yield os.path.join(root, curfile)
- def asBase64(poster):
- contentType, data = poster
- data64 = filter(lambda c: c != '\n', base64.encodestring(data))
- return "data:{};base64,{}".format(contentType, data64)
try:
from jinja2 import Template
except ImportError:
@@ -309,12 +304,15 @@ def do_index(args, imdb_ids):
'int': int,
'listMovieFiles': listMovieFiles,
'math': math,
+ 'pathjoin': os.path.join,
}
assert not os.path.exists("index.html"), "index.html already exists"
stream = template.generate(mapping)
outfile = open("index.html", "wb")
for output in stream:
- outfile.write(output.encode('utf-8'))
+ out = output.strip()
+ out = re.sub(" {2,}", " ", out)
+ outfile.write(out.encode('utf-8'))
class HelpAction(argparse._HelpAction):
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index dfdb9c7..b09abf1 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -7,9 +7,9 @@
<title>{{title}}</title>
<style>
.box {
- margin: 2em 5em auto;
+ margin: 20px 50px auto;
border-radius: 5px;
- box-shadow: 0px 0px 30px 0px gray;
+ box-shadow: 0px 0px 15px 0px gray;
background-color: #fafafa;
clear: both;
position: relative;
@@ -20,34 +20,33 @@
}
.td1, .td2, .td3, .td4, .td5 {
width: 1em;
- font-size: 18pt;
- padding: 2px;
+ font-size: 16pt;
+ margin: 2px;
vertical-align: top;
}
- .td1 .on { color: #ffd700; }
+ .td1 .on { color: rgba(0,0,0,0); }
.td2 .on { color: blue; }
- .td3 .on { color: red; }
+ .td3 .on { color: rgba(0,0,0,0); }
.td4 .on { color: black; }
.td1 .off, .td2 .off, .td4 .off, .td5 .off{ color: #c0c0c0; }
+ .off div {
+ opacity: 0.1;
+ }
+ .imdb {
+ background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABWklEQVQ4y6VTu0oDQRQ9uxslARM3SSGkEbLtNpLGRyeW/oP6ARYWoq34ATaLP2AVsRS7iE0QhNgYSCCRaKGCCIYksM/JtZidNZvd4CMHhjMM99x77swd6fZcJUyBRN9JY6oEALC6NhscMOazy9nzfHa/RZ7Dudl2eII44U9iES8NOhr9pWqk0OFulgBQ2SgQAFIzMr0/aASAAJBxvBDsS3qSGpUiAaD2jUaNSpHk8Uvp9oZottzIZZWNAmp1C6dnnwAAl/HHSwi7AmpGxs7eG9SMjG5vGJyX9FQo7ujkA60nBxEH+ayCx2cX+awS+2yi99y8glrdiiZYXkqFmPkOhWWBjZU5AIDMxtrNqUqIBe7urVhHEQeb62loizORwK39V5T0ZFB5++CFz0GnqtFob8Iqs6WR6aTQLAjYJiBfXPUnihmjWLFt8lVtDPgo/7aqbU74TJfXg3//xi8q0rI5o/Rj/gAAAABJRU5ErkJggg==) no-repeat center;
+ }
.tomato {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACd0lEQVQ4y4WTS0iUYRSGn/+fcUQdzZwZRnDUmsYLUUQXaooC29uiaFVUFLQLXGSSRJtoJ102rSKiWtSmC7SLLi4iUhdBhKBoVmqW02/jODPOzPd/32nhrWiyszrn5ZyXc3kPrGJbu+Id/MfsYmD8WKsF4M+qSwfObY2vRuApBm5rX39056HoLTM8G6pcVxmN7qurHuqdHCiWay054c211O8N1YUrfc9qass2Dg3nTNXgD7va76O6LZwPOoWrnXcTN4NTH8eKEgDcObm983nU1yOlNqbUQ85xCTWVEXw3R1nK5X2Djy1z8vBCT99hJxIjMDGyQtC7pfn6dIXdcWDKxecVjnc30PRqhs+tFRDycePiODbwotbGCZT0HX85GAewnEgMYJcNb03Yw/NmH08aS6nHors/DZ8U50+HOfIgwSbHLCxOQFucAm5bAE4k9pRyq93T4qO8sQJvqBylNLnJDHp0noGcgAU7Jt3fJ3YCEyNBLwBCO+UWVqWXQrAMWsKYZBY7qxB/nt3jBcZKVyoFUEgAwLuMasAVUBqdzCLzCpRGtKCASFqW03IipGQh9i7e4g0Z2WNmXKyvWWTeXSCaziM/DShBgDxCRoSfxpARowG8CdYAXKEge8wXhSjB9ucRDeK4yHeNArIipMQwYwzftUK0exnA0un+Eo9/p3IisVdAG7KoDllsF2EOIWk0Ca355uZJF/LjnelUA4C9WExgYmQ/8BhrYUk5S0hi+GY0465itJDnQyZFIpt5dzYUi96vqvlTiUvKSkRi8XmRrlkxB6eNJqEVSaVIqtxrv1jXzmTnHt2pquFEaqb4d03Ubfjn592rWvsX9guv1i7Q6dsNWAAAAABJRU5ErkJggg==) no-repeat center;
- width: 16px;
- height: 16px;
- padding: 1px;
- display: inline-block;
- }
- .td3 .off {
- opacity: 0.1;
}
.poster {
margin: 10px;
- width: 185px;
+ width: 154px;
float: left;
min-height: 200px;
box-shadow: 0px 0px 5px 0px gray;
}
.info {
- padding-left: 2em;
+ padding-left: 5px;
vertical-align: top;
}
.info table td { padding: .2em; }
@@ -65,8 +64,9 @@
border: 1px solid #e0e0e0;
border-radius: 4px;
}
- .files li:before { margin: 0 1em; content: '▶'; }
+ .title { font-size: 2em; }
.headline { font-size: 0.9em; color: 3e3e3e; }
+ .plot { margin-top: 10px; }
.box-footer {
position: absolute;
bottom: 0px;
@@ -90,7 +90,7 @@
{% 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 posterBase64 = tmdbcache.poster_base64(info['poster_path'],'w154') %}
{% 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) %}
@@ -103,8 +103,16 @@
<tr>
{% if "vote_average" in info.keys() %}
<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="off">
+ {% for i in range(int(imdb_data.rating),10) %}
+ <div class="imdb">☆</div>
+ {% endfor %}
+ </span>
+ <span class="on">
+ {% for i in range(0, int(imdb_data.rating)) %}
+ <div class="imdb">★</div>
+ {% endfor %}
+ </span>
</td>
{% if userMeter %}
<td class="td2" title="Rotten tomatoes user rating: {{userMeter}}%">
@@ -118,12 +126,12 @@
<td class="td3" title="Rotten tomatoes: {{fresh}}% fresh">
<span class="off">
{% for i in range(int(fresh/10),10) %}
- <span class="tomato">&nbsp;</span>
+ <div class="tomato">☆</div>
{% endfor %}
</span>
<span class="on">
{% for i in range(0, int(fresh/10)) %}
- <span class="tomato">&nbsp;</span>
+ <div class="tomato">★</div>
{% endfor %}
</span>
</td>
@@ -147,7 +155,7 @@
{% endif %}
</td>
<td class="info">
- <div style="font-size: 2em;">
+ <div class="title">
{{ info.title }}
</div>
<div class="headline">
@@ -164,8 +172,7 @@
<div class="headline">
Starring: {{ imdb_data["cast_summary"] | join(", ", attribute="name.name") }}
</div>
- <br />
- <div>{{ imdb_data.plot.outline }}</div>
+ <div class="plot">{{ "plot" in imdb_data and imdb_data.plot.outline or ""}}</div>
<table class="details">
{% if 'homepage' in info and info['homepage'] %}
<tr>
@@ -197,9 +204,13 @@
<ul class="files">
{% for file in listMovieFiles(path) %}
<li>
- <a href="{{urlencode(file)}}">
- {{ " &gt; ".join(file.split("/")[1:]) }}
+ {% set pathElements = file.split("/") %}
+ {% for i in range(1,pathElements.__len__()) %}
+ ➜
+ <a href="{{urlencode(pathjoin(*pathElements[:i+1]))}}">
+ {{ pathElements[i] }}
</a>
+ {% endfor %}
</li>
{% endfor %}
</ul>
@@ -207,7 +218,7 @@
</tr>
</table>
<div class="box-footer">
- {{ info.tagline }}
+ {{ info.tagline and info.tagline or "" }}
</div>
</div>
{% else %}