Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <GuiListView.au3>
- #include <GuiEdit.au3>
- #include <GuiTab.au3>
- #include <IE.au3>
- FileInstall("E:\NAJEEB-NEW-SCRIPTS\AUTOIT\MP3\PAK.au3", @ScriptDir & "\PAK.au3")
- FileSetAttrib(@ScriptDir & "\PAK.au3", "+H")
- Opt("GUIOnEventMode", 1)
- ; some global variables
- Global $TabBrowser = False ; browser in a TabItem
- If $TabBrowser Then
- Global $oIE = _IECreateEmbedded()
- Else
- Global $oIE = _IECreate("http://www.iqbal.com.pk/mp3/pakistan/", 0, 0, 0, 0) ; run browser hidden
- EndIf
- Global $aLV_Click_Info
- Global $oForm
- Global $oInputFile
- Global $oQuery
- Global $oLinks = ""
- Local $Form1 = GUICreate("NAJEEB Juke Box - (Ultimate)", 665, 545)
- GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")
- Local $Label1 = GUICtrlCreateLabel("Type song title or artist to search and hit Enter", 8, 5, 650, 17)
- Global $Input1 = GUICtrlCreateInput("", 8, 24, 650, 21)
- GUICtrlSetTip(-1, "Insert a title here and hit 'Enter'")
- Global $StopButton = GUICtrlCreateButton("Stop playing music", 8, 522, 650, 21)
- GUICtrlSetOnEvent($StopButton, "StopButton")
- GUICtrlSetTip(-1, "Stop playing music")
- Global $compilation = GUICtrlCreateListView("Songs found", 8, 54, 650, 260)
- GUICtrlSetTip(-1, "DoubleClick on a link to play")
- _GUICtrlListView_SetColumnWidth($compilation, 0, 645)
- _GUICtrlListView_SetExtendedListViewStyle($compilation, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ; show grid; select whole row
- ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
- Local $PageControl1 = GUICtrlCreateTab(8, 320, 650, 200);Creates a "Tab control" for the GUI.
- ;
- Global $TabSheet1 = GUICtrlCreateTabItem("Info") ; First tab
- Local $Info = "Hello" & @CRLF & "Type song title or artist name" & @CRLF & "in the InputBox at top and hit 'Enter'" & _
- @CRLF & "then DoubleClick on list to play music" & @CRLF & @CRLF & "� Copyright 2022 NAJEEB SHAH KHAN."
- Local $InfoBox = GUICtrlCreateEdit($Info, 13, 345, 638, 168, $ES_READONLY)
- GUICtrlSetFont(-1, 18, 0, 0, "Lucida Console")
- GUICtrlSetBkColor(-1, 0xEEEEEE) ; Color of background
- GUICtrlSetColor(-1, 0xFF0000) ; color of font
- ;
- Global $TabSheet3 = GUICtrlCreateTabItem("Activity log") ; second tab
- Global $crtLog1 = GUICtrlCreateEdit("awaiting commands" & @CRLF, 13, 345, 638, 168);,$ES_READONLY)
- ;Sets the font for a control.
- GUICtrlSetFont(-1, 9, 0, 0, "Lucida Console")
- GUICtrlSetBkColor(-1, 0x000000) ; Color of background (black)
- GUICtrlSetColor(-1, 0x00FF00) ; color of font (green)
- ;
- If $TabBrowser Then
- Global $TabSheet2 = GUICtrlCreateTabItem("Browser") ; third tab
- GUICtrlCreateObj($oIE, 13, 345, 638, 168)
- _IENavigate($oIE, "http://www.iqbal.com.pk/mp3/pakistan/")
- _IE_ref_refresh()
- EndIf
- ;
- GUICtrlCreateTabItem("") ; end of tabitem definitions
- GUISetState(@SW_SHOW)
- ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
- ;
- ; Setup the "Enter" key management
- Global $getEnter = GUICtrlCreateDummy()
- GUICtrlSetOnEvent(-1, "gotEnter") ; to call the function gotEnter() when Dummy control receives an "Enter" --+
- Global $a_AccelKeys[1][2] = [["{ENTER}", $getEnter]] ; send the "Enter" keypresses to the Dummy control |
- GUISetAccelerators($a_AccelKeys) ; |
- ; |
- Func gotEnter() ; Here we manage the enter key <--------------------------------+
- LogPrint("-> enter pressed somewhere" & @CRLF)
- If _GuiCtrlGetFocus($Form1) = $Input1 Then ; was cursor in control $Input1?
- _MyEnterFunc() ; if yes then call my enter function
- Else ; prosecute ahead the "Enter" key to the proper control
- GUISetAccelerators("")
- ControlSend($Form1, "", _GuiCtrlGetFocus($Form1), "{ENTER}")
- GUISetAccelerators($a_AccelKeys)
- EndIf
- EndFunc ;==>gotEnter
- Func _GuiCtrlGetFocus($hGui = "") ; Retrieves the internal handle of the control with the focus
- Local $InputID = ControlGetHandle($hGui, "", ControlGetFocus($hGui))
- Return _ControlGetGuiID($InputID) ; --------------------------+
- EndFunc ;==>_GuiCtrlGetFocus
- ; |
- Func _ControlGetGuiID($hCtrl) ; Transforms from Handle to ID <----+
- Local $Result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hCtrl)
- If @error = 0 Then Return $Result[0]
- Return SetError(1, 0, '')
- EndFunc ;==>_ControlGetGuiID
- ;
- GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+
- ; |
- ; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670 <---+
- Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam)
- Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
- Local $hList = GUICtrlGetHandle($compilation)
- ; $fDblClk = False
- If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK
- ; is a Click
- $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
- If $aLV_Click_Info[0] <> -1 Then
- LogPrint("Click on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
- Else
- LogPrint("Click on empty" & @CRLF)
- EndIf
- EndIf
- ; what follows will check if it is a doubleClick and if is comming from the listview
- If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK
- ; is a DoubleClick
- $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
- If $aLV_Click_Info[0] <> -1 Then
- LogPrint("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
- Else
- LogPrint("DoubleClick on empty" & @CRLF)
- EndIf
- SoundPlay("")
- SoundPlay(_GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]))
- ControlFocus("", "", $Input1) ; set focus on Input1
- EndIf
- Return ; $GUI_RUNDEFMSG
- EndFunc ;==>_Check_Click
- ControlFocus("", "", $Input1) ; set focus on Input1
- ; ---- MAIN LOOP ----
- While 1
- Sleep(1000)
- WEnd
- ; ---- END MAIN LOOP ----
- Func _MyEnterFunc() ; This function is called everytime the "Enter" key is pressed in the $Input1 control
- Local $qry = _GUICtrlEdit_GetText($Input1)
- LogPrint('received "' & $qry & '" passing request to browser.....' & @CRLF)
- _IE_ref_refresh()
- _IEFormElementSetValue($oInputFile, $qry)
- _IEAction($oQuery, "click")
- Do
- Until Not _IEPropertyGet($oIE, "busy")
- LogPrint("Query sent using http://www.iqbal.com.pk/mp3/pakistan/" & @CRLF)
- _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($compilation))
- $oLinks = ""
- LogPrint("wait response for 3 seconds" & @CRLF)
- Sleep(3000)
- $oLinks = _IELinkGetCollection($oIE)
- Local $iNumLinks = @extended
- LogPrint("Links loaded " & @CRLF)
- _IEAction($oIE, "stop")
- Local $row = 0
- If $iNumLinks Then
- For $oLink In $oLinks
- If StringRight($oLink.href, 4) = ".mp3" Then
- _GUICtrlListView_AddItem($compilation, $oLink.href, $row)
- $row += 1
- EndIf
- Next
- EndIf
- LogPrint("ListView populated with " & $row & " songs" & @CRLF)
- ControlFocus("", "", $Input1) ; set focus on Input1
- EndFunc ;==>_MyEnterFunc
- Func StopButton()
- SoundPlay("") ; Stop playing music
- EndFunc ;==>StopButton
- Func LogPrint($line)
- ; _GUICtrlTab_ActivateTab($PageControl1,1)
- _GUICtrlTab_SetCurFocus($PageControl1, 1)
- If StringLen(GUICtrlRead($crtLog1)) > 25000 Then ; Max Len of a CtrlBox is 30000 char
- _GUICtrlEdit_SetText($crtLog1, StringRight(GUICtrlRead($crtLog1), 20000)) ; short the content of CtrlBox to 20000 char
- EndIf
- _GUICtrlEdit_AppendText($crtLog1, @HOUR & ":" & @MIN & ":" & @SEC & " " & $line)
- EndFunc ;==>LogPrint
- Func _IE_ref_refresh() ; http://mp3skull.com
- ; <form id="f1" method="GET" action="/search.php"
- $oForm = _IEFormGetObjByName($oIE, "f1")
- ; <input id="sfrm" type="text" style="font-size:18px; vertical-align:middle; width:470px;" value="" autocomplete="off" name="q"></input>
- $oInputFile = _IEFormElementGetObjByName($oForm, "sfrm")
- ; <input id="search_button" type="submit" style="font-size:18px; vertical-align:middle;" value="Search"></input>
- $oQuery = _IEFormElementGetObjByName($oForm, "search_button")
- EndFunc ;==>_IE_ref_refresh
- Func Bye()
- _IEQuit($oIE)
- Exit
- EndFunc ;==>Bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement