isMedia() public method

Checks to see if a blob looks like a media file.
public isMedia ( data $data ) : boolean
$data data The blob data (or just the header).
return boolean TRUE if the blob looks like a media file, FALSE otherwise.
コード例 #1
0
ファイル: snapchat.php プロジェクト: krew25/SC-API
 /**
  * Downloads a snap.
  *
  * @param string $id
  *   The snap ID.
  *
  * @return mixed
  *   The snap data or FALSE on failure.
  *     Snap data can returned as an Array of more than one file.
  * 	array(
  * 		overlay~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0    => overlay_file_data,
  *		media~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0	    => m4v_file_data
  * 	)
  */
 function getMedia($id, $from = null, $time = null, $subdir = null)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     if ($subdir == null) {
         $subdir = $this->username;
     }
     $path = __DIR__ . DIRECTORY_SEPARATOR . "snaps" . DIRECTORY_SEPARATOR . $subdir . DIRECTORY_SEPARATOR . $from;
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     $file = $path . DIRECTORY_SEPARATOR . date("Y-m-d H-i-s", (int) ($time / 1000));
     $extensions = array(".jpg", ".png", ".mp4", "");
     foreach ($extensions as $ext) {
         if (file_exists($file . $ext)) {
             return false;
         }
     }
     $timestamp = parent::timestamp();
     $result = parent::post('/bq/blob', array('id' => $id, 'timestamp' => $timestamp, 'username' => $this->username), array($this->auth_token, $timestamp), $multipart = false, $debug = $this->debug);
     if (!parent::isMedia(substr($result, 0, 2))) {
         //When a snapchat video is sent with "text" or overlay
         //the overlay is a transparent PNG file Zipped together
         //with the M4V file.
         //First two bytes are "PK" x50x4B; thus the previous media check
         //will fail and would've returned a FALSE on an available media.
         if (parent::isCompressed(substr($result, 0, 2))) {
             //Uncompress
             $result = parent::unCompress($result);
             //Return Media and Overlay
         }
     }
     if ($from != null && $time != null) {
         if (is_array($result)) {
             foreach ($result as $key => $value) {
                 $this->writeToFile($file, $value);
             }
         } else {
             $this->writeToFile($file, $result);
         }
     }
     return $result;
 }
コード例 #2
0
ファイル: snapchat.php プロジェクト: sekouperry/111sts
 /**
  * Downloads a snap.
  *
  * @param string $id
  *   The snap ID.
  *
  * @return mixed
  *   The snap data or FALSE on failure.
  *     Snap data can returned as an Array of more than one file.
  * 	array(
  * 		overlay~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0    => overlay_file_data,
  *		media~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0	    => m4v_file_data
  * 	)
  */
 function getMedia($id, $from = null, $time = null, $subdir = null)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     if ($subdir == null) {
         $subdir = $this->username;
     }
     $path = __DIR__ . DIRECTORY_SEPARATOR . "snaps" . DIRECTORY_SEPARATOR . $subdir . DIRECTORY_SEPARATOR . $from;
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     $file = $path . DIRECTORY_SEPARATOR . date("Y-m-d-H-i-s", (int) ($time / 1000));
     $extensions = array(".jpg", ".png", ".mp4", "");
     foreach ($extensions as $ext) {
         if (file_exists($file . $ext)) {
             return false;
         }
     }
     $timestamp = parent::timestamp();
     $result = parent::post('/bq/blob', array('id' => $id, 'timestamp' => $timestamp, 'username' => $this->username), array($this->auth_token, $timestamp), $multipart = false, $debug = $this->debug);
     if (!parent::isMedia(substr($result, 0, 2))) {
         //When a snapchat video is sent with "text" or overlay
         //the overlay is a transparent PNG file Zipped together
         //with the M4V file.
         //First two bytes are "PK" x50x4B; thus the previous media check
         //will fail and would've returned a FALSE on an available media.
         if (parent::isCompressed(substr($result, 0, 2))) {
             //Uncompress
             $result = parent::unCompress($result);
             //Return Media and Overlay
         }
     }
     if ($from != null && $time != null) {
         if (is_array($result)) {
             $files[] = null;
             foreach ($result as $key => $value) {
                 $newFile = $this->writeToFile($file, $value);
                 $files[] = $newFile;
             }
             // array is sometimes filled in with blanks, thus we remove them
             $files = array_values(array_diff($files, array("")));
             // Ffmpeg can´t export over the same input file path, thus we create an output path, then we rename it
             $path_parts = pathinfo($files[0]);
             $original = $path_parts['filename'] . '.' . $path_parts['extension'];
             $original = $path_parts['dirname'] . "/" . $original;
             $name = $path_parts['filename'] . "-" . '.' . $path_parts['extension'];
             $out = $path_parts['dirname'] . "/" . $name;
             $videoSize = shell_exec("ffprobe -loglevel panic -v error -select_streams v:0 -show_entries stream=width,height \\-of default=nokey=1:noprint_wrappers=1 {$files['0']}");
             $videoSize = array_filter(explode("\n", $videoSize));
             shell_exec("ffmpeg -loglevel panic -y -i {$files['1']} -vf scale={$videoSize['0']}:{$videoSize['1']} {$files['1']}");
             shell_exec("ffmpeg -loglevel panic -y -i {$files['0']} -i {$files['1']} -strict -2 -filter_complex overlay -c:a copy -flags global_header {$out}");
             unlink($files[1]);
             rename($out, $original);
         } else {
             $this->writeToFile($file, $result);
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: snapchat.php プロジェクト: sadiqhirani/php-snapchat
 /**
  * Downloads a snap.
  *
  * @param string $id
  *   The snap ID.
  *
  * @return mixed
  *   The snap data or FALSE on failure.
  */
 public function getMedia($id)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     $timestamp = parent::timestamp();
     $result = parent::post('/blob', array('id' => $id, 'timestamp' => $timestamp, 'username' => $this->username), array($this->auth_token, $timestamp));
     if (parent::isMedia(substr($result, 0, 2))) {
         return $result;
     } else {
         $result = parent::decryptECB($result);
         if (parent::isMedia(substr($result, 0, 2))) {
             return $result;
         }
     }
     return FALSE;
 }
コード例 #4
0
 /**
  * Downloads a snap.
  *
  * @param string $id
  *   The snap ID.
  *
  * @return mixed
  *   The snap data or FALSE on failure.
  *     Snap data can returned as an Array of more than one file.
  * 	array(
  * 		overlay~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0    => overlay_file_data,
  *		media~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0	    => m4v_file_data
  * 	)
  */
 public function getMedia($id)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     $timestamp = parent::timestamp();
     $result = parent::post('/blob', array('id' => $id, 'timestamp' => $timestamp, 'username' => $this->username), array($this->auth_token, $timestamp));
     if (parent::isMedia(substr($result, 0, 2))) {
         return $result;
     } else {
         $result = parent::decryptECB($result);
         if (parent::isMedia(substr($result, 0, 2))) {
             return $result;
         }
         //When a snapchat video is sent with "text" or overlay
         //the overlay is a transparent PNG file Zipped together
         //with the M4V file.
         //First two bytes are "PK" x50x4B; thus the previous media check
         //will fail and would've returned a FALSE on an available media.
         if (parent::isCompressed(substr($result, 0, 2))) {
             //Uncompress
             $result = parent::unCompress($result);
             //Return Media and Overlay
             return $result;
         }
     }
     return FALSE;
 }