pass all metadata as json to poster script, fixes #1479

This commit is contained in:
j 2013-06-06 11:54:01 +00:00
parent 5d6a93d795
commit a15b68a0d5
5 changed files with 88 additions and 96 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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')
if options.data == '-':
data = json.load(sys.stdin)
else:
with open(options.data) as f:
data = json.load(f)
render_poster(**opt)
render_poster(data, poster)
if __name__ == "__main__":
main()

View file

@ -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()

View file

@ -12,14 +12,26 @@ 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()