[Download]
reloc-exif
As personal convention, I store digital photos into yyyy/mm/dd/filename hierarchy.
Though some tools to achieve it will found if I search, I made it by myself for myself. One of the reasons I did so is exercise because I'm just learning python.
Updates
Nov/13/2022
Fix abortion caused by failure of multi bytes character encoding.
Nov/13/2022
Author's environment is migrated to Python 3, so Python 2 version won't be renewed any more.
Feature
reloc-exif is my implementation for it.
Command line syntax of reloc-exif is
reloc-exif
[-fhn
] [src | src1[... srcN] dst]
If srcis a file, reloc-exif relocates src to dst/yyyy/mm/dd/src. If src is a directory, reloc-exif relocates files under src.
yyyy/mm/dd is determined by time stamp. Time stamp obtained from EXIF data(DateTimeOriginai, say proper) is preferred. When something wrong with it, if -f option is given, OS time stamp(mtime) is referred instead of EXIF time stamp, or skip to relocate src.
reloc-exif takes 3 options. -f is as mentioned above. -h is for help. -n is dry run. Just show relocate action to be taken but doesn't do actual relocation.
reloc-exif accepts 0 or more arguments other than 3 options.
If no arguments is given, DCIM is used for src and current directory is for dst, so files under DCIM is relocated into ./yyyy/mm/dd/filename.jpg.
If one argument is given, it is recognized as src and dst is still current directory.
If two or more are given, final one is recognized as dst and others are src.
Please note that the relocation is implemented by rename(), so relocate across file systems isn't supported. No plan to enhance about it is planned because it is enough as long as my personal usage. If you wish to fetch photos from flash and store them into HDD directory, your job is to add copy (and unlink?) routine.
Example
Assume that we have the following topology.
-+- tmp1 --- DCIM -+- photo1.JPG
| |- photo2.JPG
|
+- tmp2 --- DCIM -+- photo3.JPG
| |- movie1.AVI
|
+- My Pictures
If you're carefully enough, it is good tactics to invoke reloc-exif with -n option to make it dry run mode.
% reloc-exif -n tmp1 tmp2 My\ Pictures
tmp1/DCIM/photo1.JPG -> My Pictures/2008/09/07/photo1.JPG
tmp1/DCIM/photo2.JPG -> My Pictures/2008/09/07/photo2.JPG
tmp1/DCIM/photo3.JPG -> My Pictures/2008/09/19/photo3.JPG
tmp2/DCIM/photo4.JPG -> My Pictures/2008/09/20/photo4.JPG
tmp2/DCIM/movie1.AVI: Can't obtain EXIF DataTimeOriginal, so leave it.
tmp2/DCIM/photo5.JPG -> My Pictures/2008/09/27/photo5.JPG
Indeed! Let's run with -f option to use OS time stamp for movie1.AVI.
% reloc-exif -nf tmp1 tmp2 My\ Pictures
tmp1/DCIM/photo1.JPG -> My Pictures/2008/09/07/photo1.JPG
tmp1/DCIM/photo2.JPG -> My Pictures/2008/09/07/photo2.JPG
tmp1/DCIM/photo3.JPG -> My Pictures/2008/09/19/photo3.JPG
tmp2/DCIM/photo4.JPG -> My Pictures/2008/09/20/photo4.JPG
tmp2/DCIM/movie1.AVI: Can't obtain EXIF DataTimeOriginal, so use OS time stamp instead.
tmp2/DCIM/movie1.AVI -> My Pictures/2008/09/14/movie1.AVI
tmp2/DCIM/photo5.JPG -> My Pictures/2008/09/27/photo5.JPG
With -f option, reloc-exif is going to relocate movie1.AVI into 2008/09/14. If you judge that 2008/09/14 is apropriate date for movie1.AVI, go on.
% reloc-exif -f tmp1 tmp2 My\ Pictures
tmp1/DCIM/photo1.JPG -> My Pictures/2008/09/07/photo1.JPG
tmp1/DCIM/photo2.JPG -> My Pictures/2008/09/07/photo2.JPG
tmp1/DCIM/photo3.JPG -> My Pictures/2008/09/19/photo3.JPG
tmp2/DCIM/photo4.JPG -> My Pictures/2008/09/20/photo4.JPG
tmp2/DCIM/movie1.AVI: Can't obtain EXIF DataTimeOriginal, so use OS time stamp instead.
tmp2/DCIM/movie1.AVI -> My Pictures/2008/09/14/movie1.AVI
tmp2/DCIM/photo5.JPG -> My Pictures/2008/09/27/photo5.JPG
This results
-+- My Pictures --- 2008 --- 09 -+- 07 -+- photo1.JPG
| | +- photo2.JPG
| |
| +- 14 --- movie1.AVI
| |
| +- 19 --- photo3.JPG
| |
| +- 20 --- photo4.JPG
| |
| +- 27 --- photo5.JPG
|
+- tmp1 --- DCIM ---
|
+- tmp2 --- DCIM ---
Or run without -f option to remain movie1.AVI on tmp2/DCIM.
% reloc-exif tmp1 tmp2 My\ Pictures
tmp1/DCIM/photo1.JPG -> My Pictures/2008/09/07/photo1.JPG
tmp1/DCIM/photo2.JPG -> My Pictures/2008/09/07/photo2.JPG
tmp1/DCIM/photo3.JPG -> My Pictures/2008/09/19/photo3.JPG
tmp2/DCIM/photo4.JPG -> My Pictures/2008/09/20/photo4.JPG
tmp2/DCIM/movie1.AVI: Can't obtain EXIF DataTimeOriginal, so leave it.
tmp2/DCIM/photo5.JPG -> My Pictures/2008/09/27/photo5.JPG
This results
-+- My Pictures --- 2008 --- 09 -+- 07 -+- photo1.JPG
| | +- photo2.JPG
| |
| +- 19 --- photo3.JPG
| |
| +- 20 --- photo4.JPG
| |
| +- 27 --- photo5.JPG
|
+- tmp1 --- DCIM ---
|
+- tmp2 --- DCIM --- movie1.AVI
You can move tmp2/DCIM/movie1.AVI to apropriate directory by manual operation.
Installation & dependency
Python 3
- Python
- reloc-exif is written in Python.
- exif-py
- reloc-exif depends exif-py, which is distributed athttps://github.com/ianare/exif-py.
Author uses the following environment.
OS | Python | exif-py |
FreeBSD 12.3/amd64 | 3,8.15 by pkg | 2.1.2 by pkg(py38-ExifRead) |
Ubuntu 22.04.01 LTS | 3.10.6 from Ubuntu distribution | 2.3.2-1 by apt(python3-exifread) |
Python 2
Author's environment is migrated to Python 3, so Python 2 version won't be renewed any more.
- Python
- reloc-exif is written in Python. As of development time, my environment was Python 2.6.5 from ports on FreeBSD 8.2/amd64.
- EXIF.py
- reloc-exif depends EXIF.py, which is contained in exif-py distributed at https://github.com/ianare/exif-py. My one is 1.0.8.
Download and extract tar ball. Then run configure. configure accepts --with-exif-py=DIR option. Without this, existance check for exifread or EXIF.py isn't supported yet(I know that it should be done), so please make sure to your Python can find exifread(Python 3) or EXIF.py(Python 2). Then invoke make.
I believe that you got ready to run. Enjoy!
[software page(Sorry, Japanese only)|Top page(Japanese only, too)]
Last update: $Date:: 2022-11-13 15:47:15 +0900#$
Copyright 2011, 2019, 2022 Koh-ichi Ito, All rights reserved.