Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Resource file extension Filter for web #67

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion waifuc/source/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, group_name: str, session: httpx.Client = None, download_silen
self.download_silent = download_silent
self.session = session or get_requests_session()
self.group_name = group_name
self.file_ext_filter = None # not filter file extension as default

@classmethod
def _rate_limiter(cls) -> Limiter:
Expand Down Expand Up @@ -57,7 +58,14 @@ def _iter(self) -> Iterator[ImageItem]:
_, ext_name = os.path.splitext(urlsplit(url).filename)
filename = f'{self.group_name}_{id_}{ext_name}'
td_file = os.path.join(td, filename)

if self.file_ext_filter:
file_ext=filename.split(".")[-1]
if any(x.replace(".","").lower() in file_ext.lower() for x in self.file_ext_filter):
pass # only want the extension i want
else:
warnings.warn(f'Skipped due to file extension download filter')
continue

try:
self._rate_limiter().try_acquire(filename)
download_file(
Expand Down