forked from 0x2620/pandora
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
|
@ -10,6 +10,7 @@ import shutil
|
||||||
import uuid
|
import uuid
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
import json
|
||||||
|
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import Q, Sum, Max
|
from django.db.models import Q, Sum, Max
|
||||||
|
@ -1192,35 +1193,19 @@ class Item(models.Model):
|
||||||
frame = self.get_poster_frame_path()
|
frame = self.get_poster_frame_path()
|
||||||
timeline = '%stimelineantialias64p.jpg' % self.timeline_prefix
|
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,
|
cmd = [settings.ITEM_POSTER,
|
||||||
'-t', title.encode('utf-8'),
|
'-d', '-',
|
||||||
'-y', str(self.get('year', '')),
|
|
||||||
'-p', poster
|
'-p', poster
|
||||||
]
|
]
|
||||||
if director:
|
data = self.json.copy()
|
||||||
cmd += [
|
|
||||||
'-d', director.encode('utf-8'),
|
|
||||||
]
|
|
||||||
if frame:
|
if frame:
|
||||||
cmd += [
|
data['frame'] = frame
|
||||||
'-f', frame,
|
|
||||||
]
|
|
||||||
if os.path.exists(timeline):
|
if os.path.exists(timeline):
|
||||||
cmd += [
|
data['timeline'] = timeline
|
||||||
'-l', timeline,
|
data['oxdbId'] = self.oxdbId or self.oxdb_id() or self.itemId
|
||||||
]
|
|
||||||
cmd += [
|
|
||||||
'-i', self.itemId,
|
|
||||||
'-o', self.oxdbId or self.oxdb_id() or self.itemId
|
|
||||||
]
|
|
||||||
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
||||||
p = subprocess.Popen(cmd)
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
|
||||||
p.wait()
|
p.communicate(json.dumps(data, default=fields.to_json))
|
||||||
for f in glob(poster.replace('.jpg', '*.jpg')):
|
for f in glob(poster.replace('.jpg', '*.jpg')):
|
||||||
if f != poster:
|
if f != poster:
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
|
|
|
@ -12,13 +12,25 @@ execfile(activate_this, dict(__file__=activate_this))
|
||||||
|
|
||||||
import Image
|
import Image
|
||||||
import ImageDraw
|
import ImageDraw
|
||||||
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import ox
|
||||||
from ox.image import drawText, wrapText
|
from ox.image import drawText, wrapText
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
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):
|
def get_oxdb_color(oxdb_id, series=False):
|
||||||
i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32))))
|
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():
|
def main():
|
||||||
parser = OptionParser()
|
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('-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()
|
(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()
|
parser.print_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
opt = {}
|
if options.data == '-':
|
||||||
for key in ('oxdb_id', 'imdb_id', 'title', 'director', 'year', 'series', 'frame', 'timeline', 'poster'):
|
data = json.load(sys.stdin)
|
||||||
opt[key] = getattr(options, key)
|
else:
|
||||||
|
with open(options.data) as f:
|
||||||
opt['title'] = opt['title'].decode('utf-8')
|
data = json.load(f)
|
||||||
opt['director'] = opt['director'].decode('utf-8')
|
render_poster(data, poster)
|
||||||
|
|
||||||
render_poster(**opt)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -12,13 +12,22 @@ execfile(activate_this, dict(__file__=activate_this))
|
||||||
|
|
||||||
import Image
|
import Image
|
||||||
import ImageDraw
|
import ImageDraw
|
||||||
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import ox
|
||||||
from ox.image import getRGB, drawText, wrapText
|
from ox.image import getRGB, drawText, wrapText
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
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_width = 704
|
||||||
poster_height = 1024
|
poster_height = 1024
|
||||||
|
@ -199,28 +208,20 @@ def render_poster(title, director, year, frame, timeline, poster):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser()
|
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('-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()
|
(options, args) = parser.parse_args()
|
||||||
if options.oxdb_id and not options.id:
|
if None in (options.data, options.poster):
|
||||||
options.id = options.oxdb_id
|
|
||||||
if None in (options.title, options.poster):
|
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
opt = {}
|
|
||||||
for key in ('title', 'director', 'year', 'frame', 'timeline', 'poster'):
|
|
||||||
opt[key] = getattr(options, key)
|
|
||||||
|
|
||||||
opt['title'] = opt['title'].decode('utf-8')
|
if options.data == '-':
|
||||||
opt['director'] = opt['director'].decode('utf-8')
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -12,13 +12,20 @@ execfile(activate_this, dict(__file__=activate_this))
|
||||||
|
|
||||||
import Image
|
import Image
|
||||||
import ImageDraw
|
import ImageDraw
|
||||||
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import ox
|
||||||
from ox.image import drawText, wrapText
|
from ox.image import drawText, wrapText
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
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_width = 640
|
||||||
poster_height = 1024
|
poster_height = 1024
|
||||||
poster_ratio = poster_width / poster_height
|
poster_ratio = poster_width / poster_height
|
||||||
|
@ -59,27 +66,20 @@ def render_poster(id, title, frame, timeline, poster):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser()
|
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('-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()
|
(options, args) = parser.parse_args()
|
||||||
if options.oxdb_id and not options.id:
|
|
||||||
options.id = options.oxdb_id
|
if None in (options.data, options.poster):
|
||||||
if None in (options.id, options.poster):
|
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
opt = {}
|
|
||||||
for key in ('id', 'title', 'frame', 'timeline', 'poster'):
|
|
||||||
opt[key] = getattr(options, key)
|
|
||||||
|
|
||||||
opt['title'] = opt['title'].decode('utf-8')
|
if options.data == '-':
|
||||||
|
data = json.load(sys.stdin)
|
||||||
render_poster(**opt)
|
else:
|
||||||
|
with open(options.data) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
render_poster(data, poster)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -6,20 +6,32 @@ import os
|
||||||
|
|
||||||
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
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')
|
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
||||||
execfile(activate_this, dict(__file__=activate_this))
|
execfile(activate_this, dict(__file__=activate_this))
|
||||||
|
|
||||||
import Image
|
import Image
|
||||||
import ImageDraw
|
import ImageDraw
|
||||||
|
import json
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import ox
|
||||||
from ox.image import drawText, wrapText
|
from ox.image import drawText, wrapText
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
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):
|
def get_oxdb_color(oxdb_id, series=False):
|
||||||
i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32))))
|
i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32))))
|
||||||
if i < 127:
|
if i < 127:
|
||||||
|
@ -129,29 +141,20 @@ i '''
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser()
|
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('-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()
|
(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()
|
parser.print_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
opt = {}
|
if options.data == '-':
|
||||||
for key in ('oxdb_id', 'imdb_id', 'title', 'director', 'year', 'series', 'frame', 'timeline', 'poster'):
|
data = json.load(sys.stdin)
|
||||||
opt[key] = getattr(options, key)
|
else:
|
||||||
|
with open(options.data) as f:
|
||||||
opt['title'] = opt['title'].decode('utf-8')
|
data = json.load(f)
|
||||||
opt['director'] = opt['director'].decode('utf-8')
|
render_poster(data, poster)
|
||||||
|
|
||||||
render_poster(**opt)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue