From 69af82bd9fa83b1e7b83e3413915a731cfc0a2c5 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 12 Sep 2012 11:44:22 +0200 Subject: [PATCH] store full path info --- pandora/archive/models.py | 52 +++++++++++++++++++++++---------------- pandora/archive/views.py | 6 ++--- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index ab611eaae..a5bacaec7 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -47,6 +47,7 @@ class File(models.Model): duration = models.FloatField(null=True) info = fields.DictField(default={}) + path_info = fields.DictField(default={}) video_codec = models.CharField(max_length=255) pixel_format = models.CharField(max_length=255) @@ -130,45 +131,54 @@ class File(models.Model): if self.instances.count(): path = self.instances.all()[0].path data = ox.movie.parse_path(path) - self.extension = data['extension'] - self.language = data['language'] - self.part = data['part'] - self.part_title = data['partTitle'] - self.type = data['type'] or 'unknown' - self.version = data['version'] + for key in ( + 'normalizedPath', 'isEpisode', + 'title', 'director', 'year', + 'season', 'episode', 'episodeTitle', + 'seriesTitle', 'seriesYear' + ): + del data[key] + self.path_info = data - def path_data(self): - data = { - 'part': self.part, - 'partTitle': self.part_title, - 'language': self.language, - 'version': self.version, - 'extension': self.extension, - 'type': self.type, - 'directory': None - } + def get_path_info(self): + data = self.path_info.copy() for key in ( 'title', 'director', 'year', - 'episode', 'episodeTitle', 'seriesTitle', 'seriesYear' + 'season', 'episode', 'episodeTitle', + 'seriesTitle', 'seriesYear' ): data[key] = self.item.get(key) data['directorSort'] = [get_name_sort(n) for n in self.item.get('director', [])] + data['isEpisode'] = data.get('season') != None \ + or data.get('episode') != None \ + or data.get('episodes') != [] + data['type'] = 'unknown' + for type in ox.movie.EXTENSIONS: + if data['extension'] in ox.movie.EXTENSIONS[type]: + data['type'] = type return data def normalize_path(self): - return u'/'.join(ox.movie.format_path(self.path_data()).split('/')[1:]) + return u'/'.join(ox.movie.format_path(self.get_path_info()).split('/')[1:]) def save(self, *args, **kwargs): - if self.id and not self.path and self.instances.count(): + if self.id and not self.path_info and self.instances.count(): self.parse_info() self.parse_instance_path() self.path = self.normalize_path() + data = self.get_path_info() + self.extension = data.get('extension') + self.language = data.get('language') + self.part = data.get('part') + self.part_title = data.get('partTitle') + self.type = data.get('type') or 'unknown' + self.version = data.get('version') + if self.path: self.path = self.normalize_path() self.sort_path = utils.sort_string(self.path) - data = ox.movie.parse_path('_/%s' % self.path) - self.type = data['type'] or 'unknown' + self.is_audio = self.type == 'audio' self.is_video = self.type == 'video' self.is_subtitle = self.path.endswith('.srt') diff --git a/pandora/archive/views.py b/pandora/archive/views.py index b1abbfc5d..ff27cf78b 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -402,11 +402,9 @@ def editFile(request): #FIXME: is this to slow to run sync? f.item.update_selected() f.item.update_wanted() - for key in ('extension', 'language', 'part', 'partTitle', 'version'): + for key in ('episodes', 'extension', 'language', 'part', 'partTitle', 'version'): if key in data: - setattr(f, - re.sub('([A-Z])', lambda m: '_%s' % m.groups()[0].lower(), key), - data[key]) + f.path_info[key] = data[key] update = True if update: f.save()