summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUser Jack <jack@garcon.2.localnet.cc>2014-11-28 19:17:59 +0000
committerUser Jack <jack@garcon.2.localnet.cc>2014-11-28 19:17:59 +0000
commit0c7044179c9540f992642be42bac884d0a5840bd (patch)
tree634f54474ef88b37369720fb694d08b9bd001d81
parentbcc636bdd6b796bc3fd606461222a60ec5ae2f92 (diff)
downloadscripts-0c7044179c9540f992642be42bac884d0a5840bd.tar.gz
scripts-0c7044179c9540f992642be42bac884d0a5840bd.zip
Encoding Hell
-rw-r--r--imdb-lookup/README.md17
-rwxr-xr-ximdb-lookup/imdbinfo.py24
-rw-r--r--imdb-lookup/index.jinja2.html10
3 files changed, 36 insertions, 15 deletions
diff --git a/imdb-lookup/README.md b/imdb-lookup/README.md
new file mode 100644
index 0000000..2512418
--- /dev/null
+++ b/imdb-lookup/README.md
@@ -0,0 +1,17 @@
+# movie tools
+
+
+imdblookup.py Rename with Text gui
+
+
+imdbinfo.py general tools
+
+
+
+# TMDB:
+for tmdb you need a Api-Key
+
+
+# IMDB:
+for imdb we use the mobile api.
+By executing the tool you are probably violating the imdb ToS.
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py
index 504528a..163cec9 100755
--- a/imdb-lookup/imdbinfo.py
+++ b/imdb-lookup/imdbinfo.py
@@ -13,7 +13,7 @@ import argparse
import math
import logging
import hashlib
-from io import StringIO
+from io import BytesIO
from urllib.parse import quote as urlencode
@@ -86,6 +86,7 @@ class TMDBCache(object):
raise Exception("Failed to query movie with id {id}: {reason}".format(id=movie_id, reason=str(e)))
def prune(self, movie_id):
+ self.logger.debug("prune {}".format(movie_id))
keys = [
"imdb_maindetails_{}".format(movie_id),
movie_id + "movies.info",
@@ -93,8 +94,10 @@ class TMDBCache(object):
]
for key in keys:
if key in self.db:
- print("Remove {}".format(key))
+ self.logger.warn("Remove {}".format(key))
del self.db[key]
+ else:
+ self.logger.debug("Key not in db {}".format(key))
def poster(self, poster_path, format="w185"):
self.logger.debug("poster %s", poster_path)
@@ -111,8 +114,8 @@ class TMDBCache(object):
p = self.poster(poster_path, format)
if not p: return None
contentType, data = p
- image = Image.open(StringIO(data))
- buf = StringIO()
+ image = Image.open(BytesIO(data))
+ buf = BytesIO()
image.save(buf, "JPEG", quality=10, optimize=True)
data64 = "".join(map(lambda c: isinstance(c,int) and chr(c) or c,
filter(lambda c: c!='\n', base64.encodestring(buf.getvalue()))))
@@ -137,13 +140,15 @@ class TMDBCache(object):
}
q = query.copy()
q.update(PARAMS)
- return requests.get("http://{}{}".format(BASE_URI, path), params=q, headers=HEADERS)
+ return requests.get("https://{}{}".format(BASE_URI, path), params=q, headers=HEADERS)
def imdb_movie(self, movie_id):
def do_request():
r = self._imdb_request("/title/maindetails", {'tconst': movie_id})
assert r.status_code == 200, "Request must return status-code 200"
- return json.loads(r.content)
+ data = json.loads(r.text)
+ assert data != None and data['data'], "Data must not be empty"
+ return data
key = "imdb_maindetails_{}".format(movie_id)
return self._cache(key, do_request)
@@ -242,7 +247,7 @@ def do_index(args, imdb_ids):
print("Failed to import jinja2 library for html-templating")
sys.exit(1)
template_file = os.path.join(os.path.dirname(__file__), "index.jinja2.html")
- template = Template(open(template_file, "rb").read().decode('utf-8'))
+ template = Template(open(template_file, "r").read())
with TMDBCache() as tmdbcache:
mapping = {
'gmtime' : time.gmtime(),
@@ -258,8 +263,7 @@ def do_index(args, imdb_ids):
stream = template.generate(mapping)
outfile = open("index.html", "wb")
for output in stream:
- output = output.encode("utf-8")
- outfile.write(output.strip())
+ outfile.write(output.encode('utf-8'))
class HelpAction(argparse._HelpAction):
def __call__(self, parser, namespace, values, option_string=None):
@@ -340,6 +344,6 @@ if __name__ == "__main__":
if "files" in args:
ids = map(lambda filename: (lambda x: (filename, x.groups()[0]) if x else None)(re.match(".*#(tt[0-9]{7}).*", filename)),
args.files[0])
- args.func(args, filter(lambda i: i is not None, ids))
+ args.func(args, list(filter(lambda i: i is not None, ids)))
else:
args.func(args)
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index a3e004e..82647c3 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -113,13 +113,13 @@
</tr>
<tr>
<td colspan="2">
- → <a href="http://www.themoviedb.org/movie/{{ info.id }}" rel="noreferrer">themoviedb.org</a>
+ -&gt; <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>
+ -&gt; <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>
+ -&gt; <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>
+ -&gt; <a href="http://www.ofdb.de/view.php?page=suchergebnis&Kat=IMDb&SText={{ info.imdb_id }}" rel="noreferrer">ofdb.db</a>
</td>
</tr>
</table>
@@ -127,7 +127,7 @@
{% for file in listMovieFiles(path) %}
<li>
<a href="{{urlencode(file)}}">
- {{ u" → ".join(file.split("/")[1:]) }}
+ {{ " &gt; ".join(file.split("/")[1:]) }}
</a>
</li>
{% endfor %}