def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ if not matches.named('type', lambda m: m.value == 'movie'): return to_remove = [] to_append = [] others = matches.named('other') if others: other = others[0] if other.initiator.value == 'XXX': next = matches.next(other, predicate=lambda match: match.name == 'title') if next: # Prepend to title title = next[0] title.value = cleanup(other.initiator.raw + s2n(' ') + title.initiator.raw) to_remove.extend(others) to_append.append(title) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ if not matches.named('type', lambda m: m.value == 'movie'): return to_remove = [] to_append = [] countries = matches.named('country') if countries: country = countries[0] if country.initiator.value == 'US': previous = matches.previous(country, predicate=lambda match: match.name == 'title') if previous: # Append to title title = previous[0] title.value = cleanup(title.initiator.raw + s2n(' ') + country.initiator.raw) to_remove.extend(countries) to_append.append(title) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ if not matches.named('type', lambda m: m.value == 'movie'): return to_remove = [] to_append = [] parts = matches.named('part') if parts: part = parts[0] previous = matches.previous(part, predicate=lambda match: match.name == 'title') if previous: # Append to title title = previous[0] title.value = cleanup(title.initiator.raw + s2n(' ') + part.initiator.raw) to_remove.extend(parts) to_append.append(title) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ fileparts = matches.markers.named('path') for filepart in marker_sorted(fileparts, matches): # retrieve all problematic titles problematic_titles = matches.range(filepart.start, filepart.end, predicate=lambda match: match.name in self.properties) to_remove = [] to_append = [] for title in problematic_titles: m = self.absolute_re.search(title.raw) if not m: continue # Remove the problematic title to_remove.append(title) # Remove the title suffix new_value = title.raw[0: m.start()] if new_value: # Add the correct title new_title = copy.copy(title) new_title.value = cleanup(new_value) new_title.end = title.start + m.start() to_append.append(new_title) # and add the absolute episode range g = m.groupdict() if not g['absolute_episode_end'] and title.name != 'alternative_title': continue absolute_episode_start = int(g['absolute_episode_start']) absolute_episode_end = int(g['absolute_episode_end'] or g['absolute_episode_start']) for i in range(absolute_episode_start, absolute_episode_end + 1): episode = copy.copy(title) episode.name = 'absolute_episode' episode.value = i if i == absolute_episode_start: episode.start = title.start + m.start('absolute_episode_start') episode.end = title.start + m.end('absolute_episode_start') elif i < absolute_episode_end: episode.start = title.start + m.end('absolute_episode_start') episode.end = title.start + m.start('absolute_episode_end') else: episode.start = title.start + m.start('absolute_episode_end') episode.end = title.start + m.end('absolute_episode_end') to_append.append(episode) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ if context.get('show_type') == 'normal': return fileparts = matches.markers.named('path') for filepart in marker_sorted(fileparts, matches): # get the group (e.g.: [abc]) at the beginning of this filepart group = matches.markers.at_index( filepart.start, index=0, predicate=lambda marker: marker.name == 'group') if not group or matches.at_match(group): continue # don't use websites as release group websites = matches.named('website') if websites and any(ws for ws in websites if ws.value in group.value): continue if (not matches.tagged('anime') and not matches.named('video_profile') and matches.named('season') and matches.named('episode')): continue groups = matches.range( filepart.start, filepart.end, predicate=lambda match: match.name == 'release_group') if not groups: continue to_remove = [] to_append = [] if group: to_remove.extend(groups) rg = copy.copy(groups[0]) rg.start = group.start rg.end = group.end rg.value = cleanup(group.value) rg.tags = ['anime'] to_append.append(rg) else: # anime should pick the first in the list and discard the rest to_remove.append(groups[1:]) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ if context.get('show_type') == 'normal': return fileparts = matches.markers.named('path') for filepart in marker_sorted(fileparts, matches): # get the group (e.g.: [abc]) at the beginning of this filepart group = matches.markers.at_index(filepart.start, index=0, predicate=lambda marker: marker.name == 'group') if not group or matches.at_match(group): continue # don't use websites as release group websites = matches.named('website') if websites and any(ws for ws in websites if ws.value in group.value): continue if (not matches.tagged('anime') and not matches.named('video_profile') and matches.named('season') and matches.named('episode')): continue groups = matches.range(filepart.start, filepart.end, predicate=lambda match: match.name == 'release_group') if not groups: continue to_remove = [] to_append = [] if group: to_remove.extend(groups) rg = copy.copy(groups[0]) rg.start = group.start rg.end = group.end rg.value = cleanup(group.value) rg.tags = ['anime'] to_append.append(rg) else: # anime should pick the first in the list and discard the rest to_remove.append(groups[1:]) return to_remove, to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ to_append = [] for proper in matches.named('other', predicate=lambda match: match.value == 'Proper'): tag = copy.copy(proper) tag.name = 'proper_tag' tag.value = cleanup(proper.raw.upper()) to_append.append(tag) return to_append
def when(self, matches, context): """Evaluate the rule. :param matches: :type matches: rebulk.match.Matches :param context: :type context: dict :return: """ languages = matches.named('language') if not languages: return fileparts = matches.markers.named('path') parts_len = len(fileparts) if parts_len < 2: return titles = matches.named('title') if not titles: return first_title = titles[0] last_title = titles[-1] # Always use the first language first_language = languages[0] for language in languages[1:]: if language.start < first_language.start: first_language = language lang_start = first_language.start lang_end = first_language.end start = end = None # Language is before titles if lang_end == first_title.start: start = lang_start end = last_title.end # Language is after titles elif last_title.end == lang_start: start = first_title.start end = lang_end # Language is between titles elif len(titles) > 1: lang_code = last_title.value.split()[0].lower() if lang_code in context.get('allowed_languages', []): start = first_title.start end = last_title.end if start is not None: second_filepart = fileparts[parts_len - 2] rel_start = start - second_filepart.start rel_end = end - second_filepart.end new_title = second_filepart.value[rel_start:rel_end] titles[0].value = cleanup(new_title) to_append = titles[0] to_remove = first_language return to_remove, to_append