Sign in to follow this  
Followers 0
Syed23

InetGet() Doubt

7 posts in this topic

#1 ·  Posted (edited)

Hi Friends,

I have questions on InetGet() function. can any one help me on that?

1. i wanted to download a video file from youtube by using InetGet() function. is that possible?

2. when i try to download why the download does not continuing after 85.1 kb?

for your reference i have my code below. please have a look.

$LinkBox = "[url="http://www.youtube.com/watch?v=82ifMPijghw&feature=results_main&playnext=1&list=PL1DCD109B801D0DE6"]http://www.youtube.com/watch?v=82ifMPijghw&feature=results_main&playnext=1&list=PL1DCD109B801D0DE6[/url]"
$DownloadPath_Input = @MyDocumentsDir
$Filename = InputBox("Enter Desthination File name","Example: Video1.flv","")
$Download = InetGet(GUICtrlRead($LinkBox),GUICtrlRead($DownloadPath_Input)&"\"&$Filename)
Do
    $nBytes = InetGetInfo($Download)
GUICtrlSetData($FileSizeData,$nBytes)
$obj = ObjGet("winmgmts:\\" & $str & "\root\CIMV2")
$col = $obj.ExecQuery("SELECT BytesReceivedPerSec, BytesSentPerSec, Timestamp_PerfTime," _
   & "Frequency_Perftime, CurrentBandwidth FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", _
  $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
 
If IsObj($col) Then
For $Item In $col
  If $frq = 0 Then ; get first frequency counter then repeat
     $frq = $Item.BytesReceivedPersec
   $ts = $Item.Timestamp_PerfTime
   $bIN = $Item.BytesReceivedPersec
    $nMAX = $Item.CurrentBandwidth
    If $nMAX = 1000000000 Then
                    $nMAX = "1 Gb"
                    $coFAX = 125000
                ElseIf $nMAX = 100000000 Then
                    $nMAX = "100 Mb"
                    $coFAX = 12500
                ElseIf $nMAX = 10000000 Then
                    $nMAX = "10 Mb"
                    $coFAX = 1250
  
                EndIf
EndIf
EndIf
Next
$rateIN = ($bIN - $pbIN) / (($ts - $pts) / $frq); to determine the download speed
$pbIN = $bIN
$pts = $ts
$remaining = $nBytes-FileGetSize($DownloadPath_Input)
Until InetGetInfo($Download, 2)
MsgBox(0,"","Completed")
InetClose($Download)
Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites



ok Here is my completed code. i used MrCreator's Youtube Downloader as a reference and i created this tool for my personal purpose and to improve my knowledge. But struggling lot to complete, Please check this,...

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ClipBoard.au3>
#include <WinAPI.au3>
#include <IE.au3>
#include <Net.au3>
#include <EditConstants.au3>
#include<File.au3>

Global $NdisLinkSpeed, $str = @ComputerName
Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $bIN = 0, $pbIN = 0, $bOUT = 0, $pbOUT = 0, $ts = 0, $pts = 0, $frq = 0, $Download
Global $GUI, $AppName, $Img_Path, $PictureCtrl, $LastDownloadPath, $SelectPath_Button, $Author_Label, $LinkBox, $Button, $clipBut, $DownloadPath_Input, $msg
Global $DownloadingLabel, $FileSizeLabel, $Speed, $Time, $Status, $netstats, $netimg, $Log, $Logpath, $FileSizeData, $SpeedData, $TimeData, $StatusData, $remaining, $Download, $nBytes
$Logpath = @ProgramFilesDir & "\Logs\"
$Log = $Logpath & "\YT_downloader.log"
$LastDownloadPath = @DocumentsCommonDir
$Img_Path = @DesktopDir & "\YT\YouTube_Img.gif"
$netimg = @DesktopDir & "\YT\NetFail.jpg"
$AppName = "Youtube Downloader"
If DriveStatus($Logpath) = "UNKNOWN" Then
 DirCreate($Logpath)
EndIf
_FileWriteLog($Log, "INFO>>" & "Starting Youtube Downloader....")
$netstats = Connection(@ComputerName)
$GUI = GUICreate($AppName, 500, 470, -1, -1, $WS_MINIMIZEBOX + $WS_SYSMENU, $WS_EX_CLIENTEDGE)
$Author_Label = GUICtrlCreateLabel("by K.Syed Ibrahim", 370, 138, 133, 15)
GUICtrlCreateLabel("Please type or paste the link below", 35, 158, 190, 20)
$LinkBox = GUICtrlCreateInput("", 35, 178, 290, 20)
$get = GUICtrlGetHandle($LinkBox)
$Button = GUICtrlCreateButton("Download", 430, 175, 60, 20)
$clipBut = GUICtrlCreateButton("GetLink", 350, 175, 60, 20)
$SelectPath_Button = GUICtrlCreateButton("...", 460, 227, 16, 16)
$DownloadPath_Input = GUICtrlCreateInput($LastDownloadPath, _
  20, 225, 460, 20, $WS_CLIPSIBLINGS + $ES_AUTOHSCROLL, $WS_EX_DLGMODALFRAME)
GUICtrlCreateGroup("", 10, 290, 490, 10)
$FileSizeLabel = GUICtrlCreateLabel("File Size:", 10, 330, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 800)
$FileSizeData = GUICtrlCreateLabel("", 200, 330, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
$Speed = GUICtrlCreateLabel("Download Speed:", 10, 360, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 800)
$SpeedData = GUICtrlCreateLabel("", 200, 360, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
$Time = GUICtrlCreateLabel("Remaining File size :", 10, 390, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 800)
$TimeData = GUICtrlCreateLabel("", 200, 390, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
$Status = GUICtrlCreateLabel("Download Status:", 10, 420, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 9, 800)
$StatusData = GUICtrlCreateLabel("", 200, 420, 180, 15, -1, $GUI_WS_EX_PARENTDRAG)
If $netstats = "Connected" Or $netstats = "Connecting" Then
 $PictureCtrl = GUICtrlCreatePic($Img_Path, 45, 30, 306, 106)
 GUICtrlSetTip(-1, "Visit YouTube Home Page [www.youtube.com]")
 GUICtrlSetCursor(-1, 0)
Else
 $PictureCtrl = GUICtrlCreatePic($netimg, 45, 30, 306, 106)
 GUICtrlSetTip(-1, "")
 GUICtrlSetCursor(-1, 0)
 GUICtrlSetState($Button, $GUI_DISABLE)
 GUICtrlSetState($clipBut, $GUI_DISABLE)
 GUICtrlSetState($SelectPath_Button, $GUI_DISABLE)
 GUICtrlSetState($DownloadPath_Input, $GUI_DISABLE)
 GUICtrlSetState($LinkBox, $GUI_DISABLE)
EndIf
GUISetBkColor(0xFFFFFF)
GUISetState(@SW_SHOW)
While 1
 $msg = GUIGetMsg()
 If $msg = $GUI_EVENT_CLOSE Then
  _FileWriteLog($Log, "INFO>Exit process>" & "Exiting Youtube Downloader....")
  Exit
 EndIf
 If $msg = $PictureCtrl Then
  _FileWriteLog($Log, "INFO>Youtube Image>" & "User Clicked on Youtube image.Launching youtube page")
  _IECreate("[url="http://www.youtube.com"]www.youtube.com[/url]", 0, 1, 0, 0)
 EndIf
 If $msg = $clipBut Then
  _FileWriteLog($Log, "INFO>GetLink>" & "collecting the keyboard info to Inputbox")
  GUICtrlSetData($LinkBox, _ClipBoard_GetData())
 EndIf
 If $msg = $SelectPath_Button Then
  _FileWriteLog($Log, "INFO>Select Destination>" & "Folder browse option launched..")
  $Dest = FileSelectFolder("Select Destination Folder", @DesktopDepth, 5)
  GUICtrlSetData($DownloadPath_Input, $Dest)
 EndIf
 If $msg = $Button Then
  _FileWriteLog($Log, "INFO>Download Process>" & "Calling download function....")
  Download()
 EndIf
 
WEnd
Func Download()
 _FileWriteLog($Log, "INFO>Download function>" & "Starting download function...")
 $Filename = InputBox("Enter Desthination File name", "Example: Video1.flv", "")
 $Download = InetGet(GUICtrlRead($LinkBox), GUICtrlRead($DownloadPath_Input) & "\" & $Filename,1,1)
 Do
  $nBytes = InetGetInfo($Download)
  GUICtrlSetData($FileSizeData, $nBytes)
  $obj = ObjGet("winmgmts:\\" & $str & "\root\CIMV2")
  $col = $obj.ExecQuery("SELECT BytesReceivedPerSec, BytesSentPerSec, Timestamp_PerfTime," _
     & "Frequency_Perftime, CurrentBandwidth FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", _
    $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

  If IsObj($col) Then
   For $Item In $col
    If $frq = 0 Then ; get first frequency counter then repeat
     $frq = $Item.BytesReceivedPersec
     $ts = $Item.Timestamp_PerfTime
     $bIN = $Item.BytesReceivedPersec
     $nMAX = $Item.CurrentBandwidth
     If $nMAX = 1000000000 Then
      $nMAX = "1 Gb"
      $coFAX = 125000
     ElseIf $nMAX = 100000000 Then
      $nMAX = "100 Mb"
      $coFAX = 12500
     ElseIf $nMAX = 10000000 Then
      $nMAX = "10 Mb"
      $coFAX = 1250
     EndIf
    EndIf
   Next
  EndIf
  $rateIN = ($bIN - $pbIN) / (($ts - $pts) / $frq)
  $pbIN = $bIN
  $pts = $ts
  GUICtrlSetData($FileSizeData, InetGetSize(GUICtrlRead($LinkBox)))
  GUICtrlSetData($SpeedData, $rateIN)
  $remaining = $nBytes - FileGetSize($DownloadPath_Input)
  GUICtrlSetData($TimeData, $remaining)
  GUICtrlSetData($StatusData, "Inprogress")
 Until InetGetInfo($Download, 2)
 InetClose($Download)
 If InetGetInfo($Download, 4) Then
  GUICtrlSetData($StatusData, "Download interrupted")
 Else
  GUICtrlSetData($StatusData, "Completed !")
  GUICtrlSetData($SpeedData, $rateIN)
 EndIf
EndFunc   ;==>Download

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

Here is my UDF which will be needed for the above code.


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

Hi All,

I found one more thing. i have tried to download the same video from youtube by using VBScript. which downloaded only 89kb and exits. Don't know what is the reason. Any one have any suggestion for me ?

This is the vbscript which i got from google! Any clue would be much appreciated!


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

Looking at your vb script I can see that the URL you have in the first line doesn't end in a file name, it ends in the code number that points to the file.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yeah... i think when i provide this link and try to download the video file with InetGet() that downloads the html page instead the video file :oops: that shows my poor understanding... :rip: Just thinking what will be the better way i can use to download the files :D


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0