Einzelnen Beitrag anzeigen

GeMo

Registriert seit: 25. Jan 2006
80 Beiträge
 
Delphi 7 Professional
 
#7

AW: Problem mit Indy und der Rapidshare-Api

  Alt 27. Dez 2010, 21:55
@Rollstuhlfahrer:
Das war schon so gewollt
Habe das zwar jetzt geändert, aber das hatte den einfachen Grund das man die Links viel einfacher mit einer Stringlist verwalten kann anschliessend..

Allerdings verstehe ich immernoch nicht so ganz, warum das alles mit Indy nicht funktioniert (bzw nicht richtig), jedoch mit URLDownloadToFile...

Habs jetzt vorerst so gelöst:
Delphi-Quellcode:
function TMainForm.myHTTPGet(const URL : String):String;
const
  Chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
  FileName : string;
  i, N: integer;
  TMPFilePath : String;
  myFile : TextFile;
begin
  // ZUFÄLLIGER DATEINAME
  Randomize;
  FileName := '';
  for i := 1 to 12 do begin
    N := Random(Length(Chars)) + 1;
    FileName := FileName + Chars[N];
  end;
  // Datei resetten, falls vorhanden, sonst erstellen
  TMPFilePath := getTempDir + FileName + '.ttt';
  AssignFile(myFile, TMPFilePath);
  Rewrite(myFile);
  closeFile(myFile);
  // RS-API Download
  URLDownloadToFile(nil,PChar(URL),PChar(TMPFilePath), 0, nil);
  // EINLESEN
  Reset(myFile);
  while not Eof(myFile) do
  begin
    ReadLn(myFile, Result);
  end;
  closeFile(myfile);
  // DATEI LÖSCHEN
  DeleteFile(TMPFilePath);
end;
Delphi-Quellcode:
procedure TMainForm.parseLinks(x : String);
var
  y : String;
  i, j : Integer;
  errorCount : Integer;
  origList : TStringList;
  newList : TList;
  url, httpAnswer : String;
  nowLink : TRSLink;
  inList : Boolean;
begin
  // AUSLESEN DER LINKS
  origList := TStringList.Create;
  x := StringReplace(x, #13, ' ', [rfReplaceAll, rfIgnoreCase]);
  x := StringReplace(x, #10, '', [rfReplaceAll, rfIgnoreCase]);
  x := x + ' ';
  errorCount := 0;

  origList.DelimitedText := x;

  for i := origList.Count - 1 downto 0 do
  begin
    if(pos('rapidshare.com/files/', origList.Strings[i]) < 1) then
    begin
      origList.Delete(i);
    end;
  end;

  newList := TList.Create;
  ////////////////////////////////////////
  // LINKS BEARBEITEN
  ////////////////////////////////////////
  for i := 0 to origList.Count - 1 do
  begin
    Application.ProcessMessages;
    nowLink := TRSLink.create;
    nowLink.URL := origList.Strings[i];
    x := nowLink.URL;
    x := copy(x, pos('//', x) + 2, length(x));
    x := copy(x, pos('/', x) + 1, length(x));
    x := copy(x, pos('/', x) + 1, length(x));
    y := copy(x, pos('/', x) + 1, length(x));
    x := copy(x, 0, pos('/', x) - 1);
    nowLink.FileID := x;
    nowLink.FileName := y;

    ////////////////////////////////////////
    // RS.COM API - HOSTNAMEN ABRUFEN
    ////////////////////////////////////////
    Application.ProcessMessages;
    URL := API_LINK + 'sub=checkfiles';
    URL := URL + '&files=' + nowLink.FileID;
    URL := URL + '&filenames=' + nowLink.FileName;

    // Dateistatus abfragen...
    httpAnswer := '';
    httpAnswer := myHTTPGet(URL);

    // ... und verarbeiten
    if(pos('ERROR:', httpAnswer) < 1) then
    begin
      // SIZE IN BYTES
      httpAnswer := copy(httpAnswer, pos(',', httpAnswer) + 1, length(httpAnswer));
      httpAnswer := copy(httpAnswer, pos(',', httpAnswer) + 1, length(httpAnswer));
      nowlink.SizeInBytes := StrToInt(copy(httpAnswer, 0, pos(',', httpAnswer) - 1));
      httpAnswer := copy(httpAnswer, pos(',', httpAnswer) + 1, length(httpAnswer));
      // SERVER-ID
      nowlink.ServerID := copy(httpAnswer, 0, pos(',', httpAnswer) - 1);
      httpAnswer := copy(httpAnswer, pos(',', httpAnswer) + 1, length(httpAnswer));
      // STATUS
      nowlink.Status := StrToInt(copy(httpAnswer, 0, pos(',', httpAnswer) - 1));
      httpAnswer := copy(httpAnswer, pos(',', httpAnswer) + 1, length(httpAnswer));
      // SHORT HOST
      nowlink.ShortHost := copy(httpAnswer, 0, pos(',', httpAnswer) - 1);

      // STATUS AUSGABE
      case nowlink.Status of
        0 : nowlink.StatusStr := ARR_FileStatus[0];
        1 : nowlink.StatusStr := ARR_FileStatus[1];
        3 : nowlink.StatusStr := ARR_FileStatus[2];
        4 : nowlink.StatusStr := ARR_FileStatus[3];
        5 : nowlink.StatusStr := ARR_FileStatus[3];
        50..99 : nowlink.StatusStr := ARR_FileStatus[1];
        100..200: nowlink.StatusStr := ARR_FileStatus[1];
        else nowlink.StatusStr := ARR_FileStatus[5];
      end;
      nowlink.Percent := 0;
      newList.Add(nowLink);
    end
    else
    begin
      inc(errorCount);
    end;
    L_Status.Caption := 'Status: getting Fileinfo... ' + IntToStr(i + 1) + ' / ' + IntToStr(origList.Count);
    L_Status.Caption := L_Status.Caption + ' - Errors: ' + IntToStr(errorCount);
  end;

  for i := 0 to newList.Count - 1 do
  begin
    nowlink := TRSLink(newList.Items[i]);
    inList := false;
    for j := 0 to ARR_Links.Count - 1 do
    begin
      if(nowlink.URL = TRSLink(ARR_Links.Items[j]).URL) then
      begin
        inList := true;
        break;
      end;
    end;
    if(inList = false) then
    begin
      ARR_Links.Add(TRSLink(newList.Items[i]));
    end;
  end;

  ////////////////////////////////////////
  // FREIGABE
  ////////////////////////////////////////
  newList.Free;
  origList.Free;
end;

Delphi-Quellcode:
procedure TMainform.DecryptRSDFFile(FilePath : String);
var
  Stream : TIdMultiPartFormDataStream;
  httpAnswer, new, url : String;
begin
  Stream := TIdMultiPartFormDataStream.Create;
  try
    try
      URL := 'http://wirpo032.bplaced.net/rsdf/rsdf_decrypt.php';
      idHTTP.Request.ContentType := 'multipart/form-data';
      Stream.AddFile('rsdffile', FilePath, 'multipart/form-data');
      httpAnswer := idHTTP.Post(URL, Stream);
    except
      on E:Exception do
      begin
        E.Message := 'Error parsing RSDF-File!' + #13#10 + URL + #13#10 + E.Message;
        raise;
      end;
    end;
    Application.ProcessMessages;
    httpAnswer := httpAnswer + #13;
    new := httpAnswer;
    new := StringReplace(new, '<br>', #13, [rfReplaceAll, rfIgnoreCase]);
    parseLinks(new);
    RefreshDLList();
  finally
    Stream.Free;
  end;
end;
Wenn jemandem noch eine Lösung zu dem Problem einfällt, dann darf er sich gerne melden
  Mit Zitat antworten Zitat