AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Problem mit Indy und der Rapidshare-Api
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit Indy und der Rapidshare-Api

Ein Thema von GeMo · begonnen am 27. Dez 2010 · letzter Beitrag vom 20. Feb 2011
Antwort Antwort
GeMo

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

AW: Problem mit Indy und der Rapidshare-Api

  Alt 27. Dez 2010, 19:56
So... ein wenig weiter bin ich nun gekommen.
Ich habe jetzt den "Indy.get" mal einfach durch ein URLDownloadToFile ersetzt und es ausprobiert.

Delphi-Quellcode:

var
myFile : TextFile;
URL : String;
PathToTempFile : String;
httpAnswer : String;
begin
    // Dateistatus abfragen...
    httpAnswer := '';
    URLDownloadToFile(nil,PChar(URL),PChar(PathToTempFile),0,nil);
    AssignFile(myFile, PathToTempFile);
    Reset(myFile);
    while not Eof(myFile) do
    begin
      ReadLn(myFile, httpAnswer);
    end;
    closefile(myfile);
end;
Komischerweise funktioniert eben dieser Code, nicht jedoch der "Indy.get(URL)"...

Weiss da vielleicht jemand rat? Ich finde es eher unschön immer eine temporäre Datei zu erzeugen...
  Mit Zitat antworten Zitat
Benutzerbild von rollstuhlfahrer
rollstuhlfahrer

Registriert seit: 1. Aug 2007
Ort: Ludwigshafen am Rhein
1.529 Beiträge
 
Delphi 7 Professional
 
#2

AW: Problem mit Indy und der Rapidshare-Api

  Alt 27. Dez 2010, 21:19
habs: du parst nicht richtig:
new := StringReplace(new, '<br>', ' ', [rfReplaceAll, rfIgnoreCase]); Wolltest du das <br> nicht weghaben? - Oder wolltest du das Leerzeichen jetzt doch wirklich haben?

Bernhard
Bernhard
Iliacos intra muros peccatur et extra!
  Mit Zitat antworten Zitat
GeMo

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

AW: Problem mit Indy und der Rapidshare-Api

  Alt 27. Dez 2010, 22: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
Benutzerbild von geskill
geskill

Registriert seit: 17. Feb 2007
Ort: NRW
420 Beiträge
 
Delphi 2010 Professional
 
#4

AW: Problem mit Indy und der Rapidshare-Api

  Alt 20. Feb 2011, 21:51
Hi,
bei URLDownloadToFile werden noch andere Werte bei Request gesetzt, die man bei Indy erst manuell setzen muss sprich der Rapidshare Server denkt, du bist ein Bot

Delphi-Quellcode:
with IdHTTP do
begin
  Request.Accept := 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1';
  Request.AcceptCharSet := 'iso-8859-1, utf-8, utf-16, *;q=0.1';
  Request.AcceptEncoding := 'deflate, gzip, identity, *;q=0';
  Request.Connection := 'Keep-Alive';
  Request.ContentType := 'application/x-www-form-urlencoded';
  Request.UserAgent := 'Opera/9.80 (Windows NT 6.1; U; de) Presto/2.5.22 Version/10.51'; // Man kann auch den komischen Useragent mit F beginnend nehmen ...
end;
Außerdem würde ich immer noch den Request.Referer setzten.

Ich habe im Anhang mal eine Klasse die von TIdHTTP abgeleitet wird und womit ich dann halt diese "Standardwerte" setzte, außerdem solche Spezialitäten wie CookieManager, gZIP, HTTP-Proxy, SOCKS und SSL... Weil wenn man mehrere Internetabfragen hat lohnt sich sowas

Achja ich habe eine DLL zur Entschlüsselung von allen Containern, sowas würde ich nicht auf einen Server auslagern.

Und ^^ du arbeitest die ganze Zeit mit copy um Informationen aus Strings zu Filter, dafür empfehle ich mit Regulären Ausdrücken zu arbeiten, einmal eingearbeitet und verstanden sparst du Lichtjahre
Angehängte Dateien
Dateityp: pas uIdHTTPHelper.pas (4,1 KB, 23x aufgerufen)
Sebastian

Geändert von geskill (20. Feb 2011 um 21:54 Uhr) Grund: Da habe ich doch glatt was vergessen
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:06 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz