Skip to content

Commit 8b2c328

Browse files
authored
Make 'Downloads' folder creation optional
Add --no-download-folder flag to prevent creating the 'Downloads' subfolder.
1 parent afb790b commit 8b2c328

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

downloader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ async def validate_and_download(
125125
download_path = create_download_directory(
126126
directory_name,
127127
custom_path=args.custom_path,
128+
no_download_folder=args.no_download_folder,
128129
)
129130
session_info = SessionInfo(
130131
args=args,

src/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# ============================
3939
MEDIA_SLUG_REGEX = r'const\s+slug\s*=\s*"([a-zA-Z0-9_-]+)"' # Extract media slug.
4040
VALID_SLUG_REGEX = r"^[a-zA-Z0-9_-]+$" # Validate media slug.
41-
VALID_CHARACTERS_REGEX = r'[<>:"/\\|?*\x00-\x1f]' # Strip only filesystem-illegal chars
41+
VALID_CHARACTERS_REGEX = r'[<>:"/\\|?*\x00-\x1f]' # Validate characters.
4242

4343
# ============================
4444
# UI & Table Settings
@@ -224,6 +224,11 @@ def add_common_arguments(parser: ArgumentParser) -> None:
224224
default=None,
225225
help="The directory where the downloaded content will be saved.",
226226
)
227+
parser.add_argument(
228+
"--no-download-folder",
229+
action="store_true",
230+
help="Save files without a 'Downloads' subfolder.",
231+
)
227232
parser.add_argument(
228233
"--disable-ui",
229234
action="store_true",

src/file_utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def sanitize_directory_name(directory_name: str) -> str:
9191
"""
9292
invalid_chars_dict = {
9393
"nt": r'[\\/:*?"<>|]', # Windows
94-
"posix": r"[/:]", # macOS and Linux
94+
"posix": r"[/:]", # macOS and Linux
9595
}
9696
invalid_chars = invalid_chars_dict.get(os.name)
9797
return re.sub(invalid_chars, "_", directory_name)
@@ -100,6 +100,8 @@ def sanitize_directory_name(directory_name: str) -> str:
100100
def create_download_directory(
101101
directory_name: str,
102102
custom_path: str | None = None,
103+
*,
104+
no_download_folder: bool = False,
103105
) -> str:
104106
"""Create a directory for downloads if it doesn't exist."""
105107
# Sanitizing the directory name (album ID), if provided
@@ -108,9 +110,9 @@ def create_download_directory(
108110
)
109111

110112
# Determine the base download path.
111-
base_path = (
112-
Path(custom_path) / DOWNLOAD_FOLDER if custom_path else Path(DOWNLOAD_FOLDER)
113-
)
113+
base_path = Path(custom_path or ".") # default to current directory
114+
if not no_download_folder:
115+
base_path /= DOWNLOAD_FOLDER # append DOWNLOAD_FOLDER only if needed
114116

115117
# Albums containing a single file will be directly downloaded into the 'Downloads'
116118
# folder, without creating a subfolder for the album ID.
@@ -143,7 +145,7 @@ def create_urls_file_backup() -> None:
143145
sys.exit(1)
144146

145147
timestamp = datetime.now(timezone.utc).strftime("%d%m%Y_%H%M%S")
146-
backup_file = Path(f"URLs_{timestamp}.txt.bak")
148+
backup_file = Path(f"URLs_{timestamp}.bak")
147149
shutil.copy2(URLS_FILE, backup_folder / backup_file)
148150

149151

src/general_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def handle_response(response: Response) -> BeautifulSoup | None:
5757
logging.exception(log_message)
5858
return None
5959

60-
# Use raw bytes to let BS4 detect encoding
6160
return BeautifulSoup(response.content, "html.parser")
6261

6362
for attempt in range(retries):

0 commit comments

Comments
 (0)