Advertisement
markruff

Picasa Tag Linker

Dec 31st, 2015
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.86 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Linux hack to benefit from Google Picasa face tagging on NAS drive photos.
  4. # My wife has tagged bazillions of faces in Photos stored on our NAS using
  5. # Picasa in Windows. This script creates a folder for each "contact" (person
  6. # face tagged) and then places local links arranged in folders by contact for
  7. # each photo on the NAS
  8. #
  9. # Author: Mark Ruff
  10. # Date: 19 May 2012
  11.  
  12. # basedir that the photos are stored in
  13. BASEDIR="/media/Photos/"
  14.  
  15. # contacts - file that the contacts are stored in
  16. CONTACTS="/media/xxxxxx/Google/Picasa2/contacts/contacts.xml"
  17.  
  18. # targetdir for the links to photos to be stored
  19. TARGETDIR="/home/mark/pics/photo_tags"
  20.  
  21. if [ $# -ne 2 ]
  22. then
  23.     SAFECALL=$(echo $0 | sed 's/[][\.*^$/]/\\&/g')
  24.     grep "contact id" contacts.xml | sed "s/^.*\"\(.*\)\" name=\"\(.*\)\" modified.*$/"$SAFECALL" \1 \2/" | bash
  25.     exit
  26. fi
  27.  
  28. # make our subdirectory
  29. TAG=$1
  30. NAME=$2
  31. mkdir -p $TARGETDIR/$NAME
  32. # clean subdirectory for sed
  33. SUBDIR=$(echo $TARGETDIR/$NAME | sed 's/[][\.*^$/]/\\&/g')
  34.  
  35. function spider {
  36.  
  37.     # recursively drop down into each directory within the current directory
  38.     for DIR in *
  39.     do
  40.         if [ -d "$DIR" ]
  41.         then
  42.             cd "$DIR"
  43.             spider
  44.             cd ..
  45.         fi
  46.     done
  47.     # in each directory is a Picasa.ini file which lists each photo along with
  48.     # the tags. The file contains [FILENAME] followed by a list of tags.
  49.     # So we grep for the tag and pull the line above, then grep for just the
  50.     # jpegs (and only show the file name, not the [ ]). Pipe the file names
  51.     # into sed to create the cp command and enclose the filename in quotes
  52.     # in case it contains spaces. Finally pipe the output (a list of cp
  53.     # commands) into sh
  54.     PWD=$(pwd | sed 's/[][\.*^$/]/\\&/g')
  55.     grep -B2 $TAG* Picasa.ini 2>/dev/null | grep -io [^\[].*jpg | sed "s/\(.*\)/ln -s \"$PWD\/\1\" $SUBDIR/" | sh
  56. }
  57.  
  58. cd $BASEDIR
  59. spider
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement