make pad.ma config work

This commit is contained in:
j 2011-12-15 12:21:21 +01:00
parent a5c9d023c1
commit 4d113c80c6
3 changed files with 26 additions and 11 deletions

View file

@ -21,18 +21,25 @@ class Command(BaseCommand):
if ext in ('.webm', '.mp4'): if ext in ('.webm', '.mp4'):
oshash = os.path.dirname(f)[-19:].replace('/', '') oshash = os.path.dirname(f)[-19:].replace('/', '')
format = ext[1:] format = ext[1:]
resolution = int(profile[:-1]) if profile.endswith('p'):
profile = profile[:-1]
resolution = int(profile)
qs = models.Stream.objects.filter(file__oshash=oshash, format=format, resolution=resolution) qs = models.Stream.objects.filter(file__oshash=oshash, format=format, resolution=resolution)
if qs.count() == 0: if qs.count() == 0:
print 'add', f print 'add', f
print oshash, resolution, format print oshash, resolution, format
stream = models.Stream() qs = models.File.objects.filter(oshash=oshash)
stream.file = models.File.objects.get(oshash=oshash) if qs.count() == 1:
stream.resolution = resolution stream = models.Stream()
stream.format = format stream.file = qs[0]
stream.video.name = f[len(settings.MEDIA_ROOT)+1:] stream.resolution = resolution
self.available = True stream.format = format
stream.save() stream.video.name = f[len(settings.MEDIA_ROOT)+1:]
stream.available = True
stream.save()
if not stream.file.info:
stream.file.info = stream.info
stream.file.save()
#link streams #link streams
resolution = settings.CONFIG['video']['resolutions'][0] resolution = settings.CONFIG['video']['resolutions'][0]
format = settings.CONFIG['video']['formats'][0] format = settings.CONFIG['video']['formats'][0]
@ -42,3 +49,7 @@ class Command(BaseCommand):
#extract timelines #extract timelines
for s in models.Stream.objects.filter(source=None): for s in models.Stream.objects.filter(source=None):
s.make_timeline() s.make_timeline()
s.file.selected = True
s.file.save()
s.file.item.update_timeline()

View file

@ -158,7 +158,7 @@ class Item(models.Model):
icon = models.ImageField(default=None, blank=True, icon = models.ImageField(default=None, blank=True,
upload_to=lambda i, x: i.path("icon.jpg")) upload_to=lambda i, x: i.path("icon.jpg"))
torrent = models.FileField(default=None, blank=True, torrent = models.FileField(default=None, blank=True, max_length=1000,
upload_to=lambda i, x: i.path('torrent.torrent')) upload_to=lambda i, x: i.path('torrent.torrent'))
stream_info = fields.DictField(default={}, editable=False) stream_info = fields.DictField(default={}, editable=False)
@ -851,6 +851,9 @@ class Item(models.Model):
break break
def make_torrent(self): def make_torrent(self):
streams = self.streams()
if streams.count() == 0:
return
base = self.path('torrent') base = self.path('torrent')
base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base)) base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base))
if os.path.exists(base): if os.path.exists(base):
@ -861,7 +864,6 @@ class Item(models.Model):
base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base)) base = os.path.abspath(os.path.join(settings.MEDIA_ROOT, base))
size = 0 size = 0
duration = 0.0 duration = 0.0
streams = self.streams()
if streams.count() == 1: if streams.count() == 1:
url = "%s/torrent/%s.webm" % (self.get_absolute_url(), url = "%s/torrent/%s.webm" % (self.get_absolute_url(),
quote(self.get('title').encode('utf-8'))) quote(self.get('title').encode('utf-8')))
@ -1069,6 +1071,8 @@ class Item(models.Model):
return icon return icon
def load_subtitles(self): def load_subtitles(self):
if not filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']):
return
with transaction.commit_on_success(): with transaction.commit_on_success():
layer = 'subtitles' layer = 'subtitles'
Annotation.objects.filter(layer=layer,item=self).delete() Annotation.objects.filter(layer=layer,item=self).delete()

View file

@ -762,7 +762,7 @@ def video(request, id, resolution, format, index=None):
# reise Http404 # reise Http404
streams = Stream.objects.filter(file__item__itemId=item.itemId, streams = Stream.objects.filter(file__item__itemId=item.itemId,
resolution=resolution, format=format).order_by('file__part') resolution=resolution, format=format).order_by('file__part')
if index > streams.count(): if index + 1 > streams.count():
raise Http404 raise Http404
stream = streams[index] stream = streams[index]
if not stream.available or not stream.video: if not stream.available or not stream.video: