movie.py: handle some more corner cases
This commit is contained in:
parent
ccc9c90090
commit
9de043422e
1 changed files with 16 additions and 12 deletions
28
ox/movie.py
28
ox/movie.py
|
@ -13,26 +13,30 @@ from text import get_sort_name, findRe
|
||||||
|
|
||||||
__all__ = ['parse_movie_path', 'create_movie_path', 'get_oxid']
|
__all__ = ['parse_movie_path', 'create_movie_path', 'get_oxid']
|
||||||
|
|
||||||
|
'''
|
||||||
|
Naming scheme:
|
||||||
|
X/[Group, The; Lastname, Firstname/]The Title[ (YEAR[-YEAR])]/
|
||||||
|
The Title[ ([SXX][EYY])[ Episode Title]][.Version][.Part XY[.Part Title][.en].ext
|
||||||
|
'''
|
||||||
|
|
||||||
def format_path(data, has_director_directory=True):
|
def format_path(data, has_director_directory=True):
|
||||||
def format_underscores(string):
|
def format_underscores(string):
|
||||||
return re.sub('^\.|\.$|/|:', '_', string)
|
return re.sub('^\.|\.$|/|:', '_', string)
|
||||||
director = data['seriesDirectorSort' if data['isEpisode'] else 'directorSort']
|
director = data['seriesDirectorSort' if data['isEpisode'] else 'directorSort'] or ['Unknown Director']
|
||||||
title = data['seriesTitle' if data['isEpisode'] else 'title']
|
title = data['seriesTitle' if data['isEpisode'] else 'title'] or 'Untitled'
|
||||||
year = data['seriesYear' if data['isEpisode'] else 'year']
|
year = data['seriesYear' if data['isEpisode'] else 'year']
|
||||||
if has_director_directory and not director:
|
|
||||||
director = ['Unknown Director']
|
|
||||||
return '/'.join(map(format_underscores, filter(lambda x: x != None, [
|
return '/'.join(map(format_underscores, filter(lambda x: x != None, [
|
||||||
data['directory'],
|
data['directory'] or director[0][0] if has_director_directory else title[0],
|
||||||
'; '.join(director) if director else None,
|
'; '.join(director) if has_director_directory else None,
|
||||||
'%s%s' % (title, ' (%s)' % year if year else '') if title else None,
|
'%s%s' % (title, ' (%s)' % year if year else ''),
|
||||||
data['subdirectory'],
|
data['subdirectory'],
|
||||||
'%s%s%s%s%s%s' % (
|
'%s%s%s%s%s%s' % (
|
||||||
data['title'] or '',
|
data['title'] or 'Untitled',
|
||||||
'.%s' % data['version'] if data['version'] else '',
|
'.%s' % data['version'] if data['version'] else '',
|
||||||
'.Part %s' % data['part'] if data['part'] else '',
|
'.Part %s' % data['part'] if data['part'] else '',
|
||||||
'.%s' % data['partTitle'] if data['partTitle'] else '',
|
'.%s' % data['partTitle'] if data['partTitle'] else '',
|
||||||
'.%s' % data['language'].replace('/', '.') if not data['language'] in [None, 'en'] else '',
|
'.%s' % data['language'].replace('/', '.') if not data['language'] in [None, 'en'] else '',
|
||||||
'.%s' % data['extension']
|
'.%s' % data['extension'] if data['extension'] else ''
|
||||||
)
|
)
|
||||||
])))
|
])))
|
||||||
|
|
||||||
|
@ -50,7 +54,6 @@ def parse_path(path):
|
||||||
# handle underscores
|
# handle underscores
|
||||||
>>> parse_path('U/Unknown Director/_com_ 1_0 _ NaN.._/_com_ 1_0 _ NaN....avi')['title']
|
>>> parse_path('U/Unknown Director/_com_ 1_0 _ NaN.._/_com_ 1_0 _ NaN....avi')['title']
|
||||||
'.com: 1/0 / NaN...'
|
'.com: 1/0 / NaN...'
|
||||||
>>> parse_path('.foo')
|
|
||||||
'''
|
'''
|
||||||
def parse_series(string):
|
def parse_series(string):
|
||||||
match = re.search(' \((S\d{2})?(E\d{2}([+-]\d{2})?)?\)(.+)?', string)
|
match = re.search(' \((S\d{2})?(E\d{2}([+-]\d{2})?)?\)(.+)?', string)
|
||||||
|
@ -121,6 +124,8 @@ def parse_path(path):
|
||||||
parts[1:-1],
|
parts[1:-1],
|
||||||
parts[-1] if len(parts) > 1 else None
|
parts[-1] if len(parts) > 1 else None
|
||||||
]
|
]
|
||||||
|
if not data['title'] and title:
|
||||||
|
data['title'] = title
|
||||||
# season, episode, episodeTitle
|
# season, episode, episodeTitle
|
||||||
data['season'], data['episode'], data['episodeTitle'] = parse_series(title)
|
data['season'], data['episode'], data['episodeTitle'] = parse_series(title)
|
||||||
# isEpisode, seriesDirector, seriesDirectorSort, seriesTitle, seriesYear
|
# isEpisode, seriesDirector, seriesDirectorSort, seriesTitle, seriesYear
|
||||||
|
@ -156,7 +161,7 @@ def parse_path(path):
|
||||||
data['language'], parts.pop(0)
|
data['language'], parts.pop(0)
|
||||||
)
|
)
|
||||||
# extension
|
# extension
|
||||||
data['extension'] = re.sub('^mpeg$', 'mpg', extension.lower())
|
data['extension'] = re.sub('^mpeg$', 'mpg', extension.lower()) if extension else None
|
||||||
# type
|
# type
|
||||||
data['type'] = parse_type(data['extension'])
|
data['type'] = parse_type(data['extension'])
|
||||||
if data['type'] == 'subtitle' and not data['language']:
|
if data['type'] == 'subtitle' and not data['language']:
|
||||||
|
@ -329,4 +334,3 @@ def get_oxid(title, director=[], year='',
|
||||||
oxid = get_hash('\n'.join([director, title, str(year), str(season)]))[:8] + \
|
oxid = get_hash('\n'.join([director, title, str(year), str(season)]))[:8] + \
|
||||||
get_hash('\n'.join([str(episode), episode_director, episode_title, str(episode_year)]))[:8]
|
get_hash('\n'.join([str(episode), episode_director, episode_title, str(episode_year)]))[:8]
|
||||||
return u'0x' + oxid
|
return u'0x' + oxid
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue