Synology usage series 35 – Organizing photo by date, the automatical way


Update Mar 1 2017

My Digital Camera will create CR2 file as well as JPG as well. Exif cannot be read from CR2. The script is updated to handle CR2 file, applied that, both CR2 and JPG file have the same filename for the same photo.

Update Feb 24 2017

iPhone live’s photo create a short movie file for each live photo.

I’ve updated the script to scan for mov file of the photo and have them move to the same datestamp directory.

Update Mar 02 2016

The exiv2 does not able to read meta data from photo taken by iPhone! That’s bad.

I replaced exiv2 with exif provided by optware instead and it works fine!

This also further make the procedures even easier.

Finally the solution which actual works. No more manual procedure organizing my photo.

Update Feb 27 2016

I’ve revised the scripts and now only a single script will get the job done. And it can be triggered by crontab. So it is now fully automatic and no more manual procedure is required.

Just sync your mobile photo using DS Photo app. Then have the script organize your photo by datestamp automatically.

I am really busy babysitting lately and really don’t have the time manually organizing all the baby’s photo anymore. I used to categorizes my photo like these:


/baby/1 months/2012-01-10
/baby/1 months/2012-01-11
.
.

What I really need now is some kind of scripts or program to do these:

  • read all photo in a directory
  • extract the timestamp of the photo from exif, NOT from file timestamp
  • move all photo to subdirectory based on photo’s exif timestamp

Sound not much works, but I’ve got like 6 months didn’t have time sitting in front of a computer and got way too much of photo left un-categorized.

Did some search on google and here is how I get it done quickly on my old diskstation.

Install exif and bash

  • ipkg install bash
  • ipkg install exif

Create the script

Copy and paste the script below to any directory, prefer somewhere under /opt, mine using /opt/usr/local/bin


#!/opt/bin/bash

for entry in /volume1/photo/mobile_sync/iphone6sb/*; do
        if [ -d "$entry" ]
        then
          continue;
        fi

        filename=`echo $entry | cut -d'.' -f1`
        extension=`echo $entry | cut -d'.' -f2`

        if [ "$extension" == "mov" ] || [ "$extension" == "CR2" ]
        then
                continue;
        fi

        HEY=`exif $entry | grep "Date" | grep -v "(" | cut -d '|' -f 2 | tr ' ' '_'`
        IFS='_' read -a myarray <<< "$HEY"

        ts="${myarray[0]}"
        y=${ts:0:4}
        m=${ts:5:2}
        d=${ts:8:2}

        newdate="$y-$m-$d"
        if [ -d "/volume1/photo/mobile_sync/iphone6sb/$newdate" ]; then
                a=1
        else
                mkdir -p /volume1/photo/mobile_sync/iphone6sb/$newdate
        fi

        mv $entry /volume1/photo/mobile_sync/iphone6sb/$newdate

        if [ -f "$filename.mov" ]; then
                mv $filename.mov /volume1/photo/mobile_sync/iphone6sb/$newdate
        fi

        if [ -f "$filename.CR2" ]; then
                mv $filename.CR2 /volume1/photo/mobile_sync/iphone6sb/$newdate
        fi
done


Be sure to modify the path highlighted with bold.

Also make the script executable

# chmod +x /opt/usr/local/bin/organize_photo.sh

Just execute the script it will do the magic.

# /opt/usr/local/bin/organize_photo.sh

To run the script daily, you will need to install cron using optware.

# ipkg install cron

Then edit /opt/etc/crontab

Add the line below to the end of the file

0       1       *       *       *       root    /opt/bin/bash /opt/usr/local/bin/organize_photo.sh

This will tell optware execute the script daily at 1am.





Leave a Reply

Your email address will not be published. Required fields are marked *