AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

YouTube MP4 download
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Thu Aug 21, 2008 10:15 pm    Post subject: YouTube MP4 download Reply with quote

MODIFIED=20091024 LV search (youtube has changed 20091022)

see also script from member fures
http://www.autohotkey.com/forum/topic33555.html

or example
http://www.downloadhelper.net/ ; mozilla firefox addons
http://www.youtube-downloader.com/
http://keepvid.com/


player used http://www.videolan.org/ (vlc.exe)
convert2MP3 http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe

===============================================



-----------------------------
start script and
- copy url-link (CTRL+c or mouse rightclick )

downloads best quality with the correct name to xy.flv or ( xy.mp4 )
(special foreign characters removed)

place where download:
REC =c:\_RECORDED1 ; maybe change path

-----------------------------------------------------------------------------
----- freeware convert downloaded video to MP3
----- downloads youtube xy.flv or xy.MP4
---- automatically select best quality
---- logfile start > usermember / video / download again
-----------------------------------------------------------------------------






----------------------
Code:

MODIFIED= 20091206
;MODIFIED=20091024            ;youtube changed 20091022 and search
;MODIFIED=20090823            ;youtube changed 20090815
;MODIFIED=20090720            ;FMT=35 and radiobox
;MODIFIED=20090119            ;youtube changed autoselect
;MODIFIED=20090107            ;extractaudio 31351 changed
;MODIFIED=20090102            ;added listview logfile
;MODIFIED=20081217            ;added checkbox
;MODIFIED=20081122            ;added radio-box to select fmt=0/18/22
;MODIFIED=20081117            ;FMT=18 FMT=22
;MODIFIED=20081026            ;added freeware converts video to MP3
FILENAME=YOUTUBE_%MODIFIED%


REC        =c:\_RECORDED1
run,%COMSPEC% /C if not exist \%REC%\NUL MD %REC%,,hide


;----    DOWNLOADS YOUTUBE FLV (fmt=35)  or MP4 (fmt=18/22) with right name and convert to MP3  ---------
;----    automatically select best quality ----------------------------------------
; player      http://www.videolan.org/   (vlc.exe)
; convert2MP3 http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe


;.............how to use ................................................
;       start this script and youtube
;       copy video link with rightclick or CTRL+c

;       download starts, downloads ---namexy.flv-- or -- namexy.mp4 --
;       when download finished possibility to convert video to MP3
;       creates a logfile start member/youtube or download again
;........................................................................


#NoEnv
SetBatchlines -1
SendMode Input

setworkingdir, %a_scriptdir%
transform,S,chr,32   ;SPACE
clipboard=

WA=%A_screenwidth%
HA=%A_screenheight%

MP3extract  =%A_programfiles%\DVDVideoSoft\Free Video to Mp3 Converter\FreeVideoToMP3Converter.exe
;ifnotexist,%MP3extract%
;   goto,mp3converter

Settitlematchmode, 2
Gui,2:default
Gui,2: +AlwaysOnTop

Gui,2:Color,black
Gui,2:Font,  S10 CDefault , Lucida Console

   transform,ten,chr,10
   transform,tre,chr,13
   CF=%TRE%%TEN%

YOUTUBEMP4INI=%A_scriptdir%\YOUTUBEMP4a.ini
ifnotexist,%YOUTUBEMP4INI%
   {
   IniWrite,0    , %YOUTUBEMP4INI%  ,Startvideo      , KEY1
   IniWrite,0    , %YOUTUBEMP4INI%  ,Beep            , KEY1
   }



;-------- menu ----------------------------------------------


     ;--------------- SETTINGS ------------------
     ;menu ,S1 ,Add,&Ask for start video after download     ,MH1
     ;menu ,S1 ,Add,&Ask for convert to MP3 after download  ,MH2

     ;-------------- TOOLS ---------------------------
     Menu,S2,add,Converter start                        ,MH11
     Menu,S2,add,Converter download                     ,MH12
     Menu,S2,add,Converter HomePage                     ,MH13

     ;menu, myMenuBar, Add, Settings      ,:S1
     menu, myMenuBar, Add, Tools         ,:S2

gui,2:menu,MyMenuBar
;----------------------------------------------------



AFC=0
TEXTCOLOR=yellow
EDITCOLOR=red


Gui,2:add, text,   x0  y0 h0 w0  vTEXT3 ,%text4%            ;text is hidden , see settimer AAS4
Gui,2:Add,Text,c%textcolor%  x10   y10                     ,URL1
Gui,2:Add,Text,c%textcolor%  x10   y40                     ,URL2
Gui,2:Add,Text,c%textcolor%  x10   y70                     ,FILENAME
Gui,2:Add,Text,c%textcolor%  x10   y100                    ,NAME
Gui,2:Add,Text,c%textcolor%  x10   y130                    ,PROCESS
Gui,2:Add,Text,c%textcolor%  x10   y160                    ,PROGRESS
Gui,2:Add,Text,c%textcolor%  x10   y190                    ,STATUS
Gui,2:Add,Text,c%textcolor%  x10   y230                    ,SEARCH


;------- for test --------------------------------------------------------------
;ALCC=http://www.youtube.com/watch?v=lH8Xcqvs3JM    ;fmt=35 China tango   (flv)
ALCC=http://www.youtube.com/watch?v=siJLeHAnZIk    ;fmt=22 chinese 1080HD Widescreen
;ALCC=http://www.youtube.com/watch?v=DJZv_U0zGGI   ;fmt=18 Ek verlang na jou
;ALCC=http://www.youtube.com/watch?v=3ujBjUriUjI   ;jim reeves
;ALCC=http://www.youtube.com/watch?v=WR59yE0w2P8   ;Solidao
;ALCC=http://www.youtube.com/watch?v=zlfKdbWwruY   ;fmt=22 Matt
;ALCC=http://www.youtube.com/watch?v=Zd8f9Zqap6U   ;US elect
;ALCC=http://www.youtube.com/watch?v=wUPcimeiqLE   ;fmt=22 big buck bunny 720p
;ALCC=http://www.youtube.com/watch?v=kRTZoHTK608   ;Yao Lee
;ALCC=http://www.youtube.com/watch?v=n9l3bX-xWxQ   ;SULLE SALAISUUDEN KERTOA MÄ VOISIN
;ALCC=http://www.youtube.com/watch?v=SH6wgK-A6Q8   ;Molbavello Dhou Goa India
;ALCC=http://www.youtube.com/watch?v=QA7euN0KgWk   ;Lee Hsiang Lan / Li Xiang Lan / Shirley Yamaguchi / Yoshiko Otaka
;ALCC=http://www.youtube.com/watch?v=IHzIItZKmD8   ;Ye Lai Xiang
;ALCC=http://www.youtube.com/watch?v=qicARYcTe6w    ;hd=1 / fmt=22  earth
;ALCC=http://www.youtube.com/watch?v=ep7W89I_V_g
;---------------------------------------------------------------------------------

Gui,2:Add,Edit,c%editcolor%  x100   y10     h20  w400    vEditYoutube ,%ALCC%        ;EDIT YOUTUBE
Gui,2:add,button,    x100   y10   w0   default   gDOWNLOAD1,

Gui,2:Add,Edit,c%editcolor%    x100   y40     h20  w510   vURL2      Readonly    ,
Gui,2:Add,Edit,c%editcolor%    x100   y70     h20  w510   vAL1       Readonly    ,
Gui,2:Add,Edit,c%editcolor%    x100   y100    h20  w510   vNAME1     Readonly    ,
Gui,2:Add,Edit,c%editcolor%    x100   y130    h20  w510   vPROCESS11 Readonly    ,

Gui,2:Add,Progress,            x100   y160    h20  w510   vPRBAR cFF7200

Gui,2:Add,Edit,c%editcolor%    x100   y190    h20  w50    vText22 Readonly    ,   ;procent
Gui,2:Add,Edit,c%editcolor%    x160   y190    h20  w450   vText23 Readonly    ,   ;size  / name

Gui,2:add,text,  c%textcolor%          x395    y270        ,FMT=
Gui,2:Add,Edit,  c%editcolor%          x430    y270    h20  w40   vFMTX Readonly    ,

;--------------------------------------------------------------


;--- for test ---
;AAX1=Grace Chang
;AAAA=Bengawan solo

Gui,2:Add,Edit,c%editcolor%    x100   y230    h20  w280   vSRCH1       ,%AAX1%   ;for test
Gui,2:Add,Button,              x400   y230    h20  w100   gYOUTUBE     ,>YOUTUBE
Gui,2:Add,Button,              x510   y230    h20  w100   gFolder1     ,RECORDED
ifexist,%MP3extract%
  Gui,2:Add,Button,            x510   y260    h20  w100   gEXTRACTMP3  ,EXTRACTMP3
Gui,2:Add,Button,              x510   y290    h20  w100   gReload1     ,Reload

Gui,2:add,text,  c%textcolor%  x10    y300            ,When download finished

Gui,2:Add,edit,cBlack          x10    y660    h24  w200  gSEARCH2   vSRCH2    ,%AAAA%


;------------------------------------------------------------------------------------
  IniRead,VID1,  %YOUTUBEMP4INI%  ,Startvideo       , KEY1
  IniRead,BEEP1, %YOUTUBEMP4INI%  ,Beep             , KEY1

if VID1=0
  Gui,2:Add,CheckBox,c%textcolor%         x200    y300    vVID1 gVID1A  ,Run Video
else
  Gui,2:Add,CheckBox,c%textcolor% checked x200    y300    vVID1 gVID1A  ,Run Video

if BEEP1=0
  Gui,2:Add,CheckBox,c%textcolor%         x330    y300    vBEEP1 gBEEP1A  ,Beep
else
  Gui,2:Add,CheckBox,c%textcolor% checked x330    y300    vBEEP1 gBEEP1A  ,Beep
;------------------------------------------------------------------------------------



F21=%A_scriptdir%\youtubelog.txt
T1 :=100
T2 :=420
T3 :=50
T4 :=0
T5 :=0
T6 :=50
T1A:=T1
T2A:=T1+T2
T3A:=T1+T2+T3
T4A:=T1+T2+T3+T4
T5A:=T1+T2+T3+T4+T5
T6A:=T1+T2+T3+T4+T5+T6

LSW:=T1+T2+T3+T4+T5+T6+20
GSW:=LSW+30
Gui,2:Font, S12 CDefault, Verdana
Gui,2:Add, ListView, x10 y330 grid r14 w%LSW% +hscroll  altsubmit vA1 gA2,Member| < Start > Youtube|DNL|URL2|DATE|FMT
Gui,2:Font, CDefault, FixedSys

LV_ModifyCol(1,T1)
LV_ModifyCol(2,T2)
LV_ModifyCol(3,T3)
LV_ModifyCol(4,T4)
LV_ModifyCol(5,T5)
LV_ModifyCol(6,T6)

gosub,filllist1
Gui,2:add,text,  c%textcolor%          x10    y630     vLINES1   ,Links= %I%

gosub,DDDD
settimer,DDDD,1300

YTB1=YOUTUBE
SIZEVERTICAL:=(690)
Gui,2:Show,            x0   y0     h%SIZEVERTICAL%  w%GSW% ,%YTB1% [100]
return
;-------------------------------------------------------------------






;---  reads text-file ----
SEARCH2:
Gui,2:submit,nohide
LV_Delete()
NR=0
GuiControl,2:Text,Lines1,

loop,read,%F21%
  {
  LR=%A_loopreadline%
  if LR=
     continue
  stringsplit,C,LR,`;,

   CX=%C1%%C2%                     ;search in column A and B
   if SRCH2=
         CX=
   ifinstring,CX,%SRCH2%
       {
       NR++
       LV_Add("",C1,C2,C3,C4,C5,C6)
       }
  }

GuiControl,2:Text,Lines1,%NR%
return
;------  END SEARCH --------------------









EXTRACTMP3:
Gui,2: Show,minimize       ;minimize screen
run,%MP3extract%
ifexist,%rec%
    run,%rec%
return



VID1A:
Gui,2:submit,nohide
if VID1=0
  IniWrite,0, %YOUTUBEMP4INI%  ,Startvideo      , KEY1
else
  IniWrite,1, %YOUTUBEMP4INI%  ,Startvideo      , KEY1
return



BEEP1A:
Gui,2:submit,nohide
if BEEP1=0
  IniWrite,0, %YOUTUBEMP4INI%  ,BEEP  , KEY1
else
  IniWrite,1, %YOUTUBEMP4INI%  ,BEEP  , KEY1
return




MH11:
ifexist,%MP3extract%
    run,%MP3extract%
else
   goto,MP3CONVERTER
return



MH12:
run,http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe
return



MH13:
run,http://www.dvdvideosoft.com
return
;------------------------------------------------------------------------


folder1:
run,%rec%
return

reload1:
reload
return


;-------------------------------------------------------------------
filllist1:
Gui,2:default
Gui,2:ListView,A1
I=0
LV_Delete()
  loop,read,%F21%
   {
   LR=%A_loopreadline%
   if LR=
      continue
   I++
   stringsplit,C,LR,`;
   SplitPath,C2, name9, dir9, ext9, name_no_ext9, drive9
   LV_Add("",C1,name9,C3,C4,C5,C6)
   C1=
   C2=
   C3=
   C4=
   C5=
   C6=
   }
LV_Modify(LV_GetCount(), "Vis")         ;goto last position
return



;------------------ LISTVIEW --------------------------------------
A2:
  Gui,2: Submit, NoHide
  Gui,2:ListView,A1

     RN:=LV_GetNext("C")  ;2  selected checked
     RF:=LV_GetNext("F")  ;2  selected focused
     GC:=LV_GetCount()    ;4  total

   if A_GuiEvent=Normal
     {
     if (RN="" OR RN=0)
         return
     C1=
     C2=
     C3=
     C4=
     C5=
     C6=
    MouseGetPos,x,y
        {
       if x<%T1A%
          {
          LV_GetText(C1,A_EventInfo,1)
          run,http://www.youtube.com/user/%C1%&view=videos
          return
          }

     if x<%T2A%
          {
          LV_GetText(C3,A_EventInfo,3)
          run,%C3%
          return
          }

     if x<%T3A%
          {
          LV_GetText(C3,A_EventInfo,3)
          GuiControl,2:Text,EditYoutube,%C3%
          GuiControl,2:Focus,EditYoutube
          send,{enter}
          return
          }
       }

     }
return

;--------------------------------------------------------------------------------










;=================  SETTIMER =====================================================
DDDD:
Gui,2:submit,nohide

URL11=%clipboard%
stringmid,URL11,URL11,1,60

if URL11 contains watch?v=
  goto,start2

stringmid,URL1aa,URL11,1,25
if URL1aa=http://www.youtube.com/v/
   {
   stringright,STRRR,URL11,11
   URL11=http://www.youtube.com/watch?v=%STRRR%
   goto,start2
   }

return
;---------------------------





START2:
Gui,2:Show,            x0   y0     h%SIZEVERTICAL%  w%GSW% ,
GuiControl,2:Text,EditYoutube,%URL11%
clipboard=
settimer,DDDD,off
gosub,DOWNLOAD1
edityoutube=
URL2=
settimer,DDDD,ON
return
;====================================================================================






YOUTUBE:
Gui,2: Show,minimize
GuiControlGet, SRCH1
   stringreplace,SRCH1,SRCH1,%S%,`%20,all
run,http://www.youtube.com/results?search_query=%SRCH1%&search=Search
return
;====================================================================================






;============================== YOUTUBE ==================================
;------------------------------ GETTITLE and 2nd-URL ----------------------

DOWNLOAD1:
Gui,2:submit,nohide

;'VIDEO_ID': 'DJZv_U0zGGI',
;'VIDEO_TITLE': 'Jim Reeves - Ek Verlang Na Jou',
;'SWF_ARGS': .........................
;"length_seconds": "123",
;"rv.1.author": "draadnagels",
;"plid": "AAR2k1KNnhEYePbl",
;"t": "vjVQa1PpcFNEAdLJHNU1FrARRUcdpr0IWIWE25eufN0%3D",
;'IS_WIDESCREEN': false,
;'IS_HD_AVAILABLE': false,
;'EMBED_URL': 'http://www.youtube.com/v/DJZv_U0zGGI&hl=en&fs=1',
;'VIDEO_USERNAME': 'draadnagels',




Guicontrolget,EditYoutube,2:
if EditYoutube contains youtube.com/watch?v=
   URL1=%EditYoutube%

if URL1=
   return
if URL1 not contains youtube.com/watch?v=
   return

GuiControl,2:Text,process11,
WinSetTitle,%YTB1% [100], ,%YTB1% [0]
GuiControl,2:,PRBAR,%nothing%
GuiControl,2:,Text22,%nothing%
GuiControl,2:,Text23,%nothing%


URL2=
TITLE=
new2=

F1  =%A_scriptdir%\YTB1.txt
ifexist,%F1%
   filedelete,%F1%

GuiControl,2:Text,PROCESS11,Start Download
UrlDownloadToFile,%URL1%,%F1%                        ;<<<<<<<<<<<<<<<<
GuiControl,2:Text,PROCESS11,Search for name

   Fileread,AA,%F1%
   stringreplace,AA,AA,%TEN%,%CF%,all
   filedelete,%F1%
   Fileappend,%AA%`r`n,%F1%


;'IS_HD_AVAILABLE': false,
;------- HQ --------------------------------
HD4=0
SEARCHFOR='IS_HD_AVAILABLE'
   Loop,Read,%F1%
      {
      LR=%A_LoopReadLine%
      if LR contains %SEARCHFOR%
             {
             Loop, Parse,LR ,`',`
                {
                Q%A_Index%  := A_LoopField
                if Q3<>
                  break
                }
             }
      if Q3<>
        break
      }

HD4=%Q3%
stringreplace,HD4,HD4,`:,%nothing%,all
stringreplace,HD4,HD4,`,,%nothing%,all
HD4=%HD4%
;msgbox,262144,MSG,HD4=%HD4%
if HD4=true
   HD4=1
if HD4=false
   HD4=0
;msgbox,262144,MSG,HD4=%HD4%




SEARCHFOR=
USERNAME2=
Q2=
;'VIDEO_USERNAME': 'draadnagels',
SEARCHFOR='VIDEO_USERNAME'
   Loop,Read,%F1%
      {
      LR=%A_LoopReadLine%
      if LR contains %SEARCHFOR%
             {
             Loop, Parse,LR ,`',`
                {
                Q%A_Index%  := A_LoopField
                if Q4<>
                  break
                }
             }
      if Q4<>
        break
      }
USERNAME2=%Q4%
;msgbox,262144,MSG,USERNAME2=%USERNAME2%


;'VIDEO_TITLE': 'Jim Reeves - Ek Verlang Na Jou',
SEARCHFOR=
SEARCHFOR='VIDEO_TITLE'
   Loop,Read,%F1%
      {
      LR=%A_LoopReadLine%
      if LR contains %SEARCHFOR%
             {
             stringmid,LR2,LR,17,200
             title=%LR2%
             stringreplace,TITLE,TITLE,`',%nothing%,all
             stringreplace,TITLE,TITLE,`,,%nothing%,all
              title=%title%
             ;msgbox,262144,MSG,TITLE1=%TITLE%


             stringreplace,TITLE,TITLE,`&amp`;quot`;,%S%,all         ;`"
             stringreplace,TITLE,TITLE,`&amp`;amp`;,%S%and%S%,all    ;`&
             stringreplace,TITLE,TITLE,`',%nothing%,all
             stringreplace,TITLE,TITLE,`;,%nothing%,all

             ; ---- replace at least portuguese letters --
             stringreplace,TITLE,TITLE,&quot,%S%,all
             stringreplace,TITLE,TITLE,quot,%S%,all
             stringreplace,TITLE,TITLE,&amp,%S%,all
             stringreplace,TITLE,TITLE,ç,c,all
             stringreplace,TITLE,TITLE,é,e,all
             stringreplace,TITLE,TITLE,è,e,all
             stringreplace,TITLE,TITLE,ñ,n,all
             stringreplace,TITLE,TITLE,ã,a,all
             stringreplace,TITLE,TITLE,ç,c,all     ;ç
             stringreplace,TITLE,TITLE,ã,a,all     ;ã
             stringreplace,TITLE,TITLE,ö,oe,all    ;ö
             stringreplace,TITLE,TITLE,é,e,all     ;é
             stringreplace,TITLE,TITLE,Ã,a,all      ;à
             break
             }
      }
TITLE=%title%
;msgbox,262144,MSG,TITLE=%TITLE%





t=
video_id=
sk=
hl=
plid=

HSS=
HSS2=


;-------------- NEW ----------------------------------------
;'SWF_ARGS': .........................
;"rv.1.author": "draadnagels",    ;not needed now
;"plid": "AAR2k1KNnhEYePbl",
;"t": "vjVQa1PpcFNEAdLJHNU1FrARRUcdpr0IWIWE25eufN0%3D",
;"video_id": "DJZv_U0zGGI",


CONTEN='SWF_ARGS'
SEARCHFOR="t":,"plid":,"video_id":
   Loop,Read,%F1%
      {
      LR=%A_LoopReadLine%
      ifinstring,LR,%CONTEN%
             {
             Loop, Parse,LR ,`, ,`
                {
                H%A_Index%  := A_LoopField
                if H%A_Index% contains %searchfor%
                   T%A_Index%:=A_LoopField
                if T%A_Index%<>
                   HSS=%HSS%%A_LoopField%&
                if A_loopfield contains "t"
                   t=%A_LoopField%
                if A_loopfield contains "video_id"
                   video_id=%A_LoopField%
                if A_loopfield contains "plid"
                   plid=%A_LoopField%
                H%A_Index%=
                T%A_index%=
                }
             break
            }
       }

nothing=
stringreplace,plid,plid,"plid":%S%,%nothing%,all
stringreplace,video_id,video_id,"video_id":%S%,%nothing%,all
stringreplace,t,t,"t":%S%,%nothing%,all
stringreplace,t,t,`%3D,%nothing%,all
stringreplace,t,t,",%nothing%,all
stringreplace,plid,plid,",%nothing%,all
stringreplace,video_id,video_id,",%nothing%,all

HSS2=video_id=%video_id%&l=%plid%&t=%t%
URL2a=http://www.youtube.com/get_video?%HSS2%
URL2=http://www.youtube.com/get_video?%HSS2%
ADD1=



;/*
;------------ try to search fmt=35 -------------
if HD4<>1
 {
 ;fmtx =22|35|18|6
 fmtx =35|18|6
 loop, parse, fmtx, |
        {
        HQFMT=
        FMTnew=
   HQFMT=&fmt=%A_LoopField%
        FMTnew=%A_LoopField%
   url = http://www.youtube.com/get_video?video_id=%video_id%&l=%plid%&t=%t%=%HQFMT%
        SIZE7:=HttpQueryInfo(URL,5)
        ;msgbox,%size7%
        if (size7="timeout" or size7=0 or size7=-1)
           continue
        else
           break
      }
 }
;*/





;-------------------------------------------
; Low Quality FLV  -
; High Quality FLV - &fmt=35
; MP4              - &fmt=18
; High Quality MP4 - &fmt=22

   if HD4=1
      {
      URL2=%URL2%=&fmt=22
      ADD1=&fmt=22
      FMT1=22
      GuiControl,2:Text,FMTX,22
      }

 else
      {
      if FMTnew=
        {
        FMT1=18
        ADD1=&fmt=18
        URL2=%URL2a%=&fmt=18
        GuiControl,2:Text,FMTX,18
        }
      else
        {
        URL2=%URL2a%=&fmt=%fmtnew%
        ADD1=&fmt=%fmtnew%
        FMT1=%fmtnew%
        GuiControl,2:Text,FMTX,%fmtnew%
        }
      }


;--------------------------------------------


GuiControl,2:Text,URL2,%URL2%
; ---  in name should be removed all special characters
;msgbox,262144,MSG,%URL2%


gosub,removechr

SplitPath,F2, name7, dir7, ext7, name_no_ext7, drive7
;msgbox,262144,MSG,NAME7=%name7%
GuiControl,2:Text,AL1,%REC%\%F2%
GuiControl,2:Text,name1,%name7%


;-----------------------------------------------------------------------------------


;-------------------------- DOWNLOAD YOUTUBE VIDEO ---------------------------------
DOWNLOAD2:
if URL2=
   {
   msgbox,262208,TEST, YOUTUBE URL to download is missing
   WinSetTitle,%YTB1% [0], ,%YTB1% [100]
   settimer,DDDD,1000
   return
   }


;---------------------------------------------------------------------------------------
continue5:
SIZE3=
SIZE3:=HttpQueryInfo(URL2,5)                       ;<<< check size from new URL2 adress
if size3=timeout
    {
      {
      URL2=%URL2a%
      ADD1=
      GuiControl,2:Text,FMTX,NX   ;not exist
      goto,continue5
      }

   ENDED1:
   AFC=0
   settimer,AAS4,OFF
   msgbox, 262208, Youtube download,Download not possible
   GuiControl,2:Text,EditYoutube,
   GuiControl,2:Text,AL1,
   GuiControl,2:Text,name1,
   GuiControl,2:Text,URL2,
   return
   }


AFC=0
settimer,AAS4,500
GuiControl,2:Text,PROCESS11,Download

GuiControl,2:+RANGE0-%SIZE3%,PRBAR                 ;CHANGE processbar
GuiControl,2:,Text23,SIZE=%SIZE3%


URL2b=%URL2%
;  Splashimage,,b w%WA% h50 x0 Y400 CWsilver m9 b fs10 zh0,Size=%size3%`n%URL2%
;----------------------------------------------------------------------------------------
URLDownloadToFile,%URL2%,%REC%\%F2%                ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;----------------------------------------------------------------------------------------
;  sleep,500
;  Splashimage, off


;------- write logfile -------------------------------------------------------------------
stringmid,ANOW7,A_NOW,1,12
 Loop, Parse,URL1 ,`&,`
        {
        H%A_Index%  := A_LoopField
        if H1<>
           URL1NEW=%H1%
        }
;-----------------------------------------------------------------------------------------

settimer,AAS4,off
AFC=0

SIZE3:=HttpQueryInfo(URL2,5)
if size3=-1
   {
   msgbox, 262180, Youtube download,Error size=-1`nTry again ?
   ifmsgbox,no
       return
   else
      {
      GuiControl,2:Text,FMTX,
      goto,download1
      }
   }


Filegetsize,size7,%REC%\%F2%
 if size7<500
   {
   GuiControl,2:Text,PROCESS11,NO SUCCESS try again
   GuiControl,2:,Text22,0 `%
   return
   }

else
   {
   GuiControl,2:Text,EditYoutube,
   GuiControl,2:Text,PROCESS11,Download finished
   GuiControl,2:,Text22,100 `%
   Fileappend,%USERNAME2%;%REC%\%F2%;%URL1NEW%%ADD1%;%URL2b%;%ANOW7%;%FMT1%`r`n,%F21%
   }

GuiControl,2:,PRBAR, %SIZE3%
;GuiControl,2:,Text22,100 `%  %name1%    SIZE=%SIZE3%
GuiControl,2:,Text23,%name7%
WinSetTitle,%YTB1% [%RES2%], ,%YTB1% [100]

  GuiControl,2:Text,AL1,
  GuiControl,2:Text,name1,
  GuiControl,2:Text,URL2,

gosub,filllist1
GuiControl,2:Text,LINES1,Links= %I%

IniRead, VID1 , %YOUTUBEMP4INI% ,Startvideo       , KEY1
IniRead,BEEP1, %YOUTUBEMP4INI%  ,Beep             , KEY1
if BEEP1=1
   SoundBeep,400,150


  ;---------- should Start video  (?) -------------------
  if VID1=0
     return
  else
   {
   ifexist,%REC%\%F2%
       run,%REC%\%F2%            ;run video when download finished
   return
   }

return
;--------------------------------------------------------------------------








;---------- GOSUB remove special characters from video name ----------------------
REMOVECHR:
autotrim,off
new2=

Loop,Parse,TITLE
         {
         A:=(Asc(A_LoopField))
         B:=chr(a)
         if (B="_" OR B=" " OR B="-")     ;allow _space   autotrim,off
         Goto,SKIP8
         if ((a<48 or a>57) AND A<65 OR A>90 AND A<97 OR A>122)
         continue
         SKIP8:
         new2=%new2%%b%
         }

    autotrim,on
    stringmid,ANOW1,A_NOW,1,12    ;if not readable chinese...
    anow1=%anow1%
    new2=%new2%
    if new2=
       {
          if fmtnew=35
            new3=_%ANOW1%.flv
          else
            new3=_%ANOW1%.mp4
       F2=%new3%
       return
       }


  if fmtnew=35
     new3=%new2%.flv
  else
    new3=%new2%.mp4
  F2=%new3%
  ifexist,%REC%\%F2%
      F2=_%ANOW1%_%F2%
return
;===========================================================




;================= GOSUBS ==================================
AAS4:

  Filegetsize,size1,%REC%\%F2%
  if AFC=0
     {
     if size1>500
        {
        AFC=1
        sleep,2000
        Gui,2: Show,minimize       ;minimize screen
        }
     }
  RES1:=Round((100*SIZE1)/SIZE3)
  GuiControl,2:,PRBAR, %SIZE1%
  ;GuiControl,2:,Text22,%RES1% `%      SIZE=%SIZE3%
  GuiControl,2:,Text22,%RES1% `%

     Guicontrolget,text3                                     ;<< 1-99
     WinSetTitle,%YTB1% [%RES2%], ,%YTB1% [%RES1%]
     RES2=%RES1%
     Text4=%Res2%
     GuiControl,2:Text,TEXT3,%text4%

return
;================ END AAS4 =================================







;================= DOWNLOAD http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe ===================
MP3CONVERTER:
{
   text31=
   (
   If you want convert downloaded video to MP3
   needs FreeVideoToMp3Converter.exe

   Download

   from
   http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe
   Want you download this program ?
   )
msgbox, 262180, Start URL,%text31%
ifmsgbox,NO
   exitapp
else
   {
   run,http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe
   exitapp
   }
}
return
;============================================================================





2Guiclose:
Gui,2:submit,nohide
;ifexist,%F1%
;   filedelete,%F1%
exitapp



;esc::exitapp





;-------------------------- FUNCTION GETSIZE before download -------------------------
;http://www.autohotkey.com/forum/topic10510.html
; Olfen PhiLho
;SIZE:=HttpQueryInfo(URL, 5)
;msgbox,262144,MESSAGE,SIZE = %SIZE% Byte



/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QueryInfoFlag:

HTTP_QUERY_RAW_HEADERS = 21
Receives all the headers returned by the server.
Each header is terminated by "\0". An additional "\0" terminates the list of headers.

HTTP_QUERY_CONTENT_LENGTH = 5
Retrieves the size of the resource, in bytes.

HTTP_QUERY_CONTENT_TYPE = 1
Receives the content type of the resource (such as text/html).

Find more at: http://msdn.microsoft.com/library/en-us/wininet/wininet/query_info_flags.asp

Proxy Settings:

INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


; Examples:
; url1 = http://www.autohotkey.com
; url2 = http://www.autohotkey.com/download/AutoHotkeyInstall.exe
; MsgBox % HttpQueryInfo(url1)
; MsgBox % HttpQueryInfo(url2, 5)
; MsgBox % HttpQueryInfo(url2, 1)

USAGE=
Example for size:

#Include dlfilesize.ahk
;------ Jim reeves Mexican Joe ----
url=http://www.youtube.com/watch?v=YSx_kgXQJDg
SIZE:=HttpQueryInfo(URL, 5)
MsgBox,64,Info,Dateigröße = %SIZE% Byte

*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

If (Proxy != "")
AccessType=3
Else
AccessType=1

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags
If (ErrorLevel != 0 or io_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

iou_hInternet := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or iou_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

VarSetCapacity(buffer, 1024, 0)
VarSetCapacity(buffer_len, 4, 0)

Loop, 5
{
  hqi := DllCall("wininet\HttpQueryInfoA"
  , "uint", iou_hInternet
  , "uint", QueryInfoFlag ;dwInfoLevel
  , "uint", &buffer
  , "uint", &buffer_len
  , "uint", 0) ;lpdwIndex
  If (hqi = 1) {
    hqi=success
    break
  }
}

IfNotEqual, hqi, success, SetEnv, res, timeout

If (hqi = "success") {
p := &buffer
Loop
{
  l := DllCall("lstrlen", "UInt", p)
  VarSetCapacity(tmp_var, l+1, 0)
  DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
  p += l + 1
  res := res  . "`n" . tmp_var
  If (*p = 0)
  Break
}
StringTrimLeft, res, res, 1
}

DllCall("wininet\InternetCloseHandle",  "uint", iou_hInternet)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)

return, res
}
;------------------------------------------------------------------
;============================ END =================================







;=========================== remarks ==============================
/*
; http://www.youtube.com/v/WR59yE0w2P8
; http://www.splicd.com/   (?)
; hd=1

; Low Quality FLV  - http://www.youtube.com/watch?v=Z840KrgBrPc&
; High Quality FLV - http://www.youtube.com/watch?v=Z840KrgBrPc&fmt=35   (?)
; MP4              - http://www.youtube.com/watch?v=Z840KrgBrPc&fmt=18
; High Quality MP4 - http://www.youtube.com/watch?v=Z840KrgBrPc&fmt=22
; start at         - http://www.youtube.com/watch?v=Z840KrgBrPc&fmt=22#t=1m02s

Standard (fmt=0 ?) > MP3, ~64 kbps, 22.05 KHz, mono (1 channel)
fmt=5 > MP3, ~64 kbps, 22.05 KHz, mono (1 channel) (little difference in video bitrate)
fmt=6 > MP3, ~66 kbps, 44.1 KHz, mono (1 channel)
fmt=18 > AAC, ~126 kbps, 44.1 KHz, stereo (2 channels)
fmt=22 > AAC, ~248 kbps, 44.1 KHz, stereo (2 channels) (only if uploaded video have 720p)
fmt=34 > AAC, ~68 kbps, 22.05 KHz, stereo (2 channels)
fmt=35 > AAC, ~112 kbps, 44.1 KHz, stereo (2 channels)
fmt=13 and
fmt=17 > only on mobile devices (3GP with AMR or AAC audio)


fmt=0  -> flv:  320x240 (flv1) / mp3 1.0 22KHz (same as fmt=5)
fmt=5  -> flv:  320x240 (flv1) / mp3 1.0 22KHz
fmt=6  -> flv:  480x360 (flv1) / mp3 1.0 44KHz (no more ...)
fmt=13 -> 3gp:  176x144 (mpg4) / ??? 2.0  8KHz
fmt=17 -> 3gp:  176x144 (mpg4) / ??? 1.0 22KHz
fmt=18 -> mp4:  480x360 (H264) / AAC 2.0 44KHz
fmt=22 -> mp4: 1280x720 (H264) / AAC 2.0 44KHz
fmt=34 -> flv:  320x240 (flv?) / ??? 2.0 44KHz (default)
fmt=35 -> flv:  640x380 (flv?) / ??? 2.0 44KHz
*/



/*
.............how to use ................................................
       start this script and youtube
       copy video link with rightclick or CTRL+c

       download starts, downloads ---namexy.flv-- or -- namexy.mp4 --
       when download finished possibility to convert video to MP3
       creates a logfile start member/youtube or download again
........................................................................


http://www.autohotkey.net/~garry/20081122_YOUTUBE_MP4.png


size example=
-----------------------------------------------
http://www.youtube.com/watch?v=qicARYcTe6w&hd=1

-720p HD Test 2: Big Buck Bunny
http://www.youtube.com/watch?v=wUPcimeiqLE&fmt=22   166-MB  mp4
http://www.youtube.com/watch?v=wUPcimeiqLE&fmt=18    42-MB  mp4
http://www.youtube.com/watch?v=wUPcimeiqLE           24-MB  flv
------------------------------------------------
var isHDAvailable = true;


........................ http://www.dvdvideosoft.com/guides/dvd/extract-audio-from-video-to-mp3.htm
........................ http://www.dvdvideosoft.com/free-dvd-video-software.htm


.............. Free Video to MP3 Converter ...........................................................
http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe
http://www.dvdvideosoft.com/products/dvd/Free-Video-to-MP3-Converter.htm
Use Free Video to MP3 Converter to extract audio from video files
(*.avi, *mpg, *.mpg, *.mp4, *.m4v, *.mpeg, *.dvr-ms, *.wmv, *.asf, *.mov, *.qt, *.3gp, *.3g2 and *.flv)
 and save it as MP3

There are 3 pre-configured presets:
- High Quality (MP3, 256kbps, 48000Hz, STEREO);
- Standard Quality (MP3, 128kbps, 44100Hz, STEREO);
- Economy Quality (MP3, 96kbps, 22050Hz, STEREO).

and TRIM video
........................................................................................................
*/



Last edited by garry on Sun Dec 13, 2009 8:30 am; edited 23 times in total
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5042
Location: /b/

PostPosted: Fri Oct 24, 2008 6:26 pm    Post subject: Reply with quote

Why don't you make a version that checks with keepvid.com, that way you won't have to worry about youtube updating their codes.
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Fri Oct 24, 2008 6:50 pm    Post subject: Reply with quote

thank you Titan, at the moment works, save automatically with the right name and best quality (namexy.mp4 when exist, otherwise namexy.flv)
how would you do that ?
Back to top
View user's profile Send private message
Q



Joined: 24 Oct 2007
Posts: 24

PostPosted: Fri Oct 24, 2008 8:51 pm    Post subject: Reply with quote

Cool, good work Smile

Just wondering, would it be possible to have a version that would work on other flash 10 sites other than youtube for example to stream down videos from

http://archiv.nova.cz/multimedia/ordinace-ii-60-dil-hon-na-veverku.html
Back to top
View user's profile Send private message
Jex



Joined: 02 Aug 2008
Posts: 101

PostPosted: Sat Oct 25, 2008 2:37 pm    Post subject: Reply with quote

this is very interesting. could a auto convert be added to this? You would probably have to go to 3rd party freeware. But it would save so much time.
_________________
Woot.

Please read forum etiquette
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Oct 25, 2008 2:41 pm    Post subject: Reply with quote

all greasemonkeys scripts related to youtube generates links for download.
i think your script could improve with converters and other utilities.
Back to top
..:: Free Radical ::..



Joined: 20 Sep 2006
Posts: 47

PostPosted: Sat Oct 25, 2008 4:45 pm    Post subject: Command line function Reply with quote

Superb script garry.

Would appreciate more scripts like this or preferably functions for other video sites / share sites.


Last edited by ..:: Free Radical ::.. on Tue Dec 30, 2008 12:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Sun Oct 26, 2008 8:48 pm    Post subject: Reply with quote

thank you ..::Free Radical::.. , Ill try it
Jex,
added a second script above when download finished can convert video to MP3


here freeware to convert
I converted xy.flv to MP4 to my mobilphone

Quote:
........................ http://www.dvdvideosoft.com/guides/dvd/extract-audio-from-video-to-mp3.htm
........................ http://www.dvdvideosoft.com/free-dvd-video-software.htm


.............. Free Video to MP3 Converter ...........................................................
http://www.dvdvideosoft.com/download/FreeVideoToMp3Converter.exe
http://www.dvdvideosoft.com/products/dvd/Free-Video-to-MP3-Converter.htm
Use Free Video to MP3 Converter to extract audio from video files
(*.avi, *mpg, *.mpg, *.mp4, *.m4v, *.mpeg, *.dvr-ms, *.wmv, *.asf, *.mov, *.qt, *.3gp, *.3g2 and *.flv)
and save it as MP3

There are 3 pre-configured presets:
- High Quality (MP3, 256kbps, 48000Hz, STEREO);
- Standard Quality (MP3, 128kbps, 44100Hz, STEREO);
- Economy Quality (MP3, 96kbps, 22050Hz, STEREO).

and TRIM video
........................................................................................................
Back to top
View user's profile Send private message
..:: Free Radical ::..



Joined: 20 Sep 2006
Posts: 47

PostPosted: Sat Nov 15, 2008 8:42 am    Post subject: Reply with quote

Apparently, there is an fmt=22 switch for 720p vids in youtube too Very Happy
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Sat Nov 15, 2008 6:52 pm    Post subject: Reply with quote

thank you ..:: Free Radical ::..
can you give an example (URL)
at the moment searches for "watch in high quality" to get xy.mp4 ( instead of xy.flv )
Back to top
View user's profile Send private message
..:: Free Radical ::..



Joined: 20 Sep 2006
Posts: 47

PostPosted: Mon Nov 17, 2008 2:47 am    Post subject: Reply with quote

http://www.youtube.com/watch?v=zlfKdbWwruY&fmt=22

Credits:
Mocib (admin @inCrysis.com)
[M]av3r!cK @erodov.com
and Matt in the video.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Mon Nov 17, 2008 7:51 pm    Post subject: Reply with quote

thank you ..:: Free Radical ::..
modified script
;---- DOWNLOADS YOUTUBE FLV or MP4 with right name (2nd with MP3converter ) -----
;---- automatically select best quality or define fmt=0/18/22 ------------------

examples ( size )
Code:

http://www.youtube.com/watch?v=zlfKdbWwruY
FMT=22     75320 kB mp4  ( high quality )
FMT=18     20784 kB mp4  ( high quality )
FMT=       11295 kB flv
Back to top
View user's profile Send private message
menaphus



Joined: 29 Nov 2008
Posts: 99
Location: United Kingdom

PostPosted: Sat Nov 29, 2008 12:57 am    Post subject: . Reply with quote

Is this actualy copying the file to your hard disk or playing it through the app?
sorry kinda busy dont have time to look over the script properly
_________________
Adam
contact at: adamf93@gmail.com
Back to top
View user's profile Send private message Send e-mail
garry



Joined: 19 Apr 2005
Posts: 1554
Location: switzerland

PostPosted: Sat Nov 29, 2008 9:11 am    Post subject: Reply with quote

hello menaphus,
it downloads to Harddisk
start script and copy url-link (CTRL+c or mouse rightclick )

place where download:
REC =c:\_RECORDED1 ; maybe change path

;---- DOWNLOADS YOUTUBE FLV or MP4 with correct name (2nd script with MP3converter ) -----
;---- automatically select best quality or define fmt=0/18/22 ------------------


-----------------------------------------------------------------
hello Q,
sorry for the late answer
Quote:
Just wondering, would it be possible to have a version that would work on other flash 10 sites other than youtube for example to stream down videos from

http://archiv.nova.cz/multimedia/ordinace-ii-60-dil-hon-na-veverku.html

ĉesko -
I'll have to login, didn't tried
maybe are the videos downloaded in FireFox cache
http://www.autohotkey.com/forum/topic25694.html&highlight=firefox
Back to top
View user's profile Send private message
menaphus



Joined: 29 Nov 2008
Posts: 99
Location: United Kingdom

PostPosted: Sat Nov 29, 2008 4:27 pm    Post subject: Reply with quote

garry wrote:
hello menaphus,
it downloads to Harddisk
start script and copy url-link (CTRL+c or mouse rightclick )

place where download:
REC =c:\_RECORDED1 ; maybe change path

;---- DOWNLOADS YOUTUBE FLV or MP4 with correct name (2nd script with MP3converter ) -----
;---- automatically select best quality or define fmt=0/18/22 ------------------


-----------------------------------------------------------------
hello Q,
sorry for the late answer
Quote:
Just wondering, would it be possible to have a version that would work on other flash 10 sites other than youtube for example to stream down videos from

http://archiv.nova.cz/multimedia/ordinace-ii-60-dil-hon-na-veverku.html

ĉesko -
I'll have to login, didn't tried
maybe are the videos downloaded in FireFox cache
http://www.autohotkey.com/forum/topic25694.html&highlight=firefox


Ok ty i think i shall get it Very Happy Wink
_________________
Adam
contact at: adamf93@gmail.com
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group