diff --git a/SettingsTemplate.yaml b/SettingsTemplate.yaml index 7de1471..f4b1d8a 100644 --- a/SettingsTemplate.yaml +++ b/SettingsTemplate.yaml @@ -42,4 +42,9 @@ body: - flac - aac - opus - + - type: checkbox + attributes: + name: auto_open_folder + label: "Auto-open download folder" + defaultValue: true + description: "Automatically open the download folder after download completes." diff --git a/plugin/main.py b/plugin/main.py index 6add860..024edc5 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -48,16 +48,17 @@ plugin = Plugin() -def fetch_settings() -> Tuple[str, str, str, str]: +def fetch_settings() -> Tuple[str, str, str, str, bool]: """ Fetches the user settings for the plugin. Returns: - Tuple[str, str, str, str]: A tuple containing: + Tuple[str, str, str, str, bool]: A tuple containing: - download_path (str): The path where videos will be downloaded. - sorting_order (str): The order in which videos will be sorted (default is "Resolution"). - pref_video_format (str): The preferred video format (default is "mp4"). - pref_audio_format (str): The preferred audio format (default is "mp3"). + - auto_open_folder (bool): Whether to automatically open the download folder after download. """ try: download_path = settings().get("download_path") or DEFAULT_DOWNLOAD_PATH @@ -67,18 +68,20 @@ def fetch_settings() -> Tuple[str, str, str, str]: sorting_order = settings().get("sorting_order") or "Resolution" pref_video_format = settings().get("preferred_video_format") or "mp4" pref_audio_format = settings().get("preferred_audio_format") or "mp3" + auto_open_folder = settings().get("auto_open_folder", True) except Exception: download_path = DEFAULT_DOWNLOAD_PATH sorting_order = "Resolution" pref_video_format = "mp4" pref_audio_format = "mp3" + auto_open_folder = False - return download_path, sorting_order, pref_video_format, pref_audio_format + return download_path, sorting_order, pref_video_format, pref_audio_format, auto_open_folder @plugin.on_method def query(query: str) -> ResultResponse: - d_path, sort, pvf, paf = fetch_settings() + d_path, sort, pvf, paf, auto_open = fetch_settings() verified, verify_reason = verify_ffmpeg() if not verified: @@ -174,6 +177,7 @@ def query(query: str) -> ResultResponse: d_path, pvf, paf, + auto_open, ) for format in formats ] @@ -264,6 +268,7 @@ def download( pref_video_path: str, pref_audio_path: str, is_audio: bool, + auto_open_folder: bool = False, ) -> None: try: last_modified_time = datetime.fromtimestamp(os.path.getmtime(EXE_PATH)) @@ -314,6 +319,10 @@ def download( "--no-mtime", "--force-overwrites", "--no-part", + "--retries", + "3", + "--retry-sleep", + "2", ] if ffmpeg_path: @@ -333,7 +342,13 @@ def download( command = [arg for arg in command if arg is not None and arg != ""] try: - subprocess.run(command) + result = subprocess.run(command) + if ( + result.returncode == 0 + and auto_open_folder + and os.path.isdir(download_path) + ): + os.startfile(download_path) except Exception: pass diff --git a/plugin/results.py b/plugin/results.py index 6428ae2..90967e6 100644 --- a/plugin/results.py +++ b/plugin/results.py @@ -76,7 +76,7 @@ def ytdlp_update_in_progress_result() -> Result: def query_result( - query, thumbnail, title, format, download_path, pref_video_path, pref_audio_path + query, thumbnail, title, format, download_path, pref_video_path, pref_audio_path, auto_open_folder=False ) -> Result: # Build subtitle with consistent spacing subtitle_parts = [f"Res: {format['resolution']}"] @@ -106,6 +106,7 @@ def query_result( pref_video_path, pref_audio_path, format["resolution"] == "audio only", + auto_open_folder, ], }, )