use site_config for video settings

This commit is contained in:
j 2011-08-19 17:37:37 +02:00
parent 09ee5fc417
commit d9aa4a230b
7 changed files with 39 additions and 71 deletions

View file

@ -346,6 +346,13 @@
"columnWidth": 60,
"format": {"type": "unit", "args": ["kbps"]}
},
{
"id": "parts",
"title": "Parts",
"type": "integer",
"columnWidth": 60,
"rightsLevel": 1
},
{
"id": "numberoffiles",
"title": "Number of Files",

View file

@ -17,6 +17,7 @@ import ox
from ox.normalize import canonicalTitle
import chardet
from app.models import site_config
from item import utils
from item.models import Item
from person.models import get_name_sort
@ -248,10 +249,11 @@ class File(models.Model):
def save_chunk(self, chunk, chunk_id=-1, done=False):
if not self.available:
config = site_config()['video']
stream, created = Stream.objects.get_or_create(
file=self,
resolution=settings.VIDEO_RESOLUTIONS[0],
format=settings.VIDEO_FORMATS[0])
resolution=config['resolutions'][0],
format=config['formats'][0])
if created:
stream.video.save(stream.name(), chunk)
else:
@ -489,9 +491,9 @@ class Stream(models.Model):
return self.file.path(name)
def extract_derivatives(self):
self.make_timeline()
for resolution in settings.VIDEO_RESOLUTIONS:
for f in settings.VIDEO_FORMATS:
config = site_config()['video']
for resolution in config['resolutions']:
for f in config['formats']:
derivative, created = Stream.objects.get_or_create(file=self.file,
resolution=resolution, format=f)
if created:

View file

@ -14,6 +14,7 @@ from ox.django.decorators import login_required_json
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
from ox.django.views import task_status
from app.models import site_config
from item import utils
from item.models import get_item
from item.views import parse_query
@ -111,7 +112,8 @@ actions.register(update, cache=False)
@login_required_json
def encodingProfile(request):
profile = "%sp.%s" % (settings.VIDEO_RESOLUTIONS[0], settings.VIDEO_FORMATS[0])
config = site_config()['video']
profile = "%sp.%s" % (config['resolutions'][0], config['formats'][0])
response = json_response({'profile': profile})
return render_to_json_response(response)
actions.register(encodingProfile)
@ -166,13 +168,16 @@ class VideoChunkForm(forms.Form):
def firefogg_upload(request):
profile = request.GET['profile']
oshash = request.GET['id']
config = site_config()['video']
video_profile = "%sp.%s" % (config['resolutions'][0], config['formats'][0])
#handle video upload
if request.method == 'POST':
#post next chunk
if 'chunk' in request.FILES and oshash:
f = get_object_or_404(models.File, oshash=oshash)
form = VideoChunkForm(request.POST, request.FILES)
if form.is_valid() and profile == settings.VIDEO_PROFILE and f.editable(request.user):
if form.is_valid() and profile == video_profile and f.editable(request.user):
c = form.cleaned_data['chunk']
chunk_id = form.cleaned_data['chunkId']
response = {
@ -194,7 +199,7 @@ def firefogg_upload(request):
response['done'] = 1
return render_to_json_response(response)
#init upload
elif oshash and profile == settings.VIDEO_PROFILE:
elif oshash and profile == video_profile:
#404 if oshash is not know, files must be registered via update api first
f = get_object_or_404(models.File, oshash=oshash)
if f.editable(request.user):

View file

@ -792,49 +792,16 @@ class Item(models.Model):
return [video.streams.filter(source=None)[0] for video in self.main_videos()]
def update_streams(self, force=False):
files = {}
for f in self.main_videos():
files[utils.sort_title(f.name)] = f.video.path
if force or self.stream_info != files:
self.stream_info = files
stream, created = Stream.objects.get_or_create(item=self,
profile=settings.VIDEO_PROFILE)
stream.video.name = stream.path()
cmd = []
if os.path.exists(stream.video.path):
os.unlink(stream.video.path)
ox.makedirs(os.path.dirname(stream.video.path))
if len(files.values()) > 1:
if len(files.values()) > 4:
print "FIXME: to many files for this item, not merging entire tv shows"
return
for f in sorted(files):
cmd.append('+')
cmd.append(files[f])
cmd = [ 'mkvmerge', '-o', stream.video.path ] + cmd[1:]
#print cmd
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
p.wait()
else:
os.symlink(files.values()[0], stream.video.path)
stream.save()
self.make_timeline()
if 'video' in stream.info and stream.info['video']:
v = stream.info['video'][0]
self.stream_aspect = v['width']/v['height']
self.data['cuts'] = extract.cuts(self.timeline_prefix)
self.data['color'] = extract.average_color(self.timeline_prefix)
#extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
stream.extract_derivatives()
self.make_local_poster()
self.make_poster()
self.make_icon()
self.rendered = files != {}
self.save()
streams = self.streams()
self.make_timeline()
self.data['cuts'] = extract.cuts(self.timeline_prefix)
self.data['color'] = extract.average_color(self.timeline_prefix)
#extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
self.make_local_poster()
self.make_poster()
self.make_icon()
self.rendered = streams != []
self.save()
'''
Poster related functions
@ -886,7 +853,9 @@ class Item(models.Model):
return None
def make_timeline(self):
print "FIXME, needs to build timeline from parts"
streams = self.streams()
if len(streams) > 1:
print "FIXME, needs to build timeline from parts"
def make_poster(self, force=False):
if not self.poster or force:
@ -963,7 +932,7 @@ class Item(models.Model):
if frames and len(frames) > int(self.poster_frame):
return frames[int(self.poster_frame)]['path']
else:
size = int(settings.VIDEO_PROFILE.split('.')[0][:-1])
size = site_config()['video']['resolutions'][0]
return self.frame(self.poster_frame, size)
if frames:

View file

@ -697,4 +697,6 @@ def video(request, id, resolution, format, index=None):
response = HttpFileResponse(path, content_type=content_type)
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response
if not settings.XSENDFILE and not settings.XACCELREDIRECT:
return redirect(stream.video.url)
return HttpFileResponse(path)

View file

@ -437,7 +437,7 @@
"showSidebar": true,
"sidebarSize": 256,
"sitePage": "home",
"theme": "modern",
"theme": "classic",
"videoPosition": {},
"videoScreen": "fit",
"videoSize": "small"

View file

@ -169,26 +169,9 @@ SITE_CONFIG = join(PROJECT_ROOT, '0xdb.json')
DEFAULT_SORT = [{"key": "director", "operator": ""}]
DEFAULT_THEME = "classic"
VIDEO_PROFILE = '96p.webm'
VIDEO_DERIVATIVES = []
TRACKER_URL="http://url2torrent.net:6970/announce"
VIDEO_FORMATS=['webm']
VIDEO_RESOLUTIONS=[96]
#0xdb
'''
VIDEO_FORMATS=['webm', 'mp4']
VIDEO_RESOLUTIONS=[96]
'''
#Pad.ma
'''
VIDEO_FORMATS=['webm', 'mp4']
VIDEO_RESOLUTIONS=[480, 240, 96]
'''
TRANSMISSON_HOST = 'localhost'
TRANSMISSON_PORT = 9091
TRANSMISSON_USER = 'transmission'