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