generate suggested name based on item metadata
This commit is contained in:
parent
7a878e2ea4
commit
e3a637265b
1 changed files with 29 additions and 8 deletions
|
@ -17,6 +17,7 @@ import chardet
|
||||||
|
|
||||||
from item import utils
|
from item import utils
|
||||||
from item.models import Item
|
from item.models import Item
|
||||||
|
from person.models import get_name_sort
|
||||||
|
|
||||||
|
|
||||||
class File(models.Model):
|
class File(models.Model):
|
||||||
|
@ -264,10 +265,12 @@ class File(models.Model):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_part(self):
|
def get_part(self):
|
||||||
if self.is_extra:
|
if not self.is_extra:
|
||||||
return None
|
files = list(self.item.files.filter(type=self.type,
|
||||||
files = list(self.item.files.filter(type=self.type, is_main=self.is_main).order_by('sort_name'))
|
is_main=self.is_main).order_by('sort_name'))
|
||||||
|
if self in files:
|
||||||
return files.index(self) + 1
|
return files.index(self) + 1
|
||||||
|
return None
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
if self.is_video:
|
if self.is_video:
|
||||||
|
@ -279,14 +282,32 @@ class File(models.Model):
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
|
|
||||||
def get_folder(self):
|
def get_folder(self):
|
||||||
if self.instances.count() > 0:
|
name = os.path.splitext(self.get_name())[0]
|
||||||
return self.instances.all()[0].folder
|
if self.item:
|
||||||
|
if settings.USE_IMDB:
|
||||||
|
director = self.item.get('director', ['Unknown Director'])
|
||||||
|
director = map(get_name_sort, director)
|
||||||
|
director = '; '.join(director)
|
||||||
|
director = re.sub(r'[:\\/]', '_', director)
|
||||||
|
name = os.path.join(director, name)
|
||||||
|
year = self.item.get('year', None)
|
||||||
|
if year:
|
||||||
|
name += u' (%s)' % year
|
||||||
|
name = os.path.join(name[0].upper(), name)
|
||||||
|
return name
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
|
if self.item:
|
||||||
|
name = self.item.get('title', 'Untitled')
|
||||||
|
name = re.sub(r'[:\\/]', '_', name)
|
||||||
|
if not name:
|
||||||
|
name = 'Untitled'
|
||||||
if self.instances.count() > 0:
|
if self.instances.count() > 0:
|
||||||
return self.instances.all()[0].name
|
ext = os.path.splitext(self.instances.all()[0].name)[-1]
|
||||||
return ''
|
else:
|
||||||
|
ext = '.unknown'
|
||||||
|
return name + ext
|
||||||
|
|
||||||
class Volume(models.Model):
|
class Volume(models.Model):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue