YouTube Downloader

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

YouTube Downloader

Post by Droopy »

Download Youtube video is easy with this :

YoutubeDownloader:-->YouTube.zip
Image

Code: Select all

;/ PureBasic 4.10b2
; Version 2.0

; Added : ProgressBar + Cancel Download + Size Downloaded / File Size / rate
; Added : Cancel Button / Resize / Translation in English

#Title="YouTube Download at "
Global VideoTitle.s,Path.s
Global DownloadURL.s, DownloadFilename.s, StopDownload, IsDownloading 

;{/ dataSection
DataSection
Back:IncludeBinary "back.ico"
Forward:IncludeBinary "forward.ico"
Home:IncludeBinary "home.ico"
Save:IncludeBinary "Download.ico"
Stop:IncludeBinary "Cancel.ico"
Chemin:IncludeBinary "Path.ico"
EndDataSection
;}

Enumeration
  #Web
  #ToolBar
  #Home
  #Back
  #Forward
  #Path
  #Download
  #Cancel
  #StatusBar
  #Progress
EndEnumeration

Procedure.s FileNameConformation(File.s) ; Renvoie un nom de fichier sans les caractères interdits
  
  For n=1 To Len(File)
    c.s=Mid(File,n,1)
    If FindString(c,"\",1)
      Out.s+" "
    ElseIf FindString(c,"/",1)
      Out.s+" "
    ElseIf FindString(c,":",1)
      Out.s+" "
    ElseIf FindString(c,"?",1)
      Out.s+" "
    ElseIf FindString(c,"*",1)
      Out.s+" "
    ElseIf FindString(c,"<",1)
      Out.s+" "
    ElseIf FindString(c,">",1)
      Out.s+" "
    ElseIf FindString(c,"|",1)
      Out.s+" "
    ElseIf FindString(c,Chr(34),1)
      Out.s+" "
    Else
      Out.s+c
    EndIf
  Next
  
  ProcedureReturn Out
EndProcedure

Procedure SaveYoutubeVideo(VideoId.s)
  
  ;/ ( Downloader With progress And Status By Joakim L. Christiansen )
  
  DisableToolBarButton(#ToolBar,#Cancel,#False)
  IsDownloading+#True
  
  DownloadURL.s = "http://cache.googlevideo.com/get_video?video_id="+VideoId
  DownloadFilename.s= Path+VideoTitle+".flv"
  
  Protected hInet, hURL, Bytes 
  Protected BufferLength = 2048, Buffer.s = Space(BufferLength) 
  
  Protected Url.s      = DownloadURL.s 
  Protected Filename.s = DownloadFilename.s 
  Protected File 
  Protected CurrentSize, PreviousSize, FileSize, time, BytesPerSecond 
  Protected Domain.s, String.s, i, BufferLengthWas = BufferLength 
  Protected hInetCon, hHttpOpenRequest, iretval 
  
  hInet = InternetOpen_("Downloader",0,0,0,0) 
  hURL  = InternetOpenUrl_(hInet,Url.s,0,0,$80000000,0) 
  
  ;Get filesize 
  Domain.s  = StringField(Url.s,3,"/") 
  hInetCon = InternetConnect_(hInet,Domain.s,80,#Null,#Null,3,0,0) 
  If hInetCon 
    hHttpOpenRequest = HttpOpenRequest_(hInetCon,"HEAD",ReplaceString(Url.s,"http://"+Domain.s+"/",""),#Null,#Null,0,$80000000,0) 
    If hHttpOpenRequest 
      iretval = HttpSendRequest_(hHttpOpenRequest,#Null,0,0,0) 
      If iretval 
        HttpQueryInfo_(hHttpOpenRequest,19,@Buffer.s,@BufferLength,0) ;changes the buffer length 
        String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
        If Trim(String.s) = "200" 
          HttpQueryInfo_(hHttpOpenRequest,22,@Buffer.s,@BufferLength,0) 
          String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
          If FindString(String.s,"Content-Length:",1) 
            i = FindString(String.s,"Content-Length:",1) + Len("Content-Length:") 
            String.s = Mid(String.s,i,Len(String.s)-i) 
            FileSize = Val(Trim(String.s)) 
          EndIf 
        EndIf 
      EndIf 
    EndIf 
  EndIf 
  
  ;Download file and update status 
  If hURL 
    File = CreateFile(#PB_Any,Filename.s) 
    If File 
      time = ElapsedMilliseconds() 
      SetGadgetAttribute(#Progress,#PB_ProgressBar_Maximum,FileSize) 
      While InternetReadFile_(hURL,@Buffer.s,BufferLength,@Bytes) And Bytes > 0 
        If StopDownload 
          Break 
        EndIf 
        WriteData(File,@Buffer.s,Bytes) 
        CurrentSize + Bytes 
        SetGadgetState(#Progress,CurrentSize) 
        StatusBarText(#StatusBar,0,"  "+Str(CurrentSize/1024)+"/"+Str(FileSize/1024)+"kb - "+Str(BytesPerSecond/1024)+"kb/s") 
        If time < ElapsedMilliseconds() - 1000 
          time = ElapsedMilliseconds() 
          BytesPerSecond = CurrentSize - PreviousSize 
          PreviousSize = CurrentSize 
        EndIf 
      Wend 
      CloseFile(File) 
    Else 
      MessageRequester("Warning!","Error creating file!",#MB_ICONWARNING) 
    EndIf 
    StopDownload = #False 
    IsDownloading = #False 
    SetGadgetState(#Progress,0) 
    If CurrentSize < FileSize 
      DeleteFile(Filename.s) 
    EndIf 
  Else 
    MessageRequester("Warning!","Download failed!",#MB_ICONWARNING) 
  EndIf 
  
  InternetCloseHandle_(hURL) 
  InternetCloseHandle_(hInetCon) 
  InternetCloseHandle_(hInet) 
  DisableToolBarButton(#ToolBar,#Cancel,#True)
  StatusBarText(#StatusBar,0,"")
EndProcedure

Procedure ToolBarImageButtonEx(ToolBarId,ButtonId,ImageId,ToolTip.s)
  ToolBarImageButton(ButtonId,ImageId)
  ToolBarToolTip(ToolBarId,ButtonId,ToolTip)
EndProcedure


Ini.s=GetPathPart(ProgramFilename())+StringField(GetFilePart(ProgramFilename()),1,".")+".ini"
OpenPreferences(Ini)
Path.s=ReadPreferenceString("Path","c:\")

;{ Visual Design
OpenWindow(0,0,0,1024,768,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget) 
SetWindowTitle(0,#Title+Path)
CreateGadgetList(WindowID(0))
WebGadget(#Web,10,30,1024-20,768-60,"http://www.youtube.com")
CreateToolBar(#ToolBar,WindowID(0))
ToolBarImageButtonEx(#ToolBar,#Home,ImageID(CatchImage(#PB_Any,?Home)),"www.Youtube.com")
ToolBarImageButtonEx(#ToolBar,#Back,ImageID(CatchImage(#PB_Any,?Back)),"Back")
ToolBarImageButtonEx(#ToolBar,#Forward,ImageID(CatchImage(#PB_Any,?Forward)),"Forward")
ToolBarSeparator()
ToolBarImageButtonEx(#ToolBar,#Path,ImageID(CatchImage(#PB_Any,?Chemin)),"Backup Path")
ToolBarSeparator()
ToolBarImageButtonEx(#ToolBar,#Download,ImageID(CatchImage(#PB_Any,?Save)),"Download")
ToolBarImageButtonEx(#ToolBar,#Cancel,ImageID(CatchImage(#PB_Any,?Stop)),"Cancel Download")
CreateStatusBar(#StatusBar,WindowID(0))
AddStatusBarField(150)
AddStatusBarField(3000)
ProgressBarGadget(#Progress,170,5,1024-181,20,0,100, #PB_ProgressBar_Smooth)
DisableToolBarButton(#ToolBar,#Cancel,#True)
DisableToolBarButton(#ToolBar,#Download,#True)
;}

;{ Event Management
Repeat 
  evt=WaitWindowEvent()
  
  If IsThread(Tid)=0 ; If not Downloading
    StatusBarText(#StatusBar,0," "+VideoId.s) ; Show VideoId
    If Len(VideoId.s)=11
      DisableToolBarButton(#ToolBar,#Download,#False) ; Enable Download
    EndIf
  Else
    DisableToolBarButton(#ToolBar,#Download,#True) ; Disable Download
  EndIf
   
  Select evt
    
    Case #PB_Event_Gadget
      If EventGadget()=#Web
        If Url.s<>GetGadgetText(#Web)
          StatusBarText(#StatusBar,1," "+GetGadgetText(#Web))
          Url=GetGadgetText(#Web)
          ; Get the VideoId
          VideoId.s=StringField(GetGadgetText(#Web),2,"=")
          VideoId=StringField(VideoId,1,"&")
        EndIf
      EndIf
      
    Case #PB_Event_SizeWindow
      ResizeGadget(#Web,10,30,WindowWidth(0)-20,WindowHeight(0)-60)
      ResizeGadget(#Progress,170,5,WindowWidth(0)-181,20)
       
    Case #PB_Event_Menu
      Select EventMenu()
        Case #Home
          SetGadgetText(#Web,"http://www.youtube.com")
        Case #Back
          SetGadgetState(#Web,#PB_Web_Back)
        Case #Forward
          SetGadgetState(#Web,#PB_Web_Forward)
        Case #Path
          temp.s=PathRequester("Backup Video Path",Path)
          If temp<>""
            Path=temp
            SetWindowTitle(0,#Title+Path)
          EndIf
          
        Case #Download
          If Not IsDownloading And Len(VideoId)=11
            Source.s=GetGadgetItemText(#Web,#PB_Web_HtmlCode) ; Extract the HTML code from the WebGadget
            ; Extract the VideoName
            g=FindString(Source,"<title>YouTube - ",1)+17
            d=FindString(Source,"</title>",g)
            VideoTitle.s=Mid(Source,g,d-g)
            VideoTitle=FileNameConformation(VideoTitle)
            Tid=CreateThread(@SaveYoutubeVideo(),VideoId)
          EndIf
          
        Case #Cancel
          StopDownload = #True 
          IsDownloading = #False 
          SetGadgetState(#Progress,0)
          DisableToolBarButton(#ToolBar,#Cancel,#True)
          
      EndSelect
  EndSelect
  
Until evt=#PB_Event_CloseWindow
WritePreferenceString("Path",Path)
;}
Last edited by Droopy on Thu Jul 26, 2007 12:19 am, edited 1 time in total.
Sebe
Enthusiast
Enthusiast
Posts: 160
Joined: Sun Dec 19, 2004 10:55 pm
Location: Munich
Contact:

Post by Sebe »

Great thanks :D
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: YouTube Downloader

Post by NoahPhense »

Sweet!

- np
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

Whenever there is code, there is light!!
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Post by PureLust »

Thanks a lot for this nice peace of code. Image

Nevertheless I found some little things to improve.
So I hope it's ok that I had a look and done some changes to you code. :oops:

>Download here<

Image

Changes:
- showing Save-Path in Toolbar now
- fixing some ToolTip-Problems
- just enabeling Save-Button if there is a Video to save
- using own IconImageList for ToolBar so Icons can be changed at runtime
- changing Save-Icon to Stop-Icon if save is in progress
and ... *ehhm* ... changed ToolTips, Messages etc. to english, because I did not really understand the meaning of all the original ones. :roll:
Sebe
Enthusiast
Enthusiast
Posts: 160
Joined: Sun Dec 19, 2004 10:55 pm
Location: Munich
Contact:

Post by Sebe »

I used that to download my most favourite TV moment ever:

http://www.youtube.com/watch?v=VbEkKa-W55s
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

PureLust wrote:So I hope it's ok that I had a look and done some changes to you code. :oops:
No problemo, you can do what you want with this code :wink:

You can download the new version
Changes :
  • Save-Path showed in the Title
    ToolTip fixed
    Download Button enabled only if there is a Video to save
    Cancel Download button added
    Resize is now possible
    Translation in English
    StatusBar changed
    Gnozal code deleted ( PB can get the html code of a webgadget :oops: )
Thanks Sebe for your help
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Very nice! :D
I like logic, hence I dislike humans but love computers.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Joakim Christiansen wrote:Very nice! :D
Thanks to you too, i use your code to download with progressbar
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Here's a new version : (Download several files allowed )

- Catch video link by moving your mouse over a video
- High Beep = Links captured / Low Beep = already captured
- Delete links by right clic

Code: Select all

;/ PureBasic 4.10b2 / Droopy 26/07/07

Global DownloadURL.s, DownloadFilename.s, StopDownload, IsDownloading , Path.s

#Title="YouTube Multi-Downloader at "

Enumeration
  #Panel
  #Web
  #ProgressBar
  #Liste
  #SBar
  #Menu
  #Download
  #Path
EndEnumeration

Procedure.s FileNameConformation(File.s) ; Renvoie un nom de fichier sans les caractères interdits
  
  For n=1 To Len(File)
    c.s=Mid(File,n,1)
    If FindString(c,"\",1)
      Out.s+" "
    ElseIf FindString(c,"/",1)
      Out.s+" "
    ElseIf FindString(c,":",1)
      Out.s+" "
    ElseIf FindString(c,"?",1)
      Out.s+" "
    ElseIf FindString(c,"*",1)
      Out.s+" "
    ElseIf FindString(c,"<",1)
      Out.s+" "
    ElseIf FindString(c,">",1)
      Out.s+" "
    ElseIf FindString(c,"|",1)
      Out.s+" "
    ElseIf FindString(c,Chr(34),1)
      Out.s+" "
    Else
      Out.s+c
    EndIf
  Next
  
  ProcedureReturn Out
EndProcedure

ProcedureDLL.s Url2Text(Url.s, OpenType.b=1,ProxyAndPort.s="") 
  ; 1 INTERNET_OPEN_TYPE_DIRECT                       Resolves all host names locally. 
  ; 0 INTERNET_OPEN_TYPE_PRECONFIG                    Retrieves the proxy Or direct configuration from the registry. 
  ; 4 INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  Retrieves the proxy Or direct configuration from the registry And prevents the use of a startup Microsoft JScript Or Internet Setup (INS) file. 
  ; 3 INTERNET_OPEN_TYPE_PROXY                        Passes requests To the proxy unless a proxy bypass list is supplied And the name To be resolved bypasses the proxy. In this Case, the function uses INTERNET_OPEN_TYPE_DIRECT. 
  
  isLoop.b=1 
  INET_RELOAD.l = $80000000 
  hInet.l=0 
  hURL.l=0 
  Bytes.l=0 
  Buffer.s=Space(2048) 
  RES.s="" 
  
  hInet = InternetOpen_("", OpenType, ProxyAndPort, "", 0) 
  hURL = InternetOpenUrl_(hInet, Url, #Null, 0, INET_RELOAD, 0) 
  
  Repeat 
    InternetReadFile_(hURL,@Buffer, Len(Buffer), @Bytes) 
    If Bytes = 0 
      isLoop=0 
    Else 
      RES = RES + Left(Buffer, Bytes) 
    EndIf 
  Until isLoop=0 
  
  InternetCloseHandle_(hURL) 
  InternetCloseHandle_(hInet) 
  ProcedureReturn RES 
EndProcedure 

Procedure.s VideoIdToTitle(id.s)
  Source.s=Url2Text("http://www.youtube.com/watch?v="+id)
  SetClipboardText(Source)
  Chaine.s="<title>YouTube -"
  g=FindString(Source,Chaine,1)+Len(Chaine)
  d=FindString(Source,"</title>",g)
  Titre.s=Mid(Source,g,d-g)
  ProcedureReturn Titre
EndProcedure

Procedure DesactiveInterface(Etat)
  DisableGadget(#Liste,Etat)
  DisableGadget(#Web,Etat)
EndProcedure

Procedure SaveYoutubeVideo(VideoId.s,SaveFile.s) ; 0 = echec / 1 = succes / -1 = annulé
  
  ;/ ( Downloader With progress And Status By Joakim L. Christiansen )

  Retour=1
  
  IsDownloading+#True
  
  DownloadURL.s = "http://cache.googlevideo.com/get_video?video_id="+VideoId
  
  Protected hInet, hURL, Bytes 
  Protected BufferLength = 2048, Buffer.s = Space(BufferLength) 
  
  Protected Url.s      = DownloadURL.s 
  Protected Fid 
  Protected CurrentSize, PreviousSize, FileSize, time, BytesPerSecond 
  Protected Domain.s, String.s, i, BufferLengthWas = BufferLength 
  Protected hInetCon, hHttpOpenRequest, iretval 
  
  hInet = InternetOpen_("Downloader",0,0,0,0) 
  hURL  = InternetOpenUrl_(hInet,Url.s,0,0,$80000000,0) 
  
  ;Get filesize 
  Domain.s  = StringField(Url.s,3,"/") 
  hInetCon = InternetConnect_(hInet,Domain.s,80,#Null,#Null,3,0,0) 
  If hInetCon 
    hHttpOpenRequest = HttpOpenRequest_(hInetCon,"HEAD",ReplaceString(Url.s,"http://"+Domain.s+"/",""),#Null,#Null,0,$80000000,0) 
    If hHttpOpenRequest 
      iretval = HttpSendRequest_(hHttpOpenRequest,#Null,0,0,0) 
      If iretval 
        HttpQueryInfo_(hHttpOpenRequest,19,@Buffer.s,@BufferLength,0) ;changes the buffer length 
        String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
        If Trim(String.s) = "200" 
          HttpQueryInfo_(hHttpOpenRequest,22,@Buffer.s,@BufferLength,0) 
          String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
          If FindString(String.s,"Content-Length:",1) 
            i = FindString(String.s,"Content-Length:",1) + Len("Content-Length:") 
            String.s = Mid(String.s,i,Len(String.s)-i) 
            FileSize = Val(Trim(String.s)) 
          EndIf 
        EndIf 
      EndIf 
    EndIf 
  EndIf 
  
  ;Download file and update status 
  If hURL 
    Fid = CreateFile(#PB_Any,SaveFile.s) 
    If Fid 
      time = ElapsedMilliseconds() 
      SetGadgetAttribute(#ProgressBar,#PB_ProgressBar_Maximum,FileSize) 
      While InternetReadFile_(hURL,@Buffer.s,BufferLength,@Bytes) And Bytes > 0 
        If StopDownload
          Retour=-1 ;/ Download annulé
          Break 
        EndIf 
        WriteData(Fid,@Buffer.s,Bytes) 
        CurrentSize + Bytes 
        SetGadgetState(#ProgressBar,CurrentSize) 
        StatusBarText(#SBar,0,"  "+Str(CurrentSize/1024)+"/"+Str(FileSize/1024)+"kb - "+Str(BytesPerSecond/1024)+"kb/s") 
        If time < ElapsedMilliseconds() - 1000 
          time = ElapsedMilliseconds() 
          BytesPerSecond = CurrentSize - PreviousSize 
          PreviousSize = CurrentSize 
        EndIf 
      Wend 
      CloseFile(Fid) 
    EndIf 

    IsDownloading = #False 
    SetGadgetState(#ProgressBar,0) 
    
    
    If CurrentSize < FileSize 
      DeleteFile(SaveFile.s)
      If Retour=1
        Retour=0
      EndIf
    EndIf 
  EndIf 
  
  InternetCloseHandle_(hURL) 
  InternetCloseHandle_(hInetCon) 
  InternetCloseHandle_(hInet) 
  
  ProcedureReturn Retour
EndProcedure

Procedure HttpFileSize(Url.s)
  hInet = InternetOpen_("Downloader",0,0,0,0) 
  hURL  = InternetOpenUrl_(hInet,Url,0,0,$80000000,0)
  
  BufferLength = 256
  Buffer.s = Space(BufferLength)
  BufferLengthWas = BufferLength
  
  Domain.s  = StringField(Url,3,"/")
  hInetCon = InternetConnect_(hInet,Domain,80,#Null,#Null,3,0,0) 
  If hInetCon 
    hHttpOpenRequest = HttpOpenRequest_(hInetCon,"HEAD",ReplaceString(Url,"http://"+Domain+"/",""),#Null,#Null,0,$80000000,0) 
    If hHttpOpenRequest 
      iretval = HttpSendRequest_(hHttpOpenRequest,#Null,0,0,0) 
      If iretval 
        HttpQueryInfo_(hHttpOpenRequest,19,@Buffer,@BufferLength,0)
        String.s = PeekS(@Buffer,BufferLength): BufferLength = BufferLengthWas 
        If Trim(String.s) = "200" 
          HttpQueryInfo_(hHttpOpenRequest,22,@Buffer,@BufferLength,0) 
          String.s = PeekS(@Buffer,BufferLength): BufferLength = BufferLengthWas 
          If FindString(String.s,"Content-Length:",1) 
            i = FindString(String.s,"Content-Length:",1) + Len("Content-Length:") 
            String.s = Mid(String.s,i,Len(String.s)-i) 
            FileSize = Val(Trim(String.s)) 
          EndIf 
        EndIf 
      EndIf 
    EndIf 
  EndIf 
  
  InternetCloseHandle_(hURL) 
  InternetCloseHandle_(hInetCon) 
  InternetCloseHandle_(hInet) 
  ProcedureReturn FileSize
EndProcedure

Procedure Download()
  
  If CountGadgetItems(#Liste)
    
    ;/ Retrouve le titre des vidéos
    StatusBarText(#SBar,1,"Search Title")
    For n=1 To CountGadgetItems(#Liste)
      If GetGadgetItemText(#Liste,n-1,1)=""
        id.s=GetGadgetItemText(#Liste,n-1,0)
        SetGadgetItemText(#Liste,n-1,"Search Title",3)
        Titre.s=VideoIdToTitle(id)
        SetGadgetItemText(#Liste,n-1,"",3)
        SetGadgetItemText(#Liste,n-1,FileNameConformation(Titre),1)
      EndIf
      
      If StopDownload
        Anulation=#True
        Break
      EndIf
    Next
    
    ;/ Retrouve la taille des vidéos
    If StopDownload=#False
      StatusBarText(#SBar,1,"Search Video Size")
      For n=1 To CountGadgetItems(#Liste)
        If GetGadgetItemText(#Liste,n-1,2)=""
          id.s=GetGadgetItemText(#Liste,n-1,0)
          SetGadgetItemText(#Liste,n-1,"Search Size",3)
          Size=HttpFileSize("http://cache.googlevideo.com/get_video?video_id="+id)
          Size/1024
          SetGadgetItemText(#Liste,n-1,Str(Size)+"Kb",2)
          SetGadgetItemText(#Liste,n-1,"",3)
        EndIf
        If StopDownload
          Anulation=#True
          Break
        EndIf
      Next
    EndIf
    
    If StopDownload=#False
    ;/ Video Download
      For n=1 To CountGadgetItems(#Liste)
        If GetGadgetItemText(#Liste,n-1,3)<>"Success"
          id.s=GetGadgetItemText(#Liste,n-1,0)
          Titre.s=VideoIdToTitle(id)
          StatusBarText(#SBar,1,"Downloading "+Titre)
          SetGadgetItemText(#Liste,n-1,"Downloading ...",3)
          
          Retour=SaveYoutubeVideo(id,Path+Titre+".flv")
          If Retour=1
            SetGadgetItemText(#Liste,n-1,"Success",3)
          ElseIf Retour=0
            SetGadgetItemText(#Liste,n-1,"Fail *****",3)
          ElseIf Retour=-1
            SetGadgetItemText(#Liste,n-1,"Aborted",3)
          EndIf
        EndIf 
        
        If StopDownload
          Anulation=#True
          Break
        EndIf
      Next
    EndIf
    
    If Anulation=#False
      MessageRequester("","Download terminé")
    EndIf
    
  EndIf
   
  DesactiveInterface(#False)
  StopDownload=#False
  StatusBarText(#SBar,0,"")
  StatusBarText(#SBar,1,"")
  Debug "-----------"
  
EndProcedure

#Largeur=1024
#hauteur=700

;/ Lecture du chemin dans le fichier ini
Ini.s=GetPathPart(ProgramFilename())+StringField(GetFilePart(ProgramFilename()),1,".")+".ini"
OpenPreferences(Ini)
Path.s=ReadPreferenceString("Path","c:\")

OpenWindow(0,0,0,#Largeur,#hauteur,#Title+Path,#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0))
CreateMenu(#Menu,WindowID(0))
MenuTitle("File")
MenuItem(#Download,"&Download")
PanelGadget(#Panel,10,10,#Largeur-20,#hauteur-60)
AddGadgetItem(#Panel,-1,"YouTube")
WebGadget(#Web,10,10,#Largeur-40,#hauteur-110,"http://www.Youtube.com")
CloseGadgetList()
AddGadgetItem(#Panel,-1,"Download")
ListIconGadget(#Liste,10,10,#Largeur-90,#hauteur-110,"Video Id",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
ProgressBarGadget(#ProgressBar,#Largeur-70,10,30,#hauteur-110,0,100,#PB_ProgressBar_Smooth|#PB_ProgressBar_Vertical)
AddGadgetColumn(#Liste,1,"Title",#Largeur-450)
AddGadgetColumn(#Liste,2,"Size",90)
AddGadgetColumn(#Liste,3,"Status",150)
CreateStatusBar(#SBar,WindowID(0))
AddStatusBarField(200)
AddStatusBarField(1000)
SetActiveGadget(#Web)

Repeat 
  evt=WaitWindowEvent()
  
  Select evt
    
    Case #PB_Event_Menu
      Select EventMenu()
        Case #Download
          ;/ Arrêt Download
          If IsThread(Tid)
            StopDownload=#True
            SetMenuItemText(#Menu,#Download,"Download")
             
          Else
            ;/ Start Download
            If CountGadgetItems(#Liste)
              
              SetGadgetState(#Panel,1)
              DesactiveInterface(#True)
              SetMenuItemText(#Menu,#Download,"Cancel Download")
              Tid=CreateThread(@Download(),0)
            EndIf
          EndIf
          
        Case #Path
          temp.s=PathRequester("Backup Video Path",Path)
          If temp<>""
            Path=temp
            SetWindowTitle(0,#Title+Path)
          EndIf
           
      EndSelect
       
    Case #PB_Event_Gadget
      Select EventGadget()
        
        Case #Web
        StatusMessage.s=GetGadgetItemText(#Web,#PB_Web_StatusMessage)
        StatusBarText(#SBar,1,"  "+StatusMessage)
        Source.s=GetGadgetItemText(#Web,#PB_Web_HtmlCode)
        SetClipboardText(Source)
        If Left(StatusMessage,31)="http://www.youtube.com/watch?v="
          id.s=StringField(StatusMessage,2,"=")
          ;/ L'ajoute à la liste uniquement si non présent
          Absent=#True
          For n=1 To CountGadgetItems(#Liste)
            If GetGadgetItemText(#Liste,n-1,0)=id
              Absent=#False
            EndIf
          Next
          If Absent
            AddGadgetItem(#Liste,-1,id)
            beep_(700,15)
          Else
            beep_(250,25)
          EndIf
        EndIf
        
      Case #Liste
        If EventType()=#PB_EventType_RightClick
          RemoveGadgetItem(#Liste,GetGadgetState(#Liste))
        EndIf
    EndSelect
   
  EndSelect
Until evt = #PB_Event_CloseWindow

WritePreferenceString("Path",Path)

HideWindow(0,#True)

If ThreadID(Tid)
  StopDownload=#True
  Repeat
    sleep_(1)
    WindowEvent()
  Until ThreadID(Tid)=0
EndIf
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

i'll update droopy's version. it will work with dailymotion videos
Perhaps we have to change the app title ... "Youtube & co downloader"

:? PB does not support regex, it will a pain to code.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

eddy wrote:i'll update droopy's version. it will work with dailymotion videos
Perhaps we have to change the app title ... "Youtube & co downloader"
Where we can dowload your version ?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Not yet ready... :?

I'm trying to found a easy way to make a generic downloader without using REGEX.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

- save last window size
- save last url
- generic HTML parser ( XML configuration file )
- support sources : Youtube, Dailymotion, GoogleVideo
- browser download folder
Last edited by eddy on Sun Aug 19, 2007 12:17 pm, edited 2 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Hello Eddy, I cannot see a link in your post?
Post Reply