Megaupload API

Behobene Probleme und abgeschlossene Theme
Locked
geskill
Posts: 5
Joined: 13 May 2010 16:51
Megaupload API

Post by geskill »

Hallo,
wenn das Programm Megaupload.com Links überprüft, wird jeder Link einzeln geprüft. Der Hoster hat auch eine API:

post-request:

Code: Select all

http://megaupload.com/mgr_linkcheck.php
Parameter:

Code: Select all

id0=fileid1&
id1=fileid2&
id2=fileid3&
Hier mal ein Beispiel von mir:

Code: Select all

{*******************************************************}
{                                                       }
{       Megaupload.com Delphi API                       }
{       Version 1.0.0.0                                 }
{       Copyright (c) 2010 Sebastian Klatte             }
{                                                       }
{*******************************************************}

unit uMegauploadCom;

interface

uses
  Windows, SysUtils, Classes, Math, HTTPApp, IdHTTP,

  RegExpr,

  uPlugInFileHosterClass,

  uPathUtils;

type
  TMegauploadCom = class(TFileHosterPlugIn)
  public
    function GetName: WideString; override; safecall;
    function CheckSize(AFiles: WideString): Extended; override;
  end;

implementation

{ TMegauploadCom }

function TMegauploadCom.GetName: WideString;
begin
  result := 'Megaupload.com';
end;

function TMegauploadCom.CheckSize(AFiles: WideString): Extended;

  function GetDownloadlinkID(ALink: string): string;
  begin
    with TRegExpr.Create do
      try
        InputString := ALink;
        Expression := 'd=([a-zA-Z0-9]+)';

        if Exec(InputString) then
          result := Match[1];
      finally
        Free;
      end;
  end;

  function GetSizeinMegaBytes(ALinkResult: string): Extended;
  begin
    result := 0;

    with TRegExpr.Create do
      try
        InputString := ALinkResult;
        Expression := 's=(\d+)&';

        if Exec(InputString) then
        begin
          repeat
            result := result + (StrToIntDef(Match[1], 0) / 1048576);
          until not ExecNext;
        end;
      finally
        Free;
      end;
  end;

var
  I: Integer;
  _params, _postreply: TStringStream;
begin
  with TIdHTTP.Create(nil) do
    try
      with TStringList.Create do
        try
          Text := AFiles;

          _params := TStringStream.Create('');
          _postreply := TStringStream.Create('');
          try
            for I := 0 to Count - 1 do
              _params.WriteString('id' + IntToStr(I) + '=' + GetDownloadlinkID(Strings[I]) + '&');

            Request.ContentType := 'application/x-www-form-urlencoded';
            Post('http://megaupload.com/mgr_linkcheck.php', _params, _postreply);

            Text := _postreply.DataString;
          finally
            _postreply.Free;
            _params.Free;
          end;

          result := RoundTo(GetSizeinMegaBytes(Text), -2);
        finally
          Free;
        end;
    finally
      Free;
    end;
end;

end.


User avatar
Hendi
CandiSoft Developer
Posts: 433
Joined: 27 Jul 2008 13:50
Re: Megaupload API

Post by Hendi »

Danke für den Hinweis, habe GetFileInfoMulti für das Plugin implementiert. Kommt später über den Updateserver.


Locked