Skip to content
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
14 changes: 13 additions & 1 deletion e621_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def search_posts(
posts = api.posts.search(formatted_tags, limit=max_posts, ignore_pagination=True)
print(len(posts), "posts found")
if _hardcoded_download_dir is None:
directory = download_dir / formatted_tags
directory = download_dir / normalize_directory_name(formatted_tags)
directory.mkdir(exist_ok=True, parents=True)
else:
directory = _hardcoded_download_dir
Expand Down Expand Up @@ -331,5 +331,17 @@ def normalize_file_name(name: str, id: int) -> str:
return INVALID_FILE_CHAR.sub("", name).replace("\0", "") or f"e621_{id}"


def normalize_directory_name(name: str) -> str:
"""Makes directory name valid for both Windows and Unix systems

Args:
name: Original tags as a string

Returns:
The normalized directory name
"""
return INVALID_FILE_CHAR.sub("-", name).replace("\0", "")


if __name__ == "__main__":
app()