LIMITER Posted February 2, 2008 Share Posted February 2, 2008 I have an app which plays and downloads youtube videos... but when it downloads , the program freezes (says that it's not responding) but it saves the video ... how can i stop it from freezing ? expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=LMP\lmp.ico #AutoIt3Wrapper_outfile=youtuber.exe ://////=__=& #AutoIt3Wrapper_Res_Fileversion=1.0.0 #AutoIt3Wrapper_Res_LegalCopyright=© 2008 - L|M|TER #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <IE.au3> ;~ =============================== Main GUI ================================== #Region ### START Koda GUI section ### Form= $gui = GUICreate("L|M|TER YouTube Video Downloader & Viewer - © 2008 L|M|TER", 532, 90, 193, 125) $input = GUICtrlCreateInput("http://www.youtube.com/watch?v=a9dDP3qwy0k", 8, 32, 417, 21) $Label1 = GUICtrlCreateLabel("Enter your YouTube Video link ( ex. http://www.youtube.com/watch?v=a9dDP3qwy0k ) :", 8, 8, 427, 17) $dldbtn = GUICtrlCreateButton("Download !", 448, 8, 75, 25, 0) $viewbtn = GUICtrlCreateButton("View !", 448, 32, 75, 25, 0) $progress = GUICtrlCreateProgress(8, 64, 515, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### TCPStartup() Global $Socket = -1 $SEARCH2 = "timbaland one republic apologize" $SearchString = StringReplace($SEARCH2, " ", "+") $inputtext = GUICtrlRead($input) $SearchSource = $inputtext & ">" $Video_ID = _GetMidleString($SearchSource, 'youtube.com/watch\?v=', '>') $Host = "www.youtube.com" $Page = "/results?search_query=" & $SearchString & "&search=Search" $Get_Value = Get_Value($Host, $Video_ID) _HTTPClose($Socket) $URL = "http://youtube.com/watch_fullscreen?video_id=" & $Video_ID & "&t=" & $Get_Value While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE TCPShutdown() Exit Case $dldbtn TCPStartup() Global $Socket = -1 $SEARCH2 = "timbaland one republic apologize" $SearchString = StringReplace($SEARCH2, " ", "+") $inputtext = GUICtrlRead($input) $SearchSource = $inputtext & ">" $Video_ID = _GetMidleString($SearchSource, 'youtube.com/watch\?v=', '>') $Host = "www.youtube.com" $Page = "/results?search_query=" & $SearchString & "&search=Search" $Get_Value = Get_Value($Host, $Video_ID) _HTTPClose($Socket) $URL = "http://youtube.com/watch_fullscreen?video_id=" & $Video_ID & "&t=" & $Get_Value $location = FileSaveDialog("Select where to save your YouTube! Video",default,"YouTube! Video (*.flv)") If $location = "" Then MsgBox(64, "L|M|TER YouTube! Video Downloader", "Please select where to save the video !") Else If StringRegExp($location, ".flv") = 0 Then $location = $location & ".flv" Call("download") EndIf Case $viewbtn TCPStartup() Global $Socket = -1 $SEARCH2 = "timbaland one republic apologize" $SearchString = StringReplace($SEARCH2, " ", "+") $inputtext = GUICtrlRead($input) $SearchSource = $inputtext & ">" $Video_ID = _GetMidleString($SearchSource, 'youtube.com/watch\?v=', '>') $Host = "www.youtube.com" $Page = "/results?search_query=" & $SearchString & "&search=Search" $Get_Value = Get_Value($Host, $Video_ID) _HTTPClose($Socket) $URL = "http://youtube.com/watch_fullscreen?video_id=" & $Video_ID & "&t=" & $Get_Value Call("video_gui") EndSwitch WEnd ;~ Video GUI Func video_gui() $oIE = ObjCreate("Shell.Explorer.2") $video_gui = GUICreate("L|M|TER YouTube! Video Viewer", 800, 600) $video = GUICtrlCreateObj($oIE, 0, 0, 800, 600) GUISetState() $oIE.Navigate($URL) While 1 $a = GUIGetMsg() Switch $a Case $GUI_EVENT_CLOSE GUIDelete($video_gui) ExitLoop EndSwitch Sleep(10) WEnd EndFunc ;~ Functions Func Get_Value($Host, $Video_ID) $Page = "/v/" & $Video_ID $Resp = _HTTPGetRespones($Host, $Page) Local $Location_URL = StringStripWS(_GetMidleString($Resp, 'Location:', '\n'), 3) Local $URL_Value = _GetMidleString($Location_URL, '&t=', '$') If $URL_Value = '' Then $URL_Value = _GetMidleString($Location_URL, '&t=', '\?') If $URL_Value = '' Then $URL_Value = _GetMidleString($Location_URL, '&t=', '&') If $URL_Value = '' Then $URL_Value = _GetMidleString($Location_URL, '&t=', '=') Return $URL_Value EndFunc Func _HTTPGetSource($Host, $Page) Local $Recv = '', $RcvBytes = 1024 $Socket = _HTTPConnect($Host) _HTTPGet($Host, $Page, $Socket) If @error Then Return SetError(1, 0, '') While 1 $CurrentLine = TCPRecv($Socket, $RcvBytes) If @error <> 0 Then ExitLoop If $CurrentLine <> '' Then $Recv &= $CurrentLine WEnd Return $Recv EndFunc Func _HTTPConnect($Host) Local $Name_To_IP = TCPNameToIP($Host) $Socket = TCPConnect($Name_To_IP, 80) If $Socket = -1 Then TCPCloseSocket($Socket) Return SetError(1, 0, "") EndIf Return $Socket EndFunc Func _HTTPGet($Host, $Page, $Socket) Local $Command = "GET " & $Page & " HTTP/1.1" & @CRLF $Command &= "Host: " & $Host & @CRLF $Command &= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0" & @CRLF $Command &= "Connection: close" & @CRLF & @CRLF Local $BytesSent = TCPSend($Socket, $Command) If $BytesSent = 0 Then Return SetError(1, @error, 0) Return $BytesSent EndFunc Func _HTTPGetRespones($Host, $Page) $Socket = _HTTPConnect($Host) If @error Then Return SetError(1, 0, "") _HTTPHead($Host, $Page, $Socket) Local $Recv = "", $CurrentRecv While 1 $CurrentRecv = TCPRecv($Socket, 16) If @error <> 0 Then ExitLoop If $CurrentRecv <> "" Then $Recv &= $CurrentRecv WEnd If StringInStr($Recv, "HTTP/1.1 410 Gone") Then Return SetError(2, 0, "") Return $Recv EndFunc Func _HTTPHead($Host, $Page, $Socket) Local $Command = "HEAD " & $Page & " HTTP/1.1" & @CRLF $Command &= "Host: " & $Host & @CRLF $Command &= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0" & @CRLF $Command &= "Connection: close" & @CRLF & @CRLF Local $BytesSent = TCPSend($Socket, $Command) If $BytesSent = 0 Then Return SetError(2, @error, 0) Return $BytesSent EndFunc Func _HTTPClose($Socket) TCPCloseSocket($Socket) TCPShutdown() EndFunc Func _GetMidleString($sString, $sStart, $sEnd, $iCase=-1, $iRetType=0) Local $iCaseSence = '' If $iCase = -1 Then $iCaseSence = '(?i)' Local $aArray = StringRegExp($sString, '(?s)' & $iCaseSence & $sStart & '(.*?)' & $sEnd, 3) Local $IsArrayCheck = IsArray($aArray) If $IsArrayCheck And $iRetType = 1 Then Return $aArray If $IsArrayCheck And $iRetType = 2 Then Local $iUbound = UBound($aArray) If Not StringInStr($aArray[$iUbound-1], "Next") Then Return $aArray[$iUbound-1] If ($iUbound - 2) >= 0 Then Return $aArray[$iUbound-2] Return $aArray[$iUbound-1] EndIf If $IsArrayCheck Then Return $aArray[0] Return SetError(1, 0, "") EndFunc Func download() $download_url = "http://www.youtube.com/get_video?video_id=" & $Video_ID & "&t=" & $Get_Value InetGet($download_url,$location) While @InetGetActive $i_BytesRead = @InetGetBytesRead $i_DownSize = InetGetSize($download_url) $percent = Round($i_BytesRead / $i_DownSize * 100) GUICtrlSetData($progress,$percent) WEnd TrayTip("L|M|TER YouTube! Video Downloader","Download Finished !" & @CRLF & "To view the YouTube! Video you should download" & @CRLF & "ACE Mega Codecs Pack (it's FREE !)", 1, 1) EndFunc Link to comment Share on other sites More sharing options...
Kademlia Posted February 2, 2008 Share Posted February 2, 2008 (edited) You have to download in background. The InetGet freezes until the download is ready. Look at Inetget from the helpfile Edit: oh you got that...i think you just missed InetGet($download_url,$location) InetGet($download_url,$location,1,1) <--- the 1,1 CODE ; Advanced example - downloading in the background InetGet("http://www.nowhere.com/somelargefile.exe", "test.exe", 1, 1) While @InetGetActive TrayTip("Downloading", "Bytes = " & @InetGetBytesRead, 10, 16) Sleep(250) Wend MsgBox(0, "Bytes read", @InetGetBytesRead) Edited February 2, 2008 by Kademlia Link to comment Share on other sites More sharing options...
LIMITER Posted February 2, 2008 Author Share Posted February 2, 2008 THX !!! it works now Link to comment Share on other sites More sharing options...
Kademlia Posted February 2, 2008 Share Posted February 2, 2008 http://img208.imageshack.us/img208/9136/errorne0.jpgshould fix that Link to comment Share on other sites More sharing options...
LIMITER Posted February 2, 2008 Author Share Posted February 2, 2008 how can i fix that ? on my pc it works fine ... (strange) Link to comment Share on other sites More sharing options...
Kademlia Posted February 2, 2008 Share Posted February 2, 2008 (edited) i don´t realy know...i got a debugger message one time from my Microsoft Visual Studio 2005 after i ignored the 20x messages it worked fine in the window with everything set right. tried to reproduce but everytime i got this "~20% of video" window maybe IE6 / IE 7 problems (i got 6 installed for CSS/HTML developement and 7 on my notebook) Edited February 2, 2008 by Kademlia Link to comment Share on other sites More sharing options...
LIMITER Posted February 2, 2008 Author Share Posted February 2, 2008 thx anyway !!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now