From da9dd942b279c2e268767408d01e4f87050da4ad Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 22 Aug 2012 00:18:00 +0200 Subject: [PATCH] index all instance paths too, add getPath --- pandora/archive/models.py | 21 ++++++++++++--------- pandora/archive/views.py | 22 ++++++++++++++++++++++ pandora/item/models.py | 10 ++++++++-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 168b5284..06bd9066 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -77,9 +77,9 @@ class File(models.Model): def set_state(self): self.path = self.create_path() - if not os.path.splitext(self.path)[-1] in ( - '.srt', '.rar', '.sub', '.idx', '.txt', '.jpg', '.png', '.nfo') \ - and self.info: + if not self.path.split('.')[-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)) @@ -126,9 +126,9 @@ 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.path)[-1].lower() in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov', '.webm', '.mp4', '.mpg', '.wmv', '.mts', '.flv') - self.is_audio = os.path.splitext(self.path)[-1].lower() in ('.mp3', '.wav', '.ogg', '.flac', '.oga', '.wma') - self.is_subtitle = os.path.splitext(self.path)[-1].lower() in ('.srt', ) + self.is_video = self.path.split('.')[-1].lower() in ox.movie.EXTENSIONS['video'] + self.is_audio = self.path.split('.')[-1].lower() in ox.movie.EXTENSIONS['audio'] + self.is_audio = self.path.split('.')[-1].lower() == 'srt' if self.path.endswith('.srt'): self.is_subtitle = True @@ -139,8 +139,8 @@ class File(models.Model): self.type = self.get_type() if self.instances.count()>0: - info = ox.parse_movie_path(self.path) - self.language = info['language'] + info = ox.movie.parse_path(self.path) + self.language = info['language'] or '' self.part = self.get_part() if self.type not in ('audio', 'video'): @@ -271,9 +271,12 @@ class File(models.Model): def create_path(self): instance = self.get_instance() if instance: - return instance.path + return ox.movie.parse_path(instance.path)['path'] return self.path + def all_paths(self): + return [self.path] + [i.path for i in self.instances.all()] + def delete_frames(self): frames = os.path.join(settings.MEDIA_ROOT, self.get_path('frames')) if os.path.exists(frames): diff --git a/pandora/archive/views.py b/pandora/archive/views.py index fc6fd88f..04cfdebc 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -429,6 +429,28 @@ def removeFiles(request): return render_to_json_response(response) actions.register(removeFiles, cache=False) +def getPath(request): + ''' + change file / item link + param data { + ids: [hash of file] + } + + return { + status: {'code': int, 'text': string}, + data: { + path: { + id: path + } + } + } + ''' + data = json.loads(request.POST['data']) + response = json_response({'path': {}}) + for f in models.File.objects.filter(oshash__in=data['ids']): + response['data']['path'][f.oshash] = f.path + return render_to_json_response(response) +actions.register(getPath, cache=True) def lookup_file(request, oshash): oshash = oshash.replace('/', '') diff --git a/pandora/item/models.py b/pandora/item/models.py index bc677db1..5d7d46e5 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -595,8 +595,7 @@ class Item(models.Model): elif i == 'rightslevel': save(i, self.level) elif i == 'filename': - save(i, - '\n'.join([f.path for f in self.files.all()])) + save(i, '\n'.join(i.all_paths())) elif i == 'user': if self.user: save(i, self.user.username) @@ -905,6 +904,13 @@ class Item(models.Model): return os.path.join(settings.MEDIA_ROOT, videos[0].path('')) return os.path.join(settings.MEDIA_ROOT, self.path()) + def all_paths(self): + return list(set([ + item for sublist in + [f.all_paths() for f in self.files.all()] + for item in sublist + ])) + def get_files(self, user): files = self.files.all().select_related() if user.get_profile().get_level() != 'admin':