{*******************************************************}
{ }
{ 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.