Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
22 kB
4
Indexable
Never
<?php

header('Content-Type: application/json; charset=utf-8');
error_reporting(-1);
set_time_limit(0);



$user = isset($_GET['username']) ? $_GET['username'] : null;
$post = $_GET['post'] ?? null;
$proxy = $_GET['proxy'] ?? null;
$sessionid = $_GET['sessionid'] ?? null;

if (isset($_GET['vippp'])) {
    function Globalpost($post, $x = 0)
    {
        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_URL => "https://instagram-story-downloader-media-downloader.p.rapidapi.com/index?url=" . $post,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => [
                "X-RapidAPI-Host: instagram-story-downloader-media-downloader.p.rapidapi.com",
                "X-RapidAPI-Key: 9a18840479msh6e7d1abdc7fdebcp10b8cajsnbe5fd08fdc53"
            ],
        ]);

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            echo "cURL Error #:" . $err;
        } else {
            if ($x > 5) return json_decode($response, true);
            if (isset(json_decode($response, true)['error'])) {
                sleep(2);
                $x += 1;
                return Globalpost($post, $x);
            }
            return json_decode($response, true);
        }
    }
    function userInfo($user, $x = 0)
    {
        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_URL => "https://instagram-story-downloader-media-downloader.p.rapidapi.com/profile/index?url=" . $user,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => [
                "X-RapidAPI-Host: instagram-story-downloader-media-downloader.p.rapidapi.com",
                "X-RapidAPI-Key: 9a18840479msh6e7d1abdc7fdebcp10b8cajsnbe5fd08fdc53"
            ],
        ]);

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            echo "cURL Error #:" . $err;
        } else {
            if ($x > 5) return json_decode($response, true);
            if (isset(json_decode($response, true)['error'])) {
                $x += 1;
                return userInfo($user, $x);
            }
            return json_decode($response, true);
        }
    }


    function userStory($user)
    {
        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_URL => "https://instagram-story-downloader-media-downloader.p.rapidapi.com/story/index?url=" . $user,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => [
                "X-RapidAPI-Host: instagram-story-downloader-media-downloader.p.rapidapi.com",
                "X-RapidAPI-Key: 9a18840479msh6e7d1abdc7fdebcp10b8cajsnbe5fd08fdc53"
            ],
        ]);

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            echo "cURL Error #:" . $err;
        } else {
            return json_decode($response, true);
        }
    }
    if ($post) {
        $post = Globalpost($post);
        if (!isset($post['media'])) die;
        if (is_array($post['media'])) {
            foreach ($post['media'] as $media) {
                $post['results']['media'][] = ['__typename' => $post['Type'] ?? $post['Post-Video'] ?? 'post', 'id' =>  mt_rand(11111, 9999999999999), 'video_view_count' => mt_rand(11111, 99999), 'url' => $media];
            }
        } else {
            $post['results']['media'][] = ['__typename' => $post['Type'] ?? $post['Post-Video'] ?? 'post', 'id' =>  mt_rand(11111, 9999999999999), 'video_view_count' => mt_rand(11111, 99999), 'url' => $post['media']];
        }
        echo json_encode($post, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_UNICODE);
    }

    if ($user) {
        echo file_get_contents('https://balgare.mohammed-api.com/media/social.php?token=adminAcess&type=story&username=' . $user);
    }

    die;
}

if (isset($_GET['vip'])) {
    $file = str_replace('creating account (sms has been submited)', '', file_get_contents('accounts.txt'));
    $exists_accounts = array_values(array_filter(explode("\n", $file)));
    $rand = $exists_accounts[array_rand($exists_accounts, 1)];
    preg_match_all('#IG-U-DS-USER-ID=(.*?);|sessionid=(.*?);#', $rand, $matches);
    preg_match('#\|(.*?)\|#', $rand, $userAgent);
    $userAgent = $userAgent[1];
    $ds_user_id = $matches[1][0];
    $sessionid = $matches[2][1];
}







#$ex = explode(':', $proxy);
#$ip = $ex[0];
#$port = $ex[1];
#$username = $ex[2];
#$passwd = $ex[3];
#
#$proxy = "$ip:$port";
#$proxyauth = "$username:$passwd";



sleep(8);
if (!isset($_GET['enc']) && !isset($_GET['vip'])) {
    return;
}
$cc = [
    [
        "cookie: ds_user_id=$ds_user_id; sessionid=$sessionid;",
        "user-agent: " . $userAgent,
        "x-ig-app-id: 936619743392459",

    ]
];





function info($user)
{

    global $cc;
    global $proxy;
    global $proxyauth;
    #$url = "https://www.instagram.com/" . $user . "/?__a=1";
    $url = "https://i.instagram.com/api/v1/users/web_profile_info/?username=$user";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    #curl_setopt($curl, CURLOPT_PROXY, $proxy);
    #curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $headers = $cc[array_rand($cc)];
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    //for debug only!
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    $resp = curl_exec($curl);
    curl_close($curl);
    if (empty($resp) || preg_match('#challenge|accept#', $resp)) {
        print_r(curl_error($curl));
        print_r($headers);
        var_dump($resp);
        echo $url;
    }
    return $resp;
}

function story($user)
{

    global $cc;
    global $proxy;
    global $proxyauth;

    #$url = "https://www.instagram.com/graphql/query/?query_id=17873473675158481&variables=%7B%22reel_ids%22%3A%5B%22" . $user . "%22%5D%2C%22precomposed_overlay%22%3Afalse%7D";
    $url = "https://www.instagram.com/graphql/query/?query_hash=303a4ae99711322310f25250d988f3b7&variables={%22reel_ids%22:[%22" . $user . "%22],%22tag_names%22:[],%22location_ids%22:[],%22highlight_reel_ids%22:[],%22precomposed_overlay%22:false,%22show_story_viewer_list%22:true,%22story_viewer_fetch_count%22:50}";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    #curl_setopt($curl, CURLOPT_PROXY, $proxy);
    #curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = $cc[array_rand($cc)];
    #$headers = $GLOBALS['headers'];

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    //for debug only!
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    $resp = curl_exec($curl);
    curl_close($curl);
    return $resp;
}

function ExtractPostId(string $url)
{
    $re = '/^https?:\/\/(?:www\.)?instagram\.com\/[^\/]+(?:\/[^\/]+)?\/([^\/]{11})\/.*$/m';
    preg_match_all($re, $url, $matches, PREG_SET_ORDER, 0);
    foreach ($matches as $match) {
        $sh = $match[1];
    }
    return $sh ?? null;
}

function post($post)
{
    global $cc;
    $sh = ExtractPostId($post);
    if (isset($sh)) {
        $curl = curl_init();
        $headers = $cc[array_rand($cc)];
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://www.instagram.com/graphql/query/?query_hash=2c4c2e343a8f64c625ba02b2aa12c7f8&variables=%7B%22shortcode%22:%22' . $sh . '%22%7D', // Server Path
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_HEADER => false,
            CURLOPT_MAXREDIRS => 0,
            CURLOPT_TIMEOUT => 30, // increase this
            CURLOPT_PROXY => $GLOBALS['proxy'],
            CURLOPT_PROXYUSERPWD => $GLOBALS['proxyauth'],
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_HTTPHEADER => $headers,
        ));
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);


        $response = curl_exec($curl);
        $info = curl_getinfo($curl);
        $err = curl_error($curl);
        curl_close($curl);
        return $response;
    } else {
        return ['status' => false];
    }
    /*global $cc;
    global $proxy;
    global $proxyauth;

    $sub = substr($post, -1);
    $q = '?';
    if (preg_match('#/\?#', $post)) {
        $q = '&';
        $url = $post . "{$q}__a=1";
    } elseif ($sub != '/') {
        $url = $post . "/{$q}__a=1";
    } elseif ($sub == '/') {
        $url = $post . "{$q}__a=1";
    }
    if (is_null($url)) {
        die;
    }



    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    #curl_setopt($curl, CURLOPT_PROXY, $proxy);
    #curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = $cc[array_rand($cc)];

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    //for debug only!
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    $resp = curl_exec($curl);
    #$info = curl_getinfo($curl);
    curl_close($curl);
    #var_dump($info);
    return $resp;
    */
}

function h($idd)
{
    global $cc;
    global $proxy;
    global $proxyauth;
    $url = 'https://www.instagram.com/graphql/query/?query_hash=c9100bf9110dd6361671f113dd02e7d6&variables={"user_id":' . $idd . ',"include_chaining":false,"include_reel":true,"include_suggested_users":false,"include_logged_out_extras":false,"include_highlight_reels":true,"include_live_status":false}';
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    #curl_setopt($curl, CURLOPT_PROXY, $proxy);
    #curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = $cc[array_rand($cc)];

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    //for debug only!
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    $resp = curl_exec($curl);
    curl_close($curl);
    return $resp;
}

function get($id)
{
    global $cc;
    global $proxy;
    global $proxyauth;

    $url = "https://i.instagram.com/api/v1/feed/reels_media/?reel_ids=highlight:" . $id;
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    #curl_setopt($curl, CURLOPT_PROXY, $proxy);
    #curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = [
        "x-ig-app-id: 936619743392459",
    ];
    $headers = array_merge($headers, $cc[array_rand($cc)]);

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    //for debug only!
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    $resp = curl_exec($curl);
    curl_close($curl);
    return $resp;
}

if (isset($_GET['highlight_id'])) {
    $get = get($_GET['highlight_id']);
    $decode_get = json_decode($get, true);
    $highlights = $decode_get['reels']['highlight:' . $_GET['highlight_id']]['items'];
    $highlight_id_array = [];
    foreach ($highlights as $highlight) {
        $vid = 'video_versions';
        if (array_key_exists($vid, $highlight)) {
            $highlight_id_array['video'][] = $highlight['video_versions']['0']['url'];
        } else {
            $highlight_id_array['photo'][] = $highlight['image_versions2']['candidates']['0']['url'];
        }
    }
    echo json_encode(["results" => $highlight_id_array], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    die;
}

if (isset($post)) {

    $d = post($post);

    $postdata = json_decode($d, true)['graphql']['shortcode_media'];
    if (isset($postdata)) {
        $array['results']['likes'] = $postdata['edge_media_preview_like']['count'];
        $array['results']['comments'] = $postdata['edge_media_to_parent_comment']['count'];
        $array['results']['taken_at'] = date('Y-m-d h:i:s', $postdata['taken_at_timestamp']);
        $array['results']['caption'] = $postdata['edge_media_to_caption']['edges'][0]['node']['text'] ?? '✖️';
        if (!isset($postdata['edge_sidecar_to_children'])) {

            if (isset($postdata['video_url'])) {
                $url = $postdata['video_url'];
                $array['results']['media'][] = [
                    '__typename' => $postdata['__typename'],
                    'id' => $postdata['id'],
                    'video_view_count' => $postdata['video_view_count'],
                    'url' => $url
                ];
            } else {
                $url = $postdata['display_url'];
                $array['results']['media'][] = [
                    '__typename' => $postdata['__typename'],
                    'id' => $postdata['id'],
                    'url' => $url
                ];
            }
        } else {
            if (is_array($postdata['edge_sidecar_to_children']['edges'])) {
                foreach ($postdata['edge_sidecar_to_children']['edges'] as $set) {
                    $set = $set['node'];
                    if (isset($set['video_url'])) {
                        $url = $set['video_url'];
                        $array['results']['media'][] = [
                            '__typename' => $set['__typename'],
                            'id' => $set['id'],
                            'video_view_count' => $set['video_view_count'],
                            'url' => $url
                        ];
                    } else {
                        $url = $set['display_url'];
                        $array['results']['media'][] = [
                            '__typename' => $set['__typename'],
                            'id' => $set['id'],
                            'url' => $url
                        ];
                    }
                }
            }
        }
        echo json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    } elseif (!empty($d)) {
        $a = json_decode($d, true);
        if (isset($a['items'])) {
            foreach ($a as $postdata) {
                $array['results']['likes'] = $postdata['like_count'];
                $array['results']['comments'] = $postdata['comment_count'];
                $array['results']['taken_at'] = date('Y-m-d h:i:s', $postdata['taken_at']);
                $array['results']['caption'] = $postdata['caption']['text'] ?? '✖️';
                if (!isset($postdata['video_versions'][0]['url'])) {
                    if (isset($postdata['carousel_media'])) {
                        $carousel_media = $postdata['carousel_media'];
                        foreach ($carousel_media as $response) {
                            $array['results']['media'][] = [
                                '__typename' => 'photo',
                                'id' => $response['id'],
                                'url' => $response['image_versions2']['candidates'][0]['url']
                            ];
                        }
                    } else {
                        $response = $postdata;
                        $array['results']['media'][] = [
                            '__typename' => 'photo',
                            'id' => $response['id'],
                            'url' => $response['image_versions2']['candidates'][0]['url']
                        ];
                    }
                } else {
                    $array['results']['media'][] = [
                        '__typename' => $postdata['video_versions'][0]['type'],
                        'id' => $postdata['video_versions'][0]['id'],
                        'url' => $postdata['video_versions'][0]['url']
                    ];
                }
            }
        } else {
            $data = json_decode($d, true);
            $postdata = $data['data']['shortcode_media'] ?? null;
            if ($postdata != null) {
                $array['results']['likes'] = $postdata['edge_media_preview_like']['count'] ?? 0;
                $array['results']['comments'] = $postdata['edge_media_to_comment']['count'] ?? 0;
                $array['results']['taken_at'] = date('Y-m-d h:i:s', $postdata['taken_at_timestamp']);
                $array['results']['caption'] = $postdata['edge_media_to_caption']['edges'][0]['node']['text'] ?? 'empty';
                $edges = $postdata['edge_sidecar_to_children']['edges'] ?? null;
                if ($edges === null) {
                    $array['results']['media'][] = [
                        '__typename' => $postdata['__typename'],
                        'id' => $postdata['id'],
                        'url' => $postdata['video_url'] ?? $postdata['display_url']
                    ];
                } else {
                    foreach ($edges as $edge) {
                        $array['results']['media'][] = [
                            '__typename' => $postdata['__typename'],
                            'id' => $postdata['id'],
                            'url' => $edge['node']['video_url'] ?? $edge['node']['display_url'] ?? $edge['node']['display_resources'][1]['src']
                        ];
                    }
                }
            }
        }
        echo json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
}

if (isset($user) && !empty($user)) {
    $get = info($user);
    $_story = []; // array to return data

    $decode_get = json_decode($get, true);
    #$user_id = $decode_get['graphql']['user']['id'];
    $user_id = $decode_get['data']['user']['id'];
    if (!isset($user_id)) {
        die;
    }
    if (isset($_GET['highlight'])) {
        $f = h($user_id);
        $decode_h = json_decode($f, true);
        $ids = $decode_h['data']['user']['edge_highlight_reels']['edges'];
        $highlight_array = [];
        foreach ($ids as $highlight) {
            $highlight_array['id'][] = $highlight['node']['id'];
            $highlight_array['cover'][] = $highlight['node']['cover_media_cropped_thumbnail']['url'];
            $highlight_array['title'][] = $highlight['node']['title'];
        }
        echo json_encode(["results" => $highlight_array], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        die;
    }
    $c = $decode_get['data']['user']['is_private'];
    $biography = $decode_get['data']['user']['biography'];
    $edge_followed_by = $decode_get['data']['user']['edge_followed_by']['count'];
    $edge_follow = $decode_get['data']['user']['edge_follow']['count'];
    $full_name = $decode_get['data']['user']['full_name'];
    $highlight_reel_count = $decode_get['data']['user']['edge_owner_to_timeline_media']['count'];
    $is_verified = $decode_get['data']['user']['is_verified'];
    $profile_pic_url_hd = $decode_get['data']['user']['profile_pic_url_hd'];
    $profile_pic_url = $decode_get['data']['user']['profile_pic_url'];
    $username = $decode_get['data']['user']['username'];
    $stories = story($user_id);
    $data = json_decode($stories, true);
    $stories = $data['data']['reels_media']['0']['items'] ?? null;
    if (isset($stories)) {
        foreach ($stories as $story) {
            $vid = 'video_resources';
            if (isset($story['tappable_objects'][0]['username'])) {
                $_story['tags'][] = $story['tappable_objects'] ?? '✖️';
            }
            if (!array_key_exists($vid, $story)) {
                $_story['photo'][] = $story['display_url'];
            } else {
                $_story['video'][] = $story['video_resources'][0]['src'];
            }
        }
    }


    $_story['id'] = $user_id;
    $_story['username'] = $username;
    $_story['profile_pic_url'] = $profile_pic_url;
    $_story['profile_pic_url_hd'] = $profile_pic_url_hd;
    $_story['is_verified'] = $is_verified;
    $_story['posts_count'] = $highlight_reel_count;
    $_story['full_name'] = $full_name;
    $_story['following'] = $edge_follow;
    $_story['followers'] = $edge_followed_by;
    $_story['biography'] = $biography;
    $_story['is_private'] = $c;

    echo json_encode(["results" => $_story], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}