forked from dionyziz/Life
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picasa.php
79 lines (68 loc) · 3.22 KB
/
picasa.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
include 'header.php';
class Picasa {
public function __construct() {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$username = 'dionyziz@gmail.com';
$password = 'password';
$client = Zend_Gdata_ClientLogin::getHttpClient( $username, $password, $serviceName );
$gp = new Zend_Gdata_Photos( $client, 'Dionyziz-Life-1.0' );
$query = $gp->newAlbumQuery();
$query->setUser( 'default' );
$query->setAlbumName( 'Sikinos' );
$albumFeed = $gp->getAlbumFeed( $query );
$i = 0;
foreach ( $albumFeed as $albumEntry ) {
try {
$albumid = $albumEntry->getGphotoAlbumId();
$exif = $albumEntry->getExifTags();
$time = $exif->getTime();
if ( $time == null ) {
echo "Photo does not contain time information.\n";
continue;
}
$timestamp = $time->getText();
$mediaContentArray = $albumEntry->getMediaGroup()->getContent();
$contentUrl = $mediaContentArray[ 0 ]->getUrl();
$mediaThumbnailArray = $albumEntry->getMediaGroup()->getThumbnail();
if ( $mediaThumbnailArray == null ) {
echo "Photo does not contain thumbnail.\n";
continue;
}
$maxwidth = 0;
$maxid = 0;
foreach ( $mediaThumbnailArray as $id => $thumb ) {
if ( $thumb->getWidth() > $maxwidth ) {
$maxwidth = $thumb->getWidth();
$maxid = $id;
$thumbnailUrl = $thumb->getUrl();
}
}
// echo "Importing image " . $contentUrl . " from Picasa... ";
// $diff = 1310008564116;
$link = $albumEntry->getAlternateLink()->getHref();
$parts = explode( '/', $link );
$userid = $parts[ 3 ];
$parts = explode( '#', $link );
$photoid = $parts[ 1 ];
$link = 'https://plus.google.com/photos/' . $userid . '/albums/' . $albumid . '/' . $photoid;
// echo( $link . ': ' . date( "Y-m-d H:i:s", $timestamp - $diff ) . "\n" );
Post::update(
Post::create( 'picasa:' . $contentUrl . ' ' . $thumbnailUrl . ' ' . $link, 1, 'photo', 'public' ),
date( "Y-m-d H:i:s", $timestamp / 1000 )
);
++$i;
echo $i . ' / ' . count( $albumFeed ) . "\n";
}
catch ( Exception $e ) {
echo "Failed to retrieve photo EXIF information.\n";
}
}
}
}
new Picasa();
?>