Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

YouTube Video Downloader Delphi Source

Discussion in 'Delphi Components' started by AdminDF, Apr 19, 2013.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Code:
    unit uDownload;
     
    interface
     
    uses
      Classes,
      SysUtils,
      IDHttp,
      WinInet,
      Windows;
     
    const
      c_YouTubeHeader = 'http://www.youtube.com/watch?v=';
      c_YouTubeHost = 'http://www.youtube.com/';
     
    procedure TryDownloadYouTubeVideo(UrlPath: string; Dir: string);
     
    implementation
     
    procedure TryDownloadYouTubeVideo(UrlPath: string; Dir: string);
    var
      http: TIdHttp;
      strm: TStringStream;
      FName: string;
      FUrl: string;
     
      function fnc_GetSourcePath: string;
      const
        c_sBeginPath = 'img.src = "http:\/\/';
        c_sMiddlePath = '\/';
        c_dMiddlePath = '/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Cratebypass%2C';
        c_sEndPath = '"';
        c_dBeginPath = 'http://tc.';
        c_dEndPath = 'redirect_counter=1';
     
        c_sBreakChar1 = '%2C';
        c_sBreakChar2 = '\u0026';
     
        c_dBreakChar = '&';
     
      var
        tmpstr: string;
        tmpstrlst: TStringList;
        tmpRes: string;
     
        function fnc_IsTrash: Boolean;
        begin
          Result := (Pos(c_sBreakChar1, tmpstr) <> 0) and
                    (Pos(c_sBreakChar2, tmpstr) <> 0) and
                    (Pos(c_sBreakChar1, tmpstr) < Pos(c_sBreakChar2, tmpstr));
        end;
     
      begin
        Result := '';
        tmpstrlst := TStringList.Create;
        try
          tmpstr := strm.DataString;
          Delete(tmpstr, 1, Pos(c_sBeginPath, tmpstr) + Length(c_sBeginPath) - 1);
          Delete(tmpstr, Pos(c_sEndPath, tmpstr), Length(tmpstr));
     
          tmpstrlst.Delimiter := '.';
          tmpstrlst.DelimitedText := Copy(tmpstr, 1, Pos(c_sMiddlePath, tmpstr) - 1);
     
          tmpRes := Concat(c_dBeginPath,
                           tmpstrlst.Strings[3],
                           '.',
                           Copy(tmpstrlst.Strings[4], 3, Length(tmpstrlst.Strings[4])),
                           '.',
                           tmpstrlst.Strings[5],
                           '.',
                           tmpstrlst.Strings[6],
                           '.',
                           tmpstrlst.Strings[7],
                           c_dMiddlePath);
     
          while fnc_IsTrash do
            Delete(tmpstr, 1, Pos(c_sBreakChar1, tmpstr) + Length(c_sBreakChar1) - 1);
     
          tmpstrlst.Delimiter := c_dBreakChar;
          tmpstrlst.Clear;
     
          while Pos(c_sBreakChar2, tmpstr) <> 0 do
          begin
            tmpstrlst.Add(Copy(tmpstr, 1, Pos(c_sBreakChar2, tmpstr) - 1));
            Delete(tmpstr, 1, Pos(c_sBreakChar2, tmpstr) + Length(c_sBreakChar2) - 1);
          end;
     
          tmpstrlst.Add(tmpstr);
          tmpstrlst.Add(c_dEndPath);
     
          tmpRes := Concat(tmpRes,
                           tmpstrlst.DelimitedText);
        finally
          FreeAndNil(tmpstrlst);
        end;
     
        Result := tmpRes;
      end;
     
      function fnc_GetFileName: string;
     
        function fnc_GetDir: string;
        begin
          Result := Dir;
          if Result[Length(Result)] <> '\' then
            Result := Concat(Result, '\');
        end;
     
      const
        c_TitleBegin = '<meta name="title" content="';
        c_TitleEnd = '"';
      var
        tmpstr: string;
      begin
        tmpstr := strm.DataString;
        Delete(tmpstr, 1, Pos(c_TitleBegin, tmpstr) + Length(c_TitleBegin) - 1);
        Delete(tmpstr, Pos(c_TitleEnd, tmpstr), Length(tmpstr));
        tmpstr := UTF8ToUnicodeString(Trim(tmpstr));
        Result := Concat(fnc_GetDir, tmpstr, '.avi');
      end;
     
    begin
      http := TIdHTTP.Create(nil);
      strm := TStringStream.Create;
      try
        http.Request.Host := c_YouTubeHost;
        http.Get(UrlPath, strm);
     
        FName := fnc_GetFileName;
        FUrl := fnc_GetSourcePath;
     
        http.Disconnect;
        strm.Clear;
        http.Get(FUrl, strm);
     
        strm.SaveToFile(FName);
      finally
        FreeAndNil(strm);
        FreeAndNil(http);
      end;
     end;
     
    end.
     
  2. robt
    Offline

    robt Guest

    RE:

    spasibo
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block