store full path info

This commit is contained in:
j 2012-09-12 11:44:22 +02:00
parent f3605569fa
commit 69af82bd9f
2 changed files with 33 additions and 25 deletions

View file

@ -47,6 +47,7 @@ class File(models.Model):
duration = models.FloatField(null=True) duration = models.FloatField(null=True)
info = fields.DictField(default={}) info = fields.DictField(default={})
path_info = fields.DictField(default={})
video_codec = models.CharField(max_length=255) video_codec = models.CharField(max_length=255)
pixel_format = models.CharField(max_length=255) pixel_format = models.CharField(max_length=255)
@ -130,45 +131,54 @@ class File(models.Model):
if self.instances.count(): if self.instances.count():
path = self.instances.all()[0].path path = self.instances.all()[0].path
data = ox.movie.parse_path(path) data = ox.movie.parse_path(path)
self.extension = data['extension'] for key in (
self.language = data['language'] 'normalizedPath', 'isEpisode',
self.part = data['part'] 'title', 'director', 'year',
self.part_title = data['partTitle'] 'season', 'episode', 'episodeTitle',
self.type = data['type'] or 'unknown' 'seriesTitle', 'seriesYear'
self.version = data['version'] ):
del data[key]
self.path_info = data
def path_data(self): def get_path_info(self):
data = { data = self.path_info.copy()
'part': self.part,
'partTitle': self.part_title,
'language': self.language,
'version': self.version,
'extension': self.extension,
'type': self.type,
'directory': None
}
for key in ( for key in (
'title', 'director', 'year', 'title', 'director', 'year',
'episode', 'episodeTitle', 'seriesTitle', 'seriesYear' 'season', 'episode', 'episodeTitle',
'seriesTitle', 'seriesYear'
): ):
data[key] = self.item.get(key) data[key] = self.item.get(key)
data['directorSort'] = [get_name_sort(n) for n in self.item.get('director', [])] 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 return data
def normalize_path(self): 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): 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_info()
self.parse_instance_path() self.parse_instance_path()
self.path = self.normalize_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: if self.path:
self.path = self.normalize_path() self.path = self.normalize_path()
self.sort_path = utils.sort_string(self.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_audio = self.type == 'audio'
self.is_video = self.type == 'video' self.is_video = self.type == 'video'
self.is_subtitle = self.path.endswith('.srt') self.is_subtitle = self.path.endswith('.srt')

View file

@ -402,11 +402,9 @@ def editFile(request):
#FIXME: is this to slow to run sync? #FIXME: is this to slow to run sync?
f.item.update_selected() f.item.update_selected()
f.item.update_wanted() 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: if key in data:
setattr(f, f.path_info[key] = data[key]
re.sub('([A-Z])', lambda m: '_%s' % m.groups()[0].lower(), key),
data[key])
update = True update = True
if update: if update:
f.save() f.save()