Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
getDiscoversVideosByEdition added
Browse files Browse the repository at this point in the history
  • Loading branch information
mgp25 committed Sep 7, 2015
1 parent 2e7e963 commit 55fca04
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Empty file added src/Discover/.gitkeep
Empty file.
91 changes: 91 additions & 0 deletions src/snapchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,97 @@ public function getDiscoversChannelList()
return $result;
}

/**
* Gets Discover's videos by edition
* Use getDiscoversChannelList() in order to get the edition
*
* @param string $edition
* @param string $platform
*
* @return array
* An array of channels with all it's information
*/
public function getDiscoversVideosByEdition($edition, $platform = 'android')
{
// Make sure we're logged in and have a valid access token.
if(!$this->auth_token || !$this->username)
{
return FALSE;
}
$result = parent::get("/discover/video_catalog_v2?region=INTERNATIONAL&edition=$edition&platform=$platform");

$channels = json_decode($this->getDiscoversChannelList(), true);

foreach ($channels['channels'] as $channel)
{
if ($channel['edition_id'] == $edition)
{
$path = __DIR__ . DIRECTORY_SEPARATOR . "Discover" . DIRECTORY_SEPARATOR . $channel['publisher_formal_name'];
if(!file_exists($path))
{
mkdir($path, 0777, true);
}

foreach ($channel['dsnaps_data'] as $snaps)
{
parse_str($snaps['url']);
$zipFile = $path . DIRECTORY_SEPARATOR . $dsnap_id . '.zip';
file_put_contents($zipFile , parent::get($snaps['url']));
$zip = new ZipArchive;
$res = $zip->open($zipFile);
if ($res === TRUE) {
$i = 0;
for ($i; $i < 3; $i++)
{
$name = $zip->statIndex($i)['name'];
if (!strpos($name,'thumbnail') !== false)
break;
}
$zip->extractTo($path);
$zip->close();
unlink($zipFile);
} else {
if ($this->debug)
echo "Oops! Error extracting discover snap!\n";
unlink($zipFile);
}
}

$dir = opendir($path);
while (false !== ($file = readdir($dir)))
{
$file = $path . DIRECTORY_SEPARATOR . $file;
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$finfo = finfo_file($finfo, $file);
switch($finfo)
{
case "image/jpeg":
$ext = ".jpg";
break;
case "image/png":
$ext = ".png";
break;
case "video/mp4";
$ext = ".mp4";
break;
default:
$ext = null;
}

if($ext != null)
{
$newFile = $file . $ext;
rename($file, $newFile);
}
else {
unlink($file);
}
}
}
}
return $result;
}

/**
* Gets the best friends and scores of the specified users.
*
Expand Down

0 comments on commit 55fca04

Please sign in to comment.