Today I saw a post on s8s8. http://www.s8s8.net/forums/index.php?showtopic=13495 is very popular. Everyone uses different languages and scripts to download MM photos on a website, and there is a shell Script, C language, C++, vbs, php, perl, Java and C#, it is a whim. I also wrote a Delphi version, which uses multiple threads, basically not In half an hour, I drew all the thousands of photos, but after reading a few photos, they were all not suitable for children. No wonder those SLs are rushing to the top, of course, I am no exception :)
Complete program code:
//The writing is relatively rough, but it can basically realize the download function, so I can't control that much.
unit GetMM;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP;
const
Url='http://www.sergeaura.net/TGP/'; //The website address of the downloaded image
OffI=192; //Number of directories
OffJ=16; //The maximum number of pictures in each directory
girlPic='C:/girlPic/'; //Path saved locally
//Thread class
type
TGetMM = class(TThread)
PRotected
FMMUrl:string;
FDestPath:string;
FSubJ:string;
procedure Execute;override;
public
constructor Create(MMUrl,DestPath,SubJ:string);
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
IdHTTP1: TIdHTTP;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
Private
{ Private declarations }
RGetMM:TThread;
procedure GetMMThread(MMUrl,DestPath,SubJ:string);
public
{ Public declarations }
end;
var
Form1: TForm1;
Implementation
{$R *.dfm}
//Download process
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
SubI, SubJ, CurUrl, DestPath:string;
strm:TMemoryStream;
Begin
memo1.Lines.Clear;
//Create a directory
if not DirectoryExists(girlPic) then
MkDir(girlPic);
try
strm :=TMemoryStream.Create;
for I:=1 to OffI do
Begin
for j:=1 to OffJ do
Begin
if (i<10) then
SubI:='00'+IntToStr(i)
else if (i>9) and (i<100) then
SubI:='0'+inttostr(i)
else SubI:=inttostr(i);
if (j>9) then
SubJ:=inttostr(j)
else SubJ:='0'+inttostr(j);
CurUrl:=Url+SubI+'/images/';
DestPath:=girlPic+SubI+'/';
if not DirectoryExists(DestPath) then
ForceDirectories(DestPath);
//Use threads, the speed can be increased by more than N times
if CheckBox1.Checked then
Begin
GetMMThread(CurUrl,DestPath,SubJ);
sleep(500);
end else
//No threads are used
Begin
try
strm.Clear;
IdHTTP1.Get(CurUrl+SubJ+'.jpg',strm);
strm.SaveToFile(DestPath+SubJ+'.jpg');
Memo1.Lines.Add(CurUrl+' Download OK !');
strm.Clear;
IdHTTP1.Get(CurUrl+'tn_'+SubJ+'.jpg',strm);
strm.SaveToFile(DestPath+'tn_'+SubJ+'.jpg');
Memo1.Lines.Add(CurUrl+' Download OK !');
except
Memo1.Lines.Add(CurUrl+' Download Error !');
end;
end;
end;
end;
Memo1.Lines.Add('All OK!');
Finally
strm.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Begin
Close;
end;
{ TGetMM }
constructor TGetMM.Create(MMUrl,DestPath,SubJ: string);
Begin
FMMUrl :=MMUrl;
FDestPath :=DestPath;
FSubJ :=SubJ;
inherited Create(False);
end;
procedure TGetMM.Execute;
var
strm:TMemoryStream;
IdGetMM: TIdHTTP;
DestFile:string;
Begin
try
strm :=TMemoryStream.Create;
IdGetMM :=TIdHTTP.Create(nil);
try
DestFile :=FDestPath+FSubJ+'.jpg';
if Not FileExists(DestFile) then
Begin
strm.Clear;
IdGetMM.Get(FMMUrl+FSubJ+'.jpg',strm);
strm.SaveToFile(DestFile);
end;
DestFile :=FDestPath+'tn_'+FSubJ+'.jpg';
if not FileExists(DestFile) then
Begin
strm.Clear;
IdGetMM.Get(FMMUrl+'tn_'+FSubJ+'.jpg',strm);
strm.SaveToFile(DestFile);
end;
except
end;
Finally
strm.Free;
IdGetMM.Free;
end;
end;
procedure TForm1.GetMMThread(MMUrl, DestPath, SubJ: string);
Begin
RGetMM :=TGetMM.Create(MMUrl,DestPath,SubJ);
end;
end.