|home | projects | about|
Copyright (c) 2008 Scott Ludwig
buildrss.py is a simple script to build an rss feed out of a directory of images. This was built with Leopard's RSS picture screensaver in mind, to show images from a home server. Leopard's RSS picture screensaver has a number of issues:
1. It takes forever to "validate" an RSS document, for an unknown reason. My photo archive has > 60K pictures, which causes the screen saver to hang. Smaller RSS documents work fine (<1000).
2. It re-reads the RSS feed every 30 minutes, and then proceeds to download all the images in the feed right away rather than reading them as they are displayed. Another reason why many RSS items won't work.
3. Once an item with a given url is read, the screen saver won't re-read it even if it changes.
4. It doesn't auto-rotate images based on EXIF orientation settings.
5. Using enclosures causes a message to be logged to the console utility.
This RSS generator addresses these issues. It reads the picture archive then randomly selects N images from this archive, normalizes them (rotate and scale) and saves them into a normalized image cache, with a name based on the md5sum of the resulting file (to counteract Leopard's caching). This script is meant to be called periodically from a cron job such as every 24 hours to update the cache of images with fresh ones, such as 200 pictures every 24 hours. For example, here are example cron settings: 0 0 * * * /usr/bin/python buildrss.py /mnt/pics /var/www/pics http://homeserver/pics 200 1440 900 Then to have cron pick up these settings for a new cron job, save them to foo.cron for example, then run: crontab foo.cron This cron command runs the script midnight every night, selects pictures from /mnt/pics, saves normalized pictures to /var/www/pics, uses http://homeserver/pics as the root url for each RSS item, randomly selects 200 pictures from the picture archive, and scales to 1440 x 900 (scaling preserves aspect ratio). Assuming you have apache running, the RSS feed is then available as: http://homeserver/pics/pics.rss Note in the previous example, saving to /var/www/pics may require the cron job run in the right user context, such as from root. Regarding scaling: technically the screen saver does scale, but pre-scaling makes the images much smaller, which is nice every item in the RSS feed is copied to your Mac. Usage: python buildrss.py <image archive path> <dest image path> <base url> <count> <width> <height> <image archive path> The root of the tree containing the source images
<dest image path> The directory to store the RSS feed and data
<base url> The base url that accesses this directory over HTTP
<count> The number of images to process
<width> The width to scale to (preserving aspect ratio)
<height> The height to scale to (preserving aspect ratio)
The RSS feed is then available as <base url>/pics.rss. Note a file called 'map' is also stored in <dest image path>, which maps images from the cache back to images in the archive. This is for reference purposes only. License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
last modified March 04, 2008, at 03:56 PM