def episode_filter_regex(data: List[Episode], regex: str = None) -> List[Episode]: """ :param data: list of bangumi dict :param regex: regex """ if regex: try: match = re.compile(regex) data = [s for s in data if match.findall(s.title)] except re.error as e: if os.getenv("DEBUG"): # pragma: no cover import traceback traceback.print_exc() raise e return data if not ENABLE_GLOBAL_FILTER == "0": data = list( filter( lambda s: all( map( lambda t: t.strip().lower() not in s.title.lower(), GLOBAL_FILTER.split(","), ) ), data, ) ) return data
def episode_filter_regex(data: List[Episode], regex: str = None) -> List[Episode]: """ :param data: list of bangumi dict :param regex: regex """ if regex: try: match = re.compile(regex) data = [s for s in data if match.findall(s.title)] except re.error as e: if os.getenv("DEBUG"): # pragma: no cover traceback.print_exc() raise e print_warning( f"can't compile regex {regex}, skipping filter by regex") if ENABLE_GLOBAL_FILTER != "0": exclude_keywords = [ t.strip().lower() for t in GLOBAL_FILTER.split(",") ] data = [x for x in data if not x.contains_any_words(exclude_keywords)] return data
def filter_keyword(data, regex=None): """ :type regex: str :param data: list of bangumi dict :type data: list[dict] """ if regex: try: match = re.compile(regex) data = [s for s in data if match.findall(s['title'])] except re.error as e: if os.getenv('DEBUG'): # pragma: no cover import traceback traceback.print_exc() raise e return data if not ENABLE_GLOBAL_FILTER == '0': data = list( filter( lambda s: all( map( lambda t: t.strip().lower() not in s['title']. lower(), GLOBAL_FILTER.split(','))), data)) return data
def filter_keyword(self, data, regex=None): if regex: try: match = re.compile(regex) data = list( filter( lambda s: True if match.findall(s['title']) else False, data)) except re.error as e: if os.getenv('DEBUG'): # pragma: no cover import traceback traceback.print_exc() raise e return data if not ENABLE_GLOBAL_FILTER == '0': data = list( filter( lambda s: True if all( map( lambda t: t.strip().lower() not in s['title']. lower(), GLOBAL_FILTER.split(','))) else False, data)) return data