cleanup file locations
This commit is contained in:
parent
38395eeed9
commit
8aa1f119ea
9 changed files with 254 additions and 100 deletions
|
|
@ -298,7 +298,7 @@ def divide(num, by):
|
|||
arr = []
|
||||
div = int(num / by)
|
||||
mod = num % by
|
||||
for i in range(by):
|
||||
for i in range(int(by)):
|
||||
arr.append(div + (i > by - 1 - mod))
|
||||
return arr
|
||||
|
||||
|
|
@ -313,7 +313,7 @@ def timeline_strip(movie, cuts, info, prefix):
|
|||
timeline_height = 64
|
||||
timeline_width = 1500
|
||||
fps = 25
|
||||
frames = duration * fps
|
||||
frames = int(duration * fps)
|
||||
if cuts[0] != 0:
|
||||
cuts.insert(0, 0)
|
||||
|
||||
|
|
@ -327,31 +327,33 @@ def timeline_strip(movie, cuts, info, prefix):
|
|||
timeline_image = Image.new('RGB', (timeline_width, timeline_height))
|
||||
if frame in cuts:
|
||||
c = cuts.index(frame)
|
||||
duration = cuts[c + 1] - cuts[c]
|
||||
stills = math.ceil(duration / (video_width * timeline_height / video_height))
|
||||
widths = divide(duration, stills)
|
||||
still = frame
|
||||
if _debug:
|
||||
print widths, duration, stills, cuts[c], cuts[c + 1]
|
||||
for s in range(int(stills)):
|
||||
still_ratio = widths[s] / timeline_height
|
||||
if video_ratio > still_ratio:
|
||||
width = int(round(video_height * still_ratio))
|
||||
left = int((video_width - width) / 2)
|
||||
box = (left, 0, left + width, video_height)
|
||||
else:
|
||||
height = int(round(video_width / still_ratio))
|
||||
top = int((video_height - height) / 2)
|
||||
box = (0, top, video_width, top + height)
|
||||
if c +1 < len(cuts):
|
||||
duration = cuts[c + 1] - cuts[c]
|
||||
stills = math.ceil(duration / (video_width * timeline_height / video_height))
|
||||
widths = divide(duration, stills)
|
||||
still = frame
|
||||
if _debug:
|
||||
print frame, 'cut', c, 'still', s, still, 'width', widths[s], box
|
||||
#FIXME: why does this have to be still+1?
|
||||
frame_image = Image.open(movie.frame((still+1)/fps))
|
||||
frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.ANTIALIAS)
|
||||
for x_ in range(widths[s]):
|
||||
line_image.append(frame_image.crop((x_, 0, x_ + 1, timeline_height)))
|
||||
still += widths[s]
|
||||
timeline_image.paste(line_image[frame], (x, 0))
|
||||
print widths, duration, stills, cuts[c], cuts[c + 1]
|
||||
for s in range(int(stills)):
|
||||
still_ratio = widths[s] / timeline_height
|
||||
if video_ratio > still_ratio:
|
||||
width = int(round(video_height * still_ratio))
|
||||
left = int((video_width - width) / 2)
|
||||
box = (left, 0, left + width, video_height)
|
||||
else:
|
||||
height = int(round(video_width / still_ratio))
|
||||
top = int((video_height - height) / 2)
|
||||
box = (0, top, video_width, top + height)
|
||||
if _debug:
|
||||
print frame, 'cut', c, 'still', s, still, 'width', widths[s], box
|
||||
#FIXME: why does this have to be still+1?
|
||||
frame_image = Image.open(movie.frame((still+1)/fps))
|
||||
frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.ANTIALIAS)
|
||||
for x_ in range(widths[s]):
|
||||
line_image.append(frame_image.crop((x_, 0, x_ + 1, timeline_height)))
|
||||
still += widths[s]
|
||||
if len(line_image) > frame:
|
||||
timeline_image.paste(line_image[frame], (x, 0))
|
||||
if x == timeline_width - 1:
|
||||
timeline_file = '%sstrip.64.%04d.png' % (prefix, i)
|
||||
if _debug:
|
||||
|
|
|
|||
148
pandora/archive/migrations/0008_available.py
Normal file
148
pandora/archive/migrations/0008_available.py
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
# encoding: 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):
|
||||
|
||||
# Deleting field 'File.video_available'
|
||||
db.delete_column('archive_file', 'video_available')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Adding field 'File.video_available'
|
||||
db.add_column('archive_file', 'video_available', self.gf('django.db.models.fields.BooleanField')(default=False, blank=True), keep_default=False)
|
||||
|
||||
|
||||
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', 'blank': 'True'}),
|
||||
'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.IntegerField', [], {'default': '0'}),
|
||||
'episode': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||
'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': ('oxdjango.fields.DictField', [], {'default': '{}'}),
|
||||
'is_audio': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_extra': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_main': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_subtitle': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_version': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_video': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'language': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '8'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'movie': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'to': "orm['backend.Movie']"}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2048'}),
|
||||
'oshash': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||
'part': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
|
||||
'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'}),
|
||||
'season': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||
'size': ('django.db.models.fields.BigIntegerField', [], {'default': '0'}),
|
||||
'sort_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2048'}),
|
||||
'verified': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'version': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
|
||||
'video': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
|
||||
'video_codec': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'width': ('django.db.models.fields.IntegerField', [], {'default': '0'})
|
||||
},
|
||||
'archive.fileinstance': {
|
||||
'Meta': {'unique_together': "(('name', 'folder', 'volume'),)", 'object_name': 'FileInstance'},
|
||||
'atime': ('django.db.models.fields.IntegerField', [], {'default': '1283966008'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'ctime': ('django.db.models.fields.IntegerField', [], {'default': '1283966008'}),
|
||||
'file': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'instances'", 'to': "orm['archive.File']"}),
|
||||
'folder': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'mtime': ('django.db.models.fields.IntegerField', [], {'default': '1283966008'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '2048'}),
|
||||
'volume': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'to': "orm['archive.Volume']"})
|
||||
},
|
||||
'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.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': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'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': '75', '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', 'blank': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||
'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': '128'}),
|
||||
'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': '30'})
|
||||
},
|
||||
'backend.movie': {
|
||||
'Meta': {'object_name': 'Movie'},
|
||||
'available': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'imdb': ('oxdjango.fields.DictField', [], {'default': '{}'}),
|
||||
'json': ('oxdjango.fields.DictField', [], {'default': '{}'}),
|
||||
'metadata': ('oxdjango.fields.DictField', [], {'default': '{}'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'movieId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'blank': 'True'}),
|
||||
'oxdbId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '42', '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_url': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'poster_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||
'published': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'stream_aspect': ('django.db.models.fields.FloatField', [], {'default': '1.3333333333333333'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'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'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['archive']
|
||||
|
|
@ -140,7 +140,6 @@ class File(models.Model):
|
|||
return r
|
||||
|
||||
#upload and data handling
|
||||
video_available = models.BooleanField(default=False)
|
||||
video = models.FileField(null=True, blank=True, upload_to=lambda f, x: file_path(f, '%s.webm'%settings.VIDEO_PROFILE))
|
||||
data = models.FileField(null=True, blank=True, upload_to=lambda f, x: file_path(f, 'data.raw'))
|
||||
|
||||
|
|
@ -154,7 +153,7 @@ class File(models.Model):
|
|||
return True
|
||||
|
||||
def save_chunk(self, chunk, chunk_id=-1):
|
||||
if not self.video_available:
|
||||
if not self.available:
|
||||
if not self.video:
|
||||
self.video.save('%s.webm'%settings.VIDEO_PROFILE, chunk)
|
||||
else:
|
||||
|
|
@ -202,11 +201,10 @@ class FileInstance(models.Model):
|
|||
def movieId(self):
|
||||
return File.objects.get(oshash=self.oshash).movieId
|
||||
|
||||
def frame_path(f, name):
|
||||
def frame_path(frame, name):
|
||||
ext = os.path.splitext(name)[-1]
|
||||
name = "%s%s" % (f.position, ext)
|
||||
h = f.file.oshash
|
||||
return os.path.join('frame', h[:2], h[2:4], h[4:6], name)
|
||||
name = "%s%s" % (frame.position, ext)
|
||||
return file_path(frame.file, name)
|
||||
|
||||
class Frame(models.Model):
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ def api_upload(request):
|
|||
'''
|
||||
user = request.user
|
||||
f = get_object_or_404(models.File, oshash=request.POST['oshash'])
|
||||
print request.FILES
|
||||
if 'frame' in request.FILES:
|
||||
if f.frames.count() == 0:
|
||||
for frame in request.FILES.getlist('frame'):
|
||||
|
|
@ -230,7 +231,7 @@ def firefogg_upload(request):
|
|||
if f.editable(request.user):
|
||||
if f.video:
|
||||
f.video.delete()
|
||||
f.video_available = False
|
||||
f.available = False
|
||||
f.save()
|
||||
response = {
|
||||
#is it possible to no hardcode url here?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue