From fde89554ccac981ef7eddcf0e7b0f30c204f09ed 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 f1750016b..b209cc741 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 e179b755b..ee3b0a54b 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 06a3ffc8b..a9f438a7d 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 f124c1b2e17b63d0002a2ba9bc5be3d847694f23 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 a9f438a7d..3edaa86e2 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 68844b6ed08276d8a6c297bc3e75af38396af5b1 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 ee3b0a54b..933c728a9 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 3edaa86e2..9df43c046 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 56b292619de672c6e45195f4033f5c92fcbad344 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 b209cc741..cbb66530d 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 c54f47590bf5d057a05cbe3576695b20d98ca3ba 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 cbb66530d..f7fae8188 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 933c728a9..00535908a 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 a99ee4b60e22a723d55e0b644bb05a9d7f6c41f0 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 637fe71cd..85204d437 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 f04c1a7deb573d112d7658294616275d4114ffa5 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 85204d437..90dfc837c 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 19a338e21fe10a074440e38d1776c1a32000b533 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 9df43c046..ebfe80431 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 b960a94711681232968c9a7a1a554461a185e3e3 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 ebfe80431..aaf897f6c 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 ]