Last active
March 2, 2020 09:09
-
-
Save janzell/ad02548cf90b9adb7716 to your computer and use it in GitHub Desktop.
Instagram Video Source Grabber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Instagram Class | |
*/ | |
class Instagram | |
{ | |
/** | |
* Clean Input | |
* | |
* @param string $data | |
* @return string | |
*/ | |
public function clean_input($data) | |
{ | |
$data = trim($data); | |
$data = strip_tags($data); | |
return $data; | |
} | |
/** | |
* Clean input all | |
* @param string $data | |
* @return string | |
*/ | |
public function clean_input_all($data) | |
{ | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = strip_tags($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
/** | |
* Get video Information | |
* | |
* @param string $url | |
* @return json | |
*/ | |
public function get_video($url = "") | |
{ | |
$insta_link = $this->clean_input_all( $url ); | |
if( !empty($insta_link) ){ | |
// header('Content-Type: application/json; charset=utf-8'); | |
$response = $this->clean_input( @ file_get_contents($insta_link) ); | |
$response_length = strlen($response); | |
$start_position = strpos( $response ,'window._sharedData = ' ); // the start position | |
$start_positionlength = strlen('window._sharedData = '); // string length to trim before | |
$jsondata = substr($response, ( $start_position + $start_positionlength ), - 5 ); | |
return $jsondata; | |
} elseif( empty($insta_link) ) { | |
die(); //only accepts instaLink as parameter | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment