From 3064785b3e7aa838d7f8bbf5dc0125cc51fe85f3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 26 Sep 2013 14:55:37 +0000 Subject: [PATCH] remove failed transcodes, fix reuploading the same file via direct upload --- pandora/archive/extract.py | 5 +++++ pandora/archive/models.py | 1 + pandora/archive/tasks.py | 7 ++++--- pandora/archive/views.py | 6 ++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 985826a8..dede6c82 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -247,6 +247,11 @@ def stream(video, target, profile, info): stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) p.communicate() + if p.returncode != 0: + t = "%s.mp4" % target if format == 'mp4' else target + if os.path.exists(t): + os.unlink(t) + return False if format == 'mp4': cmd = ['qt-faststart', "%s.mp4" % target, target] #print cmd diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 70cee8dc..4e80cb5e 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -570,6 +570,7 @@ class Stream(models.Model): if extract.stream(media, target, self.name(), info): self.available = True else: + self.media = None self.available = False self.save() diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index d18a3bb6..828024c3 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -87,9 +87,9 @@ def process_stream(fileId): ''' file = models.File.objects.get(id=fileId) streams = file.streams.filter(source=None) + models.File.objects.filter(id=fileId).update(encoding=True, queued=False) if streams.count() > 0: stream = streams[0] - models.File.objects.filter(id=fileId).update(encoding=True, queued=False) stream.make_timeline() stream.extract_derivatives() file = models.File.objects.get(id=fileId) @@ -100,6 +100,7 @@ def process_stream(fileId): file.item.update_timeline() if file.item.rendered: file.item.save() + models.File.objects.filter(id=fileId).update(encoding=False) return True @task(queue="encoding") @@ -107,6 +108,7 @@ def extract_stream(fileId): ''' extract stream from direct upload ''' + models.File.objects.filter(id=fileId).update(encoding=True, queued=False) file = models.File.objects.get(id=fileId) if file.data: config = settings.CONFIG['video'] @@ -114,7 +116,6 @@ def extract_stream(fileId): file=file, resolution=max(config['resolutions']), format=config['formats'][0]) if created: - models.File.objects.filter(id=fileId).update(encoding=True, queued=False) stream.media.name = stream.path(stream.name()) stream.encode() if stream.available: @@ -125,7 +126,7 @@ def extract_stream(fileId): file.item.update_timeline() if file.item.rendered: file.item.save() - models.File.objects.filter(id=fileId).update(encoding=False) + models.File.objects.filter(id=fileId).update(encoding=False) @task(queue="encoding") def extract_derivatives(fileId, rebuild=False): diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 08423849..9c62aff0 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -310,6 +310,12 @@ def direct_upload(request): else: file, created = models.File.objects.get_or_create(oshash=oshash) if file.editable(request.user): + #remove previous uploads + if not created: + file.streams.all().delete() + file.delete_frames() + if file.item.rendered and file.selected: + Item.objects.filter(id=file.item.id).update(rendered=False) file.uploading = True file.save() upload_url = request.build_absolute_uri('/api/upload/direct/?id=%s' % file.oshash)