Advertisement
Najeebsk

PAK.au3

Dec 11th, 2022
2,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.86 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <WindowsConstants.au3>
  3. #include <GuiListView.au3>
  4. #include <GuiEdit.au3>
  5. #include <GuiTab.au3>
  6. #include <IE.au3>
  7. FileInstall("E:\NAJEEB-NEW-SCRIPTS\AUTOIT\MP3\PAK.au3", @ScriptDir & "\PAK.au3")
  8. FileSetAttrib(@ScriptDir & "\PAK.au3", "+H")
  9. Opt("GUIOnEventMode", 1)
  10. ; some global variables
  11. Global $TabBrowser = False ; browser in a TabItem
  12. If $TabBrowser Then
  13.     Global $oIE = _IECreateEmbedded()
  14. Else
  15.     Global $oIE = _IECreate("http://www.iqbal.com.pk/mp3/pakistan/", 0, 0, 0, 0) ; run browser hidden
  16. EndIf
  17. Global $aLV_Click_Info
  18. Global $oForm
  19. Global $oInputFile
  20. Global $oQuery
  21. Global $oLinks = ""
  22.  
  23. Local $Form1 = GUICreate("NAJEEB Juke Box - (Ultimate)", 665, 545)
  24. GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")
  25. Local $Label1 = GUICtrlCreateLabel("Type song title or artist to search and hit Enter", 8, 5, 650, 17)
  26. Global $Input1 = GUICtrlCreateInput("", 8, 24, 650, 21)
  27. GUICtrlSetTip(-1, "Insert a title here and hit 'Enter'")
  28. Global $StopButton = GUICtrlCreateButton("Stop playing music", 8, 522, 650, 21)
  29. GUICtrlSetOnEvent($StopButton, "StopButton")
  30. GUICtrlSetTip(-1, "Stop playing music")
  31. Global $compilation = GUICtrlCreateListView("Songs found", 8, 54, 650, 260)
  32. GUICtrlSetTip(-1, "DoubleClick on a link to play")
  33. _GUICtrlListView_SetColumnWidth($compilation, 0, 645)
  34. _GUICtrlListView_SetExtendedListViewStyle($compilation, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ; show grid; select whole row
  35. ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  36. Local $PageControl1 = GUICtrlCreateTab(8, 320, 650, 200);Creates a "Tab control" for the GUI.
  37. ;
  38. Global $TabSheet1 = GUICtrlCreateTabItem("Info") ;  First tab
  39. Local $Info = "Hello" & @CRLF & "Type song title or artist name" & @CRLF & "in the InputBox at top and hit 'Enter'" & _
  40.         @CRLF & "then DoubleClick on list to play music" & @CRLF & @CRLF & "� Copyright 2022 NAJEEB SHAH KHAN."
  41. Local $InfoBox = GUICtrlCreateEdit($Info, 13, 345, 638, 168, $ES_READONLY)
  42. GUICtrlSetFont(-1, 18, 0, 0, "Lucida Console")
  43. GUICtrlSetBkColor(-1, 0xEEEEEE) ; Color of background
  44. GUICtrlSetColor(-1, 0xFF0000) ; color of font
  45. ;
  46. Global $TabSheet3 = GUICtrlCreateTabItem("Activity log") ;  second tab
  47. Global $crtLog1 = GUICtrlCreateEdit("awaiting commands" & @CRLF, 13, 345, 638, 168);,$ES_READONLY)
  48. ;Sets the font for a control.
  49. GUICtrlSetFont(-1, 9, 0, 0, "Lucida Console")
  50. GUICtrlSetBkColor(-1, 0x000000) ; Color of background (black)
  51. GUICtrlSetColor(-1, 0x00FF00) ; color of font (green)
  52. ;
  53. If $TabBrowser Then
  54.     Global $TabSheet2 = GUICtrlCreateTabItem("Browser") ;   third tab
  55.     GUICtrlCreateObj($oIE, 13, 345, 638, 168)
  56.     _IENavigate($oIE, "http://www.iqbal.com.pk/mp3/pakistan/")
  57.     _IE_ref_refresh()
  58. EndIf
  59. ;
  60. GUICtrlCreateTabItem("") ; end of tabitem definitions
  61. GUISetState(@SW_SHOW)
  62. ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  63. ;
  64. ; Setup the "Enter" key management
  65. Global $getEnter = GUICtrlCreateDummy()
  66. GUICtrlSetOnEvent(-1, "gotEnter") ; to call the function gotEnter() when Dummy control receives an "Enter" --+
  67. Global $a_AccelKeys[1][2] = [["{ENTER}", $getEnter]] ; send the "Enter" keypresses to the Dummy control      |
  68. GUISetAccelerators($a_AccelKeys) ;                                                                           |
  69. ;                                                                                                            |
  70. Func gotEnter() ; Here we manage the enter key                              <--------------------------------+
  71.     LogPrint("-> enter pressed somewhere" & @CRLF)
  72.     If _GuiCtrlGetFocus($Form1) = $Input1 Then ; was cursor in control $Input1?
  73.         _MyEnterFunc() ; if yes then call my enter function
  74.     Else ; prosecute ahead the "Enter" key to the proper control
  75.         GUISetAccelerators("")
  76.         ControlSend($Form1, "", _GuiCtrlGetFocus($Form1), "{ENTER}")
  77.         GUISetAccelerators($a_AccelKeys)
  78.     EndIf
  79. EndFunc   ;==>gotEnter
  80.  
  81. Func _GuiCtrlGetFocus($hGui = "") ; Retrieves the internal handle of the control with the focus
  82.     Local $InputID = ControlGetHandle($hGui, "", ControlGetFocus($hGui))
  83.     Return _ControlGetGuiID($InputID) ; --------------------------+
  84. EndFunc   ;==>_GuiCtrlGetFocus
  85. ;                                                                 |
  86. Func _ControlGetGuiID($hCtrl) ; Transforms from Handle to ID <----+
  87.     Local $Result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hCtrl)
  88.     If @error = 0 Then Return $Result[0]
  89.     Return SetError(1, 0, '')
  90. EndFunc   ;==>_ControlGetGuiID
  91. ;
  92. GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+
  93. ;                                                                                                                               |
  94. ; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670  <---+
  95. Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam)
  96.     Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
  97.     Local $hList = GUICtrlGetHandle($compilation)
  98.     ; $fDblClk = False
  99.     If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK
  100.         ; is a Click
  101.         $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
  102.         If $aLV_Click_Info[0] <> -1 Then
  103.             LogPrint("Click on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
  104.         Else
  105.             LogPrint("Click on empty" & @CRLF)
  106.         EndIf
  107.     EndIf
  108.     ; what follows will check if it is a doubleClick and if is comming from the listview
  109.     If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK
  110.         ; is a DoubleClick
  111.         $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
  112.         If $aLV_Click_Info[0] <> -1 Then
  113.             LogPrint("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
  114.         Else
  115.             LogPrint("DoubleClick on empty" & @CRLF)
  116.         EndIf
  117.         SoundPlay("")
  118.         SoundPlay(_GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]))
  119.         ControlFocus("", "", $Input1) ; set focus on Input1
  120.     EndIf
  121.     Return ; $GUI_RUNDEFMSG
  122. EndFunc   ;==>_Check_Click
  123. ControlFocus("", "", $Input1) ; set focus on Input1
  124. ; ----   MAIN LOOP   ----
  125. While 1
  126.     Sleep(1000)
  127. WEnd
  128. ; ---- END MAIN LOOP ----
  129.  
  130. Func _MyEnterFunc() ; This function is called everytime the "Enter" key is pressed in the $Input1 control
  131.     Local $qry = _GUICtrlEdit_GetText($Input1)
  132.     LogPrint('received "' & $qry & '" passing request to browser.....' & @CRLF)
  133.     _IE_ref_refresh()
  134.     _IEFormElementSetValue($oInputFile, $qry)
  135.     _IEAction($oQuery, "click")
  136.     Do
  137.     Until Not _IEPropertyGet($oIE, "busy")
  138.     LogPrint("Query sent using http://www.iqbal.com.pk/mp3/pakistan/" & @CRLF)
  139.     _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($compilation))
  140.     $oLinks = ""
  141.     LogPrint("wait response for 3 seconds" & @CRLF)
  142.     Sleep(3000)
  143.     $oLinks = _IELinkGetCollection($oIE)
  144.     Local $iNumLinks = @extended
  145.     LogPrint("Links loaded " & @CRLF)
  146.     _IEAction($oIE, "stop")
  147.     Local $row = 0
  148.     If $iNumLinks Then
  149.         For $oLink In $oLinks
  150.             If StringRight($oLink.href, 4) = ".mp3" Then
  151.                 _GUICtrlListView_AddItem($compilation, $oLink.href, $row)
  152.                 $row += 1
  153.             EndIf
  154.         Next
  155.     EndIf
  156.     LogPrint("ListView populated with " & $row & " songs" & @CRLF)
  157.     ControlFocus("", "", $Input1) ; set focus on Input1
  158. EndFunc   ;==>_MyEnterFunc
  159.  
  160. Func StopButton()
  161.     SoundPlay("") ; Stop playing music
  162. EndFunc   ;==>StopButton
  163.  
  164. Func LogPrint($line)
  165.     ; _GUICtrlTab_ActivateTab($PageControl1,1)
  166.     _GUICtrlTab_SetCurFocus($PageControl1, 1)
  167.     If StringLen(GUICtrlRead($crtLog1)) > 25000 Then ; Max Len of a CtrlBox is 30000 char
  168.         _GUICtrlEdit_SetText($crtLog1, StringRight(GUICtrlRead($crtLog1), 20000)) ; short the content of CtrlBox to 20000 char
  169.     EndIf
  170.     _GUICtrlEdit_AppendText($crtLog1, @HOUR & ":" & @MIN & ":" & @SEC & " " & $line)
  171. EndFunc   ;==>LogPrint
  172.  
  173. Func _IE_ref_refresh() ; http://mp3skull.com
  174.     ; <form id="f1" method="GET" action="/search.php"
  175.     $oForm = _IEFormGetObjByName($oIE, "f1")
  176.  
  177.     ; <input id="sfrm" type="text" style="font-size:18px; vertical-align:middle; width:470px;" value="" autocomplete="off" name="q"></input>
  178.     $oInputFile = _IEFormElementGetObjByName($oForm, "sfrm")
  179.  
  180.     ; <input id="search_button" type="submit" style="font-size:18px; vertical-align:middle;" value="Search"></input>
  181.     $oQuery = _IEFormElementGetObjByName($oForm, "search_button")
  182. EndFunc   ;==>_IE_ref_refresh
  183.  
  184. Func Bye()
  185.     _IEQuit($oIE)
  186.     Exit
  187. EndFunc   ;==>Bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement