• R/O
  • SSH
  • HTTPS

instalikes: Commit


Commit MetaInfo

Revision10 (tree)
Zeit2019-11-14 12:15:22
Autorderekwildstar

Log Message

Novos recursos
Uso de dois parâmetros de tempo para aleatorização
Ajustes nas telas
Melhorias de performance

Ändern Zusammenfassung

Diff

--- trunk/prj/InstaLikes.dpr (revision 9)
+++ trunk/prj/InstaLikes.dpr (revision 10)
@@ -2,7 +2,6 @@
22
33 uses
44 {$IFDEF DEBUG}
5-// FastMM4,
65 {$ENDIF }
76 Vcl.Forms,
87 UFORMPrincipal in '..\src\UFORMPrincipal.pas' {FORMPrincipal},
@@ -10,7 +9,8 @@
109 Vcl.Styles,
1110 UDAMOPrincipal in '..\src\UDAMOPrincipal.pas' {DAMOPrincipal: TDataModule},
1211 UFORMStatus in '..\src\UFORMStatus.pas' {FORMStatus},
13- UFORMAddUserParams in '..\src\UFORMAddUserParams.pas' {FORMAddUserParams};
12+ UFORMAddUserParams in '..\src\UFORMAddUserParams.pas' {FORMAddUserParams},
13+ UConfigurations in '..\src\UConfigurations.pas';
1414
1515 {$R *.res}
1616
--- trunk/prj/InstaLikes.dproj (revision 9)
+++ trunk/prj/InstaLikes.dproj (revision 10)
@@ -69,9 +69,9 @@
6969 <DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;svnui;dclRBDBE1925;FireDACADSDriver;rbRIDE1925;vcltouch;vcldb;bindcompfmx;svn;inetdb;KRKOTANotifiersR;rbTC1925;FmxTeeUI;rbIDE1925;fmx;fmxdae;dbexpress;IndyCore;vclx;dsnap;VCLRESTComponents;rbTCUI1925;rbFireDAC1925;PNGComponentsR;rbRTL1925;rbDB1925;vclie;bindengine;DBXMySQLDriver;dclRBFireDAC1925;FireDACMySQLDriver;FireDACCommonODBC;dclRBE1925;rbRCL1925;UIRibbonPackageDR;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;TBGWebCharts;IndySystem;dsnapcon;rbDBE1925;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDACPgDriver;FMXTee;DbxCommonDriver;rbUSER1925;rbDIDE1925;rbADO1925;Tee;rbRest1925;xmlrtl;rbUSERDesign1925;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;rbRAP1925;bindcomp;appanalytics;rbDAD1925;IndyIPClient;rbBDE1925;bindcompvcl;TeeUI;rbCIDE1925;dbxcds;VclSmp;adortl;FireDACConnR;UserControlR;dsnapxml;dclRBADO1925;dbrtl;IndyProtocols;inetdbxpress;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
7070 <DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
7171 <BT_BuildType>Debug</BT_BuildType>
72- <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
7372 <VerInfo_Locale>1033</VerInfo_Locale>
7473 <Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
74+ <Icon_MainIcon>..\res\InstaLikes.ico</Icon_MainIcon>
7575 </PropertyGroup>
7676 <PropertyGroup Condition="'$(Base_Win64)'!=''">
7777 <DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;inetdb;FmxTeeUI;fmx;fmxdae;dbexpress;IndyCore;vclx;dsnap;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACMySQLDriver;FireDACCommonODBC;UIRibbonPackageDR;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;IndySystem;dsnapcon;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDACPgDriver;FMXTee;DbxCommonDriver;Tee;xmlrtl;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;dsnapxml;dbrtl;IndyProtocols;inetdbxpress;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
@@ -84,12 +84,9 @@
8484 <DCC_MapFile>3</DCC_MapFile>
8585 </PropertyGroup>
8686 <PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
87- <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
8887 <VerInfo_Locale>1033</VerInfo_Locale>
89- <Icon_MainIcon>..\res\icons8-heart-health-96.ico</Icon_MainIcon>
90- <UWP_DelphiLogo44>..\res\icons8-heart-health-96.png</UWP_DelphiLogo44>
88+ <Icon_MainIcon>..\res\InstaLikes.ico</Icon_MainIcon>
9189 <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
92- <UWP_DelphiLogo150>..\res\icons8-heart-health-96.png</UWP_DelphiLogo150>
9390 <AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode>
9491 </PropertyGroup>
9592 <PropertyGroup Condition="'$(Cfg_2)'!=''">
@@ -100,9 +97,9 @@
10097 </PropertyGroup>
10198 <PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
10299 <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
103- <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
104100 <VerInfo_Locale>1033</VerInfo_Locale>
105101 <AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode>
102+ <Icon_MainIcon>..\res\InstaLikes.ico</Icon_MainIcon>
106103 </PropertyGroup>
107104 <ItemGroup>
108105 <DelphiCompile Include="$(MainSource)">
@@ -121,6 +118,7 @@
121118 <DCCReference Include="..\src\UFORMAddUserParams.pas">
122119 <Form>FORMAddUserParams</Form>
123120 </DCCReference>
121+ <DCCReference Include="..\src\UConfigurations.pas"/>
124122 <BuildConfiguration Include="Release">
125123 <Key>Cfg_2</Key>
126124 <CfgParent>Base</CfgParent>
@@ -153,9 +151,16 @@
153151 <Overwrite>true</Overwrite>
154152 </Platform>
155153 </DeployFile>
156- <DeployFile LocalName="..\res\icons8-heart-health-96.png" Configuration="Debug" Class="UWP_DelphiLogo44">
154+ <DeployFile LocalName="$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png" Configuration="Debug" Class="UWP_DelphiLogo150">
157155 <Platform Name="Win32">
158156 <RemoteDir>Assets\</RemoteDir>
157+ <RemoteName>Logo150x150.png</RemoteName>
158+ <Overwrite>true</Overwrite>
159+ </Platform>
160+ </DeployFile>
161+ <DeployFile LocalName="$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png" Configuration="Debug" Class="UWP_DelphiLogo44">
162+ <Platform Name="Win32">
163+ <RemoteDir>Assets\</RemoteDir>
159164 <RemoteName>Logo44x44.png</RemoteName>
160165 <Overwrite>true</Overwrite>
161166 </Platform>
--- trunk/src/UConfigurations.pas (nonexistent)
+++ trunk/src/UConfigurations.pas (revision 10)
@@ -0,0 +1,44 @@
1+unit UConfigurations;
2+
3+interface
4+
5+uses
6+ KRK.Lib.Rtl.Common.Classes;
7+
8+type
9+ TConfigurations = class(TObjectFile)
10+ private
11+ FMinimumWaitSeconds: Word;
12+ FMaximumWaitSeconds: Word;
13+ public
14+ constructor Create; reintroduce;
15+ published
16+ property MinimumWaitSeconds: Word read FMinimumWaitSeconds write FMinimumWaitSeconds default 30;
17+ property MaximumWaitSeconds: Word read FMaximumWaitSeconds write FMaximumWaitSeconds default 120;
18+ end;
19+
20+var
21+ Configurations: TConfigurations;
22+
23+implementation
24+
25+uses
26+ System.SysUtils;
27+
28+{ TConfigurations }
29+
30+constructor TConfigurations.Create;
31+begin
32+ inherited Create(nil,asmText);
33+ FMinimumWaitSeconds := 30;
34+ FMaximumWaitSeconds := 120;
35+ LoadFromTextFile(ChangeFileExt(ParamStr(0),'.dat'));
36+end;
37+
38+initialization
39+ Configurations := TConfigurations.Create;
40+
41+finalization
42+ Configurations.Free;
43+
44+end.
--- trunk/src/UDAMOPrincipal.pas (revision 9)
+++ trunk/src/UDAMOPrincipal.pas (revision 10)
@@ -130,7 +130,6 @@
130130 { Private declarations }
131131 FRequestsSoFar: Cardinal;
132132 FQueryHash: String;
133- FWaitSeconds: Byte;
134133 FAddFollowersParams: TAddFollowersParams;
135134 FRolloutHash: String;
136135 FCSRFToken: String;
@@ -137,8 +136,8 @@
137136 FLoggedUser: TInstagramUser;
138137 FStopProcessing: Boolean;
139138 function UserExists(AUserName: String): Boolean;
140- procedure LoadProfilePicture(AUserId: String; APictureURL: String; AImage: TImage);
141- procedure DownloadProfilePicture(AUserId: String; APictureURL: String);
139+ procedure LoadProfilePicture(AUserId: String; APictureURL: String; AImage: TImage; AForceUpdateCache: Boolean = False);
140+ procedure DownloadProfilePicture(APictureURL: String; AUserId: String; AImage: TImage);
142141 procedure UpdateRequestsSoFar;
143142 function ParseSharedData(AResponse: TStringStream; out ASharedData: TJSONObject): Boolean;
144143 function ParseFollowersPage(AResponse: TStringStream; out AFollowersData: TJSONObject): Boolean;
@@ -162,19 +161,23 @@
162161 function LikeMedia(AMediaId: String; ALike: Boolean = True): Boolean;
163162 procedure GetFollowersPage(AUserId: String; var ANextPageToken: String; out AInstagramUsers: TInstagramUsers; out ATotalFollowers: Cardinal; AUsersPerPage: Byte = 50);
164163 // Obtém os dados atualizados do usuário, atualizando também as últimas
165- // mídias do mesmo!
166- procedure UpdateUser(const AUserName: String); overload;
164+ // mídias do mesmo! Este método atua no usuário selecionado no grid do form
165+ // principal
166+ procedure UpdateUser; overload;
167167 procedure AddFollowers(const AUserId: String; AParams: TAddFollowersParams);
168168 public
169169 { Public declarations }
170170 procedure ConfigureErrorHint(ATitle, AText: String; AWinControl: TWinControl; AShowHint: Boolean);
171- function Login(AUserName, APassword: String; out AInstagramUser: TInstagramUser): Boolean;
172- function UserInfo(AUserName: String; var AInstagramUser: TInstagramUser): Boolean;
171+ function Login(AUserName, APassword: String): Boolean;
172+ function GetUserInfo(AUserName: String; var AInstagramUser: TInstagramUser): Boolean;
173173 procedure Wait; { isso é gambi }
174174 function GetLoggedUser(out AInstagramUser: TInstagramUser): Boolean;
175175 function Logout: Boolean;
176- procedure ConnectSQLite;
177- property WaitSeconds: Byte write FWaitSeconds;
176+ procedure ConnectToDatabase;
177+ procedure DisplayLoggedUserImage;
178+ procedure LoadConfigurations;
179+ procedure SaveConfigurations;
180+
178181 property LoggedUser: TInstagramUser read FLoggedUser write FLoggedUser;
179182 end;
180183
@@ -187,10 +190,14 @@
187190 KRK.Lib.Rtl.Win.WinInet.Utilities, Windows, WinInet,
188191 KRK.Lib.RegExp.Utils, NetEncoding, System.RegularExpressionsCore,
189192 UFORMPrincipal, jpeg, KRK.Lib.Vcl.Forms.FormBlender,
190- UFORMStatus, UFORMAddUserParams, System.Generics.Collections;
193+ UFORMStatus, UFORMAddUserParams, System.Generics.Collections, Math,
194+ UConfigurations;
191195
192196 {%CLASSGROUP 'Vcl.Controls.TControl'}
193197
198+const
199+ USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 OPR/64.0.3417.92';
200+
194201 {$R *.dfm}
195202
196203 function TDAMOPrincipal.AddUser(const AInstagramUser: TInstagramUser; const AFollowingId: String = ''): Boolean;
@@ -338,8 +345,7 @@
338345
339346 procedure TDAMOPrincipal.ACTNUpdateUserExecute(Sender: TObject);
340347 begin
341- if (FDTAUser.State = dsBrowse) and (FDTAUser.RecordCount > 0) then
342- UpdateUser(FDTAUserusername.AsString);
348+ UpdateUser;
343349 end;
344350
345351 procedure TDAMOPrincipal.AddUser(const AUserName: String; const AFollowingId: String = '');
@@ -361,7 +367,7 @@
361367 FS.BUTNCancel.Hide;
362368 FS.Update;
363369 // - /////////////////////////////////////////////////////////////////////
364- if UserInfo(AUserName,IU) then
370+ if GetUserInfo(AUserName,IU) then
365371 AddUser(IU,AFollowingId);
366372 // - /////////////////////////////////////////////////////////////////////
367373 finally
@@ -388,7 +394,7 @@
388394 end;
389395 end;
390396
391-procedure TDAMOPrincipal.ConnectSQLite;
397+procedure TDAMOPrincipal.ConnectToDatabase;
392398 begin
393399 FDCO.Connected := True;
394400 FDTAUser.Open;
@@ -396,17 +402,29 @@
396402 FDTAFollowers.Open;
397403 end;
398404
399-procedure TDAMOPrincipal.LoadProfilePicture(AUserId: String; APictureURL: String; AImage: TImage);
405+procedure TDAMOPrincipal.LoadConfigurations;
400406 begin
401- if not FileExists(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg') then
402- DownloadProfilePicture(AUserId,APictureURL);
407+ FORMPrincipal.LAEDMinimumWait.Text := Configurations.MinimumWaitSeconds.ToString;
408+ FORMPrincipal.LAEDMaximumWaitInterval.Text := Configurations.MaximumWaitSeconds.ToString;
409+end;
403410
404- AImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg')
411+procedure TDAMOPrincipal.LoadProfilePicture(AUserId: String; APictureURL: String; AImage: TImage; AForceUpdateCache: Boolean = False);
412+begin
413+ if AForceUpdateCache or (not FileExists(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg')) then
414+ begin
415+ DownloadProfilePicture(APictureURL,AUserId,AImage);
416+
417+ if not DirectoryExists(ExtractFilePath(ParamStr(0)) + '\cache') then
418+ ForceDirectories(ExtractFilePath(ParamStr(0)) + '\cache');
419+
420+ AImage.Picture.SaveToFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg');
421+ end
422+ else
423+ AImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg')
405424 end;
406425 procedure TDAMOPrincipal.DataModuleCreate(Sender: TObject);
407426 begin
408427 FQueryHash := '56066f031e6239f35a904ac20c9f37d9';
409- FWaitSeconds := 10;
410428 FRequestsSoFar := 0;
411429 end;
412430
@@ -415,12 +433,11 @@
415433 Text := '';
416434 end;
417435
418-procedure TDAMOPrincipal.DownloadProfilePicture(AUserId: String; APictureURL: String);
436+
437+procedure TDAMOPrincipal.DownloadProfilePicture(APictureURL: String; AUserId: String; AImage: TImage);
419438 var
420439 RO: TRequestOptions;
421440 RE: TResponse;
422-// JI: TJPEGImage;
423- IM: TImage;
424441 begin
425442 ZeroMemory(@RO, SizeOf(RO));
426443 ZeroMemory(@RE, SizeOf(RE));
@@ -428,7 +445,7 @@
428445 RO.AutoClearSSLState := True;
429446
430447 { InternetOpen }
431- RO.InternetOpenParams.Agent := 'InstaLikes S2';
448+ RO.InternetOpenParams.Agent := USER_AGENT;
432449 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
433450 { InternetConnect }
434451 RO.InternetConnectParams.Service := INTERNET_SERVICE_HTTP;
@@ -446,27 +463,22 @@
446463 RO.HttpSendRequestParams.IgnoreInvalidCertificateCA := True;
447464 RE.Content := TStringStream.Create('');
448465 try
449- Request(RO, RE);
466+ Screen.Cursor := crHourGlass;
467+ try
468+ Request(RO, RE);
469+ finally
470+ Screen.Cursor := crDefault;
471+ end;
472+
450473 UpdateRequestsSoFar;
451474 RE.Content.Seek(0, soFromBeginning);
452475
453-// JI := TJPEGImage.Create;
454- try
455-// JI.LoadFromStream(RE.Content);
456- IM := TImage.Create(nil);
457- try
458- IM.Picture.LoadFromStream(RE.Content);
476+ AImage.Picture.LoadFromStream(RE.Content);
459477
460- if not DirectoryExists(ExtractFilePath(ParamStr(0)) + '\cache') then
461- ForceDirectories(ExtractFilePath(ParamStr(0)) + '\cache');
462-
463- IM.Picture.SaveToFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg');
464- finally
465- IM.Free;
466- end;
467- finally
468-// JI.Free;
469- end;
478+// if not DirectoryExists(ExtractFilePath(ParamStr(0)) + '\cache') then
479+// ForceDirectories(ExtractFilePath(ParamStr(0)) + '\cache');
480+//
481+// AImage.Picture.SaveToFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg');
470482 finally
471483 RE.Content.Free;
472484 RO.HttpOpenRequestParams.AcceptTypes.Free;
@@ -474,11 +486,73 @@
474486 end;
475487 end;
476488
489+//procedure TDAMOPrincipal.DownloadProfilePicture(AUserId: String; APictureURL: String);
490+//var
491+// RO: TRequestOptions;
492+// RE: TResponse;
493+//// JI: TJPEGImage;
494+// IM: TImage;
495+//begin
496+// ZeroMemory(@RO, SizeOf(RO));
497+// ZeroMemory(@RE, SizeOf(RE));
498+//
499+// RO.AutoClearSSLState := True;
500+//
501+// { InternetOpen }
502+// RO.InternetOpenParams.Agent := 'InstaLikes S2';
503+// RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
504+// { InternetConnect }
505+// RO.InternetConnectParams.Service := INTERNET_SERVICE_HTTP;
506+// RO.InternetConnectParams.ServerName := PChar(APictureURL);
507+// { HttpOpenRequest }
508+// RO.HttpOpenRequestParams.Verb := 'GET';
509+// RO.HttpOpenRequestParams.ConnectTimeout := 30000;
510+// RO.HttpOpenRequestParams.SendTimeout := 30000;
511+// RO.HttpOpenRequestParams.ReceiveTimeout := 30000;
512+// RO.HttpOpenRequestParams.AcceptTypes := TStringList.Create;
513+// RO.HttpOpenRequestParams.AcceptTypes.Text := '*/*';
514+// RO.HttpOpenRequestParams.AutoDetectHTTPS := True;
515+// RO.HttpOpenRequestParams.Flags := INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_PRAGMA_NOCACHE;
516+// { HttpSendRequest }
517+// RO.HttpSendRequestParams.IgnoreInvalidCertificateCA := True;
518+// RE.Content := TStringStream.Create('');
519+// try
520+// Request(RO, RE);
521+// UpdateRequestsSoFar;
522+// RE.Content.Seek(0, soFromBeginning);
523+//
524+//// JI := TJPEGImage.Create;
525+// try
526+//// JI.LoadFromStream(RE.Content);
527+// IM := TImage.Create(nil);
528+// try
529+// IM.Picture.LoadFromStream(RE.Content);
530+//
531+// if not DirectoryExists(ExtractFilePath(ParamStr(0)) + '\cache') then
532+// ForceDirectories(ExtractFilePath(ParamStr(0)) + '\cache');
533+//
534+// IM.Picture.SaveToFile(ExtractFilePath(ParamStr(0)) + '\cache\' + AUserId + '.jpg');
535+// finally
536+// IM.Free;
537+// end;
538+// finally
539+//// JI.Free;
540+// end;
541+// finally
542+// RE.Content.Free;
543+// RO.HttpOpenRequestParams.AcceptTypes.Free;
544+// RO.Content.Free;
545+// end;
546+//end;
547+
548+
477549 procedure TDAMOPrincipal.Wait;
478550 var
479551 NextTick: Cardinal;
480552 begin
481- NextTick := GetTickCount + FWaitSeconds * 1000;
553+ Randomize;
554+
555+ NextTick := GetTickCount + Cardinal(RandomRange(Configurations.MinimumWaitSeconds,Configurations.MaximumWaitSeconds)) * 1000;
482556 while (GetTickCount < NextTick) and (not FStopProcessing) do
483557 Application.ProcessMessages;
484558 end;
@@ -500,7 +574,7 @@
500574 RO.AutoClearSSLState := True;
501575
502576 { InternetOpen }
503- RO.InternetOpenParams.Agent := 'InstaLikes S2';
577+ RO.InternetOpenParams.Agent := USER_AGENT;
504578 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
505579
506580 { InternetConnect }
@@ -536,7 +610,12 @@
536610 // RO.HttpOpenRequestParams.Headers.Add('x-csrftoken: ' + HeaderValue(FCSRFToken));
537611
538612 try
539- Request(RO, RE);
613+ Screen.Cursor := crHourGlass;
614+ try
615+ Request(RO, RE);
616+ finally
617+ Screen.Cursor := crDefault;
618+ end;
540619 UpdateRequestsSoFar;
541620
542621 // ParseSharedData(TStringStream(RE.Content),JO);
@@ -704,7 +783,7 @@
704783 RO.Content := TStringStream.Create('1=1');// Satisfazendo o Krakatoa :)
705784
706785 { InternetOpen }
707- RO.InternetOpenParams.Agent := 'InstaLikes S2';
786+ RO.InternetOpenParams.Agent := USER_AGENT;
708787 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
709788
710789 { InternetConnect }
@@ -731,7 +810,12 @@
731810
732811 RE.Content := TStringStream.Create('');
733812 try
734- Request(RO, RE);
813+ Screen.Cursor := crHourGlass;
814+ try
815+ Request(RO, RE);
816+ finally
817+ Screen.Cursor := crDefault;
818+ end;
735819 UpdateRequestsSoFar;
736820 //ParseSharedData(TStringStream(RE.Content),JO);
737821
@@ -809,7 +893,7 @@
809893 // adicional para obtenção de mais dados sobre o usuário
810894 if UseExtendedFilters then
811895 begin
812- UserInfo(Followers[i].UserName,Followers[i]);
896+ GetUserInfo(Followers[i].UserName,Followers[i]);
813897
814898 case AParams.BusinessAccount of
815899 // Se for para incluir perfis empresariais e o perfil for empresarial, pula
@@ -905,7 +989,7 @@
905989 Result := FDCO.ExecSQLScalar('select count(*) from user where username = :username',[AUserName],[ftString]) <> 0;
906990 end;
907991
908-function TDAMOPrincipal.UserInfo(AUserName: String; var AInstagramUser: TInstagramUser): Boolean;
992+function TDAMOPrincipal.GetUserInfo(AUserName: String; var AInstagramUser: TInstagramUser): Boolean;
909993 var
910994 RO: TRequestOptions;
911995 RE: TResponse;
@@ -923,7 +1007,7 @@
9231007 RO.AutoClearSSLState := True;
9241008
9251009 { InternetOpen }
926- RO.InternetOpenParams.Agent := 'InstaLikes S2';
1010+ RO.InternetOpenParams.Agent := USER_AGENT;
9271011 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
9281012
9291013 { InternetConnect }
@@ -949,7 +1033,12 @@
9491033 RE.Content := TStringStream.Create('');
9501034 try
9511035 try
952- Request(RO, RE);
1036+ Screen.Cursor := crHourGlass;
1037+ try
1038+ Request(RO, RE);
1039+ finally
1040+ Screen.Cursor := crDefault;
1041+ end;
9531042 UpdateRequestsSoFar;
9541043 // ParseSharedData(TStringStream(RE.Content),JO);
9551044
@@ -1158,7 +1247,7 @@
11581247 var
11591248 ME: TMedia;
11601249 begin
1161- if FDCO.ExecSQLScalar('select count(id) from user where id = :id',[AInstagramUser.id],[ftString]) = 1 then
1250+ if (FDTAUser.State = dsBrowse) and (FDTAUser.RecordCount > 0) then
11621251 begin
11631252 FDTAUser.Edit;
11641253 FDTAUserusername.AsString := AInstagramUser.UserName;
@@ -1174,36 +1263,31 @@
11741263 FDTAUser.Post;
11751264
11761265 for ME in AInstagramUser.LastestMedia do
1177- begin
1178- FDTAMedias.Append;
1179- FDTAMediasid.AsString := ME.Id;
1180- FDTAMediasshortcode.AsString := ME.ShortCode;
1181- FDTAMediaswidth.AsInteger := Me.Width;
1182- FDTAMediasheight.AsInteger := ME.Height;
1183- FDTAMediasuserid.AsString := AInstagramUser.id;
1184- FDTAMedias.Post;
1185- end;
1266+ if not FDTAMedias.Locate('id',ME.Id,[]) then
1267+ begin
1268+ FDTAMedias.Append;
1269+ FDTAMediasid.AsString := ME.Id;
1270+ FDTAMediasshortcode.AsString := ME.ShortCode;
1271+ FDTAMediaswidth.AsInteger := Me.Width;
1272+ FDTAMediasheight.AsInteger := ME.Height;
1273+ FDTAMediasuserid.AsString := AInstagramUser.id;
1274+ FDTAMedias.Post;
1275+ end;
11861276 end;
11871277 end;
11881278
1189-procedure TDAMOPrincipal.UpdateUser(const AUserName: String);
1279+procedure TDAMOPrincipal.UpdateUser;
11901280 var
11911281 IU: TInstagramUser;
11921282 begin
1193- if UserExists(AUserName) then
1283+ if (FDTAUser.State = dsBrowse) and (FDTAUser.RecordCount > 0) and GetUserInfo(FDTAUserusername.AsString,IU) then
11941284 begin
1195- if UserInfo(AUserName,IU) then
1196- begin
1197- UpdateUser(IU);
1198- DownloadProfilePicture(IU.id,IU.PictureURL);
1199-
1200- FDTAUser.Refresh;
1201- FDTAFollowers.Refresh;
1202- FDTAMedias.Refresh;
1203- end;
1204- end
1205- else
1206- raise Exception.Create('User does not exist!');
1285+ UpdateUser(IU);
1286+ LoadProfilePicture(IU.id,IU.PictureURL,FORMPrincipal.IMAGProfile,True);
1287+ FDTAUser.Refresh;
1288+ FDTAFollowers.Refresh;
1289+ FDTAMedias.Refresh;
1290+ end;
12071291 end;
12081292
12091293 // Todas as chamadas que usam JSON sabem quem é o usuário que está executando a
@@ -1222,7 +1306,7 @@
12221306 RO.AutoClearSSLState := True;
12231307
12241308 { InternetOpen }
1225- RO.InternetOpenParams.Agent := 'InstaLikes S2';
1309+ RO.InternetOpenParams.Agent := USER_AGENT;
12261310 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
12271311
12281312 { InternetConnect }
@@ -1244,7 +1328,12 @@
12441328
12451329 RE.Content := TStringStream.Create('');
12461330 try
1247- Request(RO, RE);
1331+ Screen.Cursor := crHourGlass;
1332+ try
1333+ Request(RO, RE);
1334+ finally
1335+ Screen.Cursor := crDefault;
1336+ end;
12481337 UpdateRequestsSoFar;
12491338 // Precisa UpdateHeaders porque esta função é usada ao iniciar o programa
12501339 // para pegar os cabeçalhos de quem estiver logado
@@ -1317,7 +1406,7 @@
13171406 RO.Content := TStringStream.Create('1=1');// Satisfazendo o Krakatoa :)
13181407
13191408 { InternetOpen }
1320- RO.InternetOpenParams.Agent := 'InstaLikes S2';
1409+ RO.InternetOpenParams.Agent := USER_AGENT;
13211410 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
13221411
13231412 { InternetConnect }
@@ -1347,7 +1436,12 @@
13471436
13481437 RE.Content := TStringStream.Create('');
13491438 try
1350- Request(RO, RE);
1439+ Screen.Cursor := crHourGlass;
1440+ try
1441+ Request(RO, RE);
1442+ finally
1443+ Screen.Cursor := crDefault;
1444+ end;
13511445 UpdateRequestsSoFar;
13521446 // ParseSharedData(TStringStream(RE.Content),JO);
13531447
@@ -1360,13 +1454,18 @@
13601454 end;
13611455 end;
13621456
1363-function TDAMOPrincipal.Login(AUserName: String; APassword: String; out AInstagramUser: TInstagramUser): Boolean;
1457+procedure TDAMOPrincipal.DisplayLoggedUserImage;
1458+begin
1459+ LoadProfilePicture(FLoggedUser.id,FLoggedUser.PictureURL,FORMPrincipal.IMAGUserLogged,True);
1460+end;
1461+
1462+function TDAMOPrincipal.Login(AUserName: String; APassword: String): Boolean;
13641463 var
13651464 RO: TRequestOptions;
13661465 RE: TResponse;
13671466 JO: TJSONObject;
13681467 begin
1369- ZeroMemory(@AInstagramUser,SizeOf(TInstagramUser));
1468+ ZeroMemory(@FLoggedUser,SizeOf(TInstagramUser));
13701469 ZeroMemory(@RO,SizeOf(RO));
13711470 ZeroMemory(@RE,SizeOf(RE));
13721471
@@ -1373,7 +1472,7 @@
13731472 RO.AutoClearSSLState := True;
13741473
13751474 { InternetOpen }
1376- RO.InternetOpenParams.Agent := 'InstaLikes S2';
1475+ RO.InternetOpenParams.Agent := USER_AGENT;
13771476 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
13781477
13791478 { InternetConnect }
@@ -1398,7 +1497,12 @@
13981497 // Acessa a página inicial deslogado e obtém alguns headers ================
13991498 RO.InternetConnectParams.ServerName := 'https://www.instagram.com';
14001499 RO.HttpOpenRequestParams.Verb := 'GET';
1401- Request(RO, RE);
1500+ Screen.Cursor := crHourGlass;
1501+ try
1502+ Request(RO, RE);
1503+ finally
1504+ Screen.Cursor := crDefault;
1505+ end;
14021506 UpdateRequestsSoFar;
14031507 //ParseResponseHeaders(RE.Headers);
14041508 ParseSharedData(TStringStream(RE.Content),JO); // Só precisa disso para preencher configurar FRolloutHash e FCSRFToken
@@ -1416,11 +1520,16 @@
14161520 // RO.HttpOpenRequestParams.Headers.Add('x-csrftoken: ' + HeaderValue(FCSRFToken));
14171521 RO.Content := TStringStream.Create('username=' + AUserName +'&password=' + APassword + '&queryParams=%7B%7D');
14181522
1419- Request(RO,RE);
1523+ Screen.Cursor := crHourGlass;
1524+ try
1525+ Request(RO, RE);
1526+ finally
1527+ Screen.Cursor := crDefault;
1528+ end;
14201529 UpdateRequestsSoFar;
14211530 //ParseSharedData(TStringStream(RE.Content),JO);
14221531
1423- Result := ParseLoginResult(TStringStream(RE.Content),AInstagramUser);
1532+ Result := ParseLoginResult(TStringStream(RE.Content),FLoggedUser);
14241533 finally
14251534 RE.Content.Free;
14261535 RO.HttpOpenRequestParams.Headers.Free;
@@ -1442,7 +1551,7 @@
14421551 RO.Content := TStringStream.Create('csrfmiddlewaretoken=' + FCSRFToken);
14431552
14441553 { InternetOpen }
1445- RO.InternetOpenParams.Agent := 'InstaLikes S2';
1554+ RO.InternetOpenParams.Agent := USER_AGENT;
14461555 RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
14471556
14481557 { InternetConnect }
@@ -1474,12 +1583,20 @@
14741583
14751584 RE.Content := TStringStream.Create('');
14761585 try
1477- Request(RO, RE);
1586+ Screen.Cursor := crHourGlass;
1587+ try
1588+ Request(RO, RE);
1589+ finally
1590+ Screen.Cursor := crDefault;
1591+ end;
14781592 UpdateRequestsSoFar;
14791593 //ParseResponseHeaders(RE.Headers);
14801594 //ParseSharedData(TStringStream(RE.Content),JO);
14811595 Result := not GetLoggedUser(Dummy);
14821596
1597+ if Result then
1598+ ZeroMemory(@FLoggedUser,SizeOf(TInstagramUser));
1599+
14831600 // Limpa os valores dos headers principais! Tem que ser depois de
14841601 // LoggedUser, porque esta função preenche novamente estas duas variáveis
14851602 FRolloutHash := '';
@@ -1506,7 +1623,7 @@
15061623 // RO.AutoClearSSLState := True;
15071624 //
15081625 // { InternetOpen }
1509-// RO.InternetOpenParams.Agent := 'InstaLikes S2';
1626+// RO.InternetOpenParams.Agent := USER_AGENT;
15101627 // RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG;
15111628 //
15121629 // { InternetConnect }
@@ -1567,6 +1684,13 @@
15671684 // end;
15681685 //end;
15691686
1687+procedure TDAMOPrincipal.SaveConfigurations;
1688+begin
1689+ Configurations.MinimumWaitSeconds := StrToIntDef(FORMPrincipal.LAEDMinimumWait.Text,30);
1690+ Configurations.MaximumWaitSeconds := StrToIntDef(FORMPrincipal.LAEDMaximumWaitInterval.Text,120);
1691+ Configurations.Save;
1692+end;
1693+
15701694 procedure TDAMOPrincipal.SelectFollowers(AUserId: String; AKRKDBGrid: TKRKDBGrid);
15711695 var
15721696 BM: TBookmark;
--- trunk/src/UFORMPrincipal.pas (revision 9)
+++ trunk/src/UFORMPrincipal.pas (revision 10)
@@ -13,12 +13,9 @@
1313 TFORMPrincipal = class(TForm)
1414 PACO1: TPageControl;
1515 TASHLogado: TTabSheet;
16- LABEUserName: TLabel;
17- LABERealName: TLabel;
18- LABEId: TLabel;
19- LABEBiography: TLabel;
20- LABEProfilePicURL: TLabel;
21- BUTNLogout: TButton;
16+ LABEUserNameValue: TLabel;
17+ LABERealNameValue: TLabel;
18+ LABEUserIdValue: TLabel;
2219 TASHAbout: TTabSheet;
2320 IMAGAbout: TImage;
2421 IMAGAbout2: TImage;
@@ -29,13 +26,10 @@
2926 GRBXAddUser: TGroupBox;
3027 EDITProfile: TEdit;
3128 PNGSAddUser: TPngSpeedButton;
32- LAEDWait: TLabeledEdit;
3329 DBMOBiography: TDBMemo;
3430 DBTXFollowers: TDBText;
3531 DBTXFollowing: TDBText;
3632 DBTXMedia: TDBText;
37- STTE1: TStaticText;
38- BUTNAtivarBanco: TButton;
3933 GRBXLocateUser: TGroupBox;
4034 EDITLocateUser: TEdit;
4135 IMAGProfile: TImage;
@@ -52,13 +46,27 @@
5246 STBAMedias: TStatusBar;
5347 PANLMedias: TPanel;
5448 LABE2: TLabel;
49+ TASHLogin: TTabSheet;
50+ LAEDUserName: TLabeledEdit;
51+ LAEDPassword: TLabeledEdit;
52+ LABEUserId: TLabel;
53+ PANEImageLoggedUser: TPanel;
54+ IMAGUserLogged: TImage;
55+ LABEUserName: TLabel;
56+ LABERealName: TLabel;
57+ MEMOBiography: TMemo;
58+ PNSBLogar: TPngSpeedButton;
59+ PNSBLogout: TPngSpeedButton;
60+ LABEAbout2: TLabel;
61+ LABEAbout1: TLabel;
62+ LABEAbout0: TLabel;
63+ LABEVersion: TLabel;
5564 TASHConfigurations: TTabSheet;
56- LAEDUserName1: TLabeledEdit;
57- LAEDPassword: TLabeledEdit;
58- BUTNLogar: TButton;
59- procedure BUTNLogarClick(Sender: TObject);
65+ LAEDMinimumWait: TLabeledEdit;
66+ LAEDMaximumWaitInterval: TLabeledEdit;
67+ procedure PNSBLogarClick(Sender: TObject);
6068 procedure FormShow(Sender: TObject);
61- procedure BUTNLogoutClick(Sender: TObject);
69+ procedure PNSBLogoutClick(Sender: TObject);
6270 procedure FormCreate(Sender: TObject);
6371 procedure FormDestroy(Sender: TObject);
6472 procedure KRDGUserDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
@@ -66,9 +74,11 @@
6674 procedure LocateUser(Sender: TObject);
6775 procedure KRDGUserAfterMultiselect(aSender: TObject; aMultiSelectEventTrigger: TMultiSelectEventTrigger);
6876 procedure KRDGMediasDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
69- procedure LAEDWaitChange(Sender: TObject);
77+ procedure TASHConfigurationsHide(Sender: TObject);
78+ procedure TASHConfigurationsShow(Sender: TObject);
7079 private
7180 { Private declarations }
81+ procedure AdjustTabsVisibility;
7282 public
7383 { Public declarations }
7484 procedure UpdateUserSelectCount;
@@ -86,6 +96,14 @@
8696
8797 { TForm1 }
8898
99+procedure TFORMPrincipal.AdjustTabsVisibility;
100+begin
101+ TASHLogado.TabVisible := DAMOPrincipal.LoggedUser.id <> '';
102+ TASHUser.TabVisible := TASHLogado.TabVisible;
103+ TASHConfigurations.TabVisible := TASHLogado.TabVisible;
104+ TASHLogin.TabVisible := not TASHLogado.TabVisible;
105+end;
106+
89107 procedure TFORMPrincipal.EDITProfileKeyPress(Sender: TObject; var Key: Char);
90108 begin
91109 if Key = #13 then
@@ -92,39 +110,44 @@
92110 PNGSAddUser.Click;
93111 end;
94112
95-procedure TFORMPrincipal.BUTNLogarClick(Sender: TObject);
96-var
97- IU: TInstagramUser;
113+procedure TFORMPrincipal.PNSBLogarClick(Sender: TObject);
98114 begin
99- TASHLogado.TabVisible := DAMOPrincipal.Login(LAEDUserName1.Text,LAEDPassword.Text, IU);
100- TASHUser.TabVisible := TASHLogado.TabVisible;
101- TASHConfigurations.TabVisible := not TASHLogado.TabVisible;
102- DAMOPrincipal.LoggedUser := IU;
115+ if DAMOPrincipal.Login(LAEDUserName.Text,LAEDPassword.Text) then
116+ begin
117+ AdjustTabsVisibility;
103118
104- if TASHLogado.TabVisible then
105- begin
106- LABEId.Caption := DAMOPrincipal.LoggedUser.id;
107- LABEUserName.Caption := DAMOPrincipal.LoggedUser.UserName;
108- LABERealName.Caption := DAMOPrincipal.LoggedUser.RealName;
109- LABEBiography.Caption := DAMOPrincipal.LoggedUser.Biography;
110- LABEProfilePicURL.Caption := DAMOPrincipal.LoggedUser.PictureURL;
119+ if TASHLogado.TabVisible then
120+ begin
121+ LABEUserIdValue.Caption := DAMOPrincipal.LoggedUser.id;
122+ LABEUserNameValue.Caption := '@' + DAMOPrincipal.LoggedUser.UserName;
123+ LABERealNameValue.Caption := DAMOPrincipal.LoggedUser.RealName;
124+ MEMOBiography.Text := DAMOPrincipal.LoggedUser.Biography;
125+ DAMOPrincipal.DisplayLoggedUserImage;
126+ end;
111127 end;
112128 end;
113129
114-procedure TFORMPrincipal.BUTNLogoutClick(Sender: TObject);
130+procedure TFORMPrincipal.PNSBLogoutClick(Sender: TObject);
115131 begin
116- TASHLogado.TabVisible := not DAMOPrincipal.Logout;
117- TASHUser.TabVisible := TASHLogado.TabVisible;
118- TASHConfigurations.TabVisible := not TASHLogado.TabVisible;
119-
120- if TASHLogado.TabVisible then
132+ if DAMOPrincipal.Logout then
133+ AdjustTabsVisibility
134+ else
121135 Application.MessageBox('Não foi possível deslogar','Algo errado não está certo',MB_ICONERROR);
122136 end;
123137
138+procedure TFORMPrincipal.TASHConfigurationsHide(Sender: TObject);
139+begin
140+ DAMOPrincipal.SaveConfigurations;
141+end;
142+
143+procedure TFORMPrincipal.TASHConfigurationsShow(Sender: TObject);
144+begin
145+ DAMOPrincipal.LoadConfigurations;
146+end;
147+
124148 procedure TFORMPrincipal.FormCreate(Sender: TObject);
125149 begin
126- DAMOPrincipal.WaitSeconds := StrToInt(LAEDWait.Text);
127- DAMOPrincipal.ConnectSQLite;
150+ DAMOPrincipal.ConnectToDatabase;
128151 end;
129152
130153 procedure TFORMPrincipal.FormDestroy(Sender: TObject);
@@ -140,16 +163,16 @@
140163 // automaticamente!
141164 TASHLogado.TabVisible := DAMOPrincipal.GetLoggedUser(IU);
142165 TASHUser.TabVisible := TASHLogado.TabVisible;
143- TASHConfigurations.TabVisible := not TASHLogado.TabVisible;
166+ TASHLogin.TabVisible := not TASHLogado.TabVisible;
144167 DAMOPrincipal.LoggedUser := IU;
145168
146169 if TASHLogado.TabVisible then
147170 begin
148- LABEId.Caption := DAMOPrincipal.LoggedUser.id;
149- LABEUserName.Caption := DAMOPrincipal.LoggedUser.UserName;
150- LABERealName.Caption := DAMOPrincipal.LoggedUser.RealName;
151- LABEBiography.Caption := DAMOPrincipal.LoggedUser.Biography;
152- LABEProfilePicURL.Caption := DAMOPrincipal.LoggedUser.PictureURL;
171+ LABEUserIdValue.Caption := DAMOPrincipal.LoggedUser.id;
172+ LABEUserNameValue.Caption := '@' + DAMOPrincipal.LoggedUser.UserName;
173+ LABERealNameValue.Caption := DAMOPrincipal.LoggedUser.RealName;
174+ MEMOBiography.Text := DAMOPrincipal.LoggedUser.Biography;
175+ DAMOPrincipal.DisplayLoggedUserImage;
153176 end;
154177 end;
155178
@@ -195,12 +218,6 @@
195218 end;
196219 end;
197220
198-procedure TFORMPrincipal.LAEDWaitChange(Sender: TObject);
199-begin
200- if Trim(LAEDWait.Text) <> '' then
201- DAMOPrincipal.WaitSeconds := StrToInt(LAEDWait.Text);
202-end;
203-
204221 procedure TFORMPrincipal.LocateUser(Sender: TObject);
205222 begin
206223 DAMOPrincipal.FDTAUser.Locate('username',EDITLocateUser.Text,[loPartialKey,loCaseInsensitive]);
Show on old repository browser