Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Linux hack to benefit from Google Picasa face tagging on NAS drive photos.
- # My wife has tagged bazillions of faces in Photos stored on our NAS using
- # Picasa in Windows. This script creates a folder for each "contact" (person
- # face tagged) and then places local links arranged in folders by contact for
- # each photo on the NAS
- #
- # Author: Mark Ruff
- # Date: 19 May 2012
- # basedir that the photos are stored in
- BASEDIR="/media/Photos/"
- # contacts - file that the contacts are stored in
- CONTACTS="/media/xxxxxx/Google/Picasa2/contacts/contacts.xml"
- # targetdir for the links to photos to be stored
- TARGETDIR="/home/mark/pics/photo_tags"
- if [ $# -ne 2 ]
- then
- SAFECALL=$(echo $0 | sed 's/[][\.*^$/]/\\&/g')
- grep "contact id" contacts.xml | sed "s/^.*\"\(.*\)\" name=\"\(.*\)\" modified.*$/"$SAFECALL" \1 \2/" | bash
- exit
- fi
- # make our subdirectory
- TAG=$1
- NAME=$2
- mkdir -p $TARGETDIR/$NAME
- # clean subdirectory for sed
- SUBDIR=$(echo $TARGETDIR/$NAME | sed 's/[][\.*^$/]/\\&/g')
- function spider {
- # recursively drop down into each directory within the current directory
- for DIR in *
- do
- if [ -d "$DIR" ]
- then
- cd "$DIR"
- spider
- cd ..
- fi
- done
- # in each directory is a Picasa.ini file which lists each photo along with
- # the tags. The file contains [FILENAME] followed by a list of tags.
- # So we grep for the tag and pull the line above, then grep for just the
- # jpegs (and only show the file name, not the [ ]). Pipe the file names
- # into sed to create the cp command and enclose the filename in quotes
- # in case it contains spaces. Finally pipe the output (a list of cp
- # commands) into sh
- PWD=$(pwd | sed 's/[][\.*^$/]/\\&/g')
- grep -B2 $TAG* Picasa.ini 2>/dev/null | grep -io [^\[].*jpg | sed "s/\(.*\)/ln -s \"$PWD\/\1\" $SUBDIR/" | sh
- }
- cd $BASEDIR
- spider
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement