rename stream.video to stream.media

This commit is contained in:
j 2013-04-22 11:45:22 +00:00
parent 8903efcd55
commit 889754273a
4 changed files with 198 additions and 37 deletions

View file

@ -0,0 +1,166 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
db.rename_column('archive_stream', 'video', 'media')
def backwards(self, orm):
db.rename_column('archive_stream', 'media', 'video')
models = {
'archive.file': {
'Meta': {'object_name': 'File'},
'audio_codec': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'bits_per_pixel': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
'channels': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'display_aspect_ratio': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'duration': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
'encoding': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'extension': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True'}),
'framerate': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'info': ('ox.django.fields.DictField', [], {'default': '{}'}),
'is_audio': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_subtitle': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_video': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'item': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'null': 'True', 'to': "orm['item.Item']"}),
'language': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '8', 'null': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'oshash': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
'part': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True'}),
'part_title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True'}),
'path': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2048'}),
'pixel_format': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'pixels': ('django.db.models.fields.BigIntegerField', [], {'default': '0'}),
'samplerate': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'selected': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'size': ('django.db.models.fields.BigIntegerField', [], {'default': '0'}),
'sort_path': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2048'}),
'type': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
'uploading': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True'}),
'video_codec': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'wanted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'width': ('django.db.models.fields.IntegerField', [], {'default': '0'})
},
'archive.frame': {
'Meta': {'unique_together': "(('file', 'position'),)", 'object_name': 'Frame'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'file': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'frames'", 'to': "orm['archive.File']"}),
'frame': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'position': ('django.db.models.fields.FloatField', [], {})
},
'archive.instance': {
'Meta': {'unique_together': "(('path', 'volume'),)", 'object_name': 'Instance'},
'atime': ('django.db.models.fields.IntegerField', [], {'default': '1366568952'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'ctime': ('django.db.models.fields.IntegerField', [], {'default': '1366568952'}),
'file': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'instances'", 'to': "orm['archive.File']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignore': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'mtime': ('django.db.models.fields.IntegerField', [], {'default': '1366568952'}),
'path': ('django.db.models.fields.CharField', [], {'max_length': '2048'}),
'volume': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'to': "orm['archive.Volume']"})
},
'archive.stream': {
'Meta': {'unique_together': "(('file', 'resolution', 'format'),)", 'object_name': 'Stream'},
'aspect_ratio': ('django.db.models.fields.FloatField', [], {'default': '0'}),
'available': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'color': ('ox.django.fields.TupleField', [], {'default': '[]'}),
'cuts': ('ox.django.fields.TupleField', [], {'default': '[]'}),
'duration': ('django.db.models.fields.FloatField', [], {'default': '0'}),
'file': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'streams'", 'to': "orm['archive.File']"}),
'format': ('django.db.models.fields.CharField', [], {'default': "'webm'", 'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'info': ('ox.django.fields.DictField', [], {'default': '{}'}),
'media': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
'oshash': ('django.db.models.fields.CharField', [], {'max_length': '16', 'null': 'True', 'db_index': 'True'}),
'resolution': ('django.db.models.fields.IntegerField', [], {'default': '96'}),
'source': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'derivatives'", 'null': 'True', 'to': "orm['archive.Stream']"}),
'volume': ('django.db.models.fields.FloatField', [], {'default': '0'})
},
'archive.volume': {
'Meta': {'unique_together': "(('user', 'name'),)", 'object_name': 'Volume'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'volumes'", 'to': "orm['auth.User']"})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'item.item': {
'Meta': {'object_name': 'Item'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('ox.django.fields.DictField', [], {'default': '{}'}),
'external_data': ('ox.django.fields.DictField', [], {'default': '{}'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'items'", 'blank': 'True', 'to': "orm['auth.Group']"}),
'icon': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'itemId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'blank': 'True'}),
'json': ('ox.django.fields.DictField', [], {'default': '{}'}),
'level': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'oxdbId': ('django.db.models.fields.CharField', [], {'max_length': '42', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'poster': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}),
'poster_frame': ('django.db.models.fields.FloatField', [], {'default': '-1'}),
'poster_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'poster_source': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'poster_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'rendered': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'stream_aspect': ('django.db.models.fields.FloatField', [], {'default': '1.3333333333333333'}),
'stream_info': ('ox.django.fields.DictField', [], {'default': '{}'}),
'torrent': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '1000', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'null': 'True', 'to': "orm['auth.User']"})
}
}
complete_apps = ['archive']

View file

@ -275,13 +275,13 @@ class File(models.Model):
resolution=max(config['resolutions']), resolution=max(config['resolutions']),
format=config['formats'][0]) format=config['formats'][0])
if created: if created:
stream.video.name = stream.path(stream.name()) stream.media.name = stream.path(stream.name())
ox.makedirs(os.path.dirname(stream.video.path)) ox.makedirs(os.path.dirname(stream.media.path))
with open(stream.video.path, 'w') as f: with open(stream.media.path, 'w') as f:
f.write(chunk.read()) f.write(chunk.read())
stream.save() stream.save()
else: else:
with open(stream.video.path, 'a') as f: with open(stream.media.path, 'a') as f:
#FIXME: should check that chunk_id/offset is right #FIXME: should check that chunk_id/offset is right
f.write(chunk.read()) f.write(chunk.read())
if done: if done:
@ -436,7 +436,7 @@ class Stream(models.Model):
resolution = models.IntegerField(default=96) resolution = models.IntegerField(default=96)
format = models.CharField(max_length=255, default='webm') format = models.CharField(max_length=255, default='webm')
video = models.FileField(default=None, blank=True, upload_to=lambda f, x: f.path(x)) media = models.FileField(default=None, blank=True, upload_to=lambda f, x: f.path(x))
source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True) source = models.ForeignKey('Stream', related_name='derivatives', default=None, null=True)
available = models.BooleanField(default=False) available = models.BooleanField(default=False)
oshash = models.CharField(max_length=16, null=True, db_index=True) oshash = models.CharField(max_length=16, null=True, db_index=True)
@ -470,34 +470,34 @@ class Stream(models.Model):
resolution=resolution, format=f) resolution=resolution, format=f)
name = derivative.name() name = derivative.name()
name = os.path.join(os.path.dirname(self.video.name), name) name = os.path.join(os.path.dirname(self.media.name), name)
if created: if created:
derivative.source = self derivative.source = self
derivative.save() derivative.save()
derivative.video.name = name derivative.media.name = name
derivative.encode() derivative.encode()
derivative.save() derivative.save()
elif rebuild or not derivative.available: elif rebuild or not derivative.available:
if not derivative.video: if not derivative.media:
derivative.video.name = name derivative.media.name = name
derivative.encode() derivative.encode()
return True return True
def encode(self): def encode(self):
if self.source: if self.source:
video = self.source.video.path media = self.source.media.path
target = self.video.path target = self.media.path
info = ox.avinfo(video) info = ox.avinfo(media)
if extract.stream(video, target, self.name(), info): if extract.stream(media, target, self.name(), info):
self.available = True self.available = True
else: else:
self.available = False self.available = False
self.save() self.save()
elif self.file.data: elif self.file.data:
video = self.file.data.path media = self.file.data.path
target = self.video.path target = self.media.path
info = ox.avinfo(video) info = ox.avinfo(media)
if extract.stream(video, target, self.name(), info): if extract.stream(media, target, self.name(), info):
self.available = True self.available = True
else: else:
self.available = False self.available = False
@ -505,15 +505,15 @@ class Stream(models.Model):
def make_timeline(self): def make_timeline(self):
if self.available and not self.source: if self.available and not self.source:
extract.timeline(self.video.path, self.timeline_prefix) extract.timeline(self.media.path, self.timeline_prefix)
self.cuts = tuple(extract.cuts(self.timeline_prefix)) self.cuts = tuple(extract.cuts(self.timeline_prefix))
self.color = tuple(extract.average_color(self.timeline_prefix)) self.color = tuple(extract.average_color(self.timeline_prefix))
self.volume = extract.average_volume(self.timeline_prefix) self.volume = extract.average_volume(self.timeline_prefix)
self.save() self.save()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.video and not self.info: if self.media and not self.info:
self.info = ox.avinfo(self.video.path) self.info = ox.avinfo(self.media.path)
self.oshash = self.info.get('oshash') self.oshash = self.info.get('oshash')
self.duration = self.info.get('duration', 0) self.duration = self.info.get('duration', 0)
if 'video' in self.info and self.info['video']: if 'video' in self.info and self.info['video']:
@ -536,6 +536,6 @@ class Stream(models.Model):
def delete_stream(sender, **kwargs): def delete_stream(sender, **kwargs):
f = kwargs['instance'] f = kwargs['instance']
if f.video: if f.media:
f.video.delete() f.media.delete()
pre_delete.connect(delete_stream, sender=Stream) pre_delete.connect(delete_stream, sender=Stream)

View file

@ -943,8 +943,8 @@ class Item(models.Model):
height = min(height, stream.resolution) height = min(height, stream.resolution)
path = os.path.join(settings.MEDIA_ROOT, stream.path(), path = os.path.join(settings.MEDIA_ROOT, stream.path(),
'frames', "%dp"%height, "%s.jpg"%position) 'frames', "%dp"%height, "%s.jpg"%position)
if not os.path.exists(path) and stream.video: if not os.path.exists(path) and stream.media:
extract.frame(stream.video.path, path, position, height) extract.frame(stream.media.path, path, position, height)
if not os.path.exists(path): if not os.path.exists(path):
return None return None
return path return path
@ -1040,8 +1040,8 @@ class Item(models.Model):
quote(filename.encode('utf-8'))) quote(filename.encode('utf-8')))
video = "%s.webm" % base video = "%s.webm" % base
v = streams[0] v = streams[0]
os.symlink(v.video.path, video) os.symlink(v.media.path, video)
size = v.video.size size = v.media.size
duration = v.duration duration = v.duration
else: else:
url = "%s/torrent/" % self.get_absolute_url() url = "%s/torrent/" % self.get_absolute_url()
@ -1050,8 +1050,8 @@ class Item(models.Model):
for v in streams: for v in streams:
video = "%s/%s.Part %d.webm" % (base, filename, part) video = "%s/%s.Part %d.webm" % (base, filename, part)
part += 1 part += 1
os.symlink(v.video.path, video) os.symlink(v.media.path, video)
size += v.video.size size += v.media.size
duration += v.duration duration += v.duration
video = base video = base

View file

@ -863,20 +863,15 @@ def video(request, id, resolution, format, index=None):
index = int(index) - 1 index = int(index) - 1
else: else:
index = 0 index = 0
#streams = Stream.object.filter(file__item__itemId=item.itemId,
# file__selected=True, file__part=index,
# resolution=resolution, format=format)
#if streams.count() != 1:
# reise Http404
streams = Stream.objects.filter(file__item__itemId=item.itemId, streams = Stream.objects.filter(file__item__itemId=item.itemId,
file__selected=True, file__selected=True,
resolution=resolution, format=format).order_by('file__part', 'file__sort_path') resolution=resolution, format=format).order_by('file__part', 'file__sort_path')
if index + 1 > 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.media:
raise Http404 raise Http404
path = stream.video.path path = stream.media.path
#server side cutting #server side cutting
#FIXME: this needs to join segments if needed #FIXME: this needs to join segments if needed
@ -912,7 +907,7 @@ def video(request, id, resolution, format, index=None):
response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8')) response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
return response return response
if not settings.XSENDFILE and not settings.XACCELREDIRECT: if not settings.XSENDFILE and not settings.XACCELREDIRECT:
return redirect(stream.video.url) return redirect(stream.media.url)
response = HttpFileResponse(path) response = HttpFileResponse(path)
response['Cache-Control'] = 'public' response['Cache-Control'] = 'public'
return response return response
@ -1052,7 +1047,7 @@ def atom_xml(request):
el.attrib['rel'] = 'enclosure' el.attrib['rel'] = 'enclosure'
el.attrib['type'] = 'video/%s' % s.format el.attrib['type'] = 'video/%s' % s.format
el.attrib['href'] = '%s/%sp.%s' % (page_link, s.resolution, s.format) el.attrib['href'] = '%s/%sp.%s' % (page_link, s.resolution, s.format)
el.attrib['length'] = '%s'%s.video.size el.attrib['length'] = '%s'%s.media.size
el = ET.SubElement(entry, "media:thumbnail") el = ET.SubElement(entry, "media:thumbnail")
thumbheight = 96 thumbheight = 96