support for video fetching; new constants MEDIA_IMAGE/MEDIA_VIDEO

This commit is contained in:
Thomas Lackner 2012-12-31 16:26:22 -06:00
parent 7d61392bfd
commit bcf17e5544
3 changed files with 28 additions and 10 deletions

View file

@ -32,8 +32,9 @@ Pretty simple:
Limitations
-----------
Only login (with list of new media) and fetching of images is implemented.
This is obviously a huge failing which I am to correct when I have more time.
Only login (with list of new media) and fetching of image/video snaps is
implemented. This is obviously a huge failing which I am to correct when I
have more time.
Motivation and development process
----------------------------------
@ -85,8 +86,7 @@ The TODO list is almost endless at this point:
- DOCS!!!
- Syncing (to mark snaps as seen)
- Video fetching
- Image/video posting
- Image/video uploading
- Friend list maintenance
- Port to Javascript (probably via Node + NPM since their API doesn't seem to
support JSONP)

View file

@ -19,6 +19,7 @@
$opts = array();
$opts['username'] = $argv[1];
$opts['password'] = $argv[2];
// $opts['debug'] = 1; uncomment if having trouble
$s = new Snaphax($opts);
$result = $s->login();
@ -28,8 +29,13 @@
if ($snap['st'] == SnapHax::STATUS_NEW) {
echo "fetching $snap[id]\n";
$blob_data = $s->fetch($snap['id']);
if ($blob_data)
file_put_contents($snap['id'].'.jpg', $blob_data);
if ($blob_data) {
if ($snap['m'] == SnapHax::MEDIA_IMAGE)
$ext = '.jpg';
else
$ext = '.mp4';
file_put_contents($snap['id'].$ext, $blob_data);
}
}
}
}

View file

@ -45,10 +45,11 @@
}
class Snaphax {
// High level class to perform actions on Snapchat
const STATUS_NEW = 1;
const MEDIA_IMAGE = 0;
const MEDIA_VIDEO = 1;
function Snaphax($options) {
global $SNAPHAX_DEFAULT_OPTIONS;
@ -98,6 +99,16 @@
echo "SNAPHAX DEBUG: $text\n";
}
private function isValidBlobHeader($header) {
if (($header[0] == chr(00) && // mp4
$header[0] == chr(00)) ||
($header[0] == chr(0xFF) && // jpg
$header[1] == chr(0xD8)))
return true;
else
return false;
}
public function fetchBlob($snap_id, $username, $auth_token) {
$un = urlencode($username);
$ts = time();
@ -110,12 +121,13 @@
$this->debug('blob result: ' . $result);
$result_decoded = mcrypt_decrypt('rijndael-128', $this->options['blob_enc_key'], $result, 'ecb');
$this->debug('decoded: ' . $result_decoded);
if ($result_decoded[0] == chr(0xFF) &&
$result_decoded[1] == chr(0xD8)) {
if ($this->isValidBlobHeader(substr($result_decoded, 0, 256))) {
return $result_decoded;
} else
} else {
$this->debug('invalid image/video data header');
return false;
}
}
public function postCall($endpoint, $post_data, $param1, $param2, $json=1) {
$ch = curl_init();