isCompressed() 공개 메소드

Checks to see if a blob looks like a compressed file.
public isCompressed ( data $data ) : boolean
$data data The blob data (or just the header).
리턴 boolean TRUE if the blob looks like a compressed file, FALSE otherwise.
예제 #1
0
파일: snapchat.php 프로젝트: nodir-y/SC-API
 /**
  * Downloads a story.
  *
  * @param string $media_id
  *   The media ID of the story.
  * @param string $key
  *   The base64-encoded key of the story.
  * @param string $iv
  *   The base64-encoded IV of the story.
  *
  * @return mixed
  *   The story data or FALSE on failure.
  */
 public function getStory($media_id, $key, $iv, $from, $timestamp, $save = FALSE, $subdir = null)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     // Build path
     if ($save) {
         if ($subdir == null) {
             $subdir = $this->username;
         }
         $path = __DIR__ . DIRECTORY_SEPARATOR . "stories" . 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) ($timestamp / 1000)) . "-story-" . $media_id;
         $extensions = array(".jpg", ".png", ".mp4", "");
         foreach ($extensions as $ext) {
             if (file_exists($file . $ext)) {
                 return false;
             }
         }
     }
     // Retrieve encrypted story and decrypt.
     $blob = parent::get('/bq/story_blob?story_id=' . $media_id);
     if (!empty($blob)) {
         $result = parent::decryptCBC($blob, $key, $iv);
         if (parent::isCompressed(substr($result, 0, 2))) {
             $result = parent::unCompress($result);
         }
         if ($save) {
             if (is_array($result)) {
                 foreach ($result as &$value) {
                     if (!file_exists($file)) {
                         $this->writeToFile($file, $value);
                     }
                 }
             } else {
                 if (!file_exists($file)) {
                     $this->writeToFile($file, $result);
                 }
             }
         }
         return $result;
     }
     return FALSE;
 }
예제 #2
0
파일: snapchat.php 프로젝트: krew25/SC-API
 /**
  * Downloads a story.
  *
  * @param string $media_id
  *   The media ID of the story.
  * @param string $key
  *   The base64-encoded key of the story.
  * @param string $iv
  *   The base64-encoded IV of the story.
  *
  * @return mixed
  *   The story data or FALSE on failure.
  */
 public function getStory($media_id, $key, $iv, $from, $timestamp, $save = FALSE, $subdir = null)
 {
     // Make sure we're logged in and have a valid access token.
     if (!$this->auth_token || !$this->username) {
         return FALSE;
     }
     // Build path
     if ($save) {
         if ($subdir == null) {
             $subdir = $this->username;
         }
         $path = __DIR__ . DIRECTORY_SEPARATOR . "stories" . 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) ($timestamp / 1000)) . "-story-" . $media_id;
         $extensions = array(".jpg", ".png", ".mp4", "");
         foreach ($extensions as $ext) {
             if (file_exists($file . $ext)) {
                 return false;
             }
         }
     }
     // Retrieve encrypted story and decrypt.
     $blob = parent::get('/bq/story_blob?story_id=' . $media_id);
     if (!empty($blob)) {
         $result = parent::decryptCBC($blob, $key, $iv);
         if (parent::isCompressed(substr($result, 0, 2))) {
             $result = parent::unCompress($result);
         }
         if ($save) {
             if (is_array($result)) {
                 $files = array();
                 foreach ($result as &$value) {
                     if (!file_exists($file)) {
                         $newFile = $this->writeToFile($file, $value);
                         if ($newFile) {
                             $files[] = $newFile;
                         }
                     }
                 }
                 $output = array();
                 $returnvalue = false;
                 exec('ffmpeg -version', $output, $returnvalue);
                 if ($returnvalue === 0) {
                     $videoSize = shell_exec("ffprobe -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 -y -i {$files['1']} -vf scale={$videoSize['0']}:{$videoSize['1']} {$files['1']}");
                     shell_exec("ffmpeg -y -i {$files['0']} -i {$files['1']} -strict -2 -filter_complex overlay -c:a copy -flags global_header {$files['0']}");
                     unlink($files[1]);
                 }
             } else {
                 if (!file_exists($file)) {
                     $this->writeToFile($file, $result);
                 }
             }
         }
         return $result;
     }
     return FALSE;
 }
예제 #3
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;
 }