This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDumpItBlue-Process.plw
3287 lines (3186 loc) · 137 KB
/
DumpItBlue-Process.plw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# Perl - v: 5.16.3
#------------------------------------------------------------------------------#
# DumpItBlue-Process.plw : DumpItBlue process for Dump functions
# WebSite : http://le-tools.com/DumpItBlue.html
# Documentation : http://le-tools.com/DumpItBlueDoc.html
# SourceForge : https://sourceforge.net/p/dumpitblue
# GitHub : https://github.com/arioux/DumpItBlue
# Creation : 2015-08-01
# Modified : 2019-05-26
my $VERSION = '7.0.2';
# Author : Alain Rioux (admin@le-tools.com)
#
# Copyright (C) 2015-2018 Alain Rioux (le-tools.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Modules
#------------------------------------------------------------------------------#
use strict;
use warnings;
use threads;
use threads::shared;
use utf8;
use arybase;
use Encode qw(encode decode);
use DBI;
use Time::Local;
use Time::HiRes qw(usleep);
use DateTime;
use DateTime::Format::Strptime;
use Excel::Writer::XLSX;
use File::Copy::Recursive qw(rcopy);
use File::Path qw(remove_tree);
use URI::Escape::JavaScript qw(unescape);
use HTML::DOM;
use HTML::Entities;
use Log::Log4perl qw(:easy);
use Future::HTTP::Tiny;
use Chrome::DevToolsProtocol::Transport::AnyEvent;
use WWW::Mechanize::Chrome;
use Image::Info qw(image_info dim);
use Win32::API();
use Win32::GUI();
use Win32::GUI qw( WS_POPUP WS_CAPTION WS_THICKFRAME WS_EX_TOPMOST );
use Win32::GUI::BitmapInline();
use Win32::Process;
require "DumpItBlue-LoadGraph.pl";
require "DumpItBlueLang.pl";
#------------------------------------------------------------------------------#
# Global variables
#------------------------------------------------------------------------------#
my $REF_ARG = \@ARGV; # Parameters
my $PROCNAME = $$REF_ARG[0]; # Process Name (ex.: DumpAlbums)
my $PROCID = $$REF_ARG[1]; # Process ID
my $PROGDIR = $$REF_ARG[2]; # Program directory
my $USERDIR = $$REF_ARG[3]; # User path
my $LANG_FILE = "$USERDIR\\Lang.ini"; # Langage file
my $DEBUG_FILE = "$USERDIR\\debug.log"; # Log for error
my %STR; # Strings for GUI
my $ARROW :shared; # Arrow pointer
my $HOURGLASS :shared; # Hourglass pointer
my $THR; # Thread
#------------------------------------------------------------------------------#
# Graphic elements
#------------------------------------------------------------------------------#
my ($winICO, $logoBmp, $albumBmp, $friendsBmp, $contribBmp, $browseBmp, $explorerBmp,
$refresh16) = &loadGraph();
#------------------------------------------------------------------------------#
# Strings
#------------------------------------------------------------------------------#
&loadDefaultStr(\%STR); # Load default language (en)
&loadStr(\%STR, $LANG_FILE) if -e $LANG_FILE and -T $LANG_FILE; # If language file, load translated strings
#------------------------------------------------------------------------------#
# Windows utils
#------------------------------------------------------------------------------#
my $screen = Win32::GUI::GetDesktopWindow(); # Screen resolution
my $scrnX = Win32::GUI::Width($screen);
my $scrnY = Win32::GUI::Height($screen);
# Fonts
sub LOGPIXELSX() {88}
sub getDPI { return(Win32::GUI::DC->new()->GetDeviceCaps(LOGPIXELSX)); }
my $DPI = &getDPI();
my $fontGB;
my $fontGB2;
my $font8;
my $font10;
my $font10t;
# Larger size (125% and 150%)
if ($DPI >= 120) {
$fontGB = new Win32::GUI::Font(-name => 'Arial', -size => 10, -bold => 1);
$fontGB2 = new Win32::GUI::Font(-name => 'Arial', -size => 10, -bold => 1, -underline => 1);
$font8 = new Win32::GUI::Font(-name => 'Arial', -size => 6);
$font10 = new Win32::GUI::Font(-name => 'Arial', -size => 8);
$font10t = new Win32::GUI::Font(-name => 'Arial', -size => 8, -underline => 1);
# Normal size
} else {
$fontGB = new Win32::GUI::Font(-name => 'Arial', -size => 12, -bold => 1);
$fontGB2 = new Win32::GUI::Font(-name => 'Arial', -size => 12, -bold => 1, -underline => 1);
$font8 = new Win32::GUI::Font(-name => 'Arial', -size => 8);
$font10 = new Win32::GUI::Font(-name => 'Arial', -size => 10);
$font10t = new Win32::GUI::Font(-name => 'Arial', -size => 10, -underline => 1);
}
# Load Pointers
my $loadImage = new Win32::API('user32', 'LoadImage', ['N','N','I','I','I','I'],'N');
$HOURGLASS = $loadImage->Call(0, 32514, 2, 0, 0, 0x8040);
$ARROW = $loadImage->Call(0, 32512, 2, 0, 0, 0x8040);
# Logo
my $WIN_LOGO;
if ($PROCNAME eq 'DumpAlbums' ) { $WIN_LOGO = $albumBmp; }
elsif ($PROCNAME eq 'DumpFriends' ) { $WIN_LOGO = $friendsBmp; }
elsif ($PROCNAME eq 'DumpMutualFriends') { $WIN_LOGO = $friendsBmp; }
elsif ($PROCNAME eq 'DumpContrib' ) { $WIN_LOGO = $friendsBmp; }
elsif ($PROCNAME eq 'DumpComments' ) { $WIN_LOGO = $contribBmp; }
elsif ($PROCNAME eq 'DumpGroupMembers' ) { $WIN_LOGO = $friendsBmp; }
#------------------------------------------------------------------------------#
# Progress window
#------------------------------------------------------------------------------#
my $winWidth = 740;
my $winHeight = 180;
my $winPosX = ($scrnX - $winWidth) / 2;
my $winPosY = ($scrnY - $winHeight) / 2;
my $winPb = Win32::GUI::DialogBox->new( -name => 'winPb' ,
-text => $STR{'Progress'} ,
-pos => [$winPosX, $winPosY] ,
-size => [$winWidth, $winHeight],
-background => [255, 255, 255] ,
-hasmaximize => 0 ,
-hasminimize => 1 ,
-helpbutton => 0 ,
-resizable => 0 ,
-topmost => 1 ,
-dialogui => 1 , );
$winPb->SetIcon($winICO);
$winPb->AddLabel( -name => 'lblLogo' ,
-size => [128,128] ,
-pos => [ 0, 10] ,
-bitmap => $WIN_LOGO ,
-background => [255, 255, 255] , );
$winPb->AddLabel( -name => 'lblPbCurr1' ,
-size => [578, 22] ,
-pos => [140, 8] ,
-font => $font10 ,
-truncate => 1 ,
-background => [255, 255, 255] ,
-foreground => [ 0, 0, 102] , );
$winPb->AddProgressBar( -name => 'pbWinPb1' ,
-size => [470, 22] ,
-pos => [140, 32] ,
-smooth => 1 , );
$winPb->AddLabel( -name => 'lblCount1' ,
-size => [100, 22] ,
-pos => [620, 33] ,
-font => $font10 ,
-truncate => 1 ,
-background => [255, 255, 255] ,
-foreground => [ 0, 0, 102] , );
$winPb->AddLabel( -name => 'lblPbCurr2' ,
-size => [578, 22] ,
-pos => [140, 60] ,
-font => $font10 ,
-truncate => 1 ,
-background => [255, 255, 255] ,
-foreground => [ 0, 0, 102] , );
$winPb->AddProgressBar( -name => 'pbWinPb2' ,
-size => [470, 22] ,
-pos => [140, 84] ,
-smooth => 1 , );
$winPb->AddLabel( -name => 'lblCount2' ,
-size => [100, 22] ,
-pos => [620, 85] ,
-font => $font10 ,
-truncate => 1 ,
-background => [255, 255, 255] ,
-foreground => [ 0, 0, 102] , );
$winPb->AddButton( -name => 'btnCancel' ,
-text => $STR{'Cancel'} ,
-font => $font10 ,
-size => [ 80, 30] ,
-pos => [330,115] ,
-cancel => 1 , );
#------------------------------------------------------------------------------#
# Splash window
#------------------------------------------------------------------------------#
my $splash = new Win32::GUI::Window ( -name => 'Splash' ,
-text => 'Splash' ,
-size => [128,128] ,
-pos => [100,100] ,
-addstyle => WS_POPUP ,
-popstyle => WS_CAPTION | WS_THICKFRAME,
-addexstyle => WS_EX_TOPMOST , );
$splash->AddLabel( -name => 'Bitmap' ,
-size => [128,128] ,
-pos => [ 0, 0] ,
-bitmap => $WIN_LOGO , );
#------------------------------------------------------------------------------#
# Execute process
#------------------------------------------------------------------------------#
my $dbFile = "$USERDIR\\Queue\\$PROCNAME-$PROCID\.db";
my $dsn = "DBI:SQLite:dbname=$dbFile";
if (-f $dbFile and my $dbh = DBI->connect($dsn, undef, undef, { sqlite_unicode => 1 })) {
# Center the splash and show it
$splash->Center();
$splash->Show();
Win32::GUI::DoEvents();
# Get current infos
my $refInfos;
my $allInfos = $dbh->selectall_arrayref("SELECT key,value FROM INFOS");
foreach (@$allInfos) { $$refInfos{$$_[0]} = $$_[1]; }
$dbh->disconnect;
# Show progress window
$winPb->Center();
if ($$refInfos{silentProgress}) { $winPb->Show(2); }
else { $winPb->Show(); }
eval { my $mech = WWW::Mechanize::Chrome->new(tab => 'current'); };
if ($@) {
my $msgErr = $@;
chomp($msgErr);
$msgErr =~ s/[\t\r\n]/ /g;
&debug($msgErr) if $$refInfos{debugLogging};
Win32::GUI::MessageBox($winPb, $STR{'errChrome'}, $STR{'Error'}, 0x40010);
exit(0);
}
Win32::GUI::DoEvents();
# Hide Splash
$splash->Hide;
# Start the thread
$THR = threads->create(sub {
my $refDbh;
# Thread 'die' signal handler
$SIG{__DIE__} = sub {
my $msgErr = $_[0];
# Ignore some errors
return if ($msgErr =~ /Future\/HTTP\/Tiny\/threaded\.pm/ or $msgErr =~ /\&Errno\:\:(?:EBADMSG|EPROTO)/ or $msgErr =~ /does not map to iso-8859-1/ or
$msgErr =~ /content must be bytes at/ or $msgErr =~ /No node with given id found/ or $msgErr =~ /Could not find node with given id/ or
$msgErr =~ /Node has gone away in the meantime/ or $msgErr =~ /Cannot decode string with wide characters/);
chomp($msgErr);
$msgErr =~ s/[\t\r\n]/ /g;
&debug($msgErr) if $$refInfos{debugLogging};
undef $$refDbh;
$winPb->ChangeCursor($ARROW);
# Progress window
$winPb->pbWinPb2->SetPos(0);
$winPb->lblPbCurr2->Text('');
$winPb->lblCount2->Text('');
my $err = (split(/ at /, $msgErr))[0];
Win32::GUI::MessageBox($winPb, "$STR{'processCrash'}: $err", $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
exit(0); # Exit program
};
$winPb->ChangeCursor($HOURGLASS);
# Connect to database
my $dsn = "DBI:SQLite:dbname=$dbFile";
$$refDbh = DBI->connect($dsn, undef, undef, { AutoCommit => 0, sqlite_unicode => 1 });
# Initiate Chrome connection
my $mech = WWW::Mechanize::Chrome->new(tab => 'current');
# Select appropriate function
if ($PROCNAME eq 'DumpAlbums' ) { &dumpAlbums( \$mech, $refDbh, $dbFile, $refInfos); }
elsif ($PROCNAME eq 'DumpFriends' ) { &dumpFriends( \$mech, $refDbh, $dbFile, $refInfos); }
elsif ($PROCNAME eq 'DumpMutualFriends') { &dumpMutualFriends(\$mech, $refDbh, $dbFile, $refInfos); }
elsif ($PROCNAME eq 'DumpContrib' ) { &dumpContrib( \$mech, $refDbh, $dbFile, $refInfos); }
elsif ($PROCNAME eq 'DumpComments' ) { &dumpComments( \$mech, $refDbh, $dbFile, $refInfos); }
elsif ($PROCNAME eq 'DumpGroupMembers' ) { &dumpGroupMembers( \$mech, $refDbh, $dbFile, $refInfos); }
undef $$refDbh;
unlink($dbFile);
exit(0);
});
# Start GUI
Win32::GUI::Dialog();
} else {
Win32::GUI::MessageBox($winPb, $STR{'warn1'}, $STR{'Error'}, 0x40010);
exit(0);
}
#--------------------------#
sub dumpAlbums
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos, $nbrRetries, $firstExec) = @_;
# Number of album
my $refAllAlbums = $$refDbh->selectall_arrayref('SELECT * FROM ALBUMS');
my $nbrAlbums = scalar(@$refAllAlbums);
my $count1 = 0;
# Turn on progress bar
$winPb->pbWinPb1->SetRange(0, $nbrAlbums);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
&createPicturesDB($refDbh); # Create tables PICTURES
$winPb->Text("$STR{'Dump'} $STR{'Albums'} $STR{'inProgress'}...");
# Process each album
foreach my $entry (@$refAllAlbums) {
# $$refInfos{pageType}: 0 = unknown, 1 = People, 2 = Groups, 3 = Pages (Business)
# $$entry: 0 = Album id, 1 = name, 2 = url, 3 = tmpPage, 4 = path, 5 = step
my $encodedName = encode($$refInfos{charSet}, $$entry[1]);
$winPb->lblPbCurr1->Text("$STR{'Processing'}: $encodedName");
my $sthUpdAlbumStep = $$refDbh->prepare('UPDATE ALBUMS SET step = ? WHERE id = ?');
my $albumStep = $$entry[5];
# Steps:
# 1: Open the album page
# 2: Scroll the album page
# 3: Save the album page
# 4: Parse the album page
# 5: Browse the picture pages (if include publication date, large size picture and/or video have been selected)
# 6: Download the files
# Open the album page
if (!$albumStep) {
$winPb->lblPbCurr2->Text("$STR{'Opening'} $STR{'thePage'}...");
$winPb->lblCount2->Text('');
$winPb->pbWinPb2->SetPos(0);
# Gather album page
$$refMech->get($$entry[2]);
sleep($$refInfos{timeToWait});
$albumStep = 1;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
# Scroll the album page
if ($albumStep == 1) {
$winPb->lblPbCurr2->Text("$STR{'Scrolling'} $STR{'thePage'}...");
if ($$refInfos{pageType} == 1) { &scrollFriendPage($refMech, $$refInfos{timeToWait}); }
else { &scrollPage($refMech, $$refInfos{'timeToWait'}); }
$albumStep = 2;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
# Save the album page
if ($albumStep == 2 or !$$entry[3] or !-T $$entry[3]) {
$winPb->lblPbCurr2->Text("$STR{'Saving'} $STR{'thePage'}...");
# Create the directories
mkdir("$$refInfos{saveDir}\\$$refInfos{filename}")
if !-d "$$refInfos{saveDir}\\$$refInfos{filename}"; # Base directory
my $albumDirName = $encodedName =~ s/[\<\>\:\"\/\\\|\?\*\.]/_/gr;
my $albumsPath = "$$refInfos{saveDir}\\$$refInfos{filename}\\$albumDirName";
mkdir($albumsPath) if !-d $albumsPath; # Directory for album
mkdir($albumsPath.'\temp') if !-d $albumsPath.'\temp'; # Temp directory for album
# Save the current tab in a temp file
my $albumsTmpPage = $albumsPath.'\temp\album_'.$$entry[0].'.html';
open(my $fhCurr, ">:encoding(utf8)", $albumsTmpPage);
print $fhCurr $$refMech->content;
close($fhCurr);
# Update Albums
my $sthUpdAlbum = $$refDbh->prepare('UPDATE ALBUMS SET tmpPage = ?, path = ? WHERE id = ?');
$sthUpdAlbum->execute($albumsTmpPage, $albumsPath, $$entry[0]);
$albumStep = 3;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
# Parse the album page
if ($albumStep == 3) {
$winPb->lblPbCurr2->Text("$STR{'Parsing'} $STR{'thePage'}...");
&parseAlbumPage($refMech, $refDbh, $refInfos, $$entry[0]);
$albumStep = 4;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
# Download the files
my $nbrAlbumPics = $$refDbh->selectrow_array('SELECT COUNT(ind) FROM PICTURES WHERE album = ?', undef, $$entry[0]);
my $albumPath = $$refDbh->selectrow_array('SELECT path FROM ALBUMS WHERE id = ?' , undef, $$entry[0]);
if ($albumStep == 4 and $nbrAlbumPics) {
if ($$refInfos{incSmallPics} or $$refInfos{incLargePics} or $$refInfos{incPublishDate}) {
$winPb->lblPbCurr2->Text("$STR{'Downloading'} $STR{'pictures'}...");
&dlAlbumFiles($refMech, $refDbh, $refInfos, $$entry[0], $albumPath);
$albumStep = 6;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
} else {
$albumStep = 6;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
}
# Album has been processed
if ($albumStep == 6) {
$winPb->lblPbCurr2->Text("$STR{'Finishing'}...");
# Delete temporary files
remove_tree($albumPath.'\temp') if -d $albumPath.'\temp' and $$refInfos{delTempFiles};
$albumStep = 7;
$sthUpdAlbumStep->execute($albumStep, $$entry[0]);
$$refDbh->commit();
}
# Progress
$count1++;
$winPb->pbWinPb1->StepIt();
$winPb->lblCount1->Text("$count1/$nbrAlbums");
$winPb->pbWinPb2->SetPos(0);
$winPb->lblPbCurr2->Text('');
$winPb->lblCount2->Text('');
}
$winPb->pbWinPb1->SetPos(0);
$winPb->lblCount1->Text('');
# Create Report
my $filename;
if ($$refInfos{reportFormat} eq 'HTML') { $filename = &createAlbumReportHTML($refDbh, $refInfos); }
elsif ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createAlbumReportXLSX($refDbh, $refInfos); }
else { $filename = &createAlbumReportTXT( $refDbh, $refInfos); }
$winPb->ChangeCursor($ARROW);
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
# Open the directory
Win32::Process::Create(my $ProcessObj, "$ENV{'WINDIR'}\\explorer.exe", "explorer $$refInfos{saveDir}", 0, NORMAL_PRIORITY_CLASS, ".")
if $$refInfos{openAlbumDir};
# Warn user about error
if ($$refInfos{incSmallPics} or $$refInfos{incLargePics}) {
my $nbrItems = $$refDbh->selectrow_array('SELECT COUNT(ind) FROM PICTURES');
my $nbrErrors;
$nbrErrors = $$refDbh->selectrow_array('SELECT COUNT(ind) FROM PICTURES WHERE smallPath IS NULL or smallPath = ?', undef, '-')
if $$refInfos{incSmallPics};
$nbrErrors = $$refDbh->selectrow_array('SELECT COUNT(ind) FROM PICTURES WHERE largePath IS NULL or largePath = ?', undef, '-')
if !$nbrErrors and $$refInfos{incLargePics};
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'dumpAlbumError'}, $STR{'Error'}, 0x40010) if $nbrErrors and !$$refInfos{silentProgress};
}
$$refDbh->commit();
$$refDbh->disconnect();
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incSmallPics} or $$refInfos{incLargePics} or $$refInfos{incPublishDate};
} #--- End dumpAlbums
#--------------------------#
sub dumpFriends
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos) = @_;
# Number of Friends categories
my @listCat = split(/\|/,$$refInfos{listCat});
my $nbrCatFriends = scalar(@listCat);
my $count1 = 0;
# Turn on progress bar
$winPb->pbWinPb1->SetRange(0, $nbrCatFriends);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
$winPb->lblPbCurr1->Text('');
&createProfilesDB($refDbh); # Create table PROFILES
$winPb->Text("$STR{'Dump'} $STR{'Friends'} $STR{'inProgress'}...");
# Create image folder
mkdir("$$refInfos{saveDir}\\images_$$refInfos{filename}")
if !-d "$$refInfos{saveDir}\\images_$$refInfos{filename}" and $$refInfos{incIcons};
# Parse each friend category page
$winPb->lblCount1->Text("$count1/$nbrCatFriends");
foreach my $cat (@listCat) {
my $encodedName = encode($$refInfos{charSet}, $cat);
$winPb->lblPbCurr1->Text("$STR{'Processing'}: $encodedName");
# Dump friend category
&dumpFriendCat($refMech, $refDbh, $refInfos, $cat);
# Progress
$count1++;
$winPb->pbWinPb1->StepIt();
$winPb->lblCount1->Text("$count1/$nbrCatFriends");
$winPb->pbWinPb2->SetPos(0);
$winPb->lblPbCurr2->Text('');
$winPb->lblCount2->Text('');
}
# Parsing done, create the report
$winPb->lblPbCurr1->Text("$STR{'Creating'} $STR{'outputFile'}...");
if ($nbrCatFriends) {
# Turn on progress bar
$winPb->lblCount1->Text("0/$nbrCatFriends");
$winPb->pbWinPb1->SetRange(0, $nbrCatFriends);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
# Create and open the XLSX file
my $filename;
if ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createProfilesReportXLSX($refDbh, $refInfos, 1); }
elsif ($$refInfos{reportFormat} eq 'HTML') { $filename = &createProfilesReportHTML($refDbh, $refInfos, 1); }
else { $filename = &createProfilesReportTXT( $refDbh, $refInfos, 1); }
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
} else {
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'noProfileDumped'}, $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
}
$winPb->ChangeCursor($ARROW);
$$refDbh->disconnect();
remove_tree("$$refInfos{saveDir}\\temp") if $$refInfos{delTempFiles};
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incIcons};
} #--- End dumpFriends
#--------------------------#
sub dumpMutualFriends
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos) = @_;
my $count1 = 0;
# Turn on the progress window
&createProfilesDB($refDbh); # Create table PROFILES
my $cat = $STR{'MutualFriends'};
$winPb->Text("$STR{'Dump'} $cat $STR{'inProgress'}...");
# Create folders
mkdir("$$refInfos{saveDir}\\images_$$refInfos{filename}")
if !-d "$$refInfos{saveDir}\\images_$$refInfos{filename}" and $$refInfos{incIcons};
# Dump Mutual Friends page
# Steps:
# 1: Open the page
# 2: Scroll the page
# 3: Save the page
# 4: Parse the page
$winPb->lblPbCurr1->Text("$STR{'Processing'}: $cat");
$$refInfos{groupType} = 1;
$$refInfos{"$STR{'MutualFriends'}-url"} = $$refInfos{startingURL};
# Opening the Group Members Category
if (!exists($$refInfos{"$cat-step"}) or !$$refInfos{"$cat-step"}) {
if ($$refMech->uri() ne $$refInfos{"$cat-url"}) {
$winPb->lblPbCurr2->Text("$STR{'Opening'} $STR{'thePage'}");
$winPb->pbWinPb2->SetPos(0);
$$refMech->get($$refInfos{"$cat-url"});
sleep($$refInfos{timeToWait});
}
$$refInfos{"$cat-step"} = 1;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Scrolling the Group Members Category
if ($$refInfos{"$cat-step"} == 1) {
if ($$refInfos{autoScroll}) {
$winPb->lblPbCurr2->Text("$STR{'Scrolling'} $STR{'thePage'}");
&scrollLikePage($refMech, $$refInfos{timeToWait});
}
$$refInfos{"$cat-step"} = 2;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Saving the Group Members Category
if ($$refInfos{"$cat-step"} == 2) {
$winPb->lblPbCurr2->Text("$STR{'Saving'} $STR{'thePage'}");
# Create the directories
mkdir("$$refInfos{saveDir}\\temp") if !-d "$$refInfos{saveDir}\\temp";
$$refInfos{"$cat-tmpPage"} = "$$refInfos{saveDir}\\temp\\page.html";
open(my $fhCurr, ">:encoding(utf8)", $$refInfos{"$cat-tmpPage"});
print $fhCurr $$refMech->content;
close($fhCurr);
$$refInfos{"$cat-step"} = 3;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Parsing the Group Members Category
if ($$refInfos{"$cat-step"} == 3) {
$winPb->lblPbCurr2->Text("$STR{'Parsing'} $STR{'thePage'}");
&parseMutualFriends($refDbh, $refInfos, $cat);
$$refInfos{"$cat-step"} = 4; # Parsing done
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Download profiles icons
if ($$refInfos{"$cat-step"} == 4) {
if ($$refInfos{incIcons}) { &dlProfilesIcons($refMech, $refDbh, $refInfos, $cat); }
$$refInfos{"$cat-step"} = 5;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Group Members category has been processed
if ($$refInfos{"$cat-step"} == 5) {
$winPb->lblPbCurr2->Text("$STR{'Finishing'}...");
# Delete temporary files
remove_tree("$$refInfos{saveDir}\\$$refInfos{filename}\\temp")
if -d "$$refInfos{saveDir}\\$$refInfos{filename}\\temp" and $$refInfos{delTempFiles};
$$refInfos{"$cat-step"} = 5;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Parsing done, create the report
$winPb->lblPbCurr1->Text("$STR{'Creating'} $STR{'outputFile'}...");
my $nbrMutualFriends = $$refDbh->selectrow_array('SELECT COUNT(id) FROM PROFILES');
if ($nbrMutualFriends) {
# Create and open the XLSX file
my $filename;
if ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createProfilesReportXLSX($refDbh, $refInfos, 3); }
elsif ($$refInfos{reportFormat} eq 'HTML') { $filename = &createProfilesReportHTML($refDbh, $refInfos, 3); }
else { $filename = &createProfilesReportTXT( $refDbh, $refInfos, 3); }
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
} else {
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'noProfileDumped'}, $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
}
$winPb->ChangeCursor($ARROW);
$$refDbh->disconnect();
remove_tree("$$refInfos{saveDir}\\temp") if $$refInfos{delTempFiles};
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incIcons};
} #--- End dumpMutualFriends
#--------------------------#
sub dumpContrib
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos) = @_;
# First execution
$winPb->Text("$STR{'Dump'} $STR{'contributors'} $STR{'inProgress'}...");
# Steps (based on selected options)
# 1. Initiate
# 2. Foreach URLs in list
# 1: Open the page (if currURL is different from startingURL, scroll if autoscroll option has been selected)
# 2: Scroll and expand the page (if option has been selected)
# 3: Save the page
# 4: Parse the page
# 3: Dump Likes - Browse Likes Pages (open, save and parse)
# 4: Download profiles icons
# 5: Create report
# Turn on progress bar
my $count1 = 0;
my $nbrOperations;
if ($winPb->lblCount1->Text()) { $nbrOperations = (split(/\//, $winPb->lblCount1->Text()))[1]; }
else { $nbrOperations = 5; }
$winPb->pbWinPb1->SetRange(0, $nbrOperations);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
$winPb->lblCount1->Text("0/$nbrOperations");
# Initiate
if (!exists($$refInfos{step}) or !$$refInfos{step}) {
&createProfilesDB($refDbh); # Create table PROFILES
&createPicturesDB($refDbh); # Create table PICTURES
if ($$refInfos{startingURL}) {
$$refInfos{'currPageName'} = $STR{'CurrPage'};
$$refInfos{'currPageStep'} = 0;
}
$$refDbh->commit();
$$refInfos{step} = 1;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Recalculate number of operations
my $refAllURLs;
my $nbrURLs = 0;
if ($$refInfos{pageType}) { # Albums
$refAllURLs = $$refDbh->selectall_arrayref('SELECT * FROM ALBUMS');
$nbrURLs = scalar(@$refAllURLs);
$nbrOperations = $nbrURLs + 3;
}
$winPb->pbWinPb1->SetRange(0, $nbrOperations);
my $currCount = (split(/\//, $winPb->lblCount1->Text()))[0];
$winPb->lblCount1->Text("$currCount/$nbrOperations");
# Foreach URLs in list
if ($$refInfos{step} == 1) {
$winPb->lblPbCurr1->Text("$STR{'browseAllPagesURLs'}...");
# Dump from current page if selected
&dumpContribComments($refMech, $refDbh, $refInfos, $$refInfos{startingID}, $$refInfos{currPageName},
$$refInfos{startingURL}, 0, 1) if $$refInfos{startingURL};
foreach my $entry (@$refAllURLs) {
&dumpContribComments($refMech, $refDbh, $refInfos, $$entry[0], $$entry[1], $$entry[2], 1, 1);
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
}
$$refInfos{step} = 2;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Dump Likes - Browse Likes Pages (open, save and parse)
if ($$refInfos{step} == 2) {
if ($$refInfos{likes}) {
$winPb->lblPbCurr1->Text("$STR{'Dump'} $STR{'Likes'} $STR{'inProgress'}...");
&dumpContribLikes($refMech, $refDbh, $refInfos);
}
$$refInfos{step} = 3;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Download profiles icons
if ($$refInfos{step} == 3) {
if ($$refInfos{incIcons}) { &dlProfilesIcons($refMech, $refDbh, $refInfos); }
$$refInfos{step} = 4;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Count profiles
if (!$$refInfos{nbrProfiles}) {
$$refInfos{nbrProfiles} = $$refDbh->selectrow_array('SELECT COUNT(id) FROM PROFILES');
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Parsing done, create the report
my $filename;
if ($$refInfos{nbrProfiles}) {
$winPb->lblPbCurr1->Text("$STR{'Creating'} $STR{'outputFile'}...");
# Create and open the XLSX file
if ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createProfilesReportXLSX($refDbh, $refInfos, 2); }
elsif ($$refInfos{reportFormat} eq 'HTML') { $filename = &createProfilesReportHTML($refDbh, $refInfos, 2); }
else { $filename = &createProfilesReportTXT( $refDbh, $refInfos, 2); }
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
} else {
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'noProfileDumped'}, $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
$winPb->ChangeCursor($ARROW);
$$refDbh->disconnect();
remove_tree("$$refInfos{saveDir}\\temp") if $$refInfos{delTempFiles};
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incIcons};
} #--- End dumpContrib
#--------------------------#
sub dumpComments
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos) = @_;
&createProfilesDB($refDbh); # Create table PROFILES
&createCommentsDB($refDbh); # Create table COMMENTS
$winPb->Text("$STR{'Dump'} $STR{'contributors'} $STR{'inProgress'}...");
# Steps (based on selected options)
# 1. Initiate
# 2. Foreach URLs in list
# 1: Open the page (if currURL is different from startingURL, scroll if autoscroll option has been selected)
# 2: Scroll and expand the page (if option has been selected)
# 3: Save the page
# 4: Parse the page
# 3: Download profiles icons (if option has been selected)
# 4: Create report
# Turn on progress bar
my $count1 = 0;
my $nbrOperations;
if ($winPb->lblCount1->Text()) { $nbrOperations = (split(/\//, $winPb->lblCount1->Text()))[1]; }
else { $nbrOperations = 4; }
$winPb->pbWinPb1->SetRange(0, $nbrOperations);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
$winPb->lblCount1->Text("0/$nbrOperations");
# Initiate
if (!exists($$refInfos{step}) or !$$refInfos{step}) {
&createPicturesDB($refDbh); # Create table PICTURES
if ($$refInfos{startingURL}) {
$$refInfos{'currPageName'} = $STR{'CurrPage'};
$$refInfos{'currPageStep'} = 0;
}
$$refDbh->commit();
$$refInfos{step} = 1;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Recalculate number of operations
my $refAllURLs;
my $nbrURLs = 0;
if ($$refInfos{pageType} == 1) { # Albums
$refAllURLs = $$refDbh->selectall_arrayref('SELECT * FROM ALBUMS');
$nbrURLs = scalar(@$refAllURLs);
$nbrOperations = $nbrURLs + 3;
}
if ($$refInfos{currPageName}) { $nbrOperations++; }
$winPb->pbWinPb1->SetRange(0, $nbrOperations);
my $currCount = (split(/\//, $winPb->lblCount1->Text()))[0];
$winPb->lblCount1->Text("$currCount/$nbrOperations");
# Foreach pages
if ($$refInfos{step} == 1) {
$winPb->lblPbCurr1->Text("$STR{'browseAllPagesURLs'}...");
# Dump from current page if selected
&dumpContribComments($refMech, $refDbh, $refInfos, $$refInfos{startingID}, $$refInfos{currPageName}, $$refInfos{startingURL}, 0, 2) if $$refInfos{startingURL};
foreach my $entry (@$refAllURLs) {
&dumpContribComments($refMech, $refDbh, $refInfos, $$entry[0], $$entry[1], $$entry[2], 1, 2);
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
}
$$refInfos{step} = 2;
&updateDumpDB_INFOS($refDbh, $refInfos);
} else {
$count1 += $nbrURLs;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
}
# Download profiles icons and other images (if option has been selected)
if ($$refInfos{step} == 2) {
if ($$refInfos{incIcons} ) {
$winPb->lblPbCurr1->Text("$STR{'Downloading'} $STR{'files'}...");
&dlProfilesIcons($refMech, $refDbh, $refInfos);
&dlCommentsImg( $refMech, $refDbh, $refInfos);
}
$$refInfos{step} = 3;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
# Count comments
if (!$$refInfos{nbrComments}) {
$$refInfos{nbrComments} = $$refDbh->selectrow_array('SELECT COUNT(id) FROM COMMENTS');
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Parsing done, create the report
my $filename;
if ($$refInfos{nbrComments}) {
$winPb->lblPbCurr1->Text("$STR{'Creating'} $STR{'outputFile'}...");
# Create and open the XLSX file
if ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createCommentReportXLSX($refDbh, $refInfos, $$refInfos{nbrComments}); }
elsif ($$refInfos{reportFormat} eq 'HTML') { $filename = &createCommentReportHTML($refDbh, $refInfos, $$refInfos{nbrComments}); }
else { $filename = &createCommentReportTXT( $refDbh, $refInfos, $$refInfos{nbrComments}); }
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
} else {
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'noCommentsDumped'}, $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
}
$count1++;
$winPb->pbWinPb1->SetPos($count1);
$winPb->lblCount1->Text("$count1/$nbrOperations");
$winPb->ChangeCursor($ARROW);
$$refDbh->disconnect();
remove_tree("$$refInfos{saveDir}\\temp") if $$refInfos{delTempFiles};
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incIcons};
} #--- End dumpComments
#--------------------------#
sub dumpGroupMembers
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $dbFile, $refInfos) = @_;
# Steps:
# 1: Open the page
# 2: Scroll the page
# 3: Save the page
# 4: Parse the page
my $count1 = 0;
# Turn on progress bar
$winPb->pbWinPb1->SetRange(0, 4);
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
$winPb->lblPbCurr1->Text('');
$winPb->lblCount1->Text('');
&createProfilesDB($refDbh); # Create table PROFILES
$winPb->Text("$STR{'Dump'} $STR{'groupMembers'} $STR{'inProgress'}...");
# Create folders
mkdir("$$refInfos{saveDir}\\images_$$refInfos{filename}")
if !-d "$$refInfos{saveDir}\\images_$$refInfos{filename}" and $$refInfos{incIcons};
# Opening the Group Members page
if (!exists($$refInfos{step}) or !$$refInfos{step}) {
if ($$refMech->uri() ne $$refInfos{startingURL}) {
$winPb->lblPbCurr1->Text("$STR{'Opening'} $STR{'thePage'}");
$$refMech->get($$refInfos{startingURL});
sleep($$refInfos{timeToWait});
}
$$refInfos{step} = 1;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$winPb->pbWinPb1->SetPos($$refInfos{step});
$winPb->lblCount1->Text("$$refInfos{step}/4");
# Scrolling the Group Members page
if ($$refInfos{step} == 1) {
if ($$refInfos{autoScroll}) {
$winPb->lblPbCurr1->Text("$STR{'Scrolling'} $STR{'thePage'}");
sleep($$refInfos{timeToWait});
$$refMech->eval_in_page("var el = document.getElementsByClassName('uiMorePagerPrimary'); for (var i=0;i<el.length; i++) { el[i].click(); }"); # Expand Admins list
&scrollPage($refMech, $$refInfos{timeToWait});
}
$$refInfos{step} = 2;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$winPb->pbWinPb1->SetPos($$refInfos{step});
$winPb->lblCount1->Text("$$refInfos{step}/4");
# Saving the Group Members page
if ($$refInfos{step} == 2) {
$winPb->lblPbCurr1->Text("$STR{'Saving'} $STR{'thePage'}");
# Create the directories
mkdir("$$refInfos{saveDir}\\temp") if !-d "$$refInfos{saveDir}\\temp";
$$refInfos{tmpPage} = "$$refInfos{saveDir}\\temp\\page.html";
open(my $fhCurr, ">:encoding(utf8)", $$refInfos{tmpPage});
print $fhCurr $$refMech->content;
close($fhCurr);
$$refInfos{step} = 3;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$winPb->pbWinPb1->SetPos($$refInfos{step});
$winPb->lblCount1->Text("$$refInfos{step}/4");
# Parsing the Group Members page
if ($$refInfos{step} == 3) {
$winPb->lblPbCurr1->Text("$STR{'Parsing'} $STR{'thePage'}");
&parseGroupMembers($refDbh, $refInfos);
$$refInfos{step} = 4;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
$winPb->pbWinPb1->SetPos($$refInfos{step});
$winPb->lblCount1->Text("$$refInfos{step}/4");
# Download profiles icons
if ($$refInfos{step} == 4) {
if ($$refInfos{incIcons}) { &dlProfilesIcons($refMech, $refDbh, $refInfos); }
$$refInfos{step} = 5;
&updateDumpDB_INFOS($refDbh, $refInfos);
}
# Parsing done, create the report
$winPb->lblPbCurr1->Text("$STR{'Creating'} $STR{'outputFile'}...");
if ($$refInfos{nbrMembers}) {
# Turn on progress bar
$winPb->lblCount1->Text("0/$$refInfos{nbrMembers}");
$winPb->pbWinPb1->SetRange(0, $$refInfos{nbrMembers});
$winPb->pbWinPb1->SetPos(0);
$winPb->pbWinPb1->SetStep(1);
# Create and open the XLSX file
my $filename;
if ($$refInfos{reportFormat} eq 'XLSX') { $filename = &createProfilesReportXLSX($refDbh, $refInfos, 3); }
elsif ($$refInfos{reportFormat} eq 'HTML') { $filename = &createProfilesReportHTML($refDbh, $refInfos, 3); }
else { $filename = &createProfilesReportTXT( $refDbh, $refInfos, 3); }
# Finish
$winPb->ShellExecute('open', $filename,'','',1) if $$refInfos{openReport} and $filename;
} else {
$winPb->Hide();
Win32::GUI::MessageBox($winPb, $STR{'noProfileDumped'}, $STR{'Error'}, 0x40010) if !$$refInfos{silentProgress};
}
$winPb->ChangeCursor($ARROW);
$$refDbh->disconnect();
remove_tree("$$refInfos{saveDir}\\temp") if $$refInfos{delTempFiles};
$$refMech->get($$refInfos{startingURL} ) if $$refInfos{incIcons};
} #--- End dumpGroupMembers
#--------------------------#
sub parseAlbumPage
#--------------------------#
{
# Local variables
my ($refMech, $refDbh, $refInfos, $albumId) = @_;
# Current number of pics
my $ind = 0;
$ind = $$refDbh->selectrow_array('SELECT COUNT(ind) FROM PICTURES WHERE album = ?', undef, $albumId);
my ($tmpPage, $albumPath) = $$refDbh->selectrow_array('SELECT tmpPage, path FROM ALBUMS WHERE id = ?' , undef, $albumId);
# Load content from file
my $dom = new HTML::DOM(charset => 'utf8');
$dom->parse_file($tmpPage);
my @photoTags;
# Page profile
if ($$refInfos{pageType} == 3) { @photoTags = $dom->getElementsByClassName('_2eea'); }
# Group or People profile
else {
my $photoContent = $dom->getElementById('fbTimelinePhotosContent');
$photoContent = $dom->getElementById('set_photos_pagelet') if !$photoContent;
@photoTags = $photoContent->getElementsByClassName('fbPhotoCurationControlWrapper');
}
# Turn on progress bar
my $i = 0;
my $nbrPhotos = scalar(@photoTags);
$winPb->pbWinPb2->SetRange(0, $nbrPhotos);
$winPb->pbWinPb2->SetPos(0);
$winPb->pbWinPb2->SetStep(1);
$winPb->lblCount2->Text("0/$nbrPhotos");
my $sthPictures = $$refDbh->prepare('INSERT OR REPLACE INTO PICTURES (album,ind,pageURL,smallURL,pubDate,largeURL) VALUES(?,?,?,?,?,?)');
foreach my $tag (@photoTags) {
if (my $urlNode = ($tag->getElementsByTagName('a'))[0]) {
my $pubDate = '-';
my $largeURL = '-';
my $url = $urlNode->{href};
my ($smallURL, $imgNode, $backgroundImgCode);
if ($imgNode = ($urlNode->getElementsByTagName('img'))[0]) { $smallURL = $imgNode->{src}; }
if ($smallURL and $smallURL =~ /rsrc.php/ and $imgNode->{style}) {
$backgroundImgCode = $imgNode->{style};
} elsif (!$smallURL and $imgNode = ($urlNode->getElementsByClassName('uiMediaThumbImg'))[0]) { # Group
$backgroundImgCode = $imgNode->{style};
}
if ($backgroundImgCode and $backgroundImgCode =~ /background-image: url\(\'?([^\)\']+)/) {
$smallURL = $1;
$smallURL =~ s/&/&/g;
$smallURL =~ s/\\([0-9a-fA-F]{2}) /chr(hex($1))/eg if $smallURL =~ /^https\\3a/;
}
if ($smallURL) {
$url = 'https://www.facebook.com'.$url if $url !~ /^http/;
# Open large picture
if ($$refInfos{incLargePics} or $$refInfos{incPublishDate} or $$refInfos{reportFormat} ne 'HTML') {
if ($url =~ /$albumId\/([^\/]+)\// or $url =~ /fbid=([^\&]+)/) {
my $picID = $1;
# Open the popup
$winPb->lblPbCurr2->Text("$STR{'Opening'} $STR{'thePage'}...");
if ($$refInfos{pageType} == 3) { # Page profile
$$refMech->eval_in_page("var el=document.getElementsByClassName('_2eea');for(var i=0;i<el.length;i++) {var link=(el[i].getElementsByTagName('a'))[0];var regex=new RegExp($picID);var href=link.href;if(href && regex.test(href)){console.log('ok');link.click();break;}}");
} else { # Group or People profile
$$refMech->eval_in_page("var el=document.getElementsByClassName('fbPhotoCurationControlWrapper');for(var i=0;i<el.length;i++) {var link=(el[i].getElementsByTagName('a'))[0];var regex=new RegExp($picID);var href=link.href;if(href && regex.test(href)){console.log('ok');link.click();break;}}");
}
sleep($$refInfos{timeToWait});