From a15b68a0d5035b1db9c6b30ddef628222e310bb1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 6 Jun 2013 11:54:01 +0000 Subject: [PATCH] pass all metadata as json to poster script, fixes #1479 --- pandora/item/models.py | 31 +++++++----------------- scripts/poster.0xdb.py | 39 ++++++++++++++++-------------- scripts/poster.indiancinema.py | 37 +++++++++++++++-------------- scripts/poster.padma.py | 34 +++++++++++++-------------- scripts/poster.pandora.py | 43 ++++++++++++++++++---------------- 5 files changed, 88 insertions(+), 96 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 5e804c148..a2e852a83 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -10,6 +10,7 @@ import shutil import uuid import unicodedata from urllib import quote +import json from django.db import models, transaction from django.db.models import Q, Sum, Max @@ -1192,35 +1193,19 @@ class Item(models.Model): frame = self.get_poster_frame_path() timeline = '%stimelineantialias64p.jpg' % self.timeline_prefix - director = u', '.join(self.get('director', [])) - director = ox.decode_html(director) - title = self.get('title', '') - title = ox.decode_html(title) - cmd = [settings.ITEM_POSTER, - '-t', title.encode('utf-8'), - '-y', str(self.get('year', '')), + '-d', '-', '-p', poster ] - if director: - cmd += [ - '-d', director.encode('utf-8'), - ] + data = self.json.copy() if frame: - cmd += [ - '-f', frame, - ] + data['frame'] = frame if os.path.exists(timeline): - cmd += [ - '-l', timeline, - ] - cmd += [ - '-i', self.itemId, - '-o', self.oxdbId or self.oxdb_id() or self.itemId - ] + data['timeline'] = timeline + data['oxdbId'] = self.oxdbId or self.oxdb_id() or self.itemId ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path())) - p = subprocess.Popen(cmd) - p.wait() + p = subprocess.Popen(cmd, stdin=subprocess.PIPE) + p.communicate(json.dumps(data, default=fields.to_json)) for f in glob(poster.replace('.jpg', '*.jpg')): if f != poster: os.unlink(f) diff --git a/scripts/poster.0xdb.py b/scripts/poster.0xdb.py index 7f752fea3..8bc5d5901 100755 --- a/scripts/poster.0xdb.py +++ b/scripts/poster.0xdb.py @@ -12,13 +12,25 @@ execfile(activate_this, dict(__file__=activate_this)) import Image import ImageDraw +import json from optparse import OptionParser +import ox from ox.image import drawText, wrapText import sys static_root = os.path.join(os.path.dirname(__file__), 'data') -def render_poster(title, director, year, series, oxdb_id, imdb_id, frame, timeline, poster): +def render_poster(data, poster): + + title = ox.decode_html(data.get('title', '')) + director = u', '.join(data.get('director', [])) + director = ox.decode_html(director) + year = str(data.get('year', '')) + series = data.get('isSeries', False) + oxdb_id = data['oxdbId'] + imdb_id = data['id'] + frame = data['frame'] + timeline = data['timeline'] def get_oxdb_color(oxdb_id, series=False): i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32)))) @@ -128,29 +140,20 @@ def render_poster(title, director, year, series, oxdb_id, imdb_id, frame, timeli def main(): parser = OptionParser() - parser.add_option('-o', '--oxdbid', dest='oxdb_id', help='0xDB Id') - parser.add_option('-i', '--id', dest='imdb_id', help='Item Id') - parser.add_option('-t', '--title', dest='title', help='Title') - parser.add_option('-d', '--director', dest='director', help='Director(s)', default='') - parser.add_option('-y', '--year', dest='year', help='Year') - parser.add_option('-s', '--series', dest='series', help='Movie is an episode of a series', action='store_true') - parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)') - parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)') parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)') + parser.add_option('-d', '--data', dest='data', help='json file with metadata', default=None) (options, args) = parser.parse_args() - if None in (options.oxdb_id, options.title, options.poster): + if None in (options.data, options.poster): parser.print_help() sys.exit() - opt = {} - for key in ('oxdb_id', 'imdb_id', 'title', 'director', 'year', 'series', 'frame', 'timeline', 'poster'): - opt[key] = getattr(options, key) - - opt['title'] = opt['title'].decode('utf-8') - opt['director'] = opt['director'].decode('utf-8') - - render_poster(**opt) + if options.data == '-': + data = json.load(sys.stdin) + else: + with open(options.data) as f: + data = json.load(f) + render_poster(data, poster) if __name__ == "__main__": main() diff --git a/scripts/poster.indiancinema.py b/scripts/poster.indiancinema.py index ed13e5304..6f16aa7c0 100755 --- a/scripts/poster.indiancinema.py +++ b/scripts/poster.indiancinema.py @@ -12,13 +12,22 @@ execfile(activate_this, dict(__file__=activate_this)) import Image import ImageDraw +import json from optparse import OptionParser +import ox from ox.image import getRGB, drawText, wrapText import sys static_root = os.path.join(os.path.dirname(__file__), 'data') -def render_poster(title, director, year, frame, timeline, poster): +def render_poster(data, poster): + + title = ox.decode_html(data.get('title', '')) + director = u', '.join(data.get('director', [])) + director = ox.decode_html(director) + year = str(data.get('year', '')) + frame = data['frame'] + timeline = data['timeline'] poster_width = 704 poster_height = 1024 @@ -199,28 +208,20 @@ def render_poster(title, director, year, frame, timeline, poster): def main(): parser = OptionParser() - parser.add_option('-o', '--oxdbid', dest='oxdb_id', help='0xDB Id') - parser.add_option('-i', '--id', dest='id', help='Item Id') - parser.add_option('-t', '--title', dest='title', help='Title', default='') - parser.add_option('-d', '--director', dest='director', help='Director', default='') - parser.add_option('-y', '--year', dest='year', help='Year', default='') - parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)') - parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)') parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)') + parser.add_option('-d', '--data', dest='data', help='json file with metadata', default=None) (options, args) = parser.parse_args() - if options.oxdb_id and not options.id: - options.id = options.oxdb_id - if None in (options.title, options.poster): + if None in (options.data, options.poster): parser.print_help() sys.exit() - opt = {} - for key in ('title', 'director', 'year', 'frame', 'timeline', 'poster'): - opt[key] = getattr(options, key) - - opt['title'] = opt['title'].decode('utf-8') - opt['director'] = opt['director'].decode('utf-8') - render_poster(**opt) + if options.data == '-': + data = json.load(sys.stdin) + else: + with open(options.data) as f: + data = json.load(f) + + render_poster(data, poster) if __name__ == "__main__": main() diff --git a/scripts/poster.padma.py b/scripts/poster.padma.py index e56bdadfa..98de7b736 100755 --- a/scripts/poster.padma.py +++ b/scripts/poster.padma.py @@ -12,13 +12,20 @@ execfile(activate_this, dict(__file__=activate_this)) import Image import ImageDraw +import json from optparse import OptionParser +import ox from ox.image import drawText, wrapText import sys static_root = os.path.join(os.path.dirname(__file__), 'data') -def render_poster(id, title, frame, timeline, poster): +def render_poster(data, poster): + title = ox.decode_html(data.get('title', '')) + id = data['id'] + frame = data['frame'] + timeline = data['timeline'] + poster_width = 640 poster_height = 1024 poster_ratio = poster_width / poster_height @@ -59,27 +66,20 @@ def render_poster(id, title, frame, timeline, poster): def main(): parser = OptionParser() - parser.add_option('-o', '--oxdbid', dest='oxdb_id', help='0xDB Id') - parser.add_option('-i', '--id', dest='id', help='Item Id') - parser.add_option('-t', '--title', dest='title', help='Title', default='') - parser.add_option('-d', '--director', dest='director', help='Director', default='') - parser.add_option('-y', '--year', dest='year', help='Year', default='') - parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)') - parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)') parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)') + parser.add_option('-d', '--data', dest='data', help='json file with metadata', default=None) (options, args) = parser.parse_args() - if options.oxdb_id and not options.id: - options.id = options.oxdb_id - if None in (options.id, options.poster): + + if None in (options.data, options.poster): parser.print_help() sys.exit() - opt = {} - for key in ('id', 'title', 'frame', 'timeline', 'poster'): - opt[key] = getattr(options, key) - - opt['title'] = opt['title'].decode('utf-8') - render_poster(**opt) + if options.data == '-': + data = json.load(sys.stdin) + else: + with open(options.data) as f: + data = json.load(f) + render_poster(data, poster) if __name__ == "__main__": main() diff --git a/scripts/poster.pandora.py b/scripts/poster.pandora.py index 78508acb7..56c55854b 100755 --- a/scripts/poster.pandora.py +++ b/scripts/poster.pandora.py @@ -6,20 +6,32 @@ import os root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -#using virtualenv's activate_this.py to reorder sys.path +# using virtualenv's activate_this.py to reorder sys.path activate_this = os.path.join(root_dir, 'bin', 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) import Image import ImageDraw +import json from optparse import OptionParser +import ox from ox.image import drawText, wrapText import sys - static_root = os.path.join(os.path.dirname(__file__), 'data') -def render_poster(title, director, year, series, oxdb_id, imdb_id, frame, timeline, poster): +def render_poster(data, poster): + + title = ox.decode_html(data.get('title', '')) + director = u', '.join(data.get('director', []) + director = ox.decode_html(director) + year = str(data.get('year', '')) + series = data.get('isSeries', False) + oxdb_id = data['oxdbId'] + imdb_id = data['id'] + frame = data['frame'] + timeline = data['timeline'] + def get_oxdb_color(oxdb_id, series=False): i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32)))) if i < 127: @@ -129,29 +141,20 @@ i ''' def main(): parser = OptionParser() - parser.add_option('-o', '--oxdbid', dest='oxdb_id', help='0xDB Id') - parser.add_option('-i', '--id', dest='imdb_id', help='Item Id') - parser.add_option('-t', '--title', dest='title', help='Title') - parser.add_option('-d', '--director', dest='director', help='Director(s)', default='') - parser.add_option('-y', '--year', dest='year', help='Year') - parser.add_option('-s', '--series', dest='series', help='Movie is an episode of a series', action='store_true') - parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)') - parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)') parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)') + parser.add_option('-d', '--data', dest='data', help='json file with metadata', default=None) (options, args) = parser.parse_args() - if None in (options.oxdb_id, options.title, options.poster): + if None in (options.data, options.poster): parser.print_help() sys.exit() - opt = {} - for key in ('oxdb_id', 'imdb_id', 'title', 'director', 'year', 'series', 'frame', 'timeline', 'poster'): - opt[key] = getattr(options, key) - - opt['title'] = opt['title'].decode('utf-8') - opt['director'] = opt['director'].decode('utf-8') - - render_poster(**opt) + if options.data == '-': + data = json.load(sys.stdin) + else: + with open(options.data) as f: + data = json.load(f) + render_poster(data, poster) if __name__ == "__main__": main()