· 6 years ago · Sep 29, 2019, 05:34 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, farr
849adillajingga, saqinapaprilly, alyafrcn, dindamaulinaaa, hajarans, natasyaptr___, marsya
850ayuannisa, nabilaaprikarnin, steyllanandad, jessicadavaa, revifad, tasyaa.sa, salshabil
851laadr, lalamarionmj, nazhafira_, sarahsuci15, pevpearce, amandamadaa, nadhieraa, aryrsh
852aaar, 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";
853 if (empty($targets_input)) {
854 do {
855 $targets_input = getVarFromUser("Usernames");
856 } while (empty($targets_input));
857 }
858
859 $targets_input = str_replace(' ','',$targets_input);
860 $targets = [];
861 $targets = explode(',',trim($targets_input));
862 $targets = array_unique($targets);
863
864 $pks = [];
865 $filtered_targets = [];
866 foreach ($targets as $target) {
867
868 $is_connected = false;
869 $is_connected_count = 0;
870 do {
871 if ($is_connected_count == 10) {
872 if ($e->getResponse()) {
873 output($e->getMessage());
874 }
875 $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.";
876 output($fail_message);
877 run($ig);
878 }
879
880 try {
881 $user_resp = $ig->people->getUserIdForName($target);
882 output("@" . $target . " - [OK]");
883 $filtered_targets[] = $target;
884 $pks[] = $user_resp;
885 $is_connected = true;
886 if (($target != $targets[count($targets) - 1]) && (count($targets) > 0)) {
887 sleep(1);
888 }
889 } catch (\InstagramAPI\Exception\NetworkException $e) {
890 sleep(7);
891 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
892 sleep(7);
893 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
894 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
895 run($ig);
896 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
897 output("Please go to Instagram website or mobile app and pass checkpoint!");
898 run($ig);
899 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
900 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.");
901 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
902 run($ig);
903 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
904 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
905 run($ig);
906 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
907 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.");
908 run($ig);
909 } catch (\InstagramAPI\Exception\ThrottledException $e) {
910 output("Throttled by Instagram because of too many API requests.");
911 output("Please login again after 1 hour. You reached Instagram limits.");
912 run($ig);
913 } catch (InstagramAPI\Exception\NotFoundException $e) {
914 $is_connected = true;
915 $is_username_correct = false;
916 do {
917 output("Instagram profile username @" . $target . " is incorrect or maybe user just blocked you (Login to Instagram website or mobile app and check that).");
918 output("Type 3 for skip this target.");
919 $target_new = getVarFromUser("Please provide valid username");
920
921 if (empty($target_new)) {
922 do {
923 $target_new = getVarFromUser("Please provide valid username");
924 } while (empty($target_new));
925 }
926
927 if ($target_new == "3") {
928 break;
929 } else {
930 $is_connected = false;
931 $is_connected_count = 0;
932 do {
933 if ($is_connected_count == 10) {
934 if ($e->getResponse()) {
935 output($e->getMessage());
936 }
937 $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.";
938 output($fail_message);
939 run($ig);
940 }
941
942 try {
943 $user_resp = $ig->people->getUserIdForName($target_new);
944 output("@" . $target_new . " - [OK]");
945 $filtered_targets[] = $target_new;
946 $pks[] = $user_resp;
947 $is_username_correct = true;
948 $is_connected = true;
949 } catch (\InstagramAPI\Exception\NetworkException $e) {
950 sleep(7);
951 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
952 sleep(7);
953 } catch (InstagramAPI\Exception\NotFoundException $e) {
954 $is_username_correct = false;
955 $is_connected = true;
956 } catch (\Exception $e) {
957 output($e->getMessage());
958 run($ig);
959 }
960 $is_connected_count += 1;
961 } while (!$is_connected);
962 }
963 } while (!$is_username_correct);
964 } catch (Exception $e){
965 output($e->getMessage());
966 run($ig);
967 }
968
969 $is_connected_count += 1;
970 } while (!$is_connected);
971 }
972 } while (empty($filtered_targets));
973
974 $targets = array_unique($filtered_targets);
975 $pks = array_unique($pks);
976
977 $data = [];
978 for ($i = 0; $i < count($targets); $i++) {
979 $data[$i] = [
980 'username' => $targets[$i],
981 'pk' => $pks[$i],
982 ];
983 }
984
985 //output("Selected " . count($targets) . " targets: @" . implode(", @", $targets) . ".");
986 //output("Please confirm that the selected targets are correct.");
987 //output("1 - [Yes]");
988 //output("2 - [No]");
989 //output("3 - [Exit]");
990
991 $confirm = "1";
992
993 if (empty($confirm)) {
994 do {
995 $confirm = getVarFromUser("Choice");
996 } while (empty($confirm));
997 }
998
999 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
1000 // All fine
1001 } else {
1002 $is_choice_ok = false;
1003 do {
1004 output("Choice is incorrect. Type 1, 2 or 3.");
1005 $confirm = getVarFromUser("Choice");
1006
1007 if (empty($confirm)) {
1008 do {
1009 $confirm = getVarFromUser("Choice");
1010 } while (empty($confirm));
1011 }
1012
1013 if ($confirm == '1' || $confirm == '2' || $confirm == '3') {
1014 $is_choice_ok = true;
1015 }
1016 } while (!$is_choice_ok);
1017 }
1018
1019 if ($confirm == '3') {
1020 run($ig);
1021 } elseif ($confirm == '2') {
1022 $data = define_targets($ig);
1023 } else {
1024 // All fine. Going to masslooking.
1025 }
1026
1027 return $data;
1028}
1029
1030/**
1031 * Get varable from user
1032 */
1033function getVarFromUser($text) {
1034 echo $text . ": ";
1035 $var = trim(fgets(STDIN));
1036 return $var;
1037}
1038
1039/**
1040 * Output message with data to console
1041 */
1042function output($message) {
1043 echo "[", date("H:i:s"), "] ", $message, PHP_EOL;
1044}
1045
1046/**
1047 * Output clean message to console
1048 */
1049function output_clean($message) {
1050 echo $message, PHP_EOL;
1051}
1052
1053/**
1054 * Validates proxy address
1055 */
1056function isValidProxy($proxy) {
1057 output("Connecting to Instagram...");
1058
1059 try {
1060 $client = new \GuzzleHttp\Client();
1061 $res = $client->request('GET', 'http://www.instagram.com',
1062 [
1063 "timeout" => 60,
1064 "proxy" => $proxy
1065 ]);
1066 $code = $res->getStatusCode();
1067 $is_connected = true;
1068 } catch (\Exception $e) {
1069 output($e->getMessage());
1070 return false;
1071 }
1072
1073 return $code == 200;
1074}
1075
1076/**
1077 * Validates proxy address
1078 */
1079function finishLogin($ig, $login, $password, $proxy) {
1080 $is_connected = false;
1081 $is_connected_count = 0;
1082
1083 try {
1084 do {
1085 if ($is_connected_count == 10) {
1086 if ($e->getResponse()) {
1087 output($e->getMessage());
1088 }
1089 $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.";
1090 output($fail_message);
1091 run($ig);
1092 }
1093
1094 if ($proxy == "3") {
1095 // Skip proxy setup
1096 } else {
1097 $ig->setProxy($proxy);
1098 }
1099
1100 try {
1101 $login_resp = $ig->login($login, $password);
1102
1103 if ($login_resp !== null && $login_resp->isTwoFactorRequired()) {
1104 // Default verification method is phone
1105 $twofa_method = '1';
1106
1107 // Detect is Authentification app verification is available
1108 $is_totp = json_decode(json_encode($login_resp), true);
1109 if ($is_totp['two_factor_info']['totp_two_factor_on'] == '1'){
1110 output("Two-factor authentication required, please enter the code from you Authentication app");
1111 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1112 $twofa_method = '3';
1113 } else {
1114 output("Two-factor authentication required, please enter the code sent to your number ending in %s",
1115 $login_resp->getTwoFactorInfo()->getObfuscatedPhoneNumber());
1116 $twofa_id = $login_resp->getTwoFactorInfo()->getTwoFactorIdentifier();
1117 }
1118
1119 $twofa_code = getVarFromUser("Two-factor code");
1120
1121 if (empty($twofa_code)) {
1122 do {
1123 $twofa_code = getVarFromUser("Two-factor code");
1124 } while (empty($twofa_code));
1125 }
1126
1127 $is_connected = false;
1128 $is_connected_count = 0;
1129 do {
1130 if ($is_connected_count == 10) {
1131 if ($e->getResponse()) {
1132 output($e->getMessage());
1133 }
1134 output($fail_message);
1135 run($ig);
1136 }
1137
1138 if ($is_connected_count == 0) {
1139 output("Two-factor authentication in progress...");
1140 }
1141
1142 try {
1143 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1144 $is_connected = true;
1145 } catch (\InstagramAPI\Exception\NetworkException $e) {
1146 sleep(7);
1147 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1148 sleep(7);
1149 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1150 $is_code_correct = false;
1151 $is_connected= true;
1152 do {
1153 output("Code is incorrect. Please check the syntax and try again.");
1154 $twofa_code = getVarFromUser("Two-factor code");
1155
1156 if (empty($twofa_code)) {
1157 do {
1158 $twofa_code = getVarFromUser("Security code");
1159 } while (empty($twofa_code));
1160 }
1161
1162 $is_connected = false;
1163 $is_connected_count = 0;
1164 do {
1165 try {
1166 if ($is_connected_count == 10) {
1167 if ($e->getResponse()) {
1168 output($e->getMessage());
1169 }
1170 output($fail_message);
1171 run($ig);
1172 }
1173
1174 if ($is_connected_count == 0) {
1175 output("Verification in progress...");
1176 }
1177 $twofa_resp = $ig->finishTwoFactorLogin($login, $password, $twofa_id, $twofa_code, $twofa_method);
1178 $is_code_correct = true;
1179 $is_connected = true;
1180 } catch (\InstagramAPI\Exception\NetworkException $e) {
1181 sleep(7);
1182 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1183 sleep(7);
1184 } catch (\InstagramAPI\Exception\InvalidSmsCodeException $e) {
1185 $is_code_correct = false;
1186 $is_connected = true;
1187 } catch (\Exception $e) {
1188 throw new $e;
1189 }
1190 $is_connected_count += 1;
1191 } while (!$is_connected);
1192 } while (!$is_code_correct);
1193 } catch (\Exception $e) {
1194 throw $e;
1195 }
1196
1197 $is_connected_count += 1;
1198 } while (!$is_connected);
1199 }
1200
1201 $is_connected = true;
1202 } catch (\InstagramAPI\Exception\NetworkException $e) {
1203 sleep(7);
1204 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1205 sleep(7);
1206 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1207 throw new Exception("Please go to Instagram website or mobile app and pass checkpoint!");
1208 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1209 output("Instagram Response: " . json_encode($e->gerResponse()));
1210 output("Couldn't complete the verification challenge. Please try again later.");
1211 throw new Exception("Developer code: Challenge loop.");
1212 } catch (\Exception $e) {
1213 throw $e;
1214 }
1215
1216 $is_connected_count += 1;
1217 } while (!$is_connected);
1218 } catch (\Exception $e){
1219 output($e->getMessage());
1220 run($ig);
1221 }
1222
1223 return $ig;
1224}
1225
1226/**
1227 * Verification challenge
1228 */
1229function challange($ig, $login, $password, $api_path, $security_code, $proxy) {
1230 $is_connected = false;
1231 $is_connected_count = 0;
1232 $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.";
1233
1234 do {
1235 if ($is_connected_count == 10) {
1236 if ($e->getResponse()) {
1237 output($e->getMessage());
1238 }
1239 throw new Exception($fail_message);
1240 }
1241
1242 if ($is_connected_count == 0) {
1243 output("Verification in progress...");
1244 }
1245
1246 try {
1247 $challenge_resp = $ig->finishChallengeLogin($login, $password, $api_path, $security_code);
1248 $is_connected = true;
1249 } catch (\InstagramAPI\Exception\NetworkException $e) {
1250 sleep(7);
1251 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1252 sleep(7);
1253 } catch (\InstagramAPI\Exception\InstagramException $e) {
1254
1255 if ($e->hasResponse()) {
1256 $msg = $e->getResponse()->getMessage();
1257 output($msg);
1258 } else {
1259 $msg = explode(":", $e->getMessage(), 2);
1260 $msg = end($msg);
1261 output($msg);
1262 }
1263
1264 output("Type 3 - to exit.");
1265
1266 $security_code = getVarFromUser("Security code");
1267
1268 if (empty($security_code)) {
1269 do {
1270 $security_code = getVarFromUser("Security code");
1271 } while (empty($security_code));
1272 }
1273
1274 if ($security_code == "3") {
1275 throw new Exception("Reset in progress...");
1276 }
1277
1278 } catch (\Exception $e) {
1279 $msg = $e->getMessage();
1280 if ($msg == 'Invalid Login Response at finishChallengeLogin().') {
1281 sleep(7);
1282 $ig = finishLogin($ig, $login, $password, $proxy);
1283 $is_connected = true;
1284 } else {
1285 throw $e;
1286 }
1287 }
1288
1289 $is_connected_count += 1;
1290 } while (!$is_connected);
1291
1292 return $ig;
1293}
1294
1295/**
1296 * Masslooking loop - Algorithm #2
1297 */
1298function masslooking_v2($data, $ig, $delay) {
1299
1300 $view_count = 0;
1301 $st_count = 0;
1302 $st_count_seen = 0;
1303 $begin = strtotime(date("Y-m-d H:i:s"));
1304 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1305 $begin_f = strtotime(date("Y-m-d H:i:s"));
1306 $speed = 0;
1307 $delitel = 0;
1308 $counter1 = 0;
1309 $counter2 = 0;
1310 $stories = [];
1311
1312 output("Masslooking loop started.");
1313
1314 $targets = [];
1315 $targets = $data;
1316
1317 for ($i = 0; $i < count($data); $i++) {
1318 $data[$i] += [
1319 'rank_token' => \InstagramAPI\Signatures::generateUUID(),
1320 'users_count' => 0,
1321 'max_id' => null,
1322 'begin_gf' => null
1323 ];
1324 }
1325
1326 do {
1327 foreach ($data as $key => $d) {
1328 try {
1329 if ($d['max_id'] == null) {
1330 $is_gf_first = 1;
1331 }
1332
1333 if (!empty($d['begin_gf'])) {
1334 $current_time = strtotime(date("Y-m-d H:i:s"));
1335 if (($current_time - $d['begin_gf']) < 7) {
1336 $sleep_time = 7 - ($current_time - $d['begin_gf']);
1337 sleep($sleep_time);
1338 }
1339 }
1340
1341 $followers = $ig->people->getFollowers($d['pk'], $d['rank_token'], null, $d['max_id']);
1342 $data[$key]['begin_gf'] = strtotime(date("Y-m-d H:i:s"));
1343
1344 if (empty($followers->getUsers())) {
1345 output("@" . $d['username'] . " don't have any follower.");
1346 unset($data[$key]);
1347 continue;
1348 }
1349
1350 // Get next $max_id value
1351 $data[$key]['max_id'] = $followers->getNextMaxId();
1352
1353 $followers_ids = [];
1354 foreach ($followers->getUsers() as $follower) {
1355 $followers_ids[] = $follower->getPk();
1356 }
1357
1358 $data[$key]['users_count'] = $d['users_count'] + count($followers_ids);
1359
1360 $number = count($followers_ids);
1361
1362 if ($is_gf_first) {
1363 output($number . " followers of @" . $d['username'] . " collected.");
1364 $is_gf_first = 0;
1365 } else {
1366 output("Next " . $number . " followers of @" . $d['username'] . " collected. Total: " . number_format($data[$key]['users_count'], 0, '.', ' ') . " followers of @" . $d['username'] . " parsed.");
1367 }
1368
1369 $index_new = 0;
1370 $index_old = 0;
1371 $last = false;
1372
1373 do {
1374 $index_new += 13;
1375
1376 if (!isset($followers_ids[$index_new])) {
1377 do {
1378 $index_new -= 1;
1379 } while (!isset($followers_ids[$index_new]));
1380 $last = true;
1381 }
1382
1383 if ($index_new < $index_old) {
1384 break;
1385 }
1386
1387 $ids = [];
1388 for ($i = $index_old; $i <= $index_new; $i++) {
1389 $ids[] = $followers_ids[$i];
1390 }
1391
1392 try {
1393 $stories_reels = $ig->story->getReelsMediaFeed($ids);
1394
1395 $counter1 += 1;
1396
1397 if (isset($stories_reels) && $stories_reels->isOk() && count($stories_reels->getReels()->getData()) > 0) {
1398 // Save user story reels's to array
1399 $reels = [];
1400 $reels = $stories_reels->getReels()->getData();
1401
1402 foreach ($reels as $r) {
1403 $items = [];
1404 $stories_loop = [];
1405 $items = $r->getItems();
1406
1407 foreach ($items as $item) {
1408 if (!$item->getId()) {
1409 // Item is not valid
1410 continue;
1411 }
1412 $stories_loop[] = $item;
1413 }
1414
1415 if (empty($stories)) {
1416 $stories = $stories_loop;
1417 } else {
1418 $stories = array_merge($stories, $stories_loop);
1419 }
1420
1421 $st_count = $st_count + count($stories_loop);
1422 $view_count = $view_count + count($stories_loop);
1423
1424 $now = strtotime(date("Y-m-d H:i:s"));
1425 if ($now - $begin > 299) {
1426 $begin = strtotime(date("Y-m-d H:i:s"));
1427 $delitel = $delitel + 1;
1428 $speed = (int)($view_count * 12 * 24 / $delitel);
1429 output_clean("");
1430 output_clean("Estimated speed is " . number_format($speed, 0, '.', ' ') . " stories/day.");
1431 // output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1432 output_clean("");
1433 }
1434
1435 $now_f = strtotime(date("Y-m-d H:i:s"));
1436 if ($now_f - $begin_f > 1) {
1437 $begin_f = strtotime(date("Y-m-d H:i:s"));
1438 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1439 output($st_count . " stories found.");
1440 }
1441
1442 if ($st_count > 200) {
1443 // output($st_count . " stories found. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ")");
1444 output($st_count . " stories found.");
1445
1446 $now_ms = strtotime(date("Y-m-d H:i:s"));
1447 if ($now_ms - $begin_ms >= $delay) {
1448 // all fine
1449 } else {
1450 $counter3 = $delay - ($now_ms - $begin_ms);
1451 output("Starting " . $counter3 . " second(s) delay for bypassing Instagram limits.");
1452 do {
1453 output($counter3 . " second(s) left.");
1454 sleep(1);
1455 $counter3 -= 1;
1456 } while ($counter3 != 0);
1457 }
1458
1459 // Mark collected stories as seen
1460 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1461 $begin_ms = strtotime(date("Y-m-d H:i:s"));
1462
1463 $st_count_seen = number_format($st_count, 0, '.', ' ');
1464 $counter2 += 1;
1465 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1466 output($st_count_seen . " stories marked as seen.");
1467
1468 output_clean("");
1469 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1470 //output_clean("© Hyperloop Terminal. Developed by Nextpost Developers Team (https://nextpost.tech)");
1471 output_clean("");
1472
1473 // Initialize arrays and parameters again
1474 $stories = [];
1475 $st_count = 0;
1476 }
1477 }
1478 }
1479
1480 if (($st_count > 0) && $last && $data[$key]['max_id'] == null) {
1481 // Mark collected stories as seen
1482 $mark_seen_resp = $ig->story->markMediaSeen($stories);
1483
1484 $st_count_seen = number_format($st_count, 0, '.', ' ');
1485 $counter2 += 1;
1486 // output($st_count_seen . " stories marked as seen. / Debug: getReelsMediaFeed (" . $counter1 . "), markMediaSeen (" . $counter2 . ").");
1487 output($st_count_seen . " stories marked as seen.");
1488 output_clean("");
1489 output_clean("Total: " . number_format($view_count, 0, '.', ' ') . " stories successfully seen.");
1490 output_clean("");
1491
1492 // Initialize arrays and parameters again
1493 $stories = [];
1494 $st_count = 0;
1495 }
1496 } catch (\InstagramAPI\Exception\NetworkException $e) {
1497 output("We couldn't connect to Instagram at the moment. Trying again.");
1498 sleep(7);
1499 $index_new -= 13;
1500 continue;
1501 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1502 output("Instagram sent us empty response. Trying again.");
1503 sleep(7);
1504 $index_new -= 13;
1505 continue;
1506 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1507 output("Please login again to your Instagram account. Login required.");
1508 run($ig);
1509 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1510 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1511 run($ig);
1512 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1513 output("Please go to Instagram website or mobile app and pass checkpoint!");
1514 run($ig);
1515 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1516 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.");
1517 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1518 run($ig);
1519 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1520 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1521 run($ig);
1522 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1523 output("Access to Instagram API restricted for spam behavior or otherwise abusing.");
1524 run($ig);
1525 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1526 output("Throttled by Instagram because of too many API requests.");
1527 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1528 run($ig);
1529 } catch (Exception $e){
1530 output($e->getMessage());
1531 sleep(7);
1532 }
1533
1534 $index_old = $index_new + 1;
1535
1536 } while ($last == false);
1537
1538 // Check is $max_id is null
1539 if ($data[$key]['max_id'] == null) {
1540 output_clean("All stories of @" . $d['username'] . "'s followers successfully seen.");
1541 unset($data[$key]);
1542 continue;
1543 }
1544
1545 } catch (\InstagramAPI\Exception\NetworkException $e) {
1546 sleep(7);
1547 } catch (\InstagramAPI\Exception\EmptyResponseException $e) {
1548 sleep(7);
1549 } catch (\InstagramAPI\Exception\LoginRequiredException $e) {
1550 output("Please login again to your Instagram account. Login required.");
1551 run($ig);
1552 } catch (\InstagramAPI\Exception\ChallengeRequiredException $e) {
1553 output("Please login again and pass verification challenge. Instagram will send you a security code to verify your identity.");
1554 run($ig);
1555 } catch (\InstagramAPI\Exception\CheckpointRequiredException $e) {
1556 output("Please go to Instagram website or mobile app and pass checkpoint!");
1557 run($ig);
1558 } catch (\InstagramAPI\Exception\AccountDisabledException $e) {
1559 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.");
1560 output("Use this form for recovery your account: https://help.instagram.com/contact/1652567838289083");
1561 run($ig);
1562 } catch (\InstagramAPI\Exception\ConsentRequiredException $e) {
1563 output("Instagram updated Terms and Data Policy. Please go to Instagram website or mobile app to review these changes and accept them.");
1564 run($ig);
1565 } catch (\InstagramAPI\Exception\SentryBlockException $e) {
1566 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.");
1567 run($ig);
1568 } catch (\InstagramAPI\Exception\ThrottledException $e) {
1569 output("Throttled by Instagram because of too many API requests.");
1570 output("Please connect account again after 12 hours. You reached Instagram daily limit for masslooking. Just take a break.");
1571 run($ig);
1572 } catch (Exception $e){
1573 output($e->getMessage());
1574 sleep(7);
1575 }
1576 }
1577 } while (!empty($data));
1578
1579 output_clean("All stories related to the targets seen. Starting the new loop.");
1580 output_clean("");
1581
1582 masslooking_v2($targets, $ig, $delay);
1583}
1584
1585/**
1586 * Send request
1587 * @param $url
1588 * @return mixed
1589 */
1590function request($url) {
1591 $ch = curl_init();
1592
1593 curl_setopt($ch, CURLOPT_URL, $url);
1594 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1595 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1596 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1597
1598 $return = curl_exec($ch);
1599
1600 curl_close($ch);
1601
1602 return $return;
1603}
1604
1605/**
1606 * Get IP details
1607 */
1608function ip_details() {
1609 try {
1610 $json = request("http://www.geoplugin.net/json.gp");
1611 } catch (Exception $e){
1612 $msg = $e->getMessage();
1613 output($msg);
1614 run($ig);
1615 }
1616 $details = json_decode($json);
1617 return $details;
1618}
1619/**
1620 * Validate license
1621 * @param $license_key
1622 * @return string
1623 */
1624function activate_license($license_key, $ig) {
1625 return 'valid';
1626}
1627
1628?>