Ver Mensaje Individual
  #1  
Antiguo 22-05-2008
jlmsr63 jlmsr63 is offline
Baneado
 
Registrado: may 2008
Ubicación: La Paz Bolivia
Posts: 3
Reputación: 0
jlmsr63 Va por buen camino
Descargar un video de youtube en formato flv

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Urlmon, Buttons, StdCtrls, Ddeman, Wininet, MMSystem;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
SpeedButton2: TSpeedButton;
Label3: TLabel;
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function GetURL(Service: string): string;
var
ClDDE: TDDEClientConv;
temp: PChar;
begin
Result := '';
ClDDE := TDDEClientConv.Create(nil);
with ClDDE do
begin
SetLink(Service, 'WWW_GetWindowInfo');
temp := RequestData('0xFFFFFFFF');
Result := StrPas(temp);
StrDispose(temp);
CloseLink;
end;
ClDDE.Free;
end;

function Download(Url: string; Archivo: string): Boolean;
var
hFile: THandle;
hNet: HINTERNET;
hUrl: HINTERNET;
Buffer: array[0..102400] of Char;
BytesRead: DWORD;
BytesWritten: DWORD;
begin
Result := FALSE;
hFile := CreateFile(PChar(Archivo), GENERIC_WRITE, 0, nil, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0);
if (hFile <> INVALID_HANDLE_VALUE) then
begin
hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if (hNet <> nil) then
begin
hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if (hUrl <> nil) then
begin
while (InternetReadFile(hUrl, @Buffer, sizeof(Buffer), BytesRead)) do
begin
if (BytesRead = 0) then
begin
Result := TRUE;
break;
end;
if (not WriteFile(hFile, Buffer, BytesRead, BytesWritten, nil)) then
break;
if (BytesRead <> BytesWritten) then
break;
end;
InternetCloseHandle(hUrl);
end;
InternetCloseHandle(hNet);
end;
CloseHandle(hFile);
end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
// Copiar del Explorador
var
Video : String;
ca : iinterface;
stat : iBindStatusCallBack;
tag : _tagBindInfo;
exGuid : tguid;
rr : cardinal;
noIp : Pointer;
Linea : String;
f : textfile;
n : Integer;
direccion : String;
url_youtube : String;
id_youtube : String;
begin
Video := GetURL('IExplore');
Edit1.Text := copy(Video,Pos('http',Video),Pos('","',Video)-Pos('http',Video));
Form1.Caption := copy(Video,Pos('","',Video)+3,Length(Video)-(Pos('","',Video)+3))+'.flv';
try
// PlaySound(Pchar('START'),0,SND_ASYNC);
except
end;
// Buscar codigo de seguridad de Downloadyoutubevideos
rr := 0;
exGuid.D1 := rr;
exGuid.D2 := word('0');
exGuid.D3 := word('.');
id_youtube := copy(Edit1.Text,Pos('=',Edit1.Text)+1,length(Edit1.Text));
// Memo1.Lines.Add(id_youtube);
url_youtube := 'http://www.downloadyoutubevideos.com/watch.php?theyturl=http%3A%2F%2Fes.youtube.com%2Fwatch%3Fv%3D' + id_youtube + '&goYT=Download';
// Memo1.Lines.Add(url_youtube);
with tag do
begin
iid := exGuid;
cbSize := sizeOf(url_youtube);
securityAttributes.lpSecurityDescriptor := noIp;
securityAttributes.nLength := length('0.0.0.0');
securityAttributes.bInheritHandle := True;
end;
try
urlmon.URLDownloadToFile(ca, PAnsichar(url_youtube), 'MARIA YOUTUBE VIDEO.html', 1, stat);
except
ShowMessage('No es posible descargar la pagina web!');
end;
AssignFile(f,'MARIA YOUTUBE VIDEO.html');
reset(f);
for n := 1 to 200 do
begin
readln(f,Linea);
if Pos('DOWNLOAD VIDEO',Linea) <> 0 then
begin
direccion := copy(linea,Pos('http',Linea),Pos('">D',Linea)-Pos('http',Linea));
// memo1.Lines.Add(direccion);
end;
end;
Edit2.Text := direccion;
CloseFile(f);
try
PlaySound(Pchar('START'),0,SND_ASYNC);
except
end;
// Download de Youtube
Label3.Caption := '0%';
Download(Edit2.Text,'d:\'+Form1.Caption);
Label3.Caption := '100%';
try
PlaySound(Pchar('EXIT'),0,SND_ASYNC);
except
end;
end;

end.
Responder Con Cita