diff options
Diffstat (limited to 'imdb-lookup/imdbinfo.py')
-rwxr-xr-x | imdb-lookup/imdbinfo.py | 78 |
1 files changed, 30 insertions, 48 deletions
diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py index 85bcfe1..4c903ec 100755 --- a/imdb-lookup/imdbinfo.py +++ b/imdb-lookup/imdbinfo.py @@ -288,29 +288,11 @@ def do_rating(args, imdb_ids): def do_index(args, imdb_ids): """creates a index website""" - try: - from jinja2 import Template - except ImportError: - print("Failed to import jinja2 library for html-templating") - sys.exit(1) - - assert not os.path.exists("index.html") and not os.path.exists(".index.html"), \ - "index.html or folder .index.html already exists" - outdir = ".index.html" - os.mkdir(outdir) - os.mkdir(os.path.join(outdir, "poster")) - - def install(filename): - outpath = os.path.join(".index.html", os.path.dirname(filename)) - if not os.path.exists(outpath): - os.makedirs(outpath) - src = os.path.join(os.path.dirname(__file__),filename) - out = os.path.join(outpath, os.path.basename(filename)) - shutil.copy(src, out) - return out - - def data(callbackName): - filename = ".index.html/js/data.js" + assert not os.path.exists("index.html") and not os.path.exists("index-files"), \ + "index.html or folder index-files already exists" + + def write_data(callbackName): + filename = "index-files/data.js" if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) @@ -325,26 +307,32 @@ def do_index(args, imdb_ids): return filename def getInfo(a): - def listMovieFiles(path): - valid_extensions = [".mkv", ".avi", ".mov", ".mp4", ".mpg"] - def listFiles(): + def get_tags(path): + def find(): for root, dirs, files in os.walk(path): for curfile in files: - if sum(map(curfile.endswith, valid_extensions)): - yield os.path.join(root, curfile) - files = list(listFiles()) - if not files: - files = [path] - return list(list(map(urlencode, files))) + if curfile.endswith("mkv"): + yield "MKV" + if curfile.endswith("avi"): + yield "AVI" + for curdir in dirs: + if "german" in curdir: + yield "GERMAN" + if "1080" in curdir: + yield "1080p" + if "720p" in curdir: + yield "720p" + return list(set(find())) def poster(imdb_id): data = db.poster_low(imdb_id) if data: - out = os.path.join(".index.html/poster",imdb_id+".jpg") + out = os.path.join("index-files/poster",imdb_id+".jpg") open(out, "wb").write(data) return out else: return None + path, imdb_id = a db = Protector(TMDBCache()) imdb = db.imdb_movie(imdb_id) @@ -363,7 +351,8 @@ def do_index(args, imdb_ids): 'plot': 'plot' in imdb and imdb['plot']['outline'] or None, 'website': 'homepage' in imdb and imdb['homepage'] or omdb['Website'] != 'N/A' and omdb['Website'] or None, 'release': 'release_date' in tmdb and tmdb['release_date'] or None, - 'movieFiles': list(listMovieFiles(path)), + 'path': {'label':path, 'path':urlencode(path)}, + 'tags': get_tags(path), 'imdbRating': imdb['rating'], 'imdbVotes': imdb['num_votes'], 'omdbTomatoConsensus': (omdb['tomatoConsensus'] != 'N/A') and omdb['tomatoConsensus'] or None, @@ -374,21 +363,14 @@ def do_index(args, imdb_ids): 'tmdbId': tmdb['id'], } + datadir = os.path.join(os.path.dirname(__file__), "html") + index_files = os.path.join(datadir, "index-files") + index_html = os.path.join(datadir, "index.html") + shutil.copytree(index_files, "index-files") + shutil.copy2(index_html, ".") - template_file = os.path.join(os.path.dirname(__file__), - "index.jinja2.html") - template = Template(open(template_file, "r").read()) - mapping = { - 'title': 'Movie overview', - 'install': install, - 'data': data, - } - stream = template.generate(mapping) - outfile = open("index.html", "wb") - for output in stream: - out = output.strip() - out = re.sub(" {2,}", " ", out) - outfile.write(out.encode('utf-8')) + os.mkdir("index-files/poster") + write_data("dataCb") class HelpAction(argparse._HelpAction): |