From 1f2a5d1c62330eeaa6faab31f64b1773c5b48c0c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 16:32:00 +0200 Subject: [PATCH 1/9] tune files --- pandora/archive/models.py | 12 ++++++++---- pandora/archive/views.py | 3 +++ pandora/item/models.py | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index f175001..b209cc7 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -84,7 +84,9 @@ class File(models.Model): self.folder = self.get_folder() self.sort_name = utils.sort_string(canonicalTitle(self.name)) - if self.info: + if not os.path.splitext(self.name)[-1] in ( + '.srt', '.rar', '.sub', '.idx', '.txt', '.jpg', '.png', '.nfo') \ + and self.info: for key in ('duration', 'size'): setattr(self, key, self.info.get(key, 0)) @@ -128,12 +130,14 @@ class File(models.Model): self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration) else: - self.is_video = os.path.splitext(self.name)[-1] in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov') - self.is_audio = os.path.splitext(self.name)[-1] in ('.mp3', '.wav', '.ogg', '.flac') + self.is_video = os.path.splitext(self.name)[-1] in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov', '.webm') + self.is_audio = os.path.splitext(self.name)[-1] in ('.mp3', '.wav', '.ogg', '.flac', '.oga') self.is_subtitle = os.path.splitext(self.name)[-1] in ('.srt', ) - if not self.is_audio and not self.is_video and self.name.endswith('.srt'): + if self.name.endswith('.srt'): self.is_subtitle = True + self.is_audio = False + self.is_video = False else: self.is_subtitle = False diff --git a/pandora/archive/views.py b/pandora/archive/views.py index e179b75..ee3b0a5 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -105,6 +105,7 @@ def update(request): file__available=False, file__wanted=True)] response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True, + file__available=False, name__endswith='.srt')] return render_to_json_response(response) @@ -149,6 +150,8 @@ def upload(request): response = json_response(status=403, text='permissino denied') if 'file' in request.FILES: if not f.available: + if f.data: + f.data.delete() f.data.save('data.raw', request.FILES['file']) f.available = True f.save() diff --git a/pandora/item/models.py b/pandora/item/models.py index 06a3ffc..a9f438a 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -729,11 +729,11 @@ class Item(models.Model): users = self.users_with_files() if users.filter(is_superuser=True).count()>0: files = self.files.filter(instances__volume__user__is_superuser=True) - users = User.objects.filter(volumes__files__file__item__in=files, + users = User.objects.filter(volumes__files__file__in=files, is_superuser=True).distinct() elif users.filter(is_staff=True).count()>0: files = self.files.filter(instances__volume__user__is_staff=True) - users = User.objects.filter(volumes__files__file__item__in=files, + users = User.objects.filter(volumes__files__file__in=files, is_staff=True).distinct() else: files = self.files.all() From e35c178718a566daad72e94a04ef581f60a8499d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 16:45:04 +0200 Subject: [PATCH 2/9] current values --- pandora/item/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index a9f438a..3edaa86 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -660,7 +660,10 @@ class Item(models.Model): for key in self.facet_keys + ['title']: current_values = self.get(key, []) if key == 'title': - current_values = [current_values] + if current_values: + current_values = [current_values] + else: + current_values = [] ot = self.get('original_title') if ot: current_values.append(ot) From 0d5e6e64f60a4785fbdd594705829b375181c99d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 17:40:37 +0200 Subject: [PATCH 3/9] subtitles. search filenames --- pandora/archive/views.py | 1 + pandora/item/models.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pandora/archive/views.py b/pandora/archive/views.py index ee3b0a5..933c728 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -155,6 +155,7 @@ def upload(request): f.data.save('data.raw', request.FILES['file']) f.available = True f.save() + item.tasks.load_subtitles.delay(f.item.itemId) response = json_response(text='file saved') else: response = json_response(status=403, text='permissino denied') diff --git a/pandora/item/models.py b/pandora/item/models.py index 3edaa86..9df43c0 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -515,6 +515,7 @@ class Item(models.Model): #FIXME: qs = Annotation.objects.filter(layer__name='subtitles', item=self).order_by('start') save('subtitles', '\n'.join([l.value for l in qs])) + save('filename', '\n'.join([u'%s/%s' % (f.folder, f.name) for f in self.files.all()])) def update_sort(self): try: From 64671d32b74de977e823f4a474c1558ba502a49a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 17:43:31 +0200 Subject: [PATCH 4/9] subtitles available --- pandora/archive/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index b209cc7..cbb6653 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -151,7 +151,10 @@ class File(models.Model): def save(self, *args, **kwargs): if self.auto: self.set_state() - self.available = self.streams.filter(source=None, available=True).count() > 0 + if self.is_subtitle: + self.available = self.data and True or False + else: + self.available = self.streams.filter(source=None, available=True).count() > 0 super(File, self).save(*args, **kwargs) #upload and data handling From bc92ff9fd7457cd51b36c653b5bc9412ba60141c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 17:52:08 +0200 Subject: [PATCH 5/9] cleanup file state --- pandora/archive/models.py | 3 ++- pandora/archive/views.py | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index cbb6653..f7fae81 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -154,7 +154,8 @@ class File(models.Model): if self.is_subtitle: self.available = self.data and True or False else: - self.available = self.streams.filter(source=None, available=True).count() > 0 + self.available = not self.uploading and \ + self.streams.filter(source=None, available=True).count() > 0 super(File, self).save(*args, **kwargs) #upload and data handling diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 933c728..0053590 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -153,7 +153,6 @@ def upload(request): if f.data: f.data.delete() f.data.save('data.raw', request.FILES['file']) - f.available = True f.save() item.tasks.load_subtitles.delay(f.item.itemId) response = json_response(text='file saved') @@ -192,7 +191,6 @@ def firefogg_upload(request): if not f.save_chunk(c, chunk_id, form.cleaned_data['done']): response['result'] = -1 elif form.cleaned_data['done']: - f.available = True f.uploading = False f.save() #FIXME: this fails badly if rabbitmq goes down @@ -210,7 +208,6 @@ def firefogg_upload(request): f = get_object_or_404(models.File, oshash=oshash) if f.editable(request.user): f.streams.all().delete() - f.available = False f.uploading = True f.save() response = { From ba0c5e84c4e93a5fbb4b20d648739315a8308f21 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 18:07:32 +0200 Subject: [PATCH 6/9] update selected --- pandora/archive/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index 637fe71..85204d4 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -101,5 +101,6 @@ def process_stream(fileId): stream = streams[0] stream.make_timeline() stream.extract_derivatives() + file.item.update_selected() file.item.update_timeline() return True From f4b1fe53f198049ea6e745d102279c0c963f754b Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 18:08:50 +0200 Subject: [PATCH 7/9] dont update timeline twice --- pandora/archive/tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index 85204d4..90dfc83 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -102,5 +102,4 @@ def process_stream(fileId): stream.make_timeline() stream.extract_derivatives() file.item.update_selected() - file.item.update_timeline() return True From 383c75badc43dc9b5950618837fca0c04a14b9f7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 18:14:33 +0200 Subject: [PATCH 8/9] timelines could be from file now --- pandora/item/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 9df43c0..ebfe804 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -920,8 +920,7 @@ class Item(models.Model): poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster)) frame = self.get_poster_frame_path() - timeline = self.path('timeline.64.png') - timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline)) + timeline = '%.64.png' % self.timeline_prefix director = u', '.join(self.get('director', ['Unknown Director'])) cmd = [settings.ITEM_POSTER, @@ -989,8 +988,7 @@ class Item(models.Model): frame = self.get_poster_frame_path() icon = self.path('icon.jpg') self.icon.name = icon - timeline = self.path('timeline.64.png') - timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline)) + timeline = '%.64.png' % self.timeline_prefix cmd = [settings.ITEM_ICON, '-i', self.icon.path ] From 91dbbacc7381557e9b5801a30e35c3d05503be8a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 26 Aug 2011 18:15:29 +0200 Subject: [PATCH 9/9] typo --- pandora/item/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index ebfe804..aaf897f 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -920,7 +920,7 @@ class Item(models.Model): poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster)) frame = self.get_poster_frame_path() - timeline = '%.64.png' % self.timeline_prefix + timeline = '%s.64.png' % self.timeline_prefix director = u', '.join(self.get('director', ['Unknown Director'])) cmd = [settings.ITEM_POSTER, @@ -988,7 +988,7 @@ class Item(models.Model): frame = self.get_poster_frame_path() icon = self.path('icon.jpg') self.icon.name = icon - timeline = '%.64.png' % self.timeline_prefix + timeline = '%s.64.png' % self.timeline_prefix cmd = [settings.ITEM_ICON, '-i', self.icon.path ]