4848plugin = 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
8083def 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
0 commit comments