Skip to content

Instantly share code, notes, and snippets.

@janzell
Last active March 2, 2020 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janzell/ad02548cf90b9adb7716 to your computer and use it in GitHub Desktop.
Save janzell/ad02548cf90b9adb7716 to your computer and use it in GitHub Desktop.
Instagram Video Source Grabber
<?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