more raw regexp strings
This commit is contained in:
parent
29a309f15e
commit
ae10c5c9b9
11 changed files with 45 additions and 45 deletions
30
ox/movie.py
30
ox/movie.py
|
|
@ -25,7 +25,7 @@ The Title[ ([SXX][EYY[+ZZ|-ZZ]])[ Episode Title]][.Version][.Part XY[.Part Title
|
|||
|
||||
def format_path(data, directory_key='director'):
|
||||
def format_underscores(string):
|
||||
return re.sub('^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
return re.sub(r'^\.|\.$|:|/|\?|<|>', '_', string)
|
||||
director = data['directorSort'] or ['Unknown Director']
|
||||
title = data['seriesTitle' if data['isEpisode'] else 'title'] or 'Untitled'
|
||||
year = data['seriesYear' if data['isEpisode'] else 'year'] or None
|
||||
|
|
@ -199,14 +199,14 @@ def parse_path(path, directory_key='director'):
|
|||
string = re.sub('^_', '.', string)
|
||||
string = re.sub('_$', '.', string)
|
||||
# '_.foo$' or '_ (' is '?'
|
||||
string = re.sub(re.compile('_(?=(\.\w+$| \())', re.U), '?', string)
|
||||
string = re.sub(re.compile(r'_(?=(\.\w+$| \())', re.U), '?', string)
|
||||
# ' _..._ ' is '<...>'
|
||||
string = re.sub('(?<= )_(.+)_(?= )', '<\g<1>>', string)
|
||||
# 'foo_bar' or 'foo _ bar' is '/'
|
||||
string = re.sub(re.compile('(?<=\w)_(?=\w)', re.U), '/', string)
|
||||
string = re.sub(re.compile(r'(?<=\w)_(?=\w)', re.U), '/', string)
|
||||
string = re.sub(' _ ', ' / ', string)
|
||||
# 'foo_ ' is ':'
|
||||
string = re.sub(re.compile('(?<=[\w\)\]])_ ', re.U), ': ', string)
|
||||
string = re.sub(re.compile(r'(?<=[\w\)\]])_ ', re.U), ': ', string)
|
||||
string = unicodedata.normalize('NFD', string)
|
||||
return string
|
||||
|
||||
|
|
@ -238,14 +238,14 @@ def parse_path(path, directory_key='director'):
|
|||
# title, year
|
||||
data['title'] = data['year'] = None
|
||||
if title:
|
||||
match = re.search(' \(\d{4}(-(\d{4})?)?\)$', title)
|
||||
match = re.search(r' \(\d{4}(-(\d{4})?)?\)$', title)
|
||||
data['title'] = title[:-len(match.group(0))] if match else title
|
||||
data['year'] = match.group(0)[2:-1] if match else None
|
||||
file_title = re.sub('[/:]', '_', data['title'])
|
||||
# (remove title from beginning of filename if the rest contains a dot)
|
||||
file = re.sub('^' + re.escape(file_title) + '(?=.*\.)', '', file)
|
||||
# (split by nospace+dot+word, but remove spaces preceding extension)
|
||||
parts = re.split('(?<!\s)\.(?=\w)', re.sub('\s+(?=.\w+$)', '', file))
|
||||
parts = re.split(r'(?<!\s)\.(?=\w)', re.sub(r'\s+(?=.\w+$)', '', file))
|
||||
title, parts, extension = [
|
||||
parts[0],
|
||||
parts[1:-1],
|
||||
|
|
@ -256,7 +256,7 @@ def parse_path(path, directory_key='director'):
|
|||
# season, episode, episodes, episodeTitle
|
||||
data['season'] = data['episode'] = data['episodeTitle'] = None
|
||||
data['episodes'] = []
|
||||
match = re.search(' \((S\d{2})?(E\d{2}([+-]\d{2})?)?\)(.+)?', title)
|
||||
match = re.search(r' \((S\d{2})?(E\d{2}([+-]\d{2})?)?\)(.+)?', title)
|
||||
if match:
|
||||
if match.group(1):
|
||||
data['season'] = int(match.group(1)[1:])
|
||||
|
|
@ -267,7 +267,7 @@ def parse_path(path, directory_key='director'):
|
|||
data['episodes'] = range(int(match.group(2)[1:3]), int(match.group(2)[-2:]) + 1)
|
||||
if match.group(4):
|
||||
data['episodeTitle'] = match.group(4)[1:]
|
||||
while data['episodeTitle'] and len(parts) and re.search('^\w+\.*$', parts[0]) and not re.search('^[a-z]{2}$', parts[0]):
|
||||
while data['episodeTitle'] and len(parts) and re.search(r'^\w+\.*$', parts[0]) and not re.search(r'^[a-z]{2}$', parts[0]):
|
||||
data['episodeTitle'] += '.%s' % parts.pop(0)
|
||||
# isEpisode, seriesTitle, seriesYear
|
||||
data['isEpisode'] = False
|
||||
|
|
@ -343,14 +343,14 @@ def parse_movie_path(path):
|
|||
if title.startswith('_'):
|
||||
title = '.' + title[1:]
|
||||
|
||||
year = find_re(title, '(\(\d{4}\))')
|
||||
year = find_re(title, r'(\(\d{4}\))')
|
||||
if not year:
|
||||
year = find_re(title, '(\(\d{4}-\d*\))')
|
||||
year = find_re(title, r'(\(\d{4}-\d*\))')
|
||||
if year and title.endswith(year):
|
||||
title = title[:-len(year)].strip()
|
||||
year = year[1:-1]
|
||||
if '-' in year:
|
||||
year = find_re(year, '\d{4}')
|
||||
year = find_re(year, r'\d{4}')
|
||||
|
||||
#director
|
||||
if len(parts) == 4:
|
||||
|
|
@ -373,7 +373,7 @@ def parse_movie_path(path):
|
|||
language = ''
|
||||
|
||||
#season/episode/episodeTitle
|
||||
match = re.compile('(.+?) \((S(\d+))?(E(\d+))?\)( (.+?))?\.').match(parts[-1])
|
||||
match = re.compile(r'(.+?) \((S(\d+))?(E(\d+))?\)( (.+?))?\.').match(parts[-1])
|
||||
if match:
|
||||
seriesTitle = match.group(1)
|
||||
season = match.group(3)
|
||||
|
|
@ -386,13 +386,13 @@ def parse_movie_path(path):
|
|||
if episode and not season:
|
||||
season = 1
|
||||
else:
|
||||
season = find_re(parts[-1], '\.Season (\d+)\.')
|
||||
season = find_re(parts[-1], r'\.Season (\d+)\.')
|
||||
if season:
|
||||
season = int(season)
|
||||
else:
|
||||
season = None
|
||||
|
||||
episode = find_re(parts[-1], '\.Episode[s]* ([\d+]+)\.')
|
||||
episode = find_re(parts[-1], r'\.Episode[s]* ([\d+]+)\.')
|
||||
if episode:
|
||||
episode = episode.split('+')[0]
|
||||
episode = int(episode)
|
||||
|
|
@ -422,7 +422,7 @@ def parse_movie_path(path):
|
|||
title = u'%s %s' % (title, episodeTitle)
|
||||
|
||||
#part
|
||||
part = find_re(parts[-1], '\.Part (\d+)\.')
|
||||
part = find_re(parts[-1], r'\.Part (\d+)\.')
|
||||
if part:
|
||||
part = int(part)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue