Home > Uncategorized > Inspect the f-stop photo.db file

Inspect the f-stop photo.db file

At one point I had a need to extract various pieces of information from the f-spot photo.db file (that’s where f-spot keeps all the information), so I wrote this script. Posting it here in case others find it useful. I called it

f-spot-list


#!/bin/bash

# Author: Gabriel Burca (gburca dash fspotlist at ebixio dot com)
# Version: 1.0
#
# Copyright (C) 2006-2009  Gabriel Burca (gburca dash fspotlist at ebixio dot com)
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

set -o nounset
set -o errexit

function usage () {
    cat << EOF
Extracts various pieces of information from an f-spot photo.db file.
Usage:
    $0 <photo.db> <option>

Options:
    -P | --Photo        Pictures in the Photo directory
    -k | --links DIR... All pictures in DIR that are not links
    -a | --all          All pictures in database
    -h | --has TAG...   Show pictures tagged with the tag
    -t | --tags         Show all available tags

<photo.db> is usually "~/.config/f-spot/photos.db"

Ex:
    - Find all photos tagged "Favorites" or "Web":
    $0 photos.db -h Favorites Web | sort | uniq | sed 's|^file://||' \
        | xargs -I linkName readlink -e linkName

EOF
}

function PhotosInPhotoDir() {
    sqlite3 "$PHOTO_DB" "select id, uri from photos where uri like '%Photos%';"
}

function HasTag() {
    for TAG in $@ ; do
        SQL="select base_uri || filename from photos \
            inner join photo_tags on photos.id = photo_tags.photo_id \
            inner join tags on photo_tags.tag_id = tags.id \
            where tags.name like '$TAG';"
        #echo $SQL
        sqlite3 "$PHOTO_DB" "$SQL"
    done
}

function ShowNonLinks() {
        for DIR in $@ ; do
                find "$DIR" -type f
        done
}

function ShowTags() {
    sqlite3 "$PHOTO_DB" "select name from tags order by name;"
}

function ShowAll() {
    sqlite3 "$PHOTO_DB" "select * from photos;"
}

################################################################################
# main()
################################################################################

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

IFS_orig=$IFS
IFS='
'

PHOTO_DB=$1
shift

if [ ! -e "$PHOTO_DB" ]; then
    usage
    exit 2
fi

case $1 in
    -P | --Photo)
        shift
        PhotosInPhotoDir $@
        ;;
    -k | --links)
        shift
        ShowNonLinks $@
        ;;
    -t | --tags)
        shift
        ShowTags $@
        ;;
    -h | --has)
        shift
        HasTag $@
        ;;
    -a | --all)
        shift
        ShowAll $@
        ;;
    *)
        usage
        exit 1
        ;;
esac

IFS=$IFS_orig
Categories: Uncategorized Tags: , , , ,
  1. RZ
    November 26th, 2009 at 18:39 | #1

    Very nice, I can sur use it.. trying to convert all tags from f-spot to kphotoalbum. So f-spot-list -t works, but f-spot-list -h Tagname gives an error like SQL error: no such column: uri.
    Too tired to investigate now.

    Btw in my installation the database is ~/.config/f-spot/photos.db

  2. RZ
    November 27th, 2009 at 08:29 | #2

    so the issue was that in some versions of th f-spot database uri was replaced by base_uri,filename

  3. Gabriel Burca
    January 2nd, 2011 at 00:14 | #3

    @RZ
    Script has now been updated to work with the newer versions of f-spot.

  1. No trackbacks yet.