After several months of living without any screensaver, I decided it just would be nice to once again have something nice to watch and show while idling. I really like the photo slideshow that ships with windows vista, but as my laptop runs linux only that was not possible. The next best thing i found was glslideshow from the xscreensaver compilation. Like most slideshow programs, glslideshow will look into a given directory, and show files out of it in random order. However, there are downsides to that simple approach: My photo folder contains some private pictures, and also some pictures that are just ugly. So i decided to connect it to my digikam database, which was surprisingly simple.
By default, xscreensaver takes the directory out of its configfile ~/.xscreensaver, and passes it to a helper script xscreensaver-getimage-file, which then prints the complete path to a random file in that directory. So all one needs to do to add another source for pictures is to replace that file, there is already xscreensaver-getimage-flickr
, which pulls photos off flickr. So I wrote a similar script in python to print a random file from my digikam database. Maybe there are more?
The script is written in python, so that has to be installed (which is usually the case), it also requires sqlite and python bindings for it (apt-get install python-pysqlite2 in debian and ubuntu). If those are installed, backup the original xscreensaver-getimage-file, and copy the script there. Check that it is executable.
the overall process would look like(assuming xscreensaver-glslideshow already works)
sudo apt-get install python-pysqlite2 cd ~ wget http://andreas.goelzer.de/download/xscreensaver-getimage-digikam.py chmod +x xscreensaver-getimage-digikam.py cd /usr/bin sudo mv xscreensaver-getimage-file xscreensaver-getimage-file-original sudo mv ~/xscreensaver-getimage-digikam.py /usr/bin/ ln -s xscreensaver-getimage-digikam.py xscreensaver-getimage-file
If you had previously pointed xscreensaver to your digikam photo folder, that should work now. If not, edit ~/.xscreensaver and add a line pointing to that directory, in my case:
Right now this is all a bit hacky. at the beginning of the file, there is a line
bad_tags = "('private','me','Nophoto','Notmeanttobenice')"
If called, the script will take a random picture out of the database, then check if it has one of those tags. If it is tagged with one of those, it will be dismissed, similarly, if it has an extension indicating xscreensaver won’t be able to display it. So, set those line to the tags you do not want in your slideshow. For everything else you need to change the sql queries or the source code.
Set your screensaver to glslideshow and wait for it to start
#!/usr/bin/python # -*- coding: utf-8 -*- """ Script to choose random pictures from the digikam database Copyright (C) 2008 Andreas Goelzer 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 3 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, see <http://www.gnu.org/licenses/>. This program takes one random picture out of a sqlite-database made by digikam. This is useful for screensavers, xscreensaver-glslideshow in particular. """ #import sys; #ef=open('/home/goelzera/Documents/Programme/python/xscreensaver-errlog','a') #sys.stderr = ef good_extensions = ('jpg', 'jpeg', 'pjpeg', 'pjpg', 'png', 'gif', 'tif', 'tiff', 'xbm', 'xpm') bad_tags = "('private','me','Nophoto','Notmeanttobenice')" #good_tags = "('public')" good_tags = "" attempts = 200 import sqlite3; from sys import argv, exit; from os.path import splitext; digikamversion = "4"; if(len(argv) > 1): dirname = argv[len(argv) - 1] else: dirname = "/home/goelzera/Documents/Pictures" con = sqlite3.connect(dirname + "/digikam" + digikamversion + ".db") if(digikamversion == "4"): url = "relativePath" dirid = "album" else: url = "url" dirid = "dirid" #from time import time #f=open('/home/goelzera/Documents/Programme/python/xscreensaver-log','a') #f.write(str(time()) + '\t' + str(argv) + '\t') #get tagids for bad tags def getTagIdsFromNames(names): tag_ids = ' '; for row in con.execute("SELECT id FROM Tags WHERE name IN "+ names): tag_ids += str(row) + ',' tag_ids = '(' + tag_ids[:-1] + ')' return tag_ids if(bad_tags != ""): bad_tag_ids = getTagIdsFromNames(bad_tags) if(good_tags != ""): good_tag_ids = getTagIdsFromNames(good_tags) file = 'none'; #search for images, take a random one out of the db and see if it fulfills the criteria for attempt in range(attempts): #get a random picture, i guess this is the wrong way, performs horrible #truely random, but painfully slow #row = con.execute("SELECT id, name, $dirid FROM Images ORDER BY RANDOM() LIMIT 0,1").fetchone() #fast, but not as random row = con.execute("SELECT id, name, "+ dirid+" FROM Images WHERE id >= (abs(RANDOM()) % (SELECT max(id) FROM Images)) LIMIT 0,1").fetchone() #f.write(str(row) + ',') #check for bad tag if(bad_tags != ""): if(con.execute("SELECT 1 FROM ImageTags WHERE imageid = " + str(row) + " AND tagid IN "+ bad_tag_ids).fetchone()): continue #check for good tag if(good_tags != ""): if(not con.execute("SELECT 1 FROM ImageTags WHERE imageid = " + str(row) + " AND tagid IN "+ good_tag_ids).fetchone()): continue #check for invalid extension ext = splitext(row) ext = ext[1:].lower() if(not ext in good_extensions): continue #not rejected, get directory drow = con.execute("SELECT "+url+" FROM Albums WHERE id = " + str(row)).fetchone() file = dirname + drow + '/' + row break print file.encode('utf-8') #f.write(file.encode('latin-1') + '\n')
xscreensaver-getimage-digikam.py (3.29 kiB, 2009-08-06)