Jump to content

Recommended Posts

Posted

I have found that when setting a GUICtrlPic to blank with "" and then setting it back to the original image with a new File name it will mess with the size of the image ignoring GUICtrlSetPos both before and after setting the file to use. The pertinent lines are lines 182-186 towards the end of _SetStats(). (This tool should download a youtube thumbnail and display it. Further functionality is to be implemented). I plan to simply find a work around the issue, but felt I'd post here for others and am always open to solutions.

Replicating Yourself:

I have attached the needed custom include files and the main file.

!IMPORTANT! If you download this it is likely that the script will attempt to download dependencies to the script directory; youtube-dl, ffmpeg, and ImageMagick if they are not already on your path. ImageMagick in can be particularly messy when it does this, as it will leave you with some 30~ loose files so I'd recommend doing this in a dedicated folder.

1. Run Main.au3

2. Press Select with the default URL input

3. It will operate normally and the thumbnail will load within 30 seconds then press cancel.

4. Press select again. The thumbnail will be re downloaded to a new file with a new name but will be incorrectly sized. The amount can vary between videos.

5. Since the incorrect sized image blocks clicks you will have to exit the window and relaunch Main.au3

6. Repeat steps 2-3 but then place a new URL in instead of the original and press select. This will load correctly.

If you load the same URL twice in a row it will break, but inserting another URL in between loads will fix the issue.

 

#include <GUIConstantsEx.au3>
#include <Array.au3>

#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=f2EjgUeUHIg")

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

WindowDef.au3 ExtMngr.au3 JSON_Helpers.au3 YTDL_Get.au3 IniMngr.au3 DepMngr.au3 TimeFormat.au3 SizeFormat.au3 JSON_Translate.au3 JSON.au3 Main.au3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...