#include #include #include "IniMngr.au3" #include "DepMngr.au3" #include "ExtMngr.au3" #include "YTDL_Get.au3" #include "JSON_Helpers.au3" #include "WindowDef.au3" #include "TimeFormat.au3" #include "SizeFormat.au3" _IniMngr() #Region Globals Global $sYTID = "" Global $jVideoInfo = _JSONArray() Global $fIniFile = $__fIniFile Global $nSelFormatIndex = -1 Global $fThumb = "" Global $fDownload = "" Global $fPrevDir = "" Global $aLockState[3] = ["Before","Before","Before"] #EndRegion Opt("GUICloseOnESC", 0) _LockMngr(Default, True) GUISetState(@SW_SHOW) GUICtrlSetData($gaExternal[1][1], "https://www.youtube.com/watch?v=-J_tli6BV04") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $gaExternal[2][1];gSelect _LockMngr("Selecting During") $sYTID = _DecodeURL($gaExternal[1][1]) If $sYTID <> "" Then $fThumb = _YTDL_Get_Thmb($sYTID, $jVideoInfo) _SetStats($gaSelVidSts) _LockMngr("Selecting After") Else _LockMngr("Selecting Before") EndIf ;~ MsgBox(0,"","$g"&$gaExternal[2][0]) Case $gaSelVidSts[9][1];gDownload MsgBox(0,"","$g"&$gaSelVidSts[9][0]) Case $gaSelVidSts[10][1];gCancel Global $sYTID = "" Global $jVideoInfo = _JSONArray() Global $fThumb = "" Global $fDownload = "" Global $fPrevDir = "" _Clear_Temp_Files() _LockMngr("Selecting Before|Downloading Before|Confirming Before") ;~ MsgBox(0,"","$g"&$gaSelVidSts[10][0]) Case $gaTransitions[1][1];gActiveTrans MsgBox(0,"","$g"&$gaTransitions[1][0]) Case $gaTransitions[2][1];gInActvTrans MsgBox(0,"","$g"&$gaTransitions[2][0]) Case $gaTransitions[3][1];gFindJumpCuts_ MsgBox(0,"","$g"&$gaTransitions[3][0]) Case $gaTransitions[4][1];gActivateTrans MsgBox(0,"","$g"&$gaTransitions[4][0]) Case $gaTransitions[5][1];gDeActivtTrans MsgBox(0,"","$g"&$gaTransitions[5][0]) Case $gaTransitions[6][1];gGenVideoLists MsgBox(0,"","$g"&$gaTransitions[6][0]) Case $gaSegments[1][1];gActiveSegs MsgBox(0,"","$g"&$gaSegments[1][0]) Case $gaSegments[2][1];gInActvSegs MsgBox(0,"","$g"&$gaSegments[2][0]) Case $gaSegments[3][1];gResetSegments MsgBox(0,"","$g"&$gaSegments[3][0]) Case $gaSegments[4][1];gActivateSegs MsgBox(0,"","$g"&$gaSegments[4][0]) Case $gaSegments[5][1];gDeActivtSegs MsgBox(0,"","$g"&$gaSegments[5][0]) Case $gaSegments[6][1];gExportLists MsgBox(0,"","$g"&$gaSegments[6][0]) Case $GUI_EVENT_CLOSE _On_Exit() EndSwitch WEnd Func _SetStats(ByRef $gaArray) GUICtrlSetData($gaArray[1][1], StringSplit($gaArray[1][3],"|",2)[0]&"https://www.youtube.com/watch?v="&$sYTID) GUICtrlSetData($gaArray[2][1], StringSplit($gaArray[2][3],"|",2)[0]&$jVideoInfo[_JSON_Find_Key("title", $jVideoInfo)][1]) GUICtrlSetData($gaArray[3][1], StringSplit($gaArray[3][3],"|",2)[0]&_FormatDuration($jVideoInfo[_JSON_Find_Key("duration", $jVideoInfo)][1])) GUICtrlSetData($gaArray[4][1], StringSplit($gaArray[4][3],"|",2)[0]&$jVideoInfo[_JSON_Find_Key("width", $jVideoInfo)][1]&" x "&$jVideoInfo[_JSON_Find_Key("height", $jVideoInfo)][1]) Local $aFormats = $jVideoInfo[_JSON_Find_Key("formats", $jVideoInfo)][1] Local $aAccepted[UBound($aFormats)] For $l = 0 To UBound($aFormats) - 1 Local $aTmp = $aFormats[$l] $aAccepted[$l] = Not (_JSONIsNull($aTmp[_JSON_Find_Key("filesize", $aFormats[$l])][1]) Or _JSONIsNull($aTmp[_JSON_Find_Key("height", $aFormats[$l])][1])) Next Local $aDimSizes[0][3] For $l = 0 To UBound($aFormats) - 1 If $aAccepted[$l] Then Local $aTmp = $aFormats[$l] Local $nHeight = Number($aTmp[_JSON_Find_Key("height", $aFormats[$l])][1]) Local $nSize = Number($aTmp[_JSON_Find_Key("filesize", $aFormats[$l])][1]) Local $nIndex = _JSON_Find_Key($nHeight, $aDimSizes, 0) If _JSONIsNull($nIndex) Then _ArrayAdd($aDimSizes, $nHeight&"|"&$nSize&"|"&$l) ElseIf $nSize < $aDimSizes[$nIndex][1] Then $aDimSizes[$nIndex][1] = Number($nSize) $aDimSizes[$nIndex][2] = $l EndIf EndIf Next Local $nLTmp = 0 While UBound($aDimSizes) > 1 And $nLTmp < UBound($aDimSizes) ConsoleWrite($aDimSizes[0][0]&@CRLF) If Number($aDimSizes[$nLTmp][0]) < 480 Then _ArrayDelete($aDimSizes, $nLTmp) Else $nLTmp += 1 EndIf WEnd Local $nMaxSize = IniRead($fIniFile, "General", "Max File Size", "‭52428800‬") Local $nCount = 0 Local $aMinOver = -1 Local $aMaxQUnder = -1 For $l = 0 To UBound($aDimSizes) - 1 If Number($aDimSizes[$l][1]) > Number($nMaxSize) Then $nCount += 1 If Number($aDimSizes[$l][1]) < Number($aMinOver) Or Number($aMinOver) < 0 Then $aMinOver = Number($aDimSizes[$l][1]) EndIf Else If Number($aDimSizes[$l][0]) > Number($aMaxQUnder) Then $aMaxQUnder = Number($aDimSizes[$l][0]) EndIf EndIf Next If $nCount < UBound($aDimSizes) Then $nLTmp = 0 While UBound($aDimSizes) > 1 And $nLTmp < UBound($aDimSizes) If Number($aDimSizes[$nLTmp][1]) > $nMaxSize Then _ArrayDelete($aDimSizes, $nLTmp) Else $nLTmp += 1 EndIf WEnd EndIf $nLTmp = 0 While UBound($aDimSizes) > 1 And $nLTmp < UBound($aDimSizes) If Number($aDimSizes[$nLTmp][0]) < $aMaxQUnder then _ArrayDelete($aDimSizes, $nLTmp) Else $nLTmp += 1 EndIf WEnd For $l = 0 To UBound($aFormats) - 1 $aAccepted[$l] = False Next For $l = 0 To UBound($aDimSizes) - 1 $aAccepted[$aDimSizes[$l][2]] = True Next $nSelFormatIndex = 0 While Not $aAccepted[$nSelFormatIndex] And $nSelFormatIndex < UBound($aAccepted) $nSelFormatIndex += 1 WEnd ConsoleWrite("SelIndex: "&$nSelFormatIndex&@CRLF) ;~ _ArrayDisplay($aFormats[$nSelFormatIndex]) Local $aTmp = $aFormats[$nSelFormatIndex] GUICtrlSetData($gaArray[5][1], StringSplit($gaArray[5][3],"|",2)[0]&$aTmp[_JSON_Find_Key("width", $aTmp)][1]&" x "&$aTmp[_JSON_Find_Key("height", $aTmp)][1]) GUICtrlSetData($gaArray[6][1], StringSplit($gaArray[6][3],"|",2)[0]&_FormatFileSize($aTmp[_JSON_Find_Key("filesize", $aTmp)][1])) Local $aThumbnails = $jVideoInfo[_JSON_Find_Key("thumbnails", $jVideoInfo)][1] $aTmp = $aThumbnails[0] For $l = 1 To UBound($aThumbnails) If $jVideoInfo[_JSON_Find_Key("thumbnail", $jVideoInfo)][1] == $aTmp[_JSON_Find_Key("url", $aTmp)][1] Then ExitLoop Else $aTmp = $aThumbnails[$l] EndIf Next Local $nWidth = $aTmp[_JSON_Find_Key("width" , $aTmp)][1] Local $nHeight = $aTmp[_JSON_Find_Key("height", $aTmp)][1] Local $nRatio = $nWidth / $nHeight ConsoleWrite($nWidth&" x "&$nHeight&" : "&$nRatio&@CRLF) GUICtrlSetData($gaArray[7][1], StringSplit($gaArray[7][3],"|",2)[0]&$jVideoInfo[_JSON_Find_Key("thumbnail", $jVideoInfo)][1]) ConsoleWrite(180 * $nRatio&" x "&180&@CRLF) GUICtrlSetPos($gaArray[8][1], 16, 157, 180 * $nRatio, 180) GUICtrlSetImage($gaArray[8][1], $fThumb) GUICtrlSetPos($gaArray[8][1], 16, 157, 180 * $nRatio, 180) EndFunc Func _DecodeURL($gURL) Local $sURLID = StringRight(StringRegExpReplace(GUICtrlRead($gURL), "https:\/\/www\.youtube\.com\/watch\?v=([_\-a-zA-Z0-9]{11}).*?(?:\n|$)", "$1"), 11) If StringLen($sURLID) <> 11 Or $sURLID <> StringRegExpReplace($sURLID, "([^_\-0-9a-zA-Z])", "") Then $sURLID = "" EndIf Return($sURLID) EndFunc Func _LockMngr($sSetState = Default, $bFirst = False) If $sSetState <> Default Then Local $aUpdates = StringSplit($sSetState, "|") For $l = 1 To $aUpdates[0] Local $aUpdate = StringSplit($aUpdates[$l], " ") If $aUpdate[0] == 2 Then Switch $aUpdate[1] Case "Selecting" $aLockState[0] = $aUpdate[2] Case "Downloading" $aLockState[1] = $aUpdate[2] Case "Confirming" $aLockState[2] = $aUpdate[2] EndSwitch EndIf Next EndIf For $l = 0 To UBound($gaIndex) - 1 Local $gaTmp = $gaIndex[$l] For $l2 = 0 To UBound($gaTmp) - 1 ;~ If $bFirst Then ;~ Assign("g"&$gaTmp[$l2][0], $gaTmp[$l2][1]) ;~ EndIf Local $aLocalLockState = StringSplit($gaTmp[$l2][2],"|") Local $nResetIndex = -1 Local $sLocalLock = "U" For $l3 = 1 To $aLocalLockState[0] Local $aSingleLocalLockState = StringSplit($aLocalLockState[$l3], " ", 2) Switch $aSingleLocalLockState[0] Case "Selecting" If $aSingleLocalLockState[1] == $aLockState[0] Then $nResetIndex = $l3 $sLocalLock = "S" ExitLoop EndIf Case "Downloading" If $aSingleLocalLockState[1] == $aLockState[1] Then $nResetIndex = $l3 $sLocalLock = "D" ExitLoop EndIf Case "Confirming" If $aSingleLocalLockState[1] == $aLockState[2] Then $nResetIndex = $l3 $sLocalLock = "C" ExitLoop EndIf EndSwitch Next ;~ ConsoleWrite($gaTmp[$l2][0]&@TAB&$sLocalLock&"L"&@CRLF) If $sLocalLock == "U" Then GUICtrlSetState($gaTmp[$l2][1], 64) Else GUICtrlSetState($gaTmp[$l2][1], 128) If $gaTmp[$l2][4] <> Default Then $nResetIndex = StringSplit($gaTmp[$l2][4],",")[$nResetIndex] If $nResetIndex > 0 Then Local $aResetVals = StringSplit($gaTmp[$l2][3],"|") If $gaTmp[$l2][5] == Default Then GUICtrlSetData($gaTmp[$l2][1], $aResetVals[$nResetIndex]) Else Execute(StringReplace(StringReplace($gaTmp[$l2][5],"$HANDLE$","$gaTmp[$l2][1]"),"$INPUT$",$aResetVals[$nResetIndex])) EndIf EndIf EndIf EndIf Next Next ;~ _ArrayDisplay($aLockState) EndFunc