From ebf3b691b2dc915d0591111f05a901d44522d07e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 22 Aug 2012 00:53:08 +0200 Subject: [PATCH] support new series format in parse_movie_path --- ox/movie.py | 63 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/ox/movie.py b/ox/movie.py index d115949..2a47f12 100644 --- a/ox/movie.py +++ b/ox/movie.py @@ -374,32 +374,45 @@ def parse_movie_path(path): language = '' #season/episode/episodeTitle - season = find_re(parts[-1], '\.Season (\d+)\.') - if season: - season = int(season) - else: - season = None - - episode = find_re(parts[-1], '\.Episode[s]* ([\d+]+)\.') - if episode: - episode = episode.split('+')[0] - episode = int(episode) - else: - episode = None - - if episode and 'Episode %d'%episode in fileparts: - episodeTitle = fileparts.index('Episode %d' % episode) + 1 - episodeTitle = fileparts[episodeTitle] - if episodeTitle == extension or episodeTitle.startswith('Part'): - episodeTitle = None - - if not season and 'Episode' in fileparts: - episodeTitle = fileparts.index('Episode') + 1 - episodeTitle = fileparts[episodeTitle] - if episodeTitle == extension or episodeTitle.startswith('Part'): - episodeTitle = None - else: + match = re.compile('(.+?) \((S(\d+))?(E(\d+))?\)( (.+?))?\.').match(parts[-1]) + if match: + seriesTitle = match.group(1) + season = match.group(3) + episode = match.group(5) + episodeTitle = (match.group(6) or '').strip() + if episode != None: + episode = int(episode) + if season != None: + season = int(season) + if episode and not season: season = 1 + else: + season = find_re(parts[-1], '\.Season (\d+)\.') + if season: + season = int(season) + else: + season = None + + episode = find_re(parts[-1], '\.Episode[s]* ([\d+]+)\.') + if episode: + episode = episode.split('+')[0] + episode = int(episode) + else: + episode = None + + if episode and 'Episode %d'%episode in fileparts: + episodeTitle = fileparts.index('Episode %d' % episode) + 1 + episodeTitle = fileparts[episodeTitle] + if episodeTitle == extension or episodeTitle.startswith('Part'): + episodeTitle = None + + if not season and 'Episode' in fileparts: + episodeTitle = fileparts.index('Episode') + 1 + episodeTitle = fileparts[episodeTitle] + if episodeTitle == extension or episodeTitle.startswith('Part'): + episodeTitle = None + else: + season = 1 if season: seriesTitle = title