forked from Mirrors/itch-dl
Add filtering job URLs by regex/globs
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import re
|
||||
import logging
|
||||
from fnmatch import fnmatch
|
||||
|
||||
from typing import Literal
|
||||
|
||||
|
||||
class ItchDownloadError(Exception):
|
||||
@@ -31,3 +35,19 @@ def get_int_after_marker_in_json(text: str, marker: str, key: str) -> int | None
|
||||
return None
|
||||
|
||||
return int(found_ints[0])
|
||||
|
||||
|
||||
def should_skip_item_by_glob(kind: Literal['File'] | Literal['URL'], item: str, glob: str):
|
||||
if glob and not fnmatch(item, glob):
|
||||
logging.info("%s '%s' does not match the glob filter '%s', skipping", kind, item, glob)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def should_skip_item_by_regex(kind: Literal['File'] | Literal['URL'], item: str, regex: str):
|
||||
if regex and not re.fullmatch(regex, item):
|
||||
logging.info("%s '%s' does not match the regex filter '%s', skipping", kind, item, regex)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user