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

View file

@ -19,6 +19,7 @@
$opts = array(); $opts = array();
$opts['username'] = $argv[1]; $opts['username'] = $argv[1];
$opts['password'] = $argv[2]; $opts['password'] = $argv[2];
// $opts['debug'] = 1; uncomment if having trouble
$s = new Snaphax($opts); $s = new Snaphax($opts);
$result = $s->login(); $result = $s->login();
@ -28,8 +29,13 @@
if ($snap['st'] == SnapHax::STATUS_NEW) { if ($snap['st'] == SnapHax::STATUS_NEW) {
echo "fetching $snap[id]\n"; echo "fetching $snap[id]\n";
$blob_data = $s->fetch($snap['id']); $blob_data = $s->fetch($snap['id']);
if ($blob_data) if ($blob_data) {
file_put_contents($snap['id'].'.jpg', $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 { class Snaphax {
// High level class to perform actions on Snapchat // High level class to perform actions on Snapchat
const STATUS_NEW = 1; const STATUS_NEW = 1;
const MEDIA_IMAGE = 0;
const MEDIA_VIDEO = 1;
function Snaphax($options) { function Snaphax($options) {
global $SNAPHAX_DEFAULT_OPTIONS; global $SNAPHAX_DEFAULT_OPTIONS;
@ -98,6 +99,16 @@
echo "SNAPHAX DEBUG: $text\n"; 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) { public function fetchBlob($snap_id, $username, $auth_token) {
$un = urlencode($username); $un = urlencode($username);
$ts = time(); $ts = time();
@ -110,11 +121,12 @@
$this->debug('blob result: ' . $result); $this->debug('blob result: ' . $result);
$result_decoded = mcrypt_decrypt('rijndael-128', $this->options['blob_enc_key'], $result, 'ecb'); $result_decoded = mcrypt_decrypt('rijndael-128', $this->options['blob_enc_key'], $result, 'ecb');
$this->debug('decoded: ' . $result_decoded); $this->debug('decoded: ' . $result_decoded);
if ($result_decoded[0] == chr(0xFF) && if ($this->isValidBlobHeader(substr($result_decoded, 0, 256))) {
$result_decoded[1] == chr(0xD8)) {
return $result_decoded; return $result_decoded;
} else } else {
$this->debug('invalid image/video data header');
return false; return false;
}
} }
public function postCall($endpoint, $post_data, $param1, $param2, $json=1) { public function postCall($endpoint, $post_data, $param1, $param2, $json=1) {