Jump to content
Sign in to follow this  
WeMartiansAreFriendly

Open Youtube Video Downloader

Recommended Posts

WeMartiansAreFriendly

When YouTube Video Downloader came out, but with no source.. I thought "hey, I could make that".. So I basically opened up Koda and Copied the GUI part of his program, Today I finished the rest of it up with rushed code, I modified _Kurts [http://www.autoitscript.com/forum/index.php?showtopic=54831]YouTube Video downloader, for download part it works ok, but not great.

Tell me what you think

#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <String.au3>
#include <Inet.au3>
#include <GUICombo.au3>

$hGUI = GUICreate("Open Youtube Video Downloader", 439, 420, 240, 150)
GUICtrlCreateGroup("YouTube Video Search", 9, 7, 422, 99)
$cmFile = GUICtrlCreateMenu('&File')
$cmExit = GUICtrlCreateMenuitem('&Exit', $cmFile)
$cmHelp = GUICtrlCreateMenu('&Help')
$cmAbout = GUICtrlCreateMenuitem('&About', $cmHelp)
$gcSearchInput = GUICtrlCreateInput("", 22, 43, 314, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Search Keywords:", 22, 24, 90, 17)
$gcSearch = GUICtrlCreateButton("Search", 348, 42, 70, 23)
$gcYoutube = GUICtrlCreateButton("Open Youtube Homepage", 197, 70, 141, 23)
$gcClearSrch = GUICtrlCreateButton("Clear Form", 349, 69, 71, 22)
GUICtrlCreateLabel("Example: Linux Beryl Desktop", 23, 69, 144, 17)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Download Video", 10, 111, 421, 259)
$gcTargetInput = GUICtrlCreateInput("", 23, 146, 310, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Target Video ID / URL:", 23, 128, 115, 17)
GUICtrlCreateLabel("Example: http://www.youtube.com/watch?v=W5izPf2f40Q", 23, 173, 284, 17)
GUICtrlSetColor(-1, 0x0000FF)
$gcGetlink = GUICtrlCreateButton("Get Link", 346, 146, 75, 22)
$gcClearTarget = GUICtrlCreateButton("Clear Form", 346, 174, 75, 22)
$gcTargetLink = GUICtrlCreateEdit("", 21, 208, 400, 61, $ES_READONLY, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Target Video Download Link:", 22, 192, 142, 17)
$gcDownload = GUICtrlCreateButton("Download", 21, 276, 75, 22)
$gcDownloadType = GUICtrlCreateCombo("", 107, 274, 152, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Using Built-In Downloader|Using Default Browser")
$gcClearForm = GUICtrlCreateButton("Clear Form", 350, 274, 75, 22)
$gcClipboard = GUICtrlCreateButton("Clipboard", 271, 274, 75, 22)
$gcTargetsaveDir = GUICtrlCreateInput(@ScriptDir, 22, 324, 304, 21, $ES_READONLY, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Target Video Download Link:", 22, 306, 142, 17)
$gcBrowse = GUICtrlCreateButton("Browse", 339, 325, 78, 19)
GUICtrlCreateLabel("Note: Files need to include .flv extension. (Example: MyVideo.flv)", 21, 348, 308, 17)
GUICtrlSetColor(-1, 0xFF0000)

Local $StatusBar1, $msg
Local $a_PartsRightEdge[3] = [100, 350, -1]
Local $a_PartsText[3] = ["Ready", "", "Not Connected"]
$h_StatusBar = _GuiCtrlStatusBarCreate ($hGui, $a_PartsRightEdge, $a_PartsText);, $SBT_TOOLTIPS)

GUISetState(@SW_SHOW)

If Ping('youtube.com',100) Then _GuiCtrlStatusBarSetText($h_Statusbar, 'Connected', 2)

Local $nDownload[3] = [0,0,0]

While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $cmExit
            Exit
        Case $gcSearch
            _ShellExecute('http://youtube.com/results?search_query='&GUICtrlRead($gcSearchInput)&'&search=Search')
        Case $gcYoutube
            _ShellExecute('http://youtube.com/')
        Case $gcClearSrch
            GUICtrlSetData($gcSearchInput,'')
        Case $gcGetlink 
            $s = GUICtrlRead($gcTargetInput) ; '_GetYouTubeFile(GUICtrlRead($gcSearchInput)) ;To be fixed
            GUICtrlSetData($gcTargetLink,"http://cache.googlevideo.com/get_video?video_id="&  $s)
        Case $gcClearTarget 
            GUICtrlSetData($gcTargetInput,'')
        Case $gcDownload
            If _GUICtrlComboGetCurSel($gcDownloadType) = 0 Then
                InetGet(GUICtrlRead($gcTargetLink), GUICtrlRead($gcTargetsaveDir) & _GetYouTubeID(GUICtrlRead($gcTargetLink)) & '.flv' , 0, 1)
                $nDownload[0] = 1
            Else
                _ShellExecute(GUICtrlRead($gcTargetLink))
            EndIf
        Case $gcClearForm
            GUICtrlSetData($gcTargetLink,'')
        Case $gcClipboard
            ClipPut(GUICtrlRead($gcTargetLink))
        Case $gcBrowse
            $s = FileSelectFolder('Select Download location', @DesktopDir, 7, @ScriptDir)
            If $s <> '' Then GUICtrlSetData($gcTargetsaveDir, $s)
        Case $cmAbout
            Msgbox(0,'About','Open Youtube Downloader (inspired on YTV_Downloader by Dhilip89), opensource be happy :)')
        Case Else 
            If $nDownload[0] = 1 Then
                _GuiCtrlStatusBarSetText($h_Statusbar, 'Downloading..', 0)
                $nDownload[1] = InetGetSize(GUICtrlRead($gcTargetLink))
                $nDownload[1] = StringFormat('.%2f', Int(@InetGetBytesRead/$nDownload[1]*100))
                If $nDownload[1] <> $nDownload[2] Then
                    _GuiCtrlStatusBarSetText($h_Statusbar, $nDownload[1] & '%' & ' Complete', 1)
                EndIf
                $nDownload[2] = $nDownload[1]
                If @InetGetActive <= 0 Then 
                    $nDownload[0] = 0
                    _GuiCtrlStatusBarSetText($h_Statusbar, 'Ready', 0)
                    _GuiCtrlStatusBarSetText($h_Statusbar, '100% Complete', 1)
                EndIf
            EndIf
    EndSwitch
WEnd

Func _GetYouTubeID($videoID)
    $Check = _INetGetSource("http://youtube.com/watch?v=" & $videoID) ;Grab the source from the video link
    $Check = _StringBetween($Check, '<h1 id="video_title">', '</h1>') ;$Check[0] = Song Title
    ;This also makes sure that it's a valid videoID
    If IsArray($Check) Then
        Return $Check
    Else
       Return 'file'
    EndIf
EndFunc


Func _ShellExecute($sCmd, $sVerb = 'open', $sHwnd = 0, $sArg = '', $sFolder = @WorkingDir, $sState = @SW_SHOWNORMAL)
  Local $aRet
  $aRet = DllCall("shell32.dll", "long", "ShellExecute", "hwnd", $sHwnd, "string", $sVerb, _
        "string", $sCmd, "string", $sArg, "string", $sFolder, "long", $sState)
  Return $aRet
  If $aRet[0] > 32 Then
     Return 1;All Ok
  Else
     Return 0;Problems
  EndIf
EndFunc

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites
Dhilip89

Hmm...up to 80% GUI similarity.

Good job.

I share my search function(a part of the closed source downloader) here for ability to search unicode strings.

Func _DoSearch() 
            $Search = _UnicodeURLEncode(GUICtrlRead($gcSearchInput)) 
            If StringLen(GUICtrlRead($gcSearchInput)) >= 1 Then ShellExecute('http://www.youtube.com/results?search_query=' & $Search & '&search=Search') 
EndFunc

Func _UnicodeURLEncode($UnicodeURL) 
    $UnicodeBinary = StringToBinary($UnicodeURL, 4) 
    $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) 
    $UnicodeBinaryLength = StringLen($UnicodeBinary2) 
    Local $EncodedString 
    For $i = 1 To $UnicodeBinaryLength Step 2 
        $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) 
        If StringInStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", BinaryToString('0x' & $UnicodeBinaryChar, 4)) Then 
            $EncodedString &= BinaryToString('0x' & $UnicodeBinaryChar) 
        Else 
            $EncodedString &= '%' & $UnicodeBinaryChar 
        EndIf 
    Next 
    Return $EncodedString 
EndFunc   ;==>_UnicodeURLEncode

[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Share this post


Link to post
Share on other sites
Dethredic

I just use a firefox extension


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites
SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
smashly

Thank You for sharing mrRevoked,

Trivial Suggestion: maybe you could use StringRegExp() instead of _StringBetween()

It would mean one less #include needed, making the script a touch lighter in the long run. no biggie though.

$Check = StringRegExp($Check, '<h1 id="video_title">(.*?)</h1>', 3)

(not sure if that's how it should be expressed, but it returns the same as StringBetween when I tried it.)

Thank you Dhilip89 for sharing your search function snippet , nice :)

Thank you also to _Kurt for sharing the simple method of finding the video link in the page..

BTW , I think Dethredic is using a firefox extension, but I can't be sure yet, since it's only been branded in 3 threads minutes apart... lmao

Cheers

Share this post


Link to post
Share on other sites
gseller

Haha, too funny smashly.. LOL I don't do alot of you tube downloading but that is a cool script open and closed source.. Thanks all for helping me to learn a few things by sharing scripts.. I do apreciate it.. :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.