<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>andreas.goelzer.de &#187; screensaver</title>
	<atom:link href="http://andreas.goelzer.de/tag/screensaver/feed" rel="self" type="application/rss+xml" />
	<link>http://andreas.goelzer.de</link>
	<description>Electronics and small programs and other stuff</description>
	<lastBuildDate>Tue, 29 Nov 2011 21:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Feeding a screensaver from the digikam database</title>
		<link>http://andreas.goelzer.de/feeding-a-screensaver-from-the-digikam-database</link>
		<comments>http://andreas.goelzer.de/feeding-a-screensaver-from-the-digikam-database#comments</comments>
		<pubDate>Mon, 02 Jun 2008 20:17:09 +0000</pubDate>
		<dc:creator>Andreas Goelzer</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[digikam]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[screensaver]]></category>

		<guid isPermaLink="false">http://andreas.goelzer.de/?p=12</guid>
		<description><![CDATA[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 &#8230; <a href="http://andreas.goelzer.de/feeding-a-screensaver-from-the-digikam-database">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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 <a href="http://www.jwz.org/xscreensaver/">xscreensaver compilation</a>. 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 <a href="http://www.digicam.org">digikam</a> database, which was surprisingly simple.</p>
<p>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 <a href="http://jrwren.wrenfam.com/blog/2005/02/20/flickr-xscreensaver-fun/">xscreensaver-getimage-flickr<br />
</a>, 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?</p>
<h4>Installation</h4>
<p>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.<br />
the overall process would look like(assuming xscreensaver-glslideshow already works)</p>
<pre>
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
</pre>
<p>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:</p>
<pre>
imageDirectory: /home/goelzera/Documents/Bilder
</pre>
</p>
<h4>Modification</h4>
<p>Right now this is all a bit hacky. at the beginning of the file, there is a line</p>
<pre>bad_tags = "('private','me','Nophoto','Notmeanttobenice')"</pre>
<p>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&#8217;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.</p>
<h4>Running</h4>
<p>Set your screensaver to glslideshow and wait for it to start</p>
<pre lang="python" line="1">#!/usr/bin/python
# -*- coding: utf-8 -*-
&quot;&quot;&quot;
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 &lt;http://www.gnu.org/licenses/&gt;.


This program takes one random picture out of a sqlite-database
made by digikam.
This is useful for screensavers, xscreensaver-glslideshow in particular.
&quot;&quot;&quot;

#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 = &quot;('private','me','Nophoto','Notmeanttobenice')&quot;
#good_tags = &quot;('public')&quot;
good_tags = &quot;&quot;
attempts = 200


import sqlite3;
from sys import argv, exit;
from os.path import splitext;

digikamversion = &quot;4&quot;;

if(len(argv) &gt; 1):
	dirname = argv[len(argv) - 1]
else:
	dirname = &quot;/home/goelzera/Documents/Pictures&quot;
	
con = sqlite3.connect(dirname + &quot;/digikam&quot; + digikamversion + &quot;.db&quot;)
if(digikamversion == &quot;4&quot;):
	url = &quot;relativePath&quot;
	dirid = &quot;album&quot;
else:
	url = &quot;url&quot;
	dirid = &quot;dirid&quot;
	
#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(&quot;SELECT id FROM Tags WHERE name IN &quot;+ names):
		tag_ids += str(row[0]) + ','
	tag_ids = '(' + tag_ids[:-1] + ')'
	return tag_ids

if(bad_tags != &quot;&quot;): bad_tag_ids = getTagIdsFromNames(bad_tags)
if(good_tags != &quot;&quot;): 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(&quot;SELECT id, name, $dirid FROM Images ORDER BY RANDOM() LIMIT 0,1&quot;).fetchone()
	#fast, but not as random
	row = con.execute(&quot;SELECT id, name, &quot;+ dirid+&quot; FROM Images WHERE id &gt;= (abs(RANDOM()) % (SELECT max(id) FROM Images)) LIMIT 0,1&quot;).fetchone()
	#f.write(str(row[0]) + ',')
	
	#check for bad tag
	if(bad_tags != &quot;&quot;):
		if(con.execute(&quot;SELECT 1 FROM ImageTags WHERE imageid = &quot; + str(row[0]) + &quot; AND tagid IN &quot;+ bad_tag_ids).fetchone()): continue

	#check for good tag
	if(good_tags != &quot;&quot;):
		if(not con.execute(&quot;SELECT 1 FROM ImageTags WHERE imageid = &quot; + str(row[0]) + &quot; AND tagid IN &quot;+ good_tag_ids).fetchone()): continue


	#check for invalid extension
	ext = splitext(row[1])
	ext = ext[1][1:].lower()
	if(not ext in good_extensions): continue
	
	#not rejected, get directory
	drow = con.execute(&quot;SELECT &quot;+url+&quot; FROM Albums WHERE id = &quot; + str(row[2])).fetchone()
	file = dirname + drow[0] + '/' + row[1]
	break

print file.encode('utf-8')

#f.write(file.encode('latin-1') + '\n')





</pre><hr /><a href='http://andreas.goelzer.de/download/xscreensaver-getimage-digikam.py'><img src="http://andreas.goelzer.de/wp-content/plugins/kfile/fileicons/file-source-alt.png" width="16" height="16" alt="filetype" class="icon16" /> xscreensaver-getimage-digikam.py</a> (3.29 kiB, 2009-08-06)<br/><hr />
]]></content:encoded>
			<wfw:commentRss>http://andreas.goelzer.de/feeding-a-screensaver-from-the-digikam-database/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/7 queries in 0.543 seconds using disk: basic
Object Caching 227/230 objects using disk: basic

Served from: andreas.goelzer.de @ 2012-02-05 05:52:16 -->
