From 889754273aecc235b60fa6f963ac2a38f4886614 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 22 Apr 2013 11:45:22 +0000 Subject: [PATCH] rename stream.video to stream.media --- .../archive/migrations/0007_video_media.py | 166 ++++++++++++++++++ pandora/archive/models.py | 44 ++--- pandora/item/models.py | 12 +- pandora/item/views.py | 13 +- 4 files changed, 198 insertions(+), 37 deletions(-) create mode 100644 pandora/archive/migrations/0007_video_media.py diff --git a/pandora/archive/migrations/0007_video_media.py b/pandora/archive/migrations/0007_video_media.py new file mode 100644 index 000000000..7691e680b --- /dev/null +++ b/pandora/archive/migrations/0007_video_media.py @@ -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'] diff --git a/pandora/archive/models.py b/pandora/archive/models.py index c64e2892d..052824784 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -275,13 +275,13 @@ class File(models.Model): resolution=max(config['resolutions']), format=config['formats'][0]) if created: - stream.video.name = stream.path(stream.name()) - ox.makedirs(os.path.dirname(stream.video.path)) - with open(stream.video.path, 'w') as f: + stream.media.name = stream.path(stream.name()) + ox.makedirs(os.path.dirname(stream.media.path)) + with open(stream.media.path, 'w') as f: f.write(chunk.read()) stream.save() 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 f.write(chunk.read()) if done: @@ -436,7 +436,7 @@ class Stream(models.Model): resolution = models.IntegerField(default=96) 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) available = models.BooleanField(default=False) oshash = models.CharField(max_length=16, null=True, db_index=True) @@ -470,34 +470,34 @@ class Stream(models.Model): resolution=resolution, format=f) 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: derivative.source = self derivative.save() - derivative.video.name = name + derivative.media.name = name derivative.encode() derivative.save() elif rebuild or not derivative.available: - if not derivative.video: - derivative.video.name = name + if not derivative.media: + derivative.media.name = name derivative.encode() return True def encode(self): if self.source: - video = self.source.video.path - target = self.video.path - info = ox.avinfo(video) - if extract.stream(video, target, self.name(), info): + media = self.source.media.path + target = self.media.path + info = ox.avinfo(media) + if extract.stream(media, target, self.name(), info): self.available = True else: self.available = False self.save() elif self.file.data: - video = self.file.data.path - target = self.video.path - info = ox.avinfo(video) - if extract.stream(video, target, self.name(), info): + media = self.file.data.path + target = self.media.path + info = ox.avinfo(media) + if extract.stream(media, target, self.name(), info): self.available = True else: self.available = False @@ -505,15 +505,15 @@ class Stream(models.Model): def make_timeline(self): 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.color = tuple(extract.average_color(self.timeline_prefix)) self.volume = extract.average_volume(self.timeline_prefix) self.save() def save(self, *args, **kwargs): - if self.video and not self.info: - self.info = ox.avinfo(self.video.path) + if self.media and not self.info: + self.info = ox.avinfo(self.media.path) self.oshash = self.info.get('oshash') self.duration = self.info.get('duration', 0) if 'video' in self.info and self.info['video']: @@ -536,6 +536,6 @@ class Stream(models.Model): def delete_stream(sender, **kwargs): f = kwargs['instance'] - if f.video: - f.video.delete() + if f.media: + f.media.delete() pre_delete.connect(delete_stream, sender=Stream) diff --git a/pandora/item/models.py b/pandora/item/models.py index 78750a355..3c86282d4 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -943,8 +943,8 @@ class Item(models.Model): height = min(height, stream.resolution) path = os.path.join(settings.MEDIA_ROOT, stream.path(), 'frames', "%dp"%height, "%s.jpg"%position) - if not os.path.exists(path) and stream.video: - extract.frame(stream.video.path, path, position, height) + if not os.path.exists(path) and stream.media: + extract.frame(stream.media.path, path, position, height) if not os.path.exists(path): return None return path @@ -1040,8 +1040,8 @@ class Item(models.Model): quote(filename.encode('utf-8'))) video = "%s.webm" % base v = streams[0] - os.symlink(v.video.path, video) - size = v.video.size + os.symlink(v.media.path, video) + size = v.media.size duration = v.duration else: url = "%s/torrent/" % self.get_absolute_url() @@ -1050,8 +1050,8 @@ class Item(models.Model): for v in streams: video = "%s/%s.Part %d.webm" % (base, filename, part) part += 1 - os.symlink(v.video.path, video) - size += v.video.size + os.symlink(v.media.path, video) + size += v.media.size duration += v.duration video = base diff --git a/pandora/item/views.py b/pandora/item/views.py index 99c070353..63288a787 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -863,20 +863,15 @@ def video(request, id, resolution, format, index=None): index = int(index) - 1 else: 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, file__selected=True, resolution=resolution, format=format).order_by('file__part', 'file__sort_path') if index + 1 > streams.count(): raise Http404 stream = streams[index] - if not stream.available or not stream.video: + if not stream.available or not stream.media: raise Http404 - path = stream.video.path + path = stream.media.path #server side cutting #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')) return response if not settings.XSENDFILE and not settings.XACCELREDIRECT: - return redirect(stream.video.url) + return redirect(stream.media.url) response = HttpFileResponse(path) response['Cache-Control'] = 'public' return response @@ -1052,7 +1047,7 @@ def atom_xml(request): el.attrib['rel'] = 'enclosure' el.attrib['type'] = 'video/%s' % 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") thumbheight = 96