#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Global $metka1 = ';return false;">', $metka2 = '</a> </span>', $plus = 16
Global $metka12 = 'class="title">', $metka22 = '</span><span', $plus2 = 14
$MainForm = GUICreate("Скачивание музыки с контакта", 352, 220, 192, 124)
GUICtrlCreateTab(8, 8, 329, 201)
GUICtrlCreateTabItem("Главная")
$ProgressDownload = GUICtrlCreateProgress(16, 152, 313, 17)
$ID_Login = GUICtrlCreateInput("Логин", 16, 65, 145, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$ID_Pass = GUICtrlCreateInput("Пароль", 176, 65, 153, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
GUICtrlSetState(-1, $GUI_DISABLE)
$Download_label = GUICtrlCreateLabel("Статус: ", 16, 104, 313, 41)
GUICtrlCreateLabel("Введите Логин и Пароль: ", 16, 40, 136, 17)
$Cancel_But = GUICtrlCreateButton("Отмена", 112, 176, 121, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$Login_But = GUICtrlCreateButton("Логин", 226, 37, 100, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
$String = BinaryToString(InetRead("http://vkontakte.ru/audio"))
If StringInStr($String, "Чтобы просматривать эту страницу, нужно зайти на сайт") Then
GUICtrlSetState($Login_But, $GUI_ENABLE)
GUICtrlSetState($ID_Login, $GUI_ENABLE)
GUICtrlSetState($ID_Pass, $GUI_ENABLE)
Do
$nMsg = GUIGetMsg()
Until $nMsg = $Login_But
$login = GUICtrlRead($ID_Login)
$pass = GUICtrlRead($ID_Pass)
InetRead("http://vkontakte.ru/login.php?m=1&email="&$login&"&pass="&$pass)
$String = BinaryToString(InetRead("http://vkontakte.ru/audio"))
EndIf
Find($String, $metka1, $metka2, $plus)
Find($String, $metka12, $metka22, $plus2)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Find($String, $metka1, $metka2, $plus)
Local $pos1 = 1
Local $start = 1
While $pos1 <> 0
$pos1 = StringInStr($String, $metka1, 0, 1, $start)
$pos2 = StringInStr($String, $metka2, 0, 1, $pos1)
$start = $pos1 + 1
$startMid = $pos1 + $plus
$count = $pos2 - $startMid
$name = StringMid($String, $startMid, $count)
ConsoleWrite($pos1 & $pos2)
If $pos1 <> 0 And $pos2 <> 0 Then
$linkpos1 = StringInStr($String, 'http://cs', 0, -1, $start)
$linkpos2 = StringInStr($String, '.mp3', 0, -1, $start)
$linkStartMid = $linkpos1 + 9
$linkCount = $linkpos2 - $linkStartMid
$link = StringMid($String, $linkStartMid, $linkCount)
$hDownload = InetGet("http://cs"&$link&".mp3", @ScriptDir & "\Music\" &$name&".mp3",1,1)
GUICtrlSetData($Download_label, "Статус:"&@CRLF&"Загрузка: " & $name&".mp3")
GUICtrlSetState($Cancel_But, $GUI_ENABLE)
Do
$Data = InetGetInfo($hDownload)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Cancel_But
GUICtrlSetData($ProgressDownload, 0)
Return
EndSwitch
GUICtrlSetData($ProgressDownload, $Data[0]/$Data[1]*100)
Sleep(200)
Until InetGetInfo($hDownload, 2)
InetClose($hDownload)
EndIf
WEnd
EndFunc