Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion SettingsTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
15 changes: 11 additions & 4 deletions plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") or False
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:
Expand Down Expand Up @@ -174,6 +177,7 @@ def query(query: str) -> ResultResponse:
d_path,
pvf,
paf,
auto_open,
)
for format in formats
]
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -334,6 +339,8 @@ def download(

try:
subprocess.run(command)
if auto_open_folder and os.path.exists(download_path):
subprocess.run(f'explorer "{download_path}"')
except Exception:
pass

Expand Down
3 changes: 2 additions & 1 deletion plugin/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"]
Expand Down Expand Up @@ -106,6 +106,7 @@ def query_result(
pref_video_path,
pref_audio_path,
format["resolution"] == "audio only",
auto_open_folder,
],
},
)
Loading