diff --git a/libs/caper/__init__.py b/libs/caper/__init__.py index 3384d7d..0ebdccc 100644 --- a/libs/caper/__init__.py +++ b/libs/caper/__init__.py @@ -19,7 +19,7 @@ from caper.parsers.anime import AnimeParser from caper.parsers.scene import SceneParser -__version_info__ = ('0', '2', '3') +__version_info__ = ('0', '2', '4') __version_branch__ = 'master' __version__ = "%s%s" % ( diff --git a/libs/caper/helpers.py b/libs/caper/helpers.py index 1a127c3..2b27e57 100644 --- a/libs/caper/helpers.py +++ b/libs/caper/helpers.py @@ -51,6 +51,18 @@ def clean_dict(target, remove=None): return target +def update_dict(a, b): + for key, value in b.items(): + if key not in a: + a[key] = value + elif isinstance(a[key], dict) and isinstance(value, dict): + update_dict(a[key], value) + elif isinstance(a[key], list): + a[key].append(value) + else: + a[key] = [a[key], value] + + def xrange_six(start, stop=None, step=None): if stop is not None and step is not None: if PY3: diff --git a/libs/caper/matcher.py b/libs/caper/matcher.py index 23fdcf9..c71da97 100644 --- a/libs/caper/matcher.py +++ b/libs/caper/matcher.py @@ -14,13 +14,16 @@ import re from logr import Logr -from caper.helpers import is_list_type +from caper.helpers import is_list_type, update_dict class FragmentMatcher(object): def __init__(self, pattern_groups): self.regex = {} + self.construct_patterns(pattern_groups) + + def construct_patterns(self, pattern_groups): for group_name, patterns in pattern_groups: if group_name not in self.regex: self.regex[group_name] = [] @@ -120,7 +123,7 @@ class FragmentMatcher(object): match = fragment_pattern.match(cur_fragment.value) if match: - result.update(match.groupdict()) + update_dict(result, match.groupdict()) else: success = False break diff --git a/libs/caper/parsers/scene.py b/libs/caper/parsers/scene.py index 224a282..44274eb 100644 --- a/libs/caper/parsers/scene.py +++ b/libs/caper/parsers/scene.py @@ -77,9 +77,12 @@ PATTERN_GROUPS = [ 'PDTV', 'DSR', 'DVDRiP', - 'WEBDL' # TODO support 'WEB.DL' tag + 'WEBDL' ]), + # For 'WEB-DL', 'WEB DL', etc... + ('(?PWEB)', '(?PDL)'), + (r'(?P%s)', [ 'x264', 'XViD' diff --git a/libs/caper/result.py b/libs/caper/result.py index 6890021..4d57f89 100644 --- a/libs/caper/result.py +++ b/libs/caper/result.py @@ -95,7 +95,7 @@ class CaperResult(object): self.chains.append(chain) for chain in self.chains: - chain.weights.append(chain.num_matched / float(max_matched)) + chain.weights.append(chain.num_matched / float(max_matched or chain.num_matched)) chain.finish() self.chains.sort(key=lambda chain: chain.weight, reverse=True)