Skip to content

Commit 6d870b9

Browse files
authored
Merge pull request #59 from z1nc0r3/feat/auto-open-download-folder
[FEAT] Add new setting to toggle auto open download folder
2 parents 748ecd0 + 6a73c17 commit 6d870b9

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

SettingsTemplate.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ body:
4242
- flac
4343
- aac
4444
- opus
45-
45+
- type: checkbox
46+
attributes:
47+
name: auto_open_folder
48+
label: "Auto-open download folder"
49+
defaultValue: true
50+
description: "Automatically open the download folder after download completes."

plugin/main.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@
4848
plugin = Plugin()
4949

5050

51-
def fetch_settings() -> Tuple[str, str, str, str]:
51+
def fetch_settings() -> Tuple[str, str, str, str, bool]:
5252
"""
5353
Fetches the user settings for the plugin.
5454
5555
Returns:
56-
Tuple[str, str, str, str]: A tuple containing:
56+
Tuple[str, str, str, str, bool]: A tuple containing:
5757
- download_path (str): The path where videos will be downloaded.
5858
- sorting_order (str): The order in which videos will be sorted (default is "Resolution").
5959
- pref_video_format (str): The preferred video format (default is "mp4").
6060
- pref_audio_format (str): The preferred audio format (default is "mp3").
61+
- auto_open_folder (bool): Whether to automatically open the download folder after download.
6162
"""
6263
try:
6364
download_path = settings().get("download_path") or DEFAULT_DOWNLOAD_PATH
@@ -67,18 +68,20 @@ def fetch_settings() -> Tuple[str, str, str, str]:
6768
sorting_order = settings().get("sorting_order") or "Resolution"
6869
pref_video_format = settings().get("preferred_video_format") or "mp4"
6970
pref_audio_format = settings().get("preferred_audio_format") or "mp3"
71+
auto_open_folder = settings().get("auto_open_folder", True)
7072
except Exception:
7173
download_path = DEFAULT_DOWNLOAD_PATH
7274
sorting_order = "Resolution"
7375
pref_video_format = "mp4"
7476
pref_audio_format = "mp3"
77+
auto_open_folder = False
7578

76-
return download_path, sorting_order, pref_video_format, pref_audio_format
79+
return download_path, sorting_order, pref_video_format, pref_audio_format, auto_open_folder
7780

7881

7982
@plugin.on_method
8083
def query(query: str) -> ResultResponse:
81-
d_path, sort, pvf, paf = fetch_settings()
84+
d_path, sort, pvf, paf, auto_open = fetch_settings()
8285

8386
verified, verify_reason = verify_ffmpeg()
8487
if not verified:
@@ -174,6 +177,7 @@ def query(query: str) -> ResultResponse:
174177
d_path,
175178
pvf,
176179
paf,
180+
auto_open,
177181
)
178182
for format in formats
179183
]
@@ -264,6 +268,7 @@ def download(
264268
pref_video_path: str,
265269
pref_audio_path: str,
266270
is_audio: bool,
271+
auto_open_folder: bool = False,
267272
) -> None:
268273
try:
269274
last_modified_time = datetime.fromtimestamp(os.path.getmtime(EXE_PATH))
@@ -314,6 +319,10 @@ def download(
314319
"--no-mtime",
315320
"--force-overwrites",
316321
"--no-part",
322+
"--retries",
323+
"3",
324+
"--retry-sleep",
325+
"2",
317326
]
318327

319328
if ffmpeg_path:
@@ -333,7 +342,13 @@ def download(
333342
command = [arg for arg in command if arg is not None and arg != ""]
334343

335344
try:
336-
subprocess.run(command)
345+
result = subprocess.run(command)
346+
if (
347+
result.returncode == 0
348+
and auto_open_folder
349+
and os.path.isdir(download_path)
350+
):
351+
os.startfile(download_path)
337352
except Exception:
338353
pass
339354

plugin/results.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def ytdlp_update_in_progress_result() -> Result:
7676

7777

7878
def query_result(
79-
query, thumbnail, title, format, download_path, pref_video_path, pref_audio_path
79+
query, thumbnail, title, format, download_path, pref_video_path, pref_audio_path, auto_open_folder=False
8080
) -> Result:
8181
# Build subtitle with consistent spacing
8282
subtitle_parts = [f"Res: {format['resolution']}"]
@@ -106,6 +106,7 @@ def query_result(
106106
pref_video_path,
107107
pref_audio_path,
108108
format["resolution"] == "audio only",
109+
auto_open_folder,
109110
],
110111
},
111112
)

0 commit comments

Comments
 (0)