Author Topic: Proposed flickr.pl replacement  (Read 1597 times)

royw

  • Guru
  • ****
  • Posts: 261
    • View Profile
Proposed flickr.pl replacement
« on: July 04, 2008, 02:30:35 am »
Howdy,

The other day I had an inkling to "tune" the types of photos that the screensaver uses.  So found the /usr/pluto/bin/flickr.pl script and took a look see.  There appears to be the capability to specify search tags, but they don't work (actually specifying a tag stops all fetching from flickr).  I then dived into the flickr API to understand enough to maybe troubleshoot flickr.pl.  I ended up writing a script that can handle fetching photos by user id/name, photoset, group, photo search (tags, text,...), and of course interestingness (what works in flickr.pl).  I then started thinking of replacing flickr.pl, so added LinuxMCE file structure and reaping.  I'm at the point of adding the database hooks and daemonizing the script and decided now is probably a good time to bounce this off of the community.

BTW, my current hypothesis on what is wrong with flickr.pl is that the flickr API has changed since the Flickr::API version 0.08 module was released in March 2006.  There is a newer version, 0.09 available that was released in Feb 2008 that might resolve the tag search problem.

To give you a better feel for what my script can do, here's it's current config file:
Code: [Select]
# This is the configuration file for /home/royw/views/flickrfetchr/flickrfetchr and is where
# you specify what images you want fetched from flickr for the LinuxMCE screensaver
#
# To take full advantage of these options, you should have an account on http://www.flickr.com
#
# For those who are familiar with ruby, the format for this file should be obvious :)
# But for the vast majority, here goes:
#
# Comments start with an '#' and extend to the end of the line
#
# We are initializing the config Hash so each line starts with "config[key]".  The keys
# are all symbols so start with a colon (":key").
#
# Each hash value is an Array so is enclosed in square brackets:
#   config[:key] = []
#
# Empty brackets are permissible
#
# Each element in the value Array is a Hash so is inclosed with curly brackets:
#  config[:key] = [{}, {}, ...]
#
# Each element in the Hash is a key/value pair which are seperated by a =>
#  config[:key] = [{:key1 => value1, :key2 => value2, ...}]
#
# Again each key is a symbol and starts with a colon
#
# String values are enclosed with single quotes while integers are not.  In this
# config file, all values are either integers or strings, even though I document
# the strings with more descriptive types like 'USER_ID' or 'PATH'.
#  config[:key] = [{:key1 => '/home/flickr', :key2 => 20, ...}]
#
# Each section includes an example at the end which starts with ## which show
# proper syntax for that section.

#****** Fetch photo definitions

#***********************************************************************
# To fetch photos from a user account using either the flickr user ID or the user name:
# config[:USERS] = [{
#                       :nsid => USER_ID OR :username => FLICKR_USER_NAME,  # required
#                       :destination => :linuxmce_flickr OR PATH,           # optional, defaults to :linuxmce_flickr
#                       :limit => INTEGER                                   # optional, defaults to @config[:limit]
#                       :extras => STRING                                   # don't use
#                       :per_page => INTEGER                                # optional, defaults to :limit
#                       :page => INTEGER                                    # optional, defaults to 1
#                   }]
##
## this example selects all pictures (up to @config[:limit]) from the user "royw2" flickr account:
config[:USERS] = [{:username => 'royw2'}]

#***********************************************************************
# you can also fetch photos from flickr groups again by either group ID or group name:
# config[:GROUPS] = [{
#                       :nsid => GROUP_ID OR :groupname => GROUP_NAME,      # required
#                       :destination => :linuxmce_flickr OR PATH,           # optional, defaults to :linuxmce_flickr
#                       :limit => INTEGER                                   # optional, defaults to @config[:limit]
#                       :tags => STRING                                     # optional, A tag to filter the pool with.
#                                                                           #   At the moment only one tag at a time is supported.
#                       :extras => STRING                                   # don't use
#                       :per_page => INTEGER                                # optional, defaults to :limit
#                       :page => INTEGER                                    # optional, defaults to 1
#                   }]
##
## this example will fetch photos from two groups: 'Deep Space Astrophotography' and 'Worlds of fancy_computer generated landscapes'.
## The group id for 'Deep Space Astrophotography' is '16194850@N00' so we will use it:
## config[:GROUPS] = [{:nsid => '16194850@N00'}, {:groupname => 'Worlds of fancy_computer generated landscapes'}]

#***********************************************************************
# config[:PHOTOSETS] = [{
#                       :nsid => USER_ID OR :username => FLICKR_USER_NAME,  # required
#                       :destination => :linuxmce_flickr OR PATH,           # optional, defaults to :linuxmce_flickr
#                       :title => STRING                                    #
#                       :limit => INTEGER                                   # optional, defaults to @config[:limit]
#                       :title => STRING                                    # optional, matches one set, default is to match all sets
#                       :extras => STRING                                   # don't use
#                   }]
##
## Say I want to keep a local copy of one of my photosets ('Our Canine Family'), but not include it in the LinuxMCE screensaver
## config[:PHOTOSETS] = [{:username => 'royw2', :title => 'Our Canine Family', :destination => '/home/royw/photos/dogs'}]

#***********************************************************************
# config[:SEARCHES] = [{
#                       :nsid => USER_ID OR :username => FLICKR_USER_NAME,  # required
#                       :destination => :linuxmce_flickr OR PATH,           # optional, defaults to :linuxmce_flickr
#                       :limit => INTEGER                                   # optional, defaults to @config[:limit]
#                       :tags => STRING                                     # optional, A comma-delimited list of tags.
#                                                                           #   Photos with one or more of the tags listed will be returned.
#                       :tag_mode => 'any' OR 'all'                         # optional, Either 'any' for an OR combination of tags,
#                                                                           #   or 'all' for an AND combination.
#                                                                           #   Defaults to 'any' if not specified.
#                       :text => STRING                                     # optional, A free text search. Photos who's title,
#                                                                           #   description or tags contain the text will be returned.
#                       :min_upload_date => STRING                          # optional, Minimum upload date. Photos with an upload
#                                                                           #   date greater than or equal to this value
#                                                                           #   will be returned. The date should be in the
#                                                                           #   form of a unix timestamp.
#                       :max_upload_date => STRING                          # optional, Maximum upload date. Photos with an upload
#                                                                           #   date less than or equal to this value will be returned.
#                                                                           #   The date should be in the form of a unix timestamp.
#                       :min_taken_date => STRING                           # optional, Minimum taken date. Photos with an taken
#                                                                           #   date greater than or equal to this value will be returned.
#                                                                           #   The date should be in the form of a mysql datetime.
#                       :max_taken_date => STRING                           # optional, Maximum taken date. Photos with an taken
#                                                                           #   date less than or equal to this value will be returned.
#                                                                           #   The date should be in the form of a mysql datetime.
#                       :license => STRING                                  # optional, The license id for photos (for possible values
#                                                                           #   see the flickr.photos.licenses.getInfo method).
#                                                                           #   Multiple licenses may be comma-separated.
#                       :extras => STRING                                   # don't use
#                       :per_page => INTEGER                                # optional, defaults to :limit
#                       :page => INTEGER                                    # optional, defaults to 1
#                   }]
##
## Now say I want to include photos of LinuxMCE systems that are on flickr and up to 20 computer case mods:
## config[:SEARCHES] = [{:text => 'LinuxMCE'},
##                       {:tags => 'computer,case,mods', :limit => 20}
##                      ]

#***********************************************************************
# config[:INTERESTING] = [{
#                       :nsid => USER_ID OR :username => FLICKR_USER_NAME,  # optional
#                       :destination => :linuxmce_flickr OR PATH,           # optional, defaults to :linuxmce_flickr
#                       :limit => INTEGER                                   # optional, defaults to @config[:limit]
#                       :date => STRING                                     # optional, a date string
#                       :daycount => INTEGER                                # optional, the number of days up to :date to look
#                                                                           # for photos.  defaults = 0 (i.e., just :date)
#                       :extras => STRING                                   # don't use
#                       :per_page => INTEGER                                # optional, defaults to :limit
#                       :page => INTEGER                                    # optional, defaults to 1
#                   }]
##
## Say I'm feeling nostalgic for the orginal photo selection in LinuxMCE:
## config[:INTERESTING] = [{:limit => 100, :daycount => 5}]

#****** Global Fetch Options
# The following are global options with the default values
# please note that the value syntax differs from the above sections.

#***********************************************************************
# The maximum number of files to attempt to download at a time
## config[:limit] = 3

#***********************************************************************
# Sometimes downloading from flickr is unreliable, so we can retry the
# operation this many times:
## config[:max_save_attempts] = 3

#***********************************************************************
# When FlickrFetcher downloads an image, it limits downloading to the largest possible image that is
# less than or equal to config[:image_max_size] and greater than or equal to config[:image_min_size].

# This is the maximum photo size to download.  If the requested photo exceeds this size in either width or height,
# then we try to find the next smaller image.  If there are no smaller images, then the image is not downloaded.
## config[:image_max_size] = {:width => 1920, :height => 1080}
# Setting either width or height to less than or equal to 0 disables the checking for a maximum size.
## config[:image_max_size] = {:width => 0, :height => -1080}

# This is the minimum photo size to download.  If the requested photo is smaller than this size in either width or
# height then the photo is not downloaded.
## config[:image_min_size] = {:width => 1024, :height => 720}
# Setting either width or height to less than or equal to 0 disables the checking for a minimum size.
## config[:image_min_size] = {:width => -1920, :height => 0}

#***********************************************************************
# config[:image_scale_to_size]  = {:width => 1920, :height => 1080}

#***********************************************************************
# config[:linuxmce_flickr] = {:max_files => 100}



Thank you,
Roy


sandos

  • Regular Poster
  • **
  • Posts: 36
    • View Profile
Re: Proposed flickr.pl replacement
« Reply #1 on: July 13, 2008, 08:41:54 pm »
Looks awesome.

royw

  • Guru
  • ****
  • Posts: 261
    • View Profile
Re: Proposed flickr.pl replacement
« Reply #2 on: July 20, 2008, 01:01:00 am »
Version 0.1.0 of FlickrFetchr is now available:

  http://rubyforge.org/projects/flickrfetchr/

Documentation at:

  http://flickrfetchr.rubyforge.org/

Here's the README:

Code: [Select]
Welcome to FlickrFetchr 0.1.0, a Flickr photo retrieval script.

This script will fetch photos from Flickr.com.  You can specify to select photos based on users, photosets, groups, interestingness, or searches.  Multiple selection criteria is allowed (i.e., zero or more users AND zero or more photosets AND zero or more groups...).  Further you can select images based on size (larger or smaller than a threshold or within a range).  Also optionally resize and/or fill to a size.

You will need a Flickr account and will have to visit Flickr to authorize FlickrFetchr for your account only once.  The first time you run FlickrFetchr it will give you the URL you have to visit.

This script was originally designed as a replacement for LinuxMCE's flickr.pl script but has since evolved to be a high-level object with a command line application.  Currently the LinuxMCE support is provide via an optional plugin.

== Documentation

Further documentation is available in doc/index.html

== INSTALLATION

To install:

Extract flickrfetchr-0.1.0.tgz:

  tar xvf flickrfetchr-0.1.0.tgz

Change to the created directory:

  cd flickrfetchr

Run the setup script:

  For LinuxMCE 0710 system:
 
    ./setup-linuxmce
   
  For Kubuntu '0710' and '0804' systems:
 
    ./setup-kubuntu

When prompted, you will need to copy a URL then load it into your web browser (the web browser does not have to be running on the dcerouter) to authenticate FlickrFetchr with your Flickr account.

After the setup script completes, FlickrFetcher is installed for stand-alone usage.  You may want to read the config file ~/.flickrfetchr.conf and set up some download criteria to verify that you can actually fetch photos.  There are some examples in it that should get you up and running quickly.

LinuxMCE users note that FlickrFetchr must be ran as sudo (root permissions) to be able to save files in /home/flickr.


== Replacing Flickr.pl with FlickrFetchr.rb

From pluto-admin, Advanced, Configuration, Devices, Show Device Tree, My Devices, CORE, DCERouter, Orbiter Plug-in:

  change File Name and Path from:
   
    /usr/pluto/bin/flickr.pl
   
  to:
 
    /usr/local/bin/flickrfetchr.rb

Note, the Width, Height, and Quantity fields are not used by FlickrFetchr.  Instead use the /etc/flickrfetchr.conf or /root/.flickrfetchr.conf config files.

That should do it (you may have to restart the DCERouter).  Within 24 hours the new pictures should start to show up in the screen saver.  You can verify by examining the log file:  /var/log/flickrfetchr*.log


Have fun,
Roy