diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2014-12-23 01:35:48 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2014-12-23 01:35:48 +0100 |
commit | 94a86bb23d97c2fd1bc38fca73b99e72a7fdfa8e (patch) | |
tree | becf09c66ee26dc2dd4f7fd26652fbd296baf828 | |
parent | 82f5bd6a4aff840f21076a8bf47a022d08b1dddf (diff) | |
download | scripts-94a86bb23d97c2fd1bc38fca73b99e72a7fdfa8e.tar.gz scripts-94a86bb23d97c2fd1bc38fca73b99e72a7fdfa8e.zip |
remove jinja
-rw-r--r-- | imdb-lookup/Makefile | 23 | ||||
-rw-r--r-- | imdb-lookup/html/index-files/css/normalize.css (renamed from imdb-lookup/css/normalize.css) | 0 | ||||
-rw-r--r-- | imdb-lookup/html/index-files/css/style.css (renamed from imdb-lookup/css/style.css) | 0 | ||||
-rw-r--r-- | imdb-lookup/html/index-files/js/app.js (renamed from imdb-lookup/js/app.js) | 52 | ||||
-rw-r--r-- | imdb-lookup/html/index-files/js/libs/all.js (renamed from imdb-lookup/js/libs/all.js) | 0 | ||||
-rw-r--r-- | imdb-lookup/html/index-files/js/libs/all.min.js (renamed from imdb-lookup/js/libs/all.min.js) | 0 | ||||
-rw-r--r-- | imdb-lookup/html/index.html | 155 | ||||
-rwxr-xr-x | imdb-lookup/imdbinfo.py | 78 | ||||
-rw-r--r-- | imdb-lookup/index.jinja2.html | 119 | ||||
-rw-r--r-- | imdb-lookup/js/libs/Makefile | 24 | ||||
-rw-r--r-- | imdb-lookup/libs/ember-1.9.0.js (renamed from imdb-lookup/js/libs/ember-1.9.0.js) | 0 | ||||
-rw-r--r-- | imdb-lookup/libs/ember-data-1.0.0-beta.12.js (renamed from imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js) | 0 | ||||
-rw-r--r-- | imdb-lookup/libs/handlebars-v2.0.0.js (renamed from imdb-lookup/js/libs/handlebars-v2.0.0.js) | 0 | ||||
-rw-r--r-- | imdb-lookup/libs/jquery-1.11.2.js (renamed from imdb-lookup/js/libs/jquery-1.11.2.js) | 0 |
14 files changed, 248 insertions, 203 deletions
diff --git a/imdb-lookup/Makefile b/imdb-lookup/Makefile new file mode 100644 index 0000000..1bbbcc6 --- /dev/null +++ b/imdb-lookup/Makefile @@ -0,0 +1,23 @@ +CLOSURE=~/vcs/v86/closure-compiler/compiler.jar + +all: debug release + +debug: + java -jar $(CLOSURE) \ + --compilation_level WHITESPACE_ONLY \ + --formatting PRETTY_PRINT \ + libs/jquery-1.11.2.js \ + libs/handlebars-v2.0.0.js \ + libs/ember-1.9.0.js \ + libs/ember-data-1.0.0-beta.12.js \ + > html/index-files/js/libs/all.js + +release: + java -jar $(CLOSURE) \ + --compilation_level SIMPLE_OPTIMIZATIONS \ + libs/jquery-1.11.2.js \ + libs/handlebars-v2.0.0.js \ + libs/ember-1.9.0.js \ + libs/ember-data-1.0.0-beta.12.js \ + > html/index-files/js/libs/all.min.js + diff --git a/imdb-lookup/css/normalize.css b/imdb-lookup/html/index-files/css/normalize.css index c2de8df..c2de8df 100644 --- a/imdb-lookup/css/normalize.css +++ b/imdb-lookup/html/index-files/css/normalize.css diff --git a/imdb-lookup/css/style.css b/imdb-lookup/html/index-files/css/style.css index 497333c..497333c 100644 --- a/imdb-lookup/css/style.css +++ b/imdb-lookup/html/index-files/css/style.css diff --git a/imdb-lookup/js/app.js b/imdb-lookup/html/index-files/js/app.js index f341497..7570ba5 100644 --- a/imdb-lookup/js/app.js +++ b/imdb-lookup/html/index-files/js/app.js @@ -18,7 +18,8 @@ App.Movie = DS.Model.extend({ plot: DS.attr('string'), website: DS.attr('string'), release: DS.attr('string'), - movieFiles: DS.attr(), + path: DS.attr(), + tags: DS.attr(), imdbRating: DS.attr('int'), imdbVotes: DS.attr('int'), @@ -51,7 +52,11 @@ App.Movie = DS.Model.extend({ App.IndexController = Ember.ArrayController.extend({ page: 1, perPage: "10", - sortProperties: ["title"], + sortAscending: "false", + sortProperties: function() { + return [this.get("firstSortProperty")]; + }.property("firstSortProperty"), + firstSortProperty: "title", visiblePerPage: ["10", "20", "25", "50", "100", "250", "500"], pages: function() { var list = []; @@ -77,7 +82,11 @@ App.IndexController = Ember.ArrayController.extend({ runningLabel = "" + p1; prev = p1; } - list.push({number: i, runningLabel: runningLabel}); + var style = ""; + if (i == this.get('page')) { + style = "background-color: red;"; + } + list.push({number: i, runningLabel: runningLabel, style: style}); } return list; }.property('page','perPage','sortProperties'), @@ -95,23 +104,42 @@ App.IndexController = Ember.ArrayController.extend({ return this.get('arrangedContent').slice(start, end) }, actions: { - sortBy: function(property) { - this.set('sortProperties', [property]); - this.set('sortAscending', !this.get('sortAscending')); - }, setPage: function(property) { - this.set('page', property) + this.set('page', property); + }, + nextPage: function() { + var current = this.get('page'); + if (current < this.get('pagesCount')) { + this.set('page', current+1); + } + }, + prevPage: function() { + var current = this.get('page'); + if (current > 1) { + this.set('page', current-1); + } } } }); +App.Movie.reopenClass({FIXTURES:[]}) -Ember.Handlebars.helper('filelink', function(value, options) { - return new Ember.Handlebars.SafeString('<a href="' + value + '">' + decodeURI(value) + '</span>'); -}); +App.RadioView = Ember.Checkbox.extend({ + type: "radio", + checked: function() { + var property = this.get("property"); + var value = this.get("value"); + return this.get("controller").get(property) == value; + }.property(), + click: function() { + var property = this.get("property"); + var value = this.get("value"); + this.get("controller").set(property, value); + } +}) function dataCb(data) { - App.Movie.FIXTURES = data; + App.Movie.reopenClass({FIXTURES:data}) } window['dataCb'] = dataCb; diff --git a/imdb-lookup/js/libs/all.js b/imdb-lookup/html/index-files/js/libs/all.js index 5452dcf..5452dcf 100644 --- a/imdb-lookup/js/libs/all.js +++ b/imdb-lookup/html/index-files/js/libs/all.js diff --git a/imdb-lookup/js/libs/all.min.js b/imdb-lookup/html/index-files/js/libs/all.min.js index 90a96ca..90a96ca 100644 --- a/imdb-lookup/js/libs/all.min.js +++ b/imdb-lookup/html/index-files/js/libs/all.min.js diff --git a/imdb-lookup/html/index.html b/imdb-lookup/html/index.html new file mode 100644 index 0000000..8bace8d --- /dev/null +++ b/imdb-lookup/html/index.html @@ -0,0 +1,155 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Movies</title> + <link rel="stylesheet" href="index-files/css/normalize.css" /> + <link rel="stylesheet" href="index-files/css/style.css" /> + </head> + <body> + <script type="text/x-handlebars"> + {{outlet}} + </script> + <script type="text/x-handlebars" id="index"> + <div class="box"> + <div class="sort"> + <fieldset> + <legend>Sort by</legend> + <label> + {{view "radio" name="sortProperties" value="title" property="firstSortProperty"}} + Title + </label> + <label> + {{view "radio" name="sortProperties" value="imdbRating" property="firstSortProperty"}} + IMDB Rating + </label> + <label> + {{view "radio" name="sortProperties" value="imdbVotes" property="firstSortProperty"}} + IMDB Votes + </label> + <label> + {{view "radio" name="sortProperties" value="release" property="firstSortProperty"}} + Release Year + </label> + <label> + {{view "radio" name="sortProperties" value="omdbTomato" property="firstSortProperty"}} + RT Meter % + </label> + <label> + {{view "radio" name="sortProperties" value="omdbTomatoRating" property="firstSortProperty"}} + RT Rating + </label> + </fieldset> + <fieldset style="display: inline-block;"> + <legend>Sort Direction</legend> + <label> + {{view "radio" name="sortDirection" value="false" property="sortAscending"}} + Descending + </label> + <label> + {{view "radio" name="sortDirection" value="true" property="sortAscending"}} + Ascending + </label> + </fieldset> + <fieldset style="display: inline-block;"> + <legend>View</legend> + <label>Per page: + {{view "select" content=visiblePerPage value=perPage}} + </label> + </fieldset> + <fieldset> + <legend>Current page</legend> + <center> + {{#each pageLink in pages}} + <label>{{pageLink.runningLabel}}</label> + <button {{bind-attr style=pageLink.style}}{{action 'setPage' pageLink.number}}>{{pageLink.number}}</button> + {{/each}} + </center> + </fieldset> + </div> + </div> + + {{#each movie in paginatedContent}} + <div class="box"> + <table> + <tr> + <td class="poster"> + {{#if movie.poster}} + <img {{bind-attr src=movie.poster}} /> + {{else}} + <span> no image </span> + {{/if}} + </td> + <td class="info"> + <div class="title"> + {{movie.title}} + </div> + <div class="headline"> + <div class="plot">{{movie.plot}}</div> + <div class="consensus">{{movie.omdbTomatoConsensus}}</div> + <table class="details"> + {{#if movie.website}} + <tr> + <td colspan="2"> + ➜ <a {{bind-attr href=movie.website}}>{{movie.website}}</a> + </td> + </tr> + {{/if}} + <tr> + <td colspan="2"> + ➜ <a {{bind-attr href=movie.linkTmdb}} rel="noreferrer">themoviedb.org</a>  + ➜ <a {{bind-attr href=movie.linkImdb}} rel="noreferrer">imdb.com</a>  + ➜ <a {{bind-attr href=movie.linkLetterboxd}} rel="noreferrer">letterboxd.com</a>  + ➜ <a {{bind-attr href=movie.linkOfdb}} rel="noreferrer">ofdb.db</a>  + ➜ <a {{bind-attr href=movie.linkRotten}} rel="noreferrer">rottentomatoes</a>  + ➜ <span class="imdbid">{{movie.id}}</span> + </td> + </tr> + </table> + <ul class="files"> + <li><a {{bind-attr href=movie.path.path}}>{{movie.path.label}}</a> + <li> + {{#each tag in movie.tags}} + {{tag}} + {{/each}} + </li> + </ul> + </td> + <td class="ratings"> + <table> + <tr><td>IMDB</td><td>{{movie.imdbRating}}</td></tr> + <tr><td>IMDB votes</td><td>{{movie.imdbVotes}}</td></tr> + {{#if movie.omdbTomatoRating}} + <tr><td>RT</td><td>{{movie.omdbTomatoRating}}</td></tr> + {{/if}} + {{#if movie.omdbTomatoUserRating}} + <tr><td>RT User</td><td>{{movie.omdbTomatoUserRating}}</td></tr> + {{/if}} + {{#if movie.omdbTomato}} + <tr><td>Meter</td><td>{{movie.omdbTomato}}%</td></tr> + {{/if}} + {{#if movie.omdbUserTomato}} + <tr><td>Meter User</td><td>{{movie.omdbUserTomato}}%</td></tr> + {{/if}} + </table> + </td> + </tr> + </table> + <div class="box-footer"> + {{movie.tagline}} + </div> + </div> + {{/each}} + <div style="text-align:center; margin: 40px;"> + <button style="width:150px;" {{action 'prevPage'}}>Previous</button> + <button style="width:150px;" {{action 'nextPage'}}>Next</button> + </div> + </script> + <script type="text/javascript" src="index-files/js/libs/all.min.js"></script> + <script type="text/javascript" src="index-files/js/app.js"></script> + <script type="text/javascript" src="index-files/data.js"></script> + </body> +</html> +<!-- +vim: tabstop=1 expandtab shiftwidth=1 softtabstop=1: +--> 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): diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html deleted file mode 100644 index 94fb525..0000000 --- a/imdb-lookup/index.jinja2.html +++ /dev/null @@ -1,119 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>{{title}}</title> - <link rel="stylesheet" href="{{ install("css/normalize.css") }}"> - <link rel="stylesheet" href="{{ install("css/style.css") }}"> - </head> - <body> - <script type="text/x-handlebars"> - <h1>{{title}}</h1> - {% raw %} - {{outlet}} - </script> - <script type="text/x-handlebars" id="index"> - <div class="box"> - <div class="sort"> - <label>Sort by:</label> - <button {{action 'sortBy' 'title'}}>Title</button> - <button {{action 'sortBy' 'imdbRating'}}>IMDB Rating</button> - <button {{action 'sortBy' 'imdbVotes'}}>IMDB Votes</button> - <button {{action 'sortBy' 'release'}}>Release Year</button> - <button {{action 'sortBy' 'omdbTomato'}}>RT Meter %</button> - <button {{action 'sortBy' 'omdbTomatoRating'}}>RT Rating</button> - <label>Per page:</label> - {{view "select" content=visiblePerPage value=perPage}} - </div> - </div> - <div class="box"> - <center> - {{#each page in pages}} - <label>{{page.runningLabel}}</label> - <button {{action 'setPage' page.number}}>{{page.number}}</button> - {{/each}} - </center> - </div> - {{#each movie in paginatedContent}} - <div class="box"> - <table> - <tr> - <td class="poster"> - {{#if movie.poster}} - <img {{bind-attr src=movie.poster}} /> - {{else}} - <span> no image </span> - {{/if}} - </td> - <td class="info"> - <div class="title"> - {{movie.title}} - </div> - <div class="headline"> - <div class="plot">{{movie.plot}}</div> - <div class="consensus">{{movie.omdbTomatoConsensus}}</div> - <table class="details"> - {{#if movie.website}} - <tr> - <td colspan="2"> - ➜ <a {{bind-attr href=movie.website}}>{{movie.website}}</a> - </td> - </tr> - {{/if}} - <tr> - <td colspan="2"> - ➜ <a {{bind-attr href=movie.linkTmdb}} rel="noreferrer">themoviedb.org</a> -   - ➜ <a {{bind-attr href=movie.linkImdb}} rel="noreferrer">imdb.com</a> -   - ➜ <a {{bind-attr href=movie.linkLetterboxd}} rel="noreferrer">letterboxd.com</a> -   - ➜ <a {{bind-attr href=movie.linkOfdb}} rel="noreferrer">ofdb.db</a> -   - ➜ <a {{bind-attr href=movie.linkRotten}} rel="noreferrer">rottentomatoes</a> -   - ➜ <span class="imdbid">{{movie.id}}</span> - </td> - </tr> - </table> - <ul class="files"> - {{#each file in movie.movieFiles}} - <li>{{filelink file}}</li> - {{/each}} - </ul> - </td> - <td class="ratings"> - <table> - <tr><td>IMDB</td><td>{{movie.imdbRating}}</td></tr> - <tr><td>IMDB votes</td><td>{{movie.imdbVotes}}</td></tr> - {{#if movie.omdbTomatoRating}} - <tr><td>RT</td><td>{{movie.omdbTomatoRating}}</td></tr> - {{/if}} - {{#if movie.omdbTomatoUserRating}} - <tr><td>RT User</td><td>{{movie.omdbTomatoUserRating}}</td></tr> - {{/if}} - {{#if movie.omdbTomato}} - <tr><td>Meter</td><td>{{movie.omdbTomato}}%</td></tr> - {{/if}} - {{#if movie.omdbUserTomato}} - <tr><td>Meter User</td><td>{{movie.omdbUserTomato}}%</td></tr> - {{/if}} - </table> - </td> - </tr> - </table> - <div class="box-footer"> - {{movie.tagline}} - </div> - </div> - {{/each}} - </script> - {% endraw %} - <script type="text/javascript" src="{{ install("js/libs/all.min.js") }}"></script> - <script type="text/javascript" src="{{ install("js/app.js") }}"></script> - <script type="text/javascript" src="{{ data('dataCb') }}"></script> - </body> -</html> -<!-- -vim: tabstop=1 expandtab shiftwidth=1 softtabstop=1: ---> diff --git a/imdb-lookup/js/libs/Makefile b/imdb-lookup/js/libs/Makefile deleted file mode 100644 index d41cdd0..0000000 --- a/imdb-lookup/js/libs/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -CLOSURE_FLAGS=\ - -all: debug release - - -debug: - java -jar ~/vcs/v86/closure-compiler/compiler.jar \ - --compilation_level WHITESPACE_ONLY \ - --formatting PRETTY_PRINT \ - jquery-1.11.2.js \ - handlebars-v2.0.0.js \ - ember-1.9.0.js \ - ember-data-1.0.0-beta.12.js \ - > all.js - -release: - java -jar ~/vcs/v86/closure-compiler/compiler.jar \ - --compilation_level SIMPLE_OPTIMIZATIONS \ - jquery-1.11.2.js \ - handlebars-v2.0.0.js \ - ember-1.9.0.js \ - ember-data-1.0.0-beta.12.js \ - > all.min.js - diff --git a/imdb-lookup/js/libs/ember-1.9.0.js b/imdb-lookup/libs/ember-1.9.0.js index 3ec5c65..3ec5c65 100644 --- a/imdb-lookup/js/libs/ember-1.9.0.js +++ b/imdb-lookup/libs/ember-1.9.0.js diff --git a/imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js b/imdb-lookup/libs/ember-data-1.0.0-beta.12.js index a2851b9..a2851b9 100644 --- a/imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js +++ b/imdb-lookup/libs/ember-data-1.0.0-beta.12.js diff --git a/imdb-lookup/js/libs/handlebars-v2.0.0.js b/imdb-lookup/libs/handlebars-v2.0.0.js index f826bbf..f826bbf 100644 --- a/imdb-lookup/js/libs/handlebars-v2.0.0.js +++ b/imdb-lookup/libs/handlebars-v2.0.0.js diff --git a/imdb-lookup/js/libs/jquery-1.11.2.js b/imdb-lookup/libs/jquery-1.11.2.js index 1c3aa82..1c3aa82 100644 --- a/imdb-lookup/js/libs/jquery-1.11.2.js +++ b/imdb-lookup/libs/jquery-1.11.2.js |