#include-once #include "DepMngr.au3" #include "ExtMngr.au3" #include "JSON.au3" #include "JSON_Translate.au3" #include "JSON_Helpers.au3" Func _YTDL_Get_Info($sYTID) If $sYTID == "" Then Return(_JSONArray()) EndIf Local $t = "" Local $bRetry = True Do ConsoleWrite("youtube-dl.exe https://www.youtube.com/watch?v="&$sYTID&" --print-json --skip-download"&@CRLF) Local $pYTDL_PID = Run("youtube-dl.exe https://www.youtube.com/watch?v="&$sYTID&" --print-json --skip-download", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pYTDL_PID) $t = StdoutRead($pYTDL_PID) If $t == "" Then $e = StderrRead($pYTDL_PID) Switch MsgBox(2, "YouTube-DL Video Lookup Error", $e) Case 3 ;Abort Exit(4) Case 4 ;Retry $bRetry = False Case 5 ;Ignore ExitLoop EndSwitch EndIf Until $bRetry Local $jVideoInfo = _JSONDecode($t, 'JSON_unpack') Return($jVideoInfo) EndFunc Func _YTDL_Get_Thmb($sYTID, ByRef $jVideoInfo) If _JSONIsNull($jVideoInfo) Or UBound($jVideoInfo) <= 0 Then $jVideoInfo = _YTDL_Get_Info($sYTID) If _JSONIsNull($jVideoInfo) Or UBound($jVideoInfo) <= 0 Then Return("") EndIf EndIf Local $fTempFile = _TempFile(@ScriptDir, "~", ".webp") ConsoleWrite("TempFile: "&$fTempFile&@CRLF) ConsoleWrite('curl -L "'&$jVideoInfo[_JSON_Find_Key("thumbnail", $jVideoInfo)][1]&'" -o "'&$fTempFile&'"'&@CRLF) RunWait('curl -L "'&$jVideoInfo[_JSON_Find_Key("thumbnail", $jVideoInfo)][1]&'" -o "'&$fTempFile&'"', @ScriptDir, @SW_HIDE) Local $fThumb = StringTrimRight($fTempFile, 4)&"jpg" ConsoleWrite("ThmbFile: "&$fThumb&@CRLF) While Not FileExists($fThumb) ConsoleWrite('magick "'&$fTempFile&'" "'&$fThumb&'"'&@CRLF) RunWait('magick "'&$fTempFile&'" "'&$fThumb&'"', @ScriptDir, @SW_HIDE) Sleep(10) WEnd FileDelete($fTempFile) _On_Exit($fThumb) Return($fThumb) EndFunc