Manchmal ändert der sich, sodass es beim 10. Ergebnis zu Scriptfehlern kommt...
Code:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$Form2 = GUICreate("YT Searcher 0.9", 602, 257, 199, 126)
$hListBox = GUICtrlCreateList("", 176, 0, 425, 253, BitOR($WS_BORDER, $WS_VSCROLL,$WS_HSCROLL))
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$Combo1 = GUICtrlCreateCombo("", 8, 8, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Input1 = GUICtrlCreateInput("", 8, 48, 161, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Save last Search", 8, 80, 161, 17)
$Button1 = GUICtrlCreateButton("Search", 8, 144, 65, 25)
$Button2 = GUICtrlCreateButton("Next Page", 8, 184, 70, 25)
$Button3 = GUICtrlCreateButton("Prev Page", 91, 184, 70, 25)
$Button4 = GUICtrlCreateButton("First Page", 8, 224, 65, 25)
$Button5 = GUICtrlCreateButton("Last page", 96, 224, 65, 25)
$Checkbox2 = GUICtrlCreateCheckbox("Save all Searches", 8, 112, 161, 17)
GUISetState(@SW_SHOW)
Global $pr = 0
Global $link[10]
GUICtrlSetState($Button2,$GUI_DISABLE)
GUICtrlSetState($Button3,$GUI_DISABLE)
GUICtrlSetState($Button4,$GUI_DISABLE)
GUICtrlSetState($Button5,$GUI_DISABLE)
GUICtrlSetState($Combo1,$GUI_DISABLE)
GUICtrlSetState($Checkbox2,$GUI_DISABLE)
While 1
Sleep(10)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($hListBox,"")
$r = GUICtrlRead($Input1)
If NOT $r = "" Then
$search = _search($pr,$r)
For $i = 0 To 8
$link[$i] = $search[$i]
If $i = 8 Then
$link[9] = $search[$i+2]
EndIf
Next
$pr -= 1
GUICtrlSetState($Button2,$GUI_ENABLE)
GUICtrlSetState($Button5,$GUI_ENABLE)
GUICtrlSetState($Button3,$GUI_DISABLE)
GUICtrlSetState($Button4,$GUI_DISABLE)
Else
MsgBox(0,"","No Keywords set")
EndIf
Case $Button2
GUICtrlSetData($hListBox,"")
If $pr = 0 Then
$pr += 2
Else
$pr += 1
EndIf
$searchn = _search($pr,$search[9])
For $i = 0 To 8
$link[$i] = $searchn[$i]
If $i = 8 Then
$link[9] = $search[10]
EndIf
Next
GUICtrlSetState($Button3,$GUI_ENABLE)
GUICtrlSetState($Button4,$GUI_ENABLE)
GUICtrlSetState($Button2,$GUI_DISABLE)
If $pr = 99 Then
GUICtrlSetState($Button5,$GUI_DISABLE)
Else
GUICtrlSetState($Button5,$GUI_ENABLE)
EndIf
Case $Button3
GUICtrlSetData($hListBox,"")
If $pr = 2 Then
$pr -= 1
$searchf = _search($pr,$search[9])
For $i = 0 To 8
$link[$i] = $searchf[$i]
If $i = 8 Then
$link[9] = $search[10]
EndIf
Next
GUICtrlSetState($Button3,$GUI_DISABLE)
GUICtrlSetState($Button4,$GUI_DISABLE)
GUICtrlSetState($Button2,$GUI_ENABLE)
GUICtrlSetState($Button5,$GUI_ENABLE)
Else
$pr -= 1
$searchf = _search($pr,$search[9])
For $i = 0 To 8
$link[$i] = $searchf[$i]
If $i = 8 Then
$link[9] = $search[10]
EndIf
Next
GUICtrlSetState($Button2,$GUI_ENABLE)
GUICtrlSetState($Button3,$GUI_ENABLE)
GUICtrlSetState($Button4,$GUI_ENABLE)
GUICtrlSetState($Button5,$GUI_ENABLE)
EndIf
Case $Button4
GUICtrlSetData($hListBox,"")
$pr = 1
$searchl = _search($pr,$search[9])
For $i = 0 To 8
$link[$i] = $searchl[$i]
If $i = 8 Then
$link[9] = $search[10]
EndIf
Next
GUICtrlSetState($Button3,$GUI_DISABLE)
GUICtrlSetState($Button4,$GUI_DISABLE)
GUICtrlSetState($Button2,$GUI_ENABLE)
GUICtrlSetState($Button5,$GUI_ENABLE)
Case $Button5
GUICtrlSetData($hListBox,"")
$pr = 99
$searchl = _search($pr,$search[9])
For $i = 0 To 8
$link[$i] = $searchl[$i]
If $i = 8 Then
$link[9] = $search[10]
EndIf
Next
GUICtrlSetState($Button5,$GUI_DISABLE)
GUICtrlSetState($Button3,$GUI_ENABLE)
GUICtrlSetState($Button2,$GUI_DISABLE)
GUICtrlSetState($Button4,$GUI_ENABLE)
EndSwitch
WEnd
Func _search($page,$key)
$split = StringReplace($key," ","+")
$read = InetRead("http://m.youtube.com/results?gl=DE&client=mv-google&hl=de&search=by_search&uploaded=&q="&$split&"&p="&$page)
$get = BinaryToString($read)
$string = StringRegExp($get,'<a accesskey="(.+)" href="/watch[?]gl=DE&client=mv-google&hl=de&(.+)">(.+)</a>',3)
$string2 = StringRegExp($get,'<a href="/watch[?]gl=DE&client=mv-google&hl=de&(.+)">(.+)</a>',3)
MsgBox(0,"",$string2)
Local $array[11]
Local $tstring[9]
For $i = 2 to UBound($string) Step 3
$tstring[($i-2)/3] = $string[$i]
Next
For $i = 1 To UBound($string)-1 Step 3
If $i <> 1 Then
$zop = ($i - 1) / 3
Else
$zop = $i - 1
EndIf
$array[$zop] = $string[$i]
Next
$array[10] = $string2[0]
For $i = 0 To 8
GUICtrlSetData($hListBox,$tstring[$i])
Next
GUICtrlSetData($hListBox,$string2[1])
$array[9] = $split
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
IniWrite("Search.ini","Last - Page","Page",$page)
For $i = 0 To 8
IniWrite("Search.ini","Last - Link",$i,$array[$i])
IniWrite("Search.ini","Last - Vid",$i,$tstring[$i])
If $i = 8 Then
IniWrite("Search.ini","Last - Link",$i+1,$array[10])
IniWrite("Search.ini","Last - Vid",$i+1,$string2[1])
EndIf
Next
IniWrite("Search.ini","Last - Keyword","Keyword",$array[9])
;ElseIf GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
; For $i = 0 To 8
; IniWrite("Search.ini","All - Link",$i,$array[$i])
; IniWrite("Search.ini","All - Vid",$i,$tstring[$i])
; Next
; IniWrite("Search.ini","All - Keywords",$array[9],$array[9])
EndIf
;GUICtrlSetData($List1,$string2[3])
;_ArrayDisplay($string)
;_ArrayDisplay($array)
Return $array
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWndFrom
Case $hListBox, $hWndListBox
Switch $iCode
Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
$getzb = _GUICtrlListBox_GetCurSel($hListBox)
ShellExecute("http://www.youtube.com/watch?"&$link[$getzb])
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc






