get frame via manage.py so it also works for private items

This commit is contained in:
j 2013-06-26 14:14:10 +02:00
parent c891601cf5
commit 959479457d
3 changed files with 66 additions and 26 deletions

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.core.management.base import BaseCommand
import app.monkey_patch
from ... import models
class Command(BaseCommand):
help = 'extract frame and print path'
args = '<id> <height> <position>'
def handle(self, id, height, position, **options):
position = float(position)
i = models.Item.objects.get(itemId=id)
path = i.frame(position, height)
print path

View file

@ -16,11 +16,23 @@ import json
from optparse import OptionParser from optparse import OptionParser
import ox import ox
from ox.image import drawText, getRGB, getTextSize, wrapText from ox.image import drawText, getRGB, getTextSize, wrapText
from StringIO import StringIO import subprocess
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 get_frame(id, height, position):
cmd = [
os.path.join(root_dir, 'pandora', 'manage.py'), 'get_frame',
str(id), str(height), "%f" % (round(position * 25) / 25)
]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = p.communicate()
frame_path = output[0].strip()
if frame_path:
frame_image = Image.open(frame_path)
return frame_image
def render_poster(data, poster): def render_poster(data, poster):
title = ox.decode_html(data.get('title', '')).upper() title = ox.decode_html(data.get('title', '')).upper()
@ -83,8 +95,8 @@ def render_poster(data, poster):
if duration: if duration:
for i in range(small_frames): for i in range(small_frames):
position = duration * (i + 1) / (small_frames + 1) position = duration * (i + 1) / (small_frames + 1)
small_frame_url = 'https://0xdb.org/%s/96p%f.jpg' % (id, round(position * 25) / 25) small_frame_image = get_frame(id, 96, round(position * 25) / 25)
small_frame_image = Image.open(StringIO(ox.net.read_url(small_frame_url))) if small_frame_image:
small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1] small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1]
if small_frame_ratio < small_frame_image_ratio: if small_frame_ratio < small_frame_image_ratio:
small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS) small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS)

View file

@ -17,11 +17,23 @@ import json
from optparse import OptionParser from optparse import OptionParser
import ox import ox
from ox.image import drawText, getRGB, getTextSize, wrapText from ox.image import drawText, getRGB, getTextSize, wrapText
from StringIO import StringIO import subprocess
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 get_frame(id, height, position):
cmd = [
os.path.join(root_dir, 'pandora', 'manage.py'), 'get_frame',
str(id), str(height), "%f" % (round(position * 25) / 25)
]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = p.communicate()
frame_path = output[0].strip()
if frame_path:
frame_image = Image.open(frame_path)
return frame_image
def render_poster(data, poster): def render_poster(data, poster):
director = ox.decode_html(u', '.join(data.get('director', []))) director = ox.decode_html(u', '.join(data.get('director', [])))
@ -74,8 +86,8 @@ def render_poster(data, poster):
if duration: if duration:
for i in range(small_frames): for i in range(small_frames):
position = duration * (i + 1) / (small_frames + 1) position = duration * (i + 1) / (small_frames + 1)
small_frame_url = 'http://arsenalberl.in/%s/96p%f.jpg' % (id, round(position * 25) / 25) small_frame_image = get_frame(id, 96, round(position * 25) / 25)
small_frame_image = Image.open(StringIO(ox.net.read_url(small_frame_url))) if small_frame_image:
small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1] small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1]
if small_frame_ratio < small_frame_image_ratio: if small_frame_ratio < small_frame_image_ratio:
small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS) small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS)