Created
December 30, 2016 21:23
-
-
Save pingyen/26410958509deb0fafe2843bce15b82b to your computer and use it in GitHub Desktop.
Flickr Photo Set Diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$key = isset($argv[1]) ? $argv[1] : 'ABC'; | |
$users = array( | |
'ABC' => array( | |
'photoset_id' => '12345678901234567',, | |
'api_key' => '0123456789abcdef01234567890abcde', | |
'secret' => 'abcdef1234567890', | |
'auth_token' => '12345678901234567-1234567890abcdef' | |
), | |
'XYZ' => array( | |
'photoset_id' => '09876543210987654',, | |
'api_key' => 'abcdef0123456789abcde01234567890', | |
'secret' => '1234567890abcdef', | |
'auth_token' => '01234567123456789-abcdef1234567890' | |
) | |
); | |
$user = $users[$key]; | |
$params = array( | |
'method' => 'flickr.photosets.getPhotos', | |
'photoset_id' => $user['photoset_id'], | |
'privacy_filter' => 5, | |
'per_page' => 500, | |
'extras' => 'media', | |
'format' => 'json', | |
'nojsoncallback' => 1, | |
'api_key' => $user['api_key'], | |
'auth_token' => $user['auth_token'] | |
); | |
$flickrs = []; | |
for ($page = 1; $page <= 10; ++$page) { | |
$params['page'] = $page; | |
// die('https://api.flickr.com/services/rest/?' . get_query_string($params) . "\n"); | |
$json = json_decode(file_get_contents('https://api.flickr.com/services/rest/?' . get_query_string($params)), true); | |
$flickrs = array_merge($flickrs, $json['photoset']['photo']); | |
} | |
function get_query_string($params) { | |
global $user; | |
ksort($params); | |
$tokens = array(); | |
$seed = ''; | |
foreach ($params as $key => $value) { | |
$tokens[] = "$key=$value"; | |
$seed .= "$key$value"; | |
} | |
$tokens[] = 'api_sig=' . md5($user['secret'] . $seed); | |
return implode('&', $tokens); | |
} | |
$map = array(); | |
foreach($flickrs as $flickr) { | |
$title = $flickr['title']; | |
$media = $flickr['media']; | |
$ref =& $map["$title, $media"]; | |
isset($ref) ? ++$ref : $ref = 1; | |
} | |
$map2 = array(); | |
$files = scandir($key); | |
$num = 0; | |
foreach($files as $file) { | |
if ($file === '.' || $file === '..' || $file === '.DS_Store' || substr($file, 0, 9) === 'Thumbs.db') { | |
continue; | |
} | |
$pos = strpos($file, '.'); | |
$title = substr($file, 0, $pos); | |
switch(strtolower(substr($file, $pos + 1))) { | |
case 'mp4': | |
case 'mov': | |
$media = 'video'; | |
break; | |
case 'png': | |
case 'jpg': | |
$media = 'photo'; | |
break; | |
} | |
$ref =& $map2["$title, $media"]; | |
isset($ref) ? ++$ref : $ref = 1; | |
++$num; | |
} | |
echo 'f: ', count($flickrs), "\n"; | |
foreach($map as $key => $count) { | |
if (isset($map2[$key]) === false || $count !== $map2[$key]) { | |
echo "$key\n"; | |
} | |
} | |
echo 'm: ', $num, "\n"; | |
foreach($map2 as $key => $count) { | |
if (isset($map[$key]) === false || $count !== $map[$key]) { | |
echo "$key\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment