Subversion Repositories Plazes

[/] [Ovi/] [ovi2flickr.php] - Rev 146

Compare with Previous | Blame | View Log

#!/usr/bin/php -q
<?php
/**
  * ovi2flickr.php - A PHP script to migrate photos from Share on Ovi to Flickr.
  *
  * This allows for the migration of a single user's public Share on Ovi photos into Flickr.
  * For each image the title, description and tags are migrated, along with the original 
  * version of the image itself (complete with any EXIF data embedded).
  * 
  * Requirements for use:
  * 
  *  - PHP 5 or greater
  *  - Phlickr (see http://drewish.com/projects/phlickr/)
  *  - a Flickr account with an API key (see http://www.flickr.com/services/api/keys/)
  *  - a Share on Ovi account
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or (at
  * your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  *
  * @version 1.0, November 2, 2008
  * @link http://share.ovi.com/ Share on Ovi website
  * @link http://flickr.com/ Flickr website
  * @author Peter Rukavina <peter@rukavina.net>
  * @copyright Copyright &copy; 2008, Reinvented Inc.
  * @license http://www.fsf.org/licensing/licenses/gpl.txt GNU Public License
  */

//----- user configurable options -----

$ovi_username     "";        // Set to your Share on Ovi username -- i.e. 'ruk'
$ovi_channel    "";        // Set to the Share on Ovi "channel" you want to upload into - i.e. 'public'

$flickr_apikey    '';    // Set to your Flickr API key (see http://www.flickr.com/services/api/keys/)
$flickr_userid  '';    // Set to the Flickr User ID you want to upload photos to (see http://www.flickr.com/services/api/explore/?method=flickr.people.getPublicPhotos)

$howmanyphotos  320;            // Set to the number of photos you want to grab.
$startpage         1;            // Set to the "page" of photos you want to start grabbing from.
$perpage        32;            // Set to the number of photos per page to grab from Ovi.

// To enable Flickr authorization, you need to create a file called 'authinfo.cfg' in the form:
//
// --snip--
// api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
// api_secret=XXXXXXXXXXXXX
// api_token=XXXXXXXXXXXXX-XXXXXXXXXXXXX
// cache_file=/tmp/flickr.tmp
// --snip--
//
// The api_key and api_secret you can get from http://www.flickr.com/services/api/keys/
// and the api_token you need to generate using the code at http://drewish.com/projects/phlickr/auth_token

define('API_CONFIG_FILE''./authinfo.cfg');

//----- end of user configurable options -----

require_once 'Phlickr/Api.php';
require_once 
'Phlickr/Uploader.php';

$api Phlickr_Api::createFrom(API_CONFIG_FILE);
if (! 
$api->isAuthValid()) {
    die(
"invalid flickr logon");
}
$uploader = new Phlickr_Uploader($api);
$photo_ids = array();

while (!
$DONE) {

    
$ovi_feed_url "http://share.ovi.com/feeds/rss/channel/" $ovi_username "." $ovi_channel "?page=$startpage&count=$perpage&sort=5";

    
$fp fopen($ovi_feed_url,"r");
    
$ovixml stream_get_contents($fp);
    
fclose($fp);

    
$feed simplexml_load_string($ovixml);

    foreach (
$feed->channel->item as $item) {

        
$url $item->guid;

        
// Parse out the URL of the 'original' sized photo's page, as it's not included 
        // in the RSS feed for some reason.
        
        
preg_match("/http:\/\/share.ovi.com\/media\/(.*)\/(.*)/",$url,$matches);
        
$original_url "http://share.ovi.com/original.aspx?channelname=" $matches[1] . "&media=" $matches[2];

        
$fp fopen($original_url,"r");
        
$photo_html stream_get_contents($fp);
        
fclose($fp);

        
// Parse out the URL of the 'original' JPEG.
        
        
preg_match("/(.*)(http:\/\/media.share.ovi.com\/m1\/original\/.*\/.*\.jpeg)/",$photo_html,$matches);
        
$original_jpeg $matches[2];

        
// Rip out the Ovi-credit in the description by splitting on '<br>'
        
        
list($oviurl,$description) = split("/></a><br />",$item->description);
        
$description strip_tags($description);

        
// If we actually *found* an original JPEG, then do the upload to Flickr
        
        
if ($original_jpeg <> '') {

            
// Get the image from Ovi
            
            
system("wget $original_jpeg --quiet -O flickr.tmp.jpg");

            
// Print the title of the image we're working on...
             
print "Uploading " $item->title "...\n";

            
// Do the Flickr upload
            
$photo_id[] = $uploader->upload("./flickr.tmp.jpg"$item->title$description'');
        }
    }
    
    
$startpage++;
    if (
$startpage $perpage $howmanyphotos) {
        
$DONE 1;
    }
    else {
        print 
"Incremented to page $startpage.\n";
    }
}

Compare with Previous | Blame | View Log