pass all metadata as json to poster script, fixes #1479
This commit is contained in:
parent
5d6a93d795
commit
a15b68a0d5
5 changed files with 88 additions and 96 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue