· 6 years ago · Sep 29, 2019, 05:56 PM
1<?php
2
3require __DIR__.'/vendor/autoload.php';
4$ig = new \InstagramAPI\Instagram();
5
6/*output_clean("
7 _ _ _
8| | | | | |
9| |_| |_ _ _ __ ___ _ __| | ___ ___ _ __
10| _ | | | | '_ \ / _ \ '__| |/ _ \ / _ \| '_ \
11| | | | |_| | |_) | __/ | | | (_) | (_) | |_) |
12\_| |_/\__, | .__/ \___|_| |_|\___/ \___/| .__/
13 __/ | | | |
14 |___/|_| |_|
15");*/
16
17//output_clean("");
18//output_clean("Hyperloop Terminal");
19//output_clean("v.4.3");
20//output_clean("");
21//output_clean("© Developed by Nextpost Developers Team (https://nextpost.tech)");
22//output_clean("");
23
24run($ig);
25
26/**
27 * Let's start the show
28 */
29function run($ig) {
30 try {
31 //output('Please provide a valid license key from your Dashboard on Nextpost.tech (https://nextpost.tech).');
32 // output('Example: j5tkjkl4f7e595e9008bb77acc599453');
33
34 $license_key = "be401d794e2ca130ef5cbb5c6c5cdf52";
35
36 if (empty($license_key)) {
37 do {
38 $license_key = getVarFromUser("License key");
39 } while (empty($license_key));
40 }
41
42 $license_key = str_replace(' ', '', $license_key);
43 $license_status = activate_license($license_key, $ig);
44
45 if ($license_status == "valid") {
46 output('You license active and valid.');
47 } else {
48 output('You license key not valid.');
49 run($ig);
50 }
51
52 //output('Please provide login data of your Instagram Account.');
53
54 $login = "USERNAME";
55 if (empty($login)) {
56 do {
57 $login = getVarFromUser("Login");
58 } while (empty($login));
59 }
60
61 $password = "PASSWORD";
62 if (empty($password)) {
63 do {
64 $password = getVarFromUser("Password");
65 } while (empty($password));
66 }
67
68 $first_loop = true;
69 do {
70 if ($first_loop) {
71 // output("(Optional) Set proxy, if needed. It's better to use a proxy from the same country where you running this script.");
72 // output("Proxy should match following pattern:");
73 // output("http://ip:port or http://username:password@ip:port");
74 // output("Don't use in pattern https://.");
75 // output("Type 3 to skip and don't use proxy.");
76 $first_loop = false;
77 } else {
78 output("Proxy - [NOT VALID]");
79 output("Please check the proxy syntax and try again.");
80 }
81
82 $proxy = "3";
83
84 if (empty($proxy)) {
85 do {
86 $proxy = getVarFromUser("Proxy");
87 } while (empty($proxy));
88 }
89
90 if ($proxy == '3') {
91 // Skip proxy setup
92 break;
93 }
94 } while (!isValidProxy($proxy));
95
96 if ($proxy == "3") {
97 // Skip proxy setup
98 } else {
99 output("Proxy - [OK]");
100 $ig->setProxy($proxy);
101 }
102
103 // output('Please choose the masslooking estimated speed.');
104 // output('Type integer value without spaces from 1 to 500 000 stories/day or 0 for maximum possible speed.');
105 //output('When you are using the maximum speed you may exceed the masslooking limits per day if this account actively used by a user in the Instagram app at the same time.');
106 // output('If you are using another type of automation, we recommend to you reducing masslooking speed to find your golden ratio. In that case we recommend 400 000 stories/day.');
107 $speed = "0";
108
109 if ($speed > 500000) {
110 do {
111 // output("Speed value is incorrect. Type integer value from 1 to 500 000 stories/day.");
112 // output('Type 0 for maximum speed.');
113 $speed = (int)getVarFromUser("Delay");
114 } while ($speed > 500000);
115 }
116
117 if ($speed == 0) {
118 output("Maximum speed enabled.");
119 $delay = 34;
120 } else {
121 output("Speed set to " . $speed . " stories/day.");
122 $delay = round(60*60*24*200/$speed);
123 }
124
125 $is_connected = false;
126 $is_connected_count = 0;
127 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
128
129 do {
130 if ($is_connected_count == 10) {
131 if ($e->getResponse()) {
132 output($e->getMessage());
133 }
134 throw new Exception($fail_message);
135 }
136
137 try {
138 if ($is_connected_count == 0) {
139 // output("Emulation of an Instagram app initiated...");
140 }
141 $login_resp = $ig->login($login, $password);
142
143 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
144 // Default verification method is phone
145 $twofa_method = '1';
146
147 // Detect is Authentification app verification is available
148 $is_totp = json_decode(json_encode($login_resp), true);
149 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
150 output("Two-factor authentication required, please enter the code from you Authentication app");
151 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
152 $twofa_method = '3';
153 } else {
154 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
155 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
156 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
157 }
158
159 $twofa_code = getVarFromUser("Two-factor code");
160
161 if (empty($twofa_code)) {
162 do {
163 $twofa_code = getVarFromUser("Two-factor code");
164 } while (empty($twofa_code));
165 }
166
167 $is_connected = false;
168 $is_connected_count = 0;
169 do {
170 if ($is_connected_count == 10) {
171 if ($e->getResponse()) {
172 output($e->getMessage());
173 }
174 throw new Exception($fail_message);
175 }
176
177 if ($is_connected_count == 0) {
178 output("Two-factor authentication in progress...");
179 }
180
181 try {
182 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
183 $is_connected = true;
184 } catch (\InstagramAPI\Exception\NetworkException $e) {
185 sleep(7);
186 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
187 sleep(7);
188 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
189 $is_code_correct = false;
190 $is_connected= true;
191 do {
192 output("Code is incorrect. Please check the syntax and try again.");
193 $twofa_code = getVarFromUser("Two-factor code");
194
195 if (empty($twofa_code)) {
196 do {
197 $twofa_code = getVarFromUser("Security code");
198 } while (empty($twofa_code));
199 }
200
201 $is_connected = false;
202 $is_connected_count = 0;
203 do {
204 try {
205 if ($is_connected_count == 10) {
206 if ($e->getResponse()) {
207 output($e->getMessage());
208 }
209 throw new Exception($fail_message);
210 }
211
212 if ($is_connected_count == 0) {
213 output("Verification in progress...");
214 }
215 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
216 $is_code_correct = true;
217 $is_connected = true;
218 } catch (\InstagramAPI\Exception\NetworkException $e) {
219 sleep(7);
220 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
221 sleep(7);
222 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
223 $is_code_correct = false;
224 $is_connected = true;
225 } catch (\Exception $e) {
226 throw $e;
227 }
228 $is_connected_count += 1;
229 } while (!$is_connected);
230 } while (!$is_code_correct);
231 } catch (\Exception $e) {
232 throw $e;
233 }
234
235 $is_connected_count += 1;
236 } while (!$is_connected);
237 }
238
239 $is_connected = true;
240 } catch (\InstagramAPI\Exception\NetworkException $e) {
241 sleep(7);
242 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
243 sleep(7);
244 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
245 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
246 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
247
248 if (!($ig instanceof InstagramAPI\Instagram)) {
249 throw new Exception("Oops! Something went wrong. Please try again later! (invalid_instagram_client)");
250 }
251
252 if (!($e instanceof InstagramAPI\Exception\ChallengeRequiredException)) {
253 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception)");
254 }
255
256 if (!$e->hasResponse() || !$e->getResponse()->isChallenge()) {
257 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception_response)");
258 }
259
260 $challenge = $e->getResponse()->getChallenge();
261
262 if (is_array($challenge)) {
263 $api_path = $challenge["api_path"];
264 } else {
265 $api_path = $challenge->getApiPath();
266 }
267
268 output("Instagram want to send you a security code to verify your identity.");
269 output("How do you want receive this code?");
270 output("1 - [Email]");
271 output("2 - [SMS]");
272 output("3 - [Exit]");
273
274 $choice = getVarFromUser("Choice");
275
276 if (empty($choice)) {
277 do {
278 $choice = getVarFromUser("Choice");
279 } while (empty($choice));
280 }
281
282 if ($choice == '1' || $choice == '2' || $choice == '3') {
283 // All fine
284 } else {
285 $is_choice_ok = false;
286 do {
287 output("Choice is incorrect. Type 1, 2 or 3.");
288 $choice = getVarFromUser("Choice");
289
290 if (empty($choice)) {
291 do {
292 $choice = getVarFromUser("Choice");
293 } while (empty($choice));
294 }
295
296 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
297 $is_choice_ok = true;
298 }
299 } while (!$is_choice_ok);
300 }
301
302 $challange_choice = 0;
303 if ($choice == '3') {
304 run($ig);
305 } elseif ($choice == '1') {
306 // Email
307 $challange_choice = 1;
308 } else {
309 // SMS
310 $challange_choice = 0;
311 }
312
313 $is_connected = false;
314 $is_connected_count = 0;
315 do {
316 if ($is_connected_count == 10) {
317 if ($e->getResponse()) {
318 output($e->getMessage());
319 }
320 throw new Exception($fail_message);
321 }
322
323 try {
324 $challenge_resp = $ig->sendChallangeCode($api_path, $challange_choice);
325
326 // Failed to send challenge code via email. Try with SMS.
327 if ($challenge_resp->status != "ok") {
328 $challange_choice = 0;
329 sleep(7);
330 $challenge_resp = $ig->sendChallangeCode($api_path, $challange_choice);
331 }
332
333 $is_connected = true;
334 } catch (\InstagramAPI\Exception\NetworkException $e) {
335 sleep(7);
336 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
337 sleep(7);
338 } catch (\Exception $e) {
339 throw $e;
340 }
341
342 $is_connected_count += 1;
343 } while (!$is_connected);
344
345 if ($challenge_resp->status != "ok") {
346 if (isset($challenge_resp->message)) {
347 if ($challenge_resp->message == "This field is required.") {
348 output("We received the response 'This field is required.'. This can happen in 2 reasons:");
349 output("1. Instagram already sent to you verification code to your email or mobile phone number. Please enter this code.");
350 output("2. Instagram forced you to phone verification challenge. Try login to Instagram app or website and take a look at what happened.");
351 }
352 } else {
353 output("Instagram Response: " . json_encode($challenge_resp));
354 output("Couldn't send a verification code for the login challenge. Please try again later.");
355 output("- Is this account has attached mobile phone number in settings?");
356 output("- If no, this can be a reason of this problem. You should add mobile phone number in account settings.");
357 throw new Exception("- Sometimes Instagram can force you to phone verification challenge process.");
358 }
359 }
360
361 if (isset($challenge_resp->step_data->contact_point)){
362 $contact_point = $challenge_resp->step_data->contact_point;
363 if ($choice == 2) {
364 output("Enter the code sent to your number ending in " . $contact_point . ".");
365 } else {
366 output("Enter the 6-digit code sent to the email address " . $contact_point . ".");
367 }
368 }
369
370 $security_code = getVarFromUser("Security code");
371
372 if (empty($security_code)) {
373 do {
374 $security_code = getVarFromUser("Security code");
375 } while (empty($security_code));
376 }
377
378 if ($security_code == "3") {
379 throw new Exception("Reset in progress...");
380 }
381
382 // Verification challenge
383 $ig = challange($ig, $login, $password, $api_path, $security_code, $proxy);
384
385 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
386 throw new Exception("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
387 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
388 throw new Exception("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
389 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
390 throw new Exception("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
391 } catch (\InstagramAPI\Exception\IncorrectPasswordException $e) {
392 throw new Exception("The password you entered is incorrect. Please try again.");
393 } catch (\InstagramAPI\Exception\InvalidUserException $e) {
394 throw new Exception("The username you entered doesn't appear to belong to an account. Please check your username and try again.");
395 } catch (\Exception $e) {
396 throw $e;
397 }
398
399 $is_connected_count += 1;
400 } while (!$is_connected);
401
402 output("Logged as @" . $login . " successfully.");
403
404 $data = define_targets($ig);
405
406 // Disabled, because this feature not supported at the moment
407 // Because of new Instagram limits
408 $is_parsers_enabled = false;
409
410 if (!$is_parsers_enabled) {
411 masslooking_v2($data, $ig, $delay);
412 } else {
413 output('Do you want to add parsers? (additional Instagram accounts for speed up masslooking speed)');
414 output("1 - [Yes]");
415 output("2 - [No]");
416 output("3 - [Exit]");
417
418 $confirm_p = getVarFromUser("Choice");
419
420 if (empty($confirm_p)) {
421 do {
422 $confirm_p = getVarFromUser("Choice");
423 } while (empty($confirm_p));
424 }
425
426 if ($confirm_p == '1' || $confirm_p == '2' || $confirm_p == '3') {
427 // All fine
428 } else {
429 $is_choice_ok = false;
430 do {
431 output("Choice is incorrect. Type 1, 2 or 3.");
432 $confirm_p = getVarFromUser("Choice");
433
434 if (empty($confirm_p)) {
435 do {
436 $confirm_p = getVarFromUser("Choice");
437 } while (empty($confirm_p));
438 }
439
440 if ($confirm_p == '1' || $confirm_p == '2' || $confirm_p == '3') {
441 $is_choice_ok = true;
442 }
443 } while (!$is_choice_ok);
444 }
445
446 if ($confirm_p == '3') {
447 throw new Exception("Reset in progress...");
448 } elseif ($confirm_p == '2') {
449 masslooking_v2($data, $ig, $delay);
450 } else {
451 // Yes, I want to add parsers.
452 }
453
454 output('How many parsers do you want to add? (integer value from 1 to 5)');
455 output("Type 11 - to don't use parsers and start masslooking.");
456 output("Type 12 - to exit.");
457 $parsers_count = (int)getVarFromUser("Parsers count");
458
459 if ($parsers_count > 12) {
460 do {
461 output("Parsers count is incorrect. Type integer value from 1 to 12.");
462 $parsers_count = (int)getVarFromUser("Parsers count");
463 } while ($parsers_count > 12);
464 }
465
466 if ($parsers_count == 11) {
467 masslooking_v2($data, $ig, $delay);
468 } elseif ($parsers_count == 12) {
469 throw new Exception("Reset in progress...");
470 } else {
471 output("You want to add " . $parsers_count . " parser(s).");
472 output("Let's get started.");
473 }
474
475 for ($i = 1; $i < count($parsers_count); $i++) {
476 $ig_p[] = add_parser($i);
477 }
478
479 output("All " . $parsers_count . " parser(s) successfully connected.");
480
481 // $user_resp = $ig->people->getInfoById($data[0]["pk"]);
482 // output(json_encode($user_resp));
483
484 // $user_resp = $ig_p[1]->people->getInfoById($data[1]["pk"]);
485 // output(json_encode($user_resp));
486
487 // $user_resp = $ig_p[2]->people->getInfoById($data[2]["pk"]);
488 // output(json_encode($user_resp));
489
490 }
491
492 } catch (\Exception $e){
493 output($e->getMessage());
494 output("Please run script command again.");
495 exit;
496 }
497}
498
499/**
500 * Add parser
501 */
502function add_parser($pn) {
503 try {
504 $igp = new \InstagramAPI\Instagram();
505
506 output("Please provide login data of your parser #" . $pn . " (additional Instagram account for speed up masslooking speed)");
507
508 $login = getVarFromUser("Login");
509 if (empty($login)) {
510 do {
511 $login = getVarFromUser("Login");
512 } while (empty($login));
513 }
514
515 $password = getVarFromUser("Password");
516 if (empty($password)) {
517 do {
518 $password = getVarFromUser("Password");
519 } while (empty($password));
520 }
521
522 $first_loop = true;
523 do {
524 if ($first_loop) {
525 output("(Optional) Set proxy, if needed. It's better to use a proxy from the country from you running this script.");
526 output("Proxy should match following pattern:");
527 output("http://ip:port or http://username:password@ip:port");
528 output("Don't use in pattern https://.");
529 output("Type 3 to skip and don't use proxy.");
530 $first_loop = false;
531 } else {
532 output("Proxy - [NOT VALID]");
533 output("Please check the proxy syntax and try again.");
534 }
535
536 $proxy = getVarFromUser("Proxy");
537
538 if (empty($proxy)) {
539 do {
540 $proxy = getVarFromUser("Proxy");
541 } while (empty($proxy));
542 }
543
544 if ($proxy == '3') {
545 // Skip proxy setup
546 break;
547 }
548 } while (!isValidProxy($proxy));
549
550 if ($proxy == "3") {
551 // Skip proxy setup
552 } else {
553 output("Proxy - [OK]");
554 $igp->setProxy($proxy);
555 }
556
557 $is_connected = false;
558 $is_connected_count = 0;
559 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
560
561 do {
562 if ($is_connected_count == 10) {
563 if ($e->getResponse()) {
564 output($e->getMessage());
565 }
566 throw new Exception($fail_message);
567 }
568
569 try {
570 if ($is_connected_count == 0) {
571 output("Emulation of an Instagram app for parser #" . $pn . " initiated...");
572 }
573 $login_resp = $igp->login($login, $password);
574
575 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
576 // Default verification method is phone
577 $twofa_method = '1';
578
579 // Detect is Authentification app verification is available
580 $is_totp = json_decode(json_encode($login_resp), true);
581 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
582 output("Two-factor authentication required, please enter the code from you Authentication app");
583 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
584 $twofa_method = '3';
585 } else {
586 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
587 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
588 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
589 }
590
591 $twofa_code = getVarFromUser("Two-factor code");
592
593 if (empty($twofa_code)) {
594 do {
595 $twofa_code = getVarFromUser("Two-factor code");
596 } while (empty($twofa_code));
597 }
598
599 $is_connected = false;
600 $is_connected_count = 0;
601 do {
602 if ($is_connected_count == 10) {
603 if ($e->getResponse()) {
604 output($e->getMessage());
605 }
606 throw new Exception($fail_message);
607 }
608
609 if ($is_connected_count == 0) {
610 output("Two-factor authentication in progress...");
611 }
612
613 try {
614 $twofa_resp = $igp->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
615 $is_connected = true;
616 } catch (\InstagramAPI\Exception\NetworkException $e) {
617 sleep(7);
618 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
619 sleep(7);
620 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
621 $is_code_correct = false;
622 $is_connected= true;
623 do {
624 output("Code is incorrect. Please check the syntax and try again.");
625 $twofa_code = getVarFromUser("Two-factor code");
626
627 if (empty($twofa_code)) {
628 do {
629 $twofa_code = getVarFromUser("Security code");
630 } while (empty($twofa_code));
631 }
632
633 $is_connected = false;
634 $is_connected_count = 0;
635 do {
636 try {
637 if ($is_connected_count == 10) {
638 if ($e->getResponse()) {
639 output($e->getMessage());
640 }
641 throw new \Exception($fail_message);
642 }
643
644 if ($is_connected_count == 0) {
645 output("Verification in progress...");
646 }
647 $twofa_resp = $igp->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
648 $is_code_correct = true;
649 $is_connected = true;
650 } catch (\InstagramAPI\Exception\NetworkException $e) {
651 sleep(7);
652 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
653 sleep(7);
654 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
655 $is_code_correct = false;
656 $is_connected = true;
657 } catch (\Exception $e) {
658 throw $e;
659 }
660 $is_connected_count += 1;
661 } while (!$is_connected);
662 } while (!$is_code_correct);
663 } catch (\Exception $e) {
664 throw $e;
665 }
666
667 $is_connected_count += 1;
668 } while (!$is_connected);
669 }
670
671 $is_connected = true;
672 } catch (\InstagramAPI\Exception\NetworkException $e) {
673 sleep(7);
674 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
675 sleep(7);
676 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
677 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
678 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
679
680 if (!($igp instanceof InstagramAPI\Instagram)) {
681 throw new Exception("Oops! Something went wrong. Please try again later! (invalid_instagram_client)");
682 }
683
684 if (!($e instanceof InstagramAPI\Exception\ChallengeRequiredException)) {
685 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception)");
686 }
687
688 if (!$e->hasResponse() || !$e->getResponse()->isChallenge()) {
689 throw new Exception("Oops! Something went wrong. Please try again later! (unexpected_exception_response)");
690 }
691
692 $challenge = $e->getResponse()->getChallenge();
693
694 if (is_array($challenge)) {
695 $api_path = $challenge["api_path"];
696 } else {
697 $api_path = $challenge->getApiPath();
698 }
699
700 output("Instagram will send you a security code to verify your identity.");
701 output("How do you want receive this code?");
702 output("1 - [Email]");
703 output("2 - [SMS]");
704 output("3 - [Exit]");
705
706 $choice = getVarFromUser("Choice");
707
708 if (empty($choice)) {
709 do {
710 $choice = getVarFromUser("Choice");
711 } while (empty($choice));
712 }
713
714 if ($choice == '1' || $choice == '2' || $choice == '3') {
715 // All fine
716 } else {
717 $is_choice_ok = false;
718 do {
719 output("Choice is incorrect. Type 1, 2 or 3.");
720 $choice = getVarFromUser("Choice");
721
722 if (empty($choice)) {
723 do {
724 $choice = getVarFromUser("Choice");
725 } while (empty($choice));
726 }
727
728 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
729 $is_choice_ok = true;
730 }
731 } while (!$is_choice_ok);
732 }
733
734 $challange_choice = 0;
735 if ($choice == '3') {
736 throw new Exception("Reset in progress...");
737 } elseif ($choice == '1') {
738 // Email
739 $challange_choice = 1;
740 } else {
741 // SMS
742 $challange_choice = 0;
743 }
744
745 $is_connected = false;
746 $is_connected_count = 0;
747 do {
748 if ($is_connected_count == 10) {
749 if ($e->getResponse()) {
750 output($e->getMessage());
751 }
752 throw new Exception($fail_message);
753 }
754
755 try {
756 $challenge_resp = $igp->sendChallangeCode($api_path, $challange_choice);
757
758 // Failed to send challenge code via email. Try with SMS.
759 if ($challenge_resp->status != "ok") {
760 $challange_choice = 0;
761 $challenge_resp = $igp->sendChallangeCode($api_path, $challange_choice);
762 }
763
764 $is_connected = true;
765 } catch (\InstagramAPI\Exception\NetworkException $e) {
766 sleep(7);
767 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
768 sleep(7);
769 } catch (\Exception $e) {
770 throw $e;
771 }
772
773 $is_connected_count += 1;
774 } while (!$is_connected);
775
776 if ($challenge_resp->message == "This field is required.") {
777 output("Instagram already sent to you verification code to your email or mobile phone number. Please enter this code.");
778 } elseif ($challenge_resp->status != "ok") {
779 throw new Exception("Couldn't send a verification code for the login challenge. Please try again later.");
780 }
781
782 if (isset($challenge_resp->step_data->contact_point)){
783 $contact_point = $challenge_resp->step_data->contact_point;
784 if ($choice == 2) {
785 output("Enter the code sent to your number ending in " . $contact_point . ".");
786 } else {
787 output("Enter the 6-digit code sent to the email address " . $contact_point . ".");
788 }
789 }
790
791 output("Type 3 - to exit.");
792
793 $security_code = getVarFromUser("Security code");
794
795 if (empty($security_code)) {
796 do {
797 $security_code = getVarFromUser("Security code");
798 } while (empty($security_code));
799 }
800
801 if ($security_code == "3") {
802 throw new Exception("Reset in progress...");
803 }
804
805 // Verification challenge
806 $igp = challange($igp, $login, $password, $api_path, $security_code, $proxy);
807
808 if ($igp == "3") {
809 throw new Exception("Reset in progress...");
810 }
811
812 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
813 throw new Exception("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
814 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
815 throw new Exception("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
816 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
817 throw new Exception("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
818 } catch (\InstagramAPI\Exception\IncorrectPasswordException $e) {
819 throw new Exception("The password you entered is incorrect. Please try again.");
820 } catch (\InstagramAPI\Exception\InvalidUserException $e) {
821 throw new Exception("The username you entered doesn't appear to belong to an account. Please check your username and try again.");
822 } catch (\Exception $e) {
823 throw $e;
824 }
825
826 $is_connected_count += 1;
827 } while (!$is_connected);
828
829 output("Logged as @" . $login . " successfully. Parser #" . $pn . " connected.");
830
831 } catch (\Exception $e){
832 output($e->getMessage());
833 $igp = add_parser($pn);
834 }
835
836 return $igp;
837}
838
839/**
840 * Define targets for masslooking
841 */
842function define_targets($ig) {
843
844 do {
845 //output("Please define the targets.");
846 // output("Write all Instagram profile usernames via comma without '@' symbol.");
847 //output("Example: apple, instagram, zendaya");
848 $targets_input = "igineyz, inkathh, rhesmanissa_, putrianggianiii, dindadn99, devyerianti, farradillajingga, saqinapaprilly, alyafrcn, dindamaulinaaa, hajarans, natasyaptr___, marsyaayuannisa, nabilaaprikarnin, steyllanandad, jessicadavaa, revifad, tasyaa.sa, salshabillaadr, lalamarionmj, nazhafira_, sarahsuci15, pevpearce, amandamadaa, nadhieraa, aryrsh
849aaar, hijabalila, cewehijrah, dewi.n.aisyah, menjadisalihah, beraniberhijrah, catatancintamuslimah, hijrahcinta_, fiqihwanita_, tausiyahku_, calonumishalehah,berusahabaik, muslimah.community, duniahijab, sahabatmuslimah, fiqihmuslimah, untukmu.ukhti, nasehatcinta_, yang.terdalam, rintiksedu, najwashihab, haneenakira, hanan_attaki, aagym, adihidayatofficial, teukuwisnu, muzammilhb, anisarahma_12, video.islam, sahabatsurga, teladan.rasul, ustadzabdulsomad_official, oemar_mita, salimafillah, fatihkarim, felixsiauw, asmanadia, kajianmusawarah, aniesbaswedan, sahabat.anies, dewisandra, ssg_dt, masjiddtbandung, aagymreminders, dakwahdigital.info, ds_equestrian, pesantrendaaruttauhiid, gdaghaida, terasdakwah, cordova.media, daarul_quran, aqlislamiccenter, bachtiarnasir, khalidbasalamahofficial, okisetianadewi, sandiuno, ariekuntung, fuadbakh, actforhumanity, masjidallathiif, masjidjogokariyan, tadabburdaily, felix.siauw, salingsapaid, buyayahya_albahjah, shiftmedia.id, evieefendie, prabowo, haikalhassan_quote, alvin_411, anyageraldine, rintiksedu, najwashihab, dramatwitteran, dramatwitter.id, recehintwitter, tumblr.indo, pejuang.harapan, sindirankeren.id, drama.sosialmedia, pekadoi, yang.terdalam, zonabaper.id, pejuang.kampus, sekedar.rahasia, zonanyaman.idn, tweetreceh, dramatwiter.id, twitter.update, fokusquotes, twider.id, jendelatwitter, twitter.iid, nyesekk, lagu_baper.id, dagelantwitterid, sobat_twitter, lagu_baper.id, storymood_, sejak_literasii, story_whasapp_, zona.aman_, quoteswa_id
850nabilagardena, indahnadapuspita, jessyamanda, igiovany, mffary_ , abunsungkar, abipraya28, danissdanial, amrikhairudin, alfasubagio8, umarpad_, ryan.plv, mattnmou, kazamahusein, mffashar, mrfsnjy, farizaynn, andyrakaa, munggaran6, dhannsskuy, aryafebriannnn, srasyau1, alwiassegaf03, diat_zon, auwgenta_, feezaraizer, liefelixx, andibesset, anggayunandareal16, raooyz, muhraynaldiii, raihandaff, awkarin, ferdinan_sule, najwashihab, dennycagur, indrowarkop_asli, agnezmo, hotmanparisofficial, realmobilelegendsid, telkomsel, motogp, pupgmobile, pubg, pubgmobile_id, freefirebgid, evosesports, teamrrq, jessnolimit, onic.esports, sarahvilo.id, maell_lee, raditya_dika, viavallen, auraesports, natashawilona12, edhozell, yahya_ali_maksum, dylandpros, aerowolfproteam, misellia_, mobilelegendswtf, nissa_sabyan, persib_official, ikhsan_lemon, ml_leak, unipinindonesia, nabilagardena, indahnadapuspita, jessyamanda, igiovany, mffary_ , abunsungkar, abipraya28, danissdanial, amrikhairudin, alfasubagio8, umarpad_, ryan.plv, mattnmou, kazamahusein, mffashar, mrfsnjy, farizaynn, andyrakaa, munggaran6, dhannsskuy, aryafebriannnn,srasyau1, alwiassegaf03, diat_zon, auwgenta_, feezaraizer, liefelixx, andibesset, anggayunandareal16, raooyz, muhraynaldiii, raihandaff, riaricis1795, hotmanparisofficial, realmobilelegendsid, telkomsel, motogp, pupgmobile, pubg, pubgmobile_id, freefirebgid, evosesports, teamrrq, jessnolimit, onic.esports, maell_lee, raditya_dika, viavallen, auraesports, natashawilona12, edhozell, yahya_ali_maksum, dylandpros, aerowolfproteam, misellia_, lambe_moba, listychanpokemon, mobilelegendswtf, nissa_sabyan, persib_official, ikhsan_lemon, ml_leak, unipinindonesia, persib_official, najwashihab, kehoblogan.unfaedah, dramaojol.id, tumming_abu, raditya_dika, iqbaal.e, aliandooo, duniamanji, tirtoid, ariefmuhammad, indovidgram, viavallen, brianimanuel, bastiansteel, hanan_attaki, bassitoayya, nurdin.abdullah, fiersabesari, jefrinichol, jeromepolin, susipudjiastuti115, mamakbeti, alghazali7, vaneshaass, raffinagita1717, moektito";
851 if (empty($targets_input)) {
852 do {
853 $targets_input = getVarFromUser("Usernames");
854 } while (empty($targets_input));
855 }
856
857 $targets_input = str_replace(' ','',$targets_input);
858 $targets = [];
859 $targets = explode(',',trim($targets_input));
860 $targets = array_unique($targets);
861
862 $pks = [];
863 $filtered_targets = [];
864 foreach ($targets as $target) {
865
866 $is_connected = false;
867 $is_connected_count = 0;
868 do {
869 if ($is_connected_count == 10) {
870 if ($e->getResponse()) {
871 output($e->getMessage());
872 }
873 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
874 output($fail_message);
875 run($ig);
876 }
877
878 try {
879 $user_resp = $ig->people->getUserIdForName($target);
880 output("@" . $target . " - [OK]");
881 $filtered_targets[] = $target;
882 $pks[] = $user_resp;
883 $is_connected = true;
884 if (($target != $targets[count($targets) - 1]) && (count($targets) > 0)) {
885 sleep(1);
886 }
887 } catch (\InstagramAPI\Exception\NetworkException $e) {
888 sleep(7);
889 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
890 sleep(7);
891 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
892 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
893 run($ig);
894 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
895 output("Please go to Instagram website or mobile app and pass checkpoint!");
896 run($ig);
897 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
898 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
899 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
900 run($ig);
901 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
902 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
903 run($ig);
904 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
905 output("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
906 run($ig);
907 } catch (\InstagramAPI\Exception\ThrottledException $e) {
908 output("Throttled by Instagram because of too many API requests.");
909 output("Please login again after 1 hour. You reached Instagram limits.");
910 run($ig);
911 } catch (InstagramAPI\Exception\NotFoundException $e) {
912 $is_connected = true;
913 $is_username_correct = false;
914 do {
915 output("Instagram profile username @" . $target . " is incorrect or maybe user just blocked you (Login to Instagram website or mobile app and check that).");
916 output("Type 3 for skip this target.");
917 $target_new = getVarFromUser("Please provide valid username");
918
919 if (empty($target_new)) {
920 do {
921 $target_new = getVarFromUser("Please provide valid username");
922 } while (empty($target_new));
923 }
924
925 if ($target_new == "3") {
926 break;
927 } else {
928 $is_connected = false;
929 $is_connected_count = 0;
930 do {
931 if ($is_connected_count == 10) {
932 if ($e->getResponse()) {
933 output($e->getMessage());
934 }
935 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
936 output($fail_message);
937 run($ig);
938 }
939
940 try {
941 $user_resp = $ig->people->getUserIdForName($target_new);
942 output("@" . $target_new . " - [OK]");
943 $filtered_targets[] = $target_new;
944 $pks[] = $user_resp;
945 $is_username_correct = true;
946 $is_connected = true;
947 } catch (\InstagramAPI\Exception\NetworkException $e) {
948 sleep(7);
949 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
950 sleep(7);
951 } catch (InstagramAPI\Exception\NotFoundException $e) {
952 $is_username_correct = false;
953 $is_connected = true;
954 } catch (\Exception $e) {
955 output($e->getMessage());
956 run($ig);
957 }
958 $is_connected_count += 1;
959 } while (!$is_connected);
960 }
961 } while (!$is_username_correct);
962 } catch (Exception $e){
963 output($e->getMessage());
964 run($ig);
965 }
966
967 $is_connected_count += 1;
968 } while (!$is_connected);
969 }
970 } while (empty($filtered_targets));
971
972 $targets = array_unique($filtered_targets);
973 $pks = array_unique($pks);
974
975 $data = [];
976 for ($i = 0; $i < count($targets); $i++) {
977 $data[$i] = [
978 'username' => $targets[$i],
979 'pk' => $pks[$i],
980 ];
981 }
982
983 //output("Selected " . count($targets) . " targets: @" . implode(", @", $targets) . ".");
984 //output("Please confirm that the selected targets are correct.");
985 //output("1 - [Yes]");
986 //output("2 - [No]");
987 //output("3 - [Exit]");
988
989 $confirm = "1";
990
991 if (empty($confirm)) {
992 do {
993 $confirm = getVarFromUser("Choice");
994 } while (empty($confirm));
995 }
996
997 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
998 // All fine
999 } else {
1000 $is_choice_ok = false;
1001 do {
1002 output("Choice is incorrect. Type 1, 2 or 3.");
1003 $confirm = getVarFromUser("Choice");
1004
1005 if (empty($confirm)) {
1006 do {
1007 $confirm = getVarFromUser("Choice");
1008 } while (empty($confirm));
1009 }
1010
1011 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
1012 $is_choice_ok = true;
1013 }
1014 } while (!$is_choice_ok);
1015 }
1016
1017 if ($confirm == '3') {
1018 run($ig);
1019 } elseif ($confirm == '2') {
1020 $data = define_targets($ig);
1021 } else {
1022 // All fine. Going to masslooking.
1023 }
1024
1025 return $data;
1026}
1027
1028/**
1029 * Get varable from user
1030 */
1031function getVarFromUser($text) {
1032 echo $text . ": ";
1033 $var = trim(fgets(STDIN));
1034 return $var;
1035}
1036
1037/**
1038 * Output message with data to console
1039 */
1040function output($message) {
1041 echo "[", date("H:i:s"), "] ", $message, PHP_EOL;
1042}
1043
1044/**
1045 * Output clean message to console
1046 */
1047function output_clean($message) {
1048 echo $message, PHP_EOL;
1049}
1050
1051/**
1052 * Validates proxy address
1053 */
1054function isValidProxy($proxy) {
1055 output("Connecting to Instagram...");
1056
1057 try {
1058 $client = new \GuzzleHttp\Client();
1059 $res = $client->request('GET', 'http://www.instagram.com',
1060 [
1061 "timeout" => 60,
1062 "proxy" => $proxy
1063 ]);
1064 $code = $res->getStatusCode();
1065 $is_connected = true;
1066 } catch (\Exception $e) {
1067 output($e->getMessage());
1068 return false;
1069 }
1070
1071 return $code == 200;
1072}
1073
1074/**
1075 * Validates proxy address
1076 */
1077function finishLogin($ig, $login, $password, $proxy) {
1078 $is_connected = false;
1079 $is_connected_count = 0;
1080
1081 try {
1082 do {
1083 if ($is_connected_count == 10) {
1084 if ($e->getResponse()) {
1085 output($e->getMessage());
1086 }
1087 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
1088 output($fail_message);
1089 run($ig);
1090 }
1091
1092 if ($proxy == "3") {
1093 // Skip proxy setup
1094 } else {
1095 $ig->setProxy($proxy);
1096 }
1097
1098 try {
1099 $login_resp = $ig->login($login, $password);
1100
1101 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
1102 // Default verification method is phone
1103 $twofa_method = '1';
1104
1105 // Detect is Authentification app verification is available
1106 $is_totp = json_decode(json_encode($login_resp), true);
1107 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
1108 output("Two-factor authentication required, please enter the code from you Authentication app");
1109 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1110 $twofa_method = '3';
1111 } else {
1112 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
1113 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
1114 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1115 }
1116
1117 $twofa_code = getVarFromUser("Two-factor code");
1118
1119 if (empty($twofa_code)) {
1120 do {
1121 $twofa_code = getVarFromUser("Two-factor code");
1122 } while (empty($twofa_code));
1123 }
1124
1125 $is_connected = false;
1126 $is_connected_count = 0;
1127 do {
1128 if ($is_connected_count == 10) {
1129 if ($e->getResponse()) {
1130 output($e->getMessage());
1131 }
1132 output($fail_message);
1133 run($ig);
1134 }
1135
1136 if ($is_connected_count == 0) {
1137 output("Two-factor authentication in progress...");
1138 }
1139
1140 try {
1141 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1142 $is_connected = true;
1143 } catch (\InstagramAPI\Exception\NetworkException $e) {
1144 sleep(7);
1145 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1146 sleep(7);
1147 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1148 $is_code_correct = false;
1149 $is_connected= true;
1150 do {
1151 output("Code is incorrect. Please check the syntax and try again.");
1152 $twofa_code = getVarFromUser("Two-factor code");
1153
1154 if (empty($twofa_code)) {
1155 do {
1156 $twofa_code = getVarFromUser("Security code");
1157 } while (empty($twofa_code));
1158 }
1159
1160 $is_connected = false;
1161 $is_connected_count = 0;
1162 do {
1163 try {
1164 if ($is_connected_count == 10) {
1165 if ($e->getResponse()) {
1166 output($e->getMessage());
1167 }
1168 output($fail_message);
1169 run($ig);
1170 }
1171
1172 if ($is_connected_count == 0) {
1173 output("Verification in progress...");
1174 }
1175 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1176 $is_code_correct = true;
1177 $is_connected = true;
1178 } catch (\InstagramAPI\Exception\NetworkException $e) {
1179 sleep(7);
1180 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1181 sleep(7);
1182 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1183 $is_code_correct = false;
1184 $is_connected = true;
1185 } catch (\Exception $e) {
1186 throw new $e;
1187 }
1188 $is_connected_count += 1;
1189 } while (!$is_connected);
1190 } while (!$is_code_correct);
1191 } catch (\Exception $e) {
1192 throw $e;
1193 }
1194
1195 $is_connected_count += 1;
1196 } while (!$is_connected);
1197 }
1198
1199 $is_connected = true;
1200 } catch (\InstagramAPI\Exception\NetworkException $e) {
1201 sleep(7);
1202 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1203 sleep(7);
1204 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1205 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
1206 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1207 output("Instagram Response: " . json_encode($e->gerResponse()));
1208 output("Couldn't complete the verification challenge. Please try again later.");
1209 throw new Exception("Developer code: Challenge loop.");
1210 } catch (\Exception $e) {
1211 throw $e;
1212 }
1213
1214 $is_connected_count += 1;
1215 } while (!$is_connected);
1216 } catch (\Exception $e){
1217 output($e->getMessage());
1218 run($ig);
1219 }
1220
1221 return $ig;
1222}
1223
1224/**
1225 * Verification challenge
1226 */
1227function challange($ig, $login, $password, $api_path, $security_code, $proxy) {
1228 $is_connected = false;
1229 $is_connected_count = 0;
1230 $fail_message = "There is a problem with your Ethernet connection or Instagram is down at the moment. We couldn't establish connection with Instagram 10 times. Please try again later.";
1231
1232 do {
1233 if ($is_connected_count == 10) {
1234 if ($e->getResponse()) {
1235 output($e->getMessage());
1236 }
1237 throw new Exception($fail_message);
1238 }
1239
1240 if ($is_connected_count == 0) {
1241 output("Verification in progress...");
1242 }
1243
1244 try {
1245 $challenge_resp = $ig->finishChallengeLogin($login, $password, $api_path, $security_code);
1246 $is_connected = true;
1247 } catch (\InstagramAPI\Exception\NetworkException $e) {
1248 sleep(7);
1249 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1250 sleep(7);
1251 } catch (\InstagramAPI\Exception\InstagramException $e) {
1252
1253 if ($e->hasResponse()) {
1254 $msg = $e->getResponse()->getMessage();
1255 output($msg);
1256 } else {
1257 $msg = explode(":", $e->getMessage(), 2);
1258 $msg = end($msg);
1259 output($msg);
1260 }
1261
1262 output("Type 3 - to exit.");
1263
1264 $security_code = getVarFromUser("Security code");
1265
1266 if (empty($security_code)) {
1267 do {
1268 $security_code = getVarFromUser("Security code");
1269 } while (empty($security_code));
1270 }
1271
1272 if ($security_code == "3") {
1273 throw new Exception("Reset in progress...");
1274 }
1275
1276 } catch (\Exception $e) {
1277 $msg = $e->getMessage();
1278 if ($msg == 'Invalid Login Response at finishChallengeLogin().') {
1279 sleep(7);
1280 $ig = finishLogin($ig, $login, $password, $proxy);
1281 $is_connected = true;
1282 } else {
1283 throw $e;
1284 }
1285 }
1286
1287 $is_connected_count += 1;
1288 } while (!$is_connected);
1289
1290 return $ig;
1291}
1292
1293/**
1294 * Masslooking loop - Algorithm #2
1295 */
1296function masslooking_v2($data, $ig, $delay) {
1297
1298 $view_count = 0;
1299 $st_count = 0;
1300 $st_count_seen = 0;
1301 $begin = strtotime(date("Y-m-d H:i:s"));
1302 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1303 $begin_f = strtotime(date("Y-m-d H:i:s"));
1304 $speed = 0;
1305 $delitel = 0;
1306 $counter1 = 0;
1307 $counter2 = 0;
1308 $stories = [];
1309
1310 output("Masslooking loop started.");
1311
1312 $targets = [];
1313 $targets = $data;
1314
1315 for ($i = 0; $i < count($data); $i++) {
1316 $data[$i] += [
1317 'rank_token' => \InstagramAPI\Signatures::generateUUID(),
1318 'users_count' => 0,
1319 'max_id' => null,
1320 'begin_gf' => null
1321 ];
1322 }
1323
1324 do {
1325 foreach ($data as $key => $d) {
1326 try {
1327 if ($d['max_id'] == null) {
1328 $is_gf_first = 1;
1329 }
1330
1331 if (!empty($d['begin_gf'])) {
1332 $current_time = strtotime(date("Y-m-d H:i:s"));
1333 if (($current_time - $d['begin_gf']) < 7) {
1334 $sleep_time = 7 - ($current_time - $d['begin_gf']);
1335 sleep($sleep_time);
1336 }
1337 }
1338
1339 $followers = $ig->people->getFollowers($d['pk'], $d['rank_token'], null, $d['max_id']);
1340 $data[$key]['begin_gf'] = strtotime(date("Y-m-d H:i:s"));
1341
1342 if (empty($followers->getUsers())) {
1343 output("@" . $d['username'] . " don't have any follower.");
1344 unset($data[$key]);
1345 continue;
1346 }
1347
1348 // Get next $max_id value
1349 $data[$key]['max_id'] = $followers->getNextMaxId();
1350
1351 $followers_ids = [];
1352 foreach ($followers->getUsers() as $follower) {
1353 $followers_ids[] = $follower->getPk();
1354 }
1355
1356 $data[$key]['users_count'] = $d['users_count'] + count($followers_ids);
1357
1358 $number = count($followers_ids);
1359
1360 if ($is_gf_first) {
1361 output($number . " followers of @" . $d['username'] . " collected.");
1362 $is_gf_first = 0;
1363 } else {
1364 output("Next " . $number . " followers of @" . $d['username'] . " collected. Total: " . number_format($data[$key]['users_count'], 0, '.', ' ') . " followers of @" . $d['username'] . " parsed.");
1365 }
1366
1367 $index_new = 0;
1368 $index_old = 0;
1369 $last = false;
1370
1371 do {
1372 $index_new += 13;
1373
1374 if (!isset($followers_ids[$index_new])) {
1375 do {
1376 $index_new -= 1;
1377 } while (!isset($followers_ids[$index_new]));
1378 $last = true;
1379 }
1380
1381 if ($index_new < $index_old) {
1382 break;
1383 }
1384
1385 $ids = [];
1386 for ($i = $index_old; $i <= $index_new; $i++) {
1387 $ids[] = $followers_ids[$i];
1388 }
1389
1390 try {
1391 $stories_reels = $ig->story->getReelsMediaFeed($ids);
1392
1393 $counter1 += 1;
1394
1395 if (isset($stories_reels) && $stories_reels->isOk() && count($stories_reels->getReels()->getData()) > 0) {
1396 // Save user story reels's to array
1397 $reels = [];
1398 $reels = $stories_reels->getReels()->getData();
1399
1400 foreach ($reels as $r) {
1401 $items = [];
1402 $stories_loop = [];
1403 $items = $r->getItems();
1404
1405 foreach ($items as $item) {
1406 if (!$item->getId()) {
1407 // Item is not valid
1408 continue;
1409 }
1410 $stories_loop[] = $item;
1411 }
1412
1413 if (empty($stories)) {
1414 $stories = $stories_loop;
1415 } else {
1416 $stories = array_merge($stories, $stories_loop);
1417 }
1418
1419 $st_count = $st_count + count($stories_loop);
1420 $view_count = $view_count + count($stories_loop);
1421
1422 $now = strtotime(date("Y-m-d H:i:s"));
1423 if ($now - $begin > 299) {
1424 $begin = strtotime(date("Y-m-d H:i:s"));
1425 $delitel = $delitel + 1;
1426 $speed = (int)($view_count * 12 * 24 / $delitel);
1427 output_clean("");
1428 output_clean("Estimated speed is " . number_format($speed, 0, '.', ' ') . " stories/day.");
1429 // output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1430 output_clean("");
1431 }
1432
1433 $now_f = strtotime(date("Y-m-d H:i:s"));
1434 if ($now_f - $begin_f > 1) {
1435 $begin_f = strtotime(date("Y-m-d H:i:s"));
1436 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1437 output($st_count . " stories found.");
1438 }
1439
1440 if ($st_count > 200) {
1441 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1442 output($st_count . " stories found.");
1443
1444 $now_ms = strtotime(date("Y-m-d H:i:s"));
1445 if ($now_ms - $begin_ms >= $delay) {
1446 // all fine
1447 } else {
1448 $counter3 = $delay - ($now_ms - $begin_ms);
1449 output("Starting " . $counter3 . " second(s) delay for bypassing Instagram limits.");
1450 do {
1451 output($counter3 . " second(s) left.");
1452 sleep(1);
1453 $counter3 -= 1;
1454 } while ($counter3 != 0);
1455 }
1456
1457 // Mark collected stories as seen
1458 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1459 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1460
1461 $st_count_seen = number_format($st_count, 0, '.', ' ');
1462 $counter2 += 1;
1463 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1464 output($st_count_seen . " stories marked as seen.");
1465
1466 output_clean("");
1467 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1468 //output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1469 output_clean("");
1470
1471 // Initialize arrays and parameters again
1472 $stories = [];
1473 $st_count = 0;
1474 }
1475 }
1476 }
1477
1478 if (($st_count > 0) && $last && $data[$key]['max_id'] == null) {
1479 // Mark collected stories as seen
1480 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1481
1482 $st_count_seen = number_format($st_count, 0, '.', ' ');
1483 $counter2 += 1;
1484 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1485 output($st_count_seen . " stories marked as seen.");
1486 output_clean("");
1487 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1488 output_clean("");
1489
1490 // Initialize arrays and parameters again
1491 $stories = [];
1492 $st_count = 0;
1493 }
1494 } catch (\InstagramAPI\Exception\NetworkException $e) {
1495 output("We couldn't connect to Instagram at the moment. Trying again.");
1496 sleep(7);
1497 $index_new -= 13;
1498 continue;
1499 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1500 output("Instagram sent us empty response. Trying again.");
1501 sleep(7);
1502 $index_new -= 13;
1503 continue;
1504 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1505 output("Please login again to your Instagram account. Login required.");
1506 run($ig);
1507 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1508 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1509 run($ig);
1510 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1511 output("Please go to Instagram website or mobile app and pass checkpoint!");
1512 run($ig);
1513 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1514 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
1515 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1516 run($ig);
1517 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1518 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1519 run($ig);
1520 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1521 output("Access to Instagram API restricted for spam behavior or otherwise abusing.");
1522 run($ig);
1523 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1524 output("Throttled by Instagram because of too many API requests.");
1525 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1526 run($ig);
1527 } catch (Exception $e){
1528 output($e->getMessage());
1529 sleep(7);
1530 }
1531
1532 $index_old = $index_new + 1;
1533
1534 } while ($last == false);
1535
1536 // Check is $max_id is null
1537 if ($data[$key]['max_id'] == null) {
1538 output_clean("All stories of @" . $d['username'] . "'s followers successfully seen.");
1539 unset($data[$key]);
1540 continue;
1541 }
1542
1543 } catch (\InstagramAPI\Exception\NetworkException $e) {
1544 sleep(7);
1545 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1546 sleep(7);
1547 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1548 output("Please login again to your Instagram account. Login required.");
1549 run($ig);
1550 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1551 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1552 run($ig);
1553 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1554 output("Please go to Instagram website or mobile app and pass checkpoint!");
1555 run($ig);
1556 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1557 output("Your account has been disabled for violating Instagram terms. Go Instagram website or mobile app to learn how you may be able to restore your account.");
1558 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1559 run($ig);
1560 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1561 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1562 run($ig);
1563 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1564 output("Access to Instagram API restricted for spam behavior or otherwise abusing. You can try to use Session Catcher script (available by https://nextpost.tech/session-catcher) to get valid Instagram session from location, where your account created from.");
1565 run($ig);
1566 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1567 output("Throttled by Instagram because of too many API requests.");
1568 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1569 run($ig);
1570 } catch (Exception $e){
1571 output($e->getMessage());
1572 sleep(7);
1573 }
1574 }
1575 } while (!empty($data));
1576
1577 output_clean("All stories related to the targets seen. Starting the new loop.");
1578 output_clean("");
1579
1580 masslooking_v2($targets, $ig, $delay);
1581}
1582
1583/**
1584 * Send request
1585 * @param $url
1586 * @return mixed
1587 */
1588function request($url) {
1589 $ch = curl_init();
1590
1591 curl_setopt($ch, CURLOPT_URL, $url);
1592 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1593 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1594 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1595
1596 $return = curl_exec($ch);
1597
1598 curl_close($ch);
1599
1600 return $return;
1601}
1602
1603/**
1604 * Get IP details
1605 */
1606function ip_details() {
1607 try {
1608 $json = request("http://www.geoplugin.net/json.gp");
1609 } catch (Exception $e){
1610 $msg = $e->getMessage();
1611 output($msg);
1612 run($ig);
1613 }
1614 $details = json_decode($json);
1615 return $details;
1616}
1617/**
1618 * Validate license
1619 * @param $license_key
1620 * @return string
1621 */
1622function activate_license($license_key, $ig) {
1623 return 'valid';
1624}
1625
1626?>