y0u tub3 Video Uploader FreePascal

Discussion in 'General Programming Chat' started by Redneck, Sep 23, 2008.

  1. Redneck

    Redneck Newbie

    Joined:
    May 24, 2008
    Messages:
    15
    Likes Received:
    2
    Location:
    South
    This is a y0u tub3 Video Uploader. It was a quick little project
    I made to show everyone how to do it in FreePascal.
    I made sure that it ran on windows (XP Pro).

    This is a command line program. You will need
    FreePascal (FPC): h**p://www.freepascal.org/
    and cUrl: h**p://curl.haxx.se/

    I use Arch Linux, but this code should compile and run, with minimal modification, on
    any OS that you can install FPC and cUrl.

    Save the 2 code blocks into text files called:
    youtubecliupload.pas
    and
    nusecurl.pas

    You will need to edit one line in the youtubecliupload.pas file.
    Line #12 holds the path to your cUrl executable. You will need to
    set this to the path of cUrl on your system.
    On my windows box:
    cUrlLocation : string = 'C:\curl_718_2\curl.exe';
    On my Linux box:
    cUrlLocation : string = '/usr/bin/curl';

    NOTE: On Linux, in a terminal type "which curl" and it *should* tell you
    where it is.

    On Linux:
    Open a terminal, cd into the folder that has youtubecliupload.pas & nusecurl.pas and type:
    "fpc youtubecliupload.pas"
    and it will compile.

    On windows:
    Find out where your fpc.exe is. Mine is at
    C:\FPC\2.1.4\bin\i386-win32\fpc.exe

    The 2 sources file are in a folder at:
    C:\projects\tubeupper\

    Click the Start button, click on Run, type "cmd" and hit Enter.
    In the cmd.exe window type:
    C:\FPC\2.1.4\bin\i386-win32\fpc.exe C:\projects\tubeupper\youtubecliupload.pas

    I am not sure how it is done on OSX. It should be the same as linux. I do have a couple
    OSX machines here, if anyone needs to know I will try it out.

    After you compile it, run the program.
    windows: youtubecliupload.exe -h
    Linux: youtubecliupload -h
    And it will tell you how to use it to upload a video.

    Save this as "youtubecliupload.pas"
    Code:
    program youtubecliupload;
    
    {$mode objfpc}{$H+}
    
    uses
      {$IFDEF UNIX}
      cthreads,
      {$ENDIF}
      Classes, SysUtils, StrUtils, nusecurl;
      
    const
      cUrlLocation : string = 'C:\curl_718_2\curl.exe';
      beverbose: boolean = False;
      usethehelp: boolean = True;
      appdirname: string = 'ytcliupload';
      appname: string = 'youtubecliupload';
      aproxy: string = '';
      aproxytype: string = '0';
      isgoogle: boolean = False;
      
    var
      MycUrl: AbuseCurl;
      workfolder, cookiesflli: string;
      vidtitle, viddescription, vidcategory, vidtags: string;
      usernamep, passwordp, thevideop, infofilep, getbackurl: string;
      vcategory, proxyport, proxytype, loggedin, savtafille: string;
      getback, durle, reffer, formdata, sessiontken, aserver: string;
      i, ig: integer;
      tmpstrlst: TStringList;
    
      
    procedure WriteHelp;
    begin
      writeln('Usage: ' + appname + ' -u [username] -p [password] -vp [/path/to/video] -inf [/path/to/infofile]');
      writeln(appname + ': the name of this program');
      writeln('-u [username]: your youtube login username');
      writeln('-p [password]: your youtube login password');
      writeln('-vp [/path/to/video]: the video you want to upload to youtube');
      writeln('-inf [/path/to/infofile]: the file that holds info on video');
      writeln('If you want this program to give updates add the -v option');
      writeln('Example:');
      writeln('   ' + appname + ' -u bobbygreen -p koolpass24 -vp /home/bobby/videos/wombat.avi -inf /home/bobby/infofile.txt -v');
      writeln(' ');
      writeln('If you want to use a proxy:');
      writeln('-px [proxy:port]: the proxy to use');
      writeln('-pt [proxytype]: the type of proxy. Types are http, socks4 and socks5');
      writeln('Example:');
      writeln('   ' + appname + ' -u bobbygreen -p koolpass24 -vp /home/bobby/videos/wombat.avi -inf /home/bobby/infofile.txt -px 24.125.45.112:3190 -pt http');
      writeln(' ');
      writeln('If you do not want to use the info file then give these options:');
      writeln('-t [title]: your youtube video title');
      writeln('  use the "@" in front of a file path to read your youtube video title from a file.');
      writeln('-d [description]: your youtube video description');
      writeln('  use the "@" in front of a file path to read your youtube video description from a file.');
      writeln('-vc [videocategory]: your youtube video category');
      writeln('  use the "@" in front of a file path to read your youtube video category from a file.');
      writeln('-tg [tags]: your youtube video tags');
      writeln('  use the "@" in front of a file path to read your youtube video tags from a file.');
      writeln('Example:');
      writeln('   ' + appname + ' -u bobbygreen -p koolpass24 -vp /home/bobby/videos/wombat.avi -t "Super Cool Video" -d "This is my new super cool video. Check out my others" -vc "Film & Animation" -tg "new, awesome, cool, fabulous, hip, happening, boobs"');
      writeln(' ');
      writeln('   ' + appname + ' -u bobbygreen -p koolpass24 -vp /home/bobby/videos/wombat.avi -t @/home/bobby/titlefile.txt -d @/home/bobby/descriptionfile.txt -vc "Film & Animation" -tg @/home/bobby/tagfile.txt');
      writeln(' ');
      writeln('Note: Put quote marks "" around items that have spaces in them.');
      writeln(' ');
      writeln('Note 2: If you use google to log into youtube, put "google=" in front of your username.');
      writeln('Example:');
      writeln('   ' + appname + ' -u google=bobbygreen -p koolpass24 -vp /home/bobby/videos/wombat.avi -inf /home/bobby/infofile.txt -v');
      writeln(' ');
      writeln('Note 3: If you do not want to see the help when an error occurs, add "-nh" to the command line.');
      writeln(' ');
      writeln('to see help on the info file, type:');
      writeln('   ' + appname + ' -infohelp');
    end;
    
    procedure WriteInfoHelp;
    begin
      writeln('Info file help');
      writeln('The info file is a text file that holds video info that can be randomized.');
      writeln('Each item on a seperate line.');
      writeln(' ');
      writeln('Example contents of an info file:');
      writeln('Title=Super awesome vid!');
      writeln('Title=Hot nasty MILF!');
      writeln('Title=Spongebob smokes pot! Serious!');
      writeln('Description=This is a howto video on self healing with the power of homemade beer.');
      writeln('Description=Here is a look at my last night at my aunts nudist ranch.');
      writeln('Description=My GF has 6 toes on each foot. this is a short vid of her showing off her new toenail job.');
      writeln('Description=Nothing special. Just sitting around talking with my dog..');
      writeln('Video Category=Entertainment');
      writeln('Video Category=Pets & Animals');
      writeln('Tags=spongebob, patrick, dogs, toes, boobs');
      writeln('Tags=beer, howto, pot, milf, dilf, nasty, nudist');
      writeln(' ');
      writeln('when you give the info file option, one Title, Description, Video Category and Tags line');
      writeln('will be chosen at random and used for the video you want to upload.');
      writeln(' ');
      writeln('Video Categories that can be used:');
      writeln('Autos & Vehicles');
      writeln('Comedy');
      writeln('Education');
      writeln('Entertainment');
      writeln('Film & Animation');
      writeln('Gaming');
      writeln('Howto & Style');
      writeln('Music');
      writeln('News & Politics');
      writeln('Nonprofits & Activism');
      writeln('People & Blogs');
      writeln('Pets & Animals');
      writeln('Science & Technology');
      writeln('Sports');
      writeln('Travel & Events');
      writeln(' ');
    end;
    
    function MakeRandomString: string;
    const
      Chars = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    var
      S: string;
      i, N: integer;
    begin
      Randomize;
      S := '';
      for i := 1 to 6 do
      begin
        N := Random(Length(Chars)) + 1;
        S := S + Chars[N];
      end;
      result := S;
    end;
    
    function TellMeCatagory: string;
    begin
      if (vidcategory = 'Autos & Vehicles') then result := '2';
      if (vidcategory = 'Comedy') then result := '23';
      if (vidcategory = 'Education') then result := '27';
      if (vidcategory = 'Entertainment') then result := '24';
      if (vidcategory = 'Film & Animation') then result := '1';
      if (vidcategory = 'Gaming') then result := '20';
      if (vidcategory = 'Howto & Style') then result := '26';
      if (vidcategory = 'Music') then result := '10';
      if (vidcategory = 'News & Politics') then result := '25';
      if (vidcategory = 'Nonprofits & Activism') then result := '29';
      if (vidcategory = 'People & Blogs') then result := '22';
      if (vidcategory = 'Pets & Animals') then result := '15';
      if (vidcategory = 'Science & Technology') then result := '28';
      if (vidcategory = 'Sports') then result := '17';
      if (vidcategory = 'Travel & Events') then result := '19';
    end;
    
    function GiveMeTheSessionToken(Linput: string): string;
    var
      turetrun: string;
    begin
       Linput := StringReplace(Linput, '"', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '''', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '	gXSRF_token = ', 'DEJSUSER=', [rfReplaceAll]);
       turetrun := Copy(Linput, pos('DEJSUSER=', Linput) + 9, Length(Linput));
       turetrun := Copy(turetrun, 1, pos(';', turetrun) - 1);
       result := turetrun;
    end;
    
    function GiveMeTheAddresserToken(Linput: string): string;
    var
      turetrun: string;
    begin
       Linput := StringReplace(Linput, '"', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '''', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '<input type=hidden name=addresser value=', 'DEJSUSER=', [rfReplaceAll]);
       turetrun := Copy(Linput, pos('DEJSUSER=', Linput) + 9, Length(Linput));
       turetrun := Copy(turetrun, 1, pos('>', turetrun) - 1);
       result := turetrun;
    end;
    
    function GiveMeTheServer(Linput: string): string;
    var
      turetrun: string;
    begin
       Linput := StringReplace(Linput, '"', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '''', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, 'enctype=multipart/form-data action=', 'DEJSUSER=', [rfReplaceAll]);
       turetrun := Copy(Linput, pos('DEJSUSER=', Linput) + 9, Length(Linput));
       turetrun := Copy(turetrun, 1, pos(' name=theForm', turetrun) - 1);
       result := turetrun;
    end;
    
    function GiveMeTheVideoUrl(Linput: string): string;
    var
      turetrun: string;
    begin
       Linput := StringReplace(Linput, '"', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '''', '', [rfReplaceAll, rfIgnoreCase]);
       Linput := StringReplace(Linput, '<embed src=', 'DEJSUSER=', [rfReplaceAll]);
       turetrun := Copy(Linput, pos('DEJSUSER=', Linput) + 9, Length(Linput));
       turetrun := Copy(turetrun, 1, pos(' ', turetrun) - 1);
       result := turetrun;
    end;
    
    procedure LoadInfoFile(thefille: string);
    var
      infofille: TStringList;
      titles, descrips, tags, categores: TStringList;
      i: integer;
    begin
     titles := TStringList.Create;
     descrips := TStringList.Create;
     tags := TStringList.Create;
     categores := TStringList.Create;
     infofille := TStringList.Create;
     infofille.LoadFromFile(thefille);
     for i := 0 to infofille.count - 1 do
     begin
       if (pos('Title=', Trim(infofille[i])) = 1) then
         titles.Add(Copy(Trim(infofille[i]), Length('Title=')+1, Length(Trim(infofille[i]))));
       if (pos('Description=', Trim(infofille[i])) = 1) then
         descrips.Add(Copy(Trim(infofille[i]), Length('Description=')+1, Length(Trim(infofille[i]))));
       if (pos('Video Category=', Trim(infofille[i])) = 1) then
         categores.Add(Copy(Trim(infofille[i]), Length('Video Category=')+1, Length(Trim(infofille[i]))));
       if (pos('Tags=', Trim(infofille[i])) = 1) then
         tags.Add(Copy(Trim(infofille[i]), Length('Tags=')+1, Length(Trim(infofille[i]))));
     end;
     if (titles.Count > 1) then
     begin
       vidtitle := titles[Random(titles.Count)];
     end else if (titles.Count = 0) then begin
       vidtitle := '#!NONE';
     end else begin
       vidtitle := titles[0];
     end;
     if (descrips.Count > 1) then
     begin
       viddescription := descrips[Random(descrips.Count)];
     end else if (descrips.Count = 0) then begin
       viddescription := '#!NONE';
     end else begin
       viddescription := descrips[0];
     end;
     if (categores.Count > 1) then
     begin
       vidcategory := categores[Random(categores.Count)];
     end else if (categores.Count = 0) then begin
       vidcategory := '#!NONE';
     end else begin
       vidcategory := categores[0];
     end;
     if (tags.Count > 1) then
     begin
       vidtags := tags[Random(tags.Count)];
     end else if (tags.Count = 0) then begin
       vidtags := '#!NONE';
     end else begin
       vidtags := tags[0];
     end;
     FreeAndNil(titles);
     FreeAndNil(descrips);
     FreeAndNil(categores);
     FreeAndNil(tags);
     FreeAndNil(infofille);
    end;
    
    function LoadTheRequatedFile(descstr, thefille: string; addnewlines: boolean): string;
    var
      tmpfille: TStringList;
    
      tmpstr: string;
      ig: integer;
    begin
      if (FileExists(thefille) = False) then
      begin
        writeln('Error: The ' + descstr + ' file does not exist: ' + thefille);
        if (usethehelp = True) then WriteHelp;
        Halt;
      end
      else
      begin
        tmpfille := TStringList.Create;
        tmpfille.LoadFromFile(thefille);
        tmpstr := '';
        for ig := 0 to tmpfille.count - 1 do
        begin
          if (addnewlines = True) then
            tmpstr := tmpstr + Trim(tmpfille[ig]) + #13+#10
          else
           tmpstr := tmpstr + Trim(tmpfille[ig]) + ' ';
        end;
        FreeAndNil(tmpfille);
        if (Trim(tmpstr) = '') then
        begin
          writeln('Error: The ' + descstr + ' file is empty: ' + thefille);
          if (usethehelp = True) then WriteHelp;
          Halt;
        end
      end;
      result := Trim(tmpstr);
    end;
    
    function SaveAllThisToFile(errmessage, savfoldr, thistosave: string): string;
    var
      myFile : TextFile;
      newfile: string;
    begin
      repeat
        newfile := savfoldr + '/error-' + MakeRandomString + '.txt';
      until (FileExists(newfile) = False);
      
      AssignFile(myFile, newfile);
      ReWrite(myFile);
      WriteLn(myFile, errmessage + #13+#10);
      WriteLn(myFile, ' ' + #13+#10);
      WriteLn(myFile, thistosave);
      CloseFile(myFile);
      result := newfile;
    end;
    
    begin
      for i := 0 to ParamCount do
      begin
        if (ParamStr(i)='-h') then
        begin
          WriteHelp;
          Halt;
        end;
        if (ParamStr(i)='-infohelp') then
        begin
          WriteInfoHelp;
          Halt;
        end;
        if (ParamStr(i)='-v') then
        begin
          beverbose := True;
        end;
        if (ParamStr(i)='-nh') then
        begin
          usethehelp := False;
        end;
      end;
    
      tmpstrlst := TStringList.create;
      usernamep := Trim(GetCmdLineArg('u', ['-']));
      passwordp := Trim(GetCmdLineArg('p', ['-']));
      thevideop := Trim(GetCmdLineArg('vp', ['-']));
      infofilep := Trim(GetCmdLineArg('inf', ['-']));
      vidtitle    := Trim(GetCmdLineArg('t', ['-']));
      viddescription  := Trim(GetCmdLineArg('d', ['-']));
      vidcategory := Trim(GetCmdLineArg('vc', ['-']));
        if (pos('@', vidcategory) = 1) then
          vidcategory := LoadTheRequatedFile('Category', Copy(Trim(vidcategory), 2, Length(Trim(vidcategory))), False);
      vcategory := TellMeCatagory;
      vidtags     := Trim(GetCmdLineArg('tg', ['-']));
      proxyport := Trim(GetCmdLineArg('px', ['-']));
      proxytype := Trim(GetCmdLineArg('pt', ['-']));
      
      if (FileExists(thevideop) = False) then
      begin
        writeln('Error: The file does not exist: ' + thevideop);
        if (usethehelp = True) then WriteHelp;
        Halt;
      end;
      
      if (infofilep = '') then
      begin
        if (vidtitle = '') or (viddescription = '') or (vcategory = '') or (vidtags = '') then
        begin
        if (vidtitle = '')  then writeln('Error: Title is blank');
        if (viddescription = '')  then writeln('Error: Description is blank');
        if (vcategory = '')  then writeln('Error: Video Category is blank');
        if (vidtags = '')  then writeln('Error: Tag is blank');
        if (vidtitle = '') and (viddescription = '') and (vcategory = '') and (vidtags = '') and (infofilep = '') then
        writeln('Error: You have to supply the info file or the seperate items. See the help.');
        if (usethehelp = True) then WriteHelp;
        Halt;
        end
        else
        begin
          if (pos('@', viddescription) = 1) then
          begin
            viddescription := Copy(Trim(viddescription), 2, Length(Trim(viddescription)));
            viddescription := LoadTheRequatedFile('Description', viddescription, True);
          end;
          if (pos('@', vidtitle) = 1) then
          begin
            vidtitle := Copy(Trim(vidtitle), 2, Length(Trim(vidtitle)));
            vidtitle := LoadTheRequatedFile('Title', vidtitle, False);
          end;
          if (pos('@', vidtags) = 1) then
          begin
            vidtags := Copy(Trim(vidtags), 2, Length(Trim(vidtags)));
            vidtags := LoadTheRequatedFile('Tag', vidtags, False);
          end;
        end;
      end
      else if (FileExists(infofilep) = False) then
      begin
        writeln('Error: The file does not exist: ' + infofilep);
        if (usethehelp = True) then WriteHelp;
        Halt;
      end;
      
    
      if not (proxyport = '') then
      begin
        if (proxytype = '') then
        begin
          writeln('Error: You have to supply the proxy type.');
          if (usethehelp = True) then WriteHelp;
          Halt;
        end;
        aproxytype := '9';
        if (LowerCase(proxytype) = 'http') then
          aproxytype := '2';
        if (LowerCase(proxytype) = 'socks4') then
          aproxytype := '4';
        if (LowerCase(proxytype) = 'socks5') then
          aproxytype := '5';
        if (aproxytype = '9') then
        begin
          writeln('Error: Unknown proxy type ', proxytype, ' use only http, socks4 or socks5');
          if (usethehelp = True) then WriteHelp;
          Halt;
        end;
        aproxy := proxyport;
      end;
      
      if (pos('google=', usernamep) > 0) then
      begin
        usernamep := Copy(Trim(usernamep), Length('google=')+1, Length(Trim(usernamep)));
        isgoogle := True;
      end;
    
      if (beverbose = True) then writeln('Username:    ' + usernamep);
      if (beverbose = True) then writeln('Password:    ' + passwordp);
      if (beverbose = True) and (isgoogle = True) then writeln('              Google login');
      if (beverbose = True) then writeln('Video:       ' + thevideop);
      if not (infofilep = '') then
      begin
        if (beverbose = True) then writeln('Info:        ' + infofilep);
        LoadInfoFile(infofilep);
      end;
      
      if (vidtitle <> '#!NONE') and (viddescription <> '#!NONE') and (vidcategory <> '#!NONE') and (vidtags <> '#!NONE') then
      begin
        if (beverbose = True) then writeln('Title:       ' + vidtitle);
        if (beverbose = True) then writeln('Description: ' + viddescription);
        if (beverbose = True) then writeln('Category:    ' + vidcategory + '(' + TellMeCatagory + ')');
        if (beverbose = True) then writeln('Tags:        ' + vidtags);
      end
      else
      begin
        if (vidtitle = '#!NONE') then writeln('Error: Title is blank');
        if (viddescription = '#!NONE') then writeln('Error: Description is blank');
        if (vidcategory = '#!NONE') then writeln('Error: #! Video Category is blank');
        if (vidtags = '#!NONE') then writeln('Error: Tag is blank');
        if (usethehelp = True) then WriteHelp;
        Halt;
      end;
    
      if (beverbose = True) and (aproxytype <> '0') then
      begin
        if (aproxytype = '2') then
          writeln('Proxy:       ' + aproxy);
        if (aproxytype = '4') then
          writeln('Socks4:      ' + aproxy);
        if (aproxytype = '5') then
          writeln('Socks5:      ' + aproxy);
      end;
    
      workfolder := Trim(GetEnvironmentVariable('HOME')) + '/' + appdirname;
      if DirectoryExists(workfolder) = False then
      begin
        CreateDir(workfolder);
      end;
      
      repeat
        cookiesflli := workfolder + '/cookie-' + MakeRandomString + '.txt';
      until (FileExists(cookiesflli) = False);
    
      savtafille := workfolder + '/thesavtafille.txt';
      loggedin := 'NO';
      
      if (isgoogle = True) then
      begin
        if (beverbose = True) then writeln('Logging in through Google');
        durle := 'https://www.google.com/accounts/ServiceLoginAuth?service=youtube';
        reffer := 'https://www.google.com/accounts/ServiceLogin?service=youtube&hl=en_US&passive=true&continue=http%3A//www.youtube.com/signup%3Fhl%3Den_US%26next%3D/';
        formdata := 'continue=http%3A%2F%2Fwww.youtube.com%2Fsignup%3Fhl%3Den_US%26next%3D%2F&service=youtube&hl=en_US&Email='+ usernamep + '&Passwd='+ passwordp + '&PersistentCookie=yes&rmShown=1&signIn=Sign+in&asts=';
        if (FileExists(savtafille)) then DeleteFile(savtafille);
        getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 30, 0);
        if (FileExists(savtafille)) then
        begin
          tmpstrlst.Clear;
          tmpstrlst.LoadFromFile(savtafille);
          getback := '';
          for ig := 0 to tmpstrlst.Count - 1 do
            getback := getback + tmpstrlst[ig];
            
        DeleteFile(savtafille);
        end;
        if (pos('language="javascript">    location.replace("', getback) <> 0) then
        begin
          durle := Copy(getback, pos('language="javascript">    location.replace("', getback) + Length('language="javascript">    location.replace("'), Length(getback));
          durle := Copy(durle, 1, pos('")  </script><', durle)-1);
          durle := StringReplace(durle, '\x3d', '=', [rfReplaceAll, rfIgnoreCase]);
          durle := StringReplace(durle, '\x26next=/\x26', '&', [rfReplaceAll, rfIgnoreCase]);
          reffer := 'https://www.google.com/accounts/ServiceLoginAuth?service=youtube';
          formdata := '';
          if (FileExists(savtafille)) then DeleteFile(savtafille);
          getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 30, 0);
          if (FileExists(savtafille)) then DeleteFile(savtafille);
        end
        else
        begin
          writeln('Error: check your usernameand/or password.');
          if FileExists(cookiesflli) then DeleteFile(cookiesflli);
          Halt;
        end;
      end
      else
      begin
        if (beverbose = True) then writeln('Logging in');
        durle := 'http://www.youtube.com/login?next=/';
        reffer := 'http://www.youtube.com/login?next=/';
        formdata := 'next=/&username='+ usernamep + '&password='+ passwordp + '&action_login=Log In';
        if (FileExists(savtafille)) then DeleteFile(savtafille);
        getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 30, 0);
        if (FileExists(savtafille)) then
        begin
          tmpstrlst.Clear;
          tmpstrlst.LoadFromFile(savtafille);
          getback := '';
          for ig := 0 to tmpstrlst.Count - 1 do
            getback := getback + tmpstrlst[ig];
            
        DeleteFile(savtafille);
        end;
        getback := StringReplace(getback, '''', '', [rfReplaceAll, rfIgnoreCase]);
        if (pos('UtilLinks/Channel);">' + usernamep + '</a>', getback) <> 0) then loggedin := 'YES';
        if (pos('Sorry, your login was incorrect.', getback) <> 0) then
        begin
          writeln('Error: Sorry, your login was incorrect.');
          if FileExists(cookiesflli) then DeleteFile(cookiesflli);
          Halt;
        end;
        if (pos('Please check your username.', getback) <> 0) then
        begin
          writeln('Error: Please check your username.');
          if FileExists(cookiesflli) then DeleteFile(cookiesflli);
          Halt;
        end;
      end;
      
      if not (loggedin = 'YES') then
      begin
        writeln('Error: reply saved to ' + SaveAllThisToFile('Error after login', workfolder, getback));
        if FileExists(cookiesflli) then DeleteFile(cookiesflli);
        Halt;
      end;
    
      sessiontken := '';
      if (beverbose = True) then writeln('Getting session token');
      durle := 'http://www.youtube.com/my_videos_upload';
      reffer := 'http://www.youtube.com/';
      formdata := '';
      if (FileExists(savtafille)) then DeleteFile(savtafille);
      getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 30, 0);
      if (FileExists(savtafille)) then
        begin
          tmpstrlst.Clear;
          tmpstrlst.LoadFromFile(savtafille);
          getback := '';
          for ig := 0 to tmpstrlst.Count - 1 do
            getback := getback + tmpstrlst[ig];
            
        DeleteFile(savtafille);
        end;
      
      sessiontken := GiveMeTheSessionToken(getback);
      
      if (sessiontken = '') then
      begin
        writeln('Error: no sessiontoken, reply saved to ' + SaveAllThisToFile('Error: no sessiontoken', workfolder, getback));
        if FileExists(cookiesflli) then DeleteFile(cookiesflli);
        Halt;
      end;
        
      
      if (beverbose = True) then writeln('Getting upload server');
      durle := 'http://www.youtube.com/my_videos_upload';
      reffer := 'http://www.youtube.com/my_videos_upload';
      formdata := '--form-string "field_myvideo_title=' + vidtitle + '" ';
      formdata := formdata + '--form-string "field_myvideo_descr=' + viddescription + '" ';
      formdata := formdata + '--form-string "language=EN" ';
      formdata := formdata + '--form-string "field_myvideo_categories=' + TellMeCatagory + '" ';
      formdata := formdata + '--form-string "field_myvideo_keywords=' + vidtags + '" ';
      formdata := formdata + '--form-string "ignore_broadcast_settings=0" ';
      formdata := formdata + '--form-string "field_privacy=public" ';
      formdata := formdata + '--form-string "field_date_mon=0" ';
      formdata := formdata + '--form-string "field_date_day=0" ';
      formdata := formdata + '--form-string "field_date_yr=0" ';
      formdata := formdata + '--form-string "location=" ';
      formdata := formdata + '--form-string "allow_comments=Yes" ';
      formdata := formdata + '--form-string "allow_comment_ratings=Yes" ';
      formdata := formdata + '--form-string "allow_responses=Yes" ';
      formdata := formdata + '--form-string "allow_ratings=Yes" ';
      formdata := formdata + '--form-string "allow_embedding=Yes" ';
      formdata := formdata + '--form-string "allow_syndication=Yes" ';
      formdata := formdata + '--form-string "action_upload=Upload a video..." ';
      formdata := formdata + '--form-string "session_token=' + sessiontken + '" ';
      if (FileExists(savtafille)) then DeleteFile(savtafille);
      getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 30, 0);
      if (FileExists(savtafille)) then
      begin
        tmpstrlst.Clear;
        tmpstrlst.LoadFromFile(savtafille);
        getback := '';
        for ig := 0 to tmpstrlst.Count - 1 do
          getback := getback + tmpstrlst[ig];
            
      DeleteFile(savtafille);
      end;
      
      sessiontken := '';
      
      sessiontken := GiveMeTheAddresserToken(getback);
      
      if (sessiontken = '') then
      begin
        writeln('Error: no sessiontoken, reply saved to ' + SaveAllThisToFile('Error: no sessiontoken after Getting upload server',  workfolder, getback));
        if FileExists(cookiesflli) then DeleteFile(cookiesflli);
        Halt;
      end;
      
      aserver := '';
      
      aserver := GiveMeTheServer(getback);
      
      if (aserver = '') then
      begin
        writeln('Error: no aserver, reply saved to ' + SaveAllThisToFile('Error: no aserver', workfolder, getback));
        if FileExists(cookiesflli) then DeleteFile(cookiesflli);
        Halt;
      end;
    
      if (beverbose = True) then writeln('Uploading video');
      durle := aserver;
      reffer := 'http://www.youtube.com/my_videos_upload';
      formdata := '-F "[email protected]' + thevideop + ';type=video/x-msvideo" ';
      formdata := formdata + '--form-string "field_command=myvideo_submit" ';
      formdata := formdata + '--form-string "field_myvideo_keywords=' + vidtags + '" ';
      formdata := formdata + '--form-string "field_myvideo_title=' + vidtitle + '" ';
      formdata := formdata + '--form-string "field_myvideo_descr=' + viddescription + '" ';
      formdata := formdata + '--form-string "field_myvideo_categories=' + TellMeCatagory + '" ';
      formdata := formdata + '--form-string "language=EN" ';
      formdata := formdata + '--form-string "field_privacy=public" ';
      formdata := formdata + '--form-string "field_private_share_entities=" ';
      formdata := formdata + '--form-string "addresser=' + sessiontken + '" '; // see if this is the session token....or should i look for it
      formdata := formdata + '--form-string "contact=" ';
      formdata := formdata + '--form-string "field_date_day=0" ';
      formdata := formdata + '--form-string "field_date_yr=0" ';
      formdata := formdata + '--form-string "field_date_mon=0" ';
      formdata := formdata + '--form-string "location=" ';
      formdata := formdata + '--form-string "allow_comments=Yes" ';
      formdata := formdata + '--form-string "allow_comment_ratings=Yes" ';
      formdata := formdata + '--form-string "allow_responses=Yes" ';
      formdata := formdata + '--form-string "allow_embedding=Yes" ';
      formdata := formdata + '--form-string "allow_offweb=" ';
      formdata := formdata + '--form-string "allow_ratings=Yes" ';
      formdata := formdata + '--form-string "allow_syndication=Yes" ';
      if (FileExists(savtafille)) then DeleteFile(savtafille);
      getback := MycUrl.DoTheCurl(durle, cUrlLocation, cookiesflli, reffer, formdata, aproxytype, aproxy, savtafille, 30, 600, 0);
      if (FileExists(savtafille)) then
      begin
        tmpstrlst.Clear;
        tmpstrlst.LoadFromFile(savtafille);
        getback := '';
        for ig := 0 to tmpstrlst.Count - 1 do
          getback := getback + tmpstrlst[ig];
            
      DeleteFile(savtafille);
      end;
      
      if (beverbose = True) then writeln('Finished');
      
      getbackurl := '';
      
      getbackurl := GiveMeTheVideoUrl(getback);
      
      if (getbackurl = '') then
      begin
        writeln('Error: no url, reply saved to ' + SaveAllThisToFile('Error: no url', workfolder, getback));
        if FileExists(cookiesflli) then DeleteFile(cookiesflli);
        Halt;
      end;
      
      writeln('File Url: ' + getbackurl);
      if FileExists(cookiesflli) then DeleteFile(cookiesflli);
    end.
    
    Save this as "nusecurl.pas"
    Code:
    unit nusecurl;
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, Process, SysUtils;
      
    type
      AbuseCurl = class
      private
        { private declarations }
      public
        function DoTheCurl(URL, curlpath, cookyfile, repherer, postvarstr, proxytype, proxieport, fillename: string; conntimeout, jobtimeout, index: integer) : string;
        function NexecuteProgram(execstr: string) : string;
      end;
    
    implementation
    
    function AbuseCurl.DoTheCurl(URL, curlpath, cookyfile, repherer, postvarstr, proxytype, proxieport, fillename: string; conntimeout, jobtimeout, index: integer) : string;
    var
      headers: string;
    begin
      headers := curlpath + ' ';
      
      headers := headers + '--header "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" ';
      headers := headers + '--header "Accept-Language: en-us,en;q=0.5" ';
      headers := headers + '--header "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" ';
      if (postvarstr <> '') and (pos('-F ', postvarstr) = 1) then
      begin
        headers := headers + '--header "Keep-Alive: 300" ';
        headers := headers + '--header "Connection: keep-alive" ';
        headers := headers + '--header "Expect:" ';
      end
      else
      begin
        headers := headers + '--header "Connection: Close" ';
      end;
      if (postvarstr <> '') and ((pos('--form-string ', postvarstr) = 1) or (pos('-F ', postvarstr) = 1)) then
        headers := headers + '--header "Content-Type: multipart/form-data" ';
        
      headers := headers + '--user-agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11" ';
      if (repherer <> '') then
        headers := headers + '--referer "' + repherer + '" ';
            
      if (proxytype = '4') then
        headers := headers + '--socks4 "' + proxieport + '" ';
      if (proxytype = '5') then
        headers := headers + '--socks5 "' + proxieport + '" ';
      if (proxytype = '2') then
        headers := headers + '--proxy "' + proxieport + '" ';
            
      headers := headers + '--connect-timeout "' + inttostr(conntimeout) + '" ';
      headers := headers + '--max-time "' + inttostr(jobtimeout) + '" ';
      headers := headers + '--insecure ';
      headers := headers + '--location ';
      headers := headers + '--compressed ';
      headers := headers + '--cookie "' + cookyfile + '" ';
      headers := headers + '--cookie-jar "' + cookyfile + '" ';
          
      if not (postvarstr = '') then
      begin
        if (pos('--form-string ', postvarstr) = 1) or (pos('-F ', postvarstr) = 1) then
          headers := headers + postvarstr
        else
          headers := headers + '--data "' + postvarstr + '" ';
      end;
          
      if not (fillename = '') then
      begin
        headers := headers + '--output "' + fillename + '" ';
        headers := headers + '--write-out "' + fillename + '" ';
      end;
      
      headers := headers + '--url "' + URL + '"';
    //  writeln(headers);
      result := NexecuteProgram(headers);
    end;
    
    function AbuseCurl.NexecuteProgram(execstr: string) : string;
    const
      READ_BYTES = 2048;
    var
      S: TStringList;
      M: TMemoryStream;
      P: TProcess;
      n: LongInt;
      BytesRead: LongInt;
      GiveBack: string;
    begin
      M := TMemoryStream.Create;
      BytesRead := 0;
      GiveBack := '';
      P := TProcess.Create(nil);
      P.CommandLine := execstr;
      P.Options := [poUsePipes];
      P.Execute;
      while P.Running do
      begin
        M.SetSize(BytesRead + READ_BYTES);
        n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
        if n > 0 then
        begin
          Inc(BytesRead, n);
        end
        else
        begin
          Sleep(100);
        end;
      end;
      repeat
        M.SetSize(BytesRead + READ_BYTES);
        n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
        if n > 0 then
        begin
          Inc(BytesRead, n);
        end;
       until n <= 0;
       M.SetSize(BytesRead);
       S := TStringList.Create;
       S.LoadFromStream(M);
       for n := 0 to S.Count - 1 do
       begin
         GiveBack := GiveBack +S[n];
       end;
       S.Free;
       P.Free;
       M.Free;
       result := GiveBack;
    end;
    
    end.
    
     
    • Thanks Thanks x 1