#! /usr/bin/env python """ Renames images in a directory from native filename to name based on date and time of picture. ver.: 20030807 Copyright (c) 2003 Jiri Baum 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ # prejmenuje fotografie z fotoaparatu podle jejich data a casu import sys, os, re, string if len(sys.argv)>1: os.chdir(sys.argv[1]) for orig in os.listdir('.'): if not os.path.isfile(orig) or (not re.match('dscf0.*\.jpe?g', orig) and not re.match('IMG_[0-9]+\.JPG', orig) # Filipuv aparat je dscnNNNN.JPG: and not re.match('dscn[0-9]+\.jpg', orig) # Panasonic NV-GS50 je imgaNNNN.jpg: and not re.match('imga[0-9]+\.jpg', orig)): continue print orig, " -> ", f=os.popen("metacam "+orig) while 1: s=f.readline() if not len(s): break d=re.match('\s*Image Creation Date: (\d+):(\d+):(\d+) (\d+):(\d+):(\d+)\s*', s) if not d: continue base=d.group(1)+d.group(2)+d.group(3)+"_"+d.group(4)+d.group(5)+d.group(6) # Filipovi pridavat jeste -fz, aby se poznaly # base=d.group(1)+d.group(2)+d.group(3)+"_"+d.group(4)+d.group(5)+d.group(6)+"-fz" sfx="" if os.path.exists(base+".jpg"): for sfx in [chr(x) for x in range(ord('a'), ord('z')+1)]: if not os.path.exists(base+sfx+".jpg"): break else: raise "prilis mnoho se stejnym datem" print base+sfx+".jpg" os.rename(orig, base+sfx+".jpg") break