Skip to content
Permalink
Browse files

file_info: Handle guessit returning list for title

Fixes #34
  • Loading branch information...
iamkroot committed Nov 4, 2019
1 parent 1e1658d commit 5390dfce36beaf72c8a9082810ae275be9aa89de
Showing with 11 additions and 6 deletions.
  1. +11 −6 trakt_scrobbler/file_info.py
@@ -6,24 +6,26 @@
from utils import config

logger = logging.getLogger('trakt_scrobbler')
config = config.get('fileinfo', {})
whitelist = config.get('whitelist')
regexes = config.get('include_regexes', {})


def whitelist_file(file_path):
if not config['fileinfo'].get('whitelist'):
if not whitelist:
return True
parents = list(file_path.absolute().resolve().parents)
return any(Path(path).resolve() in parents
for path in config['fileinfo']['whitelist'])
parents = tuple(file_path.absolute().resolve().parents)
return any(Path(path).resolve() in parents for path in whitelist)


def custom_regex(file_path):
logger.debug('Trying to match custom regex.')
regexes = config['fileinfo'].get('include_regexes', {})
path_posix = str(file_path.as_posix())
for item_type, patterns in regexes.items():
for pattern in patterns:
m = re.match(pattern, path_posix)
if m:
logger.debug(f"Matched pattern '{pattern}' for '{path_posix}'")
guess = m.groupdict()
guess['type'] = item_type
return guess
@@ -39,7 +41,7 @@ def use_guessit(file_path):

@lru_cache(maxsize=None)
def get_media_info(file_path):
logger.debug(f'Filepath {file_path}')
logger.debug(f"Filepath '{file_path}'")
file_path = Path(file_path)
if not whitelist_file(file_path):
logger.info("File path not in whitelist.")
@@ -52,6 +54,9 @@ def get_media_info(file_path):
'Consider renaming/using custom regex.')
return None

if isinstance(guess['title'], list):
guess['title'] = " ".join(guess['title'])

req_keys = ['type', 'title']
if guess['type'] == 'episode':
guess['season'] = int(guess.get('season', 1))

0 comments on commit 5390dfc

Please sign in to comment.
You can’t perform that action at this time.