1
0
forked from Mirrors/itch-dl

Add filtering job URLs by regex/globs

This commit is contained in:
Ryszard Knop
2025-04-03 18:50:33 +02:00
parent 5ab0dc0309
commit a092532192
4 changed files with 50 additions and 3 deletions

View File

@@ -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