CamFetch!

CamFetch!

Pozdravljeni ljubitelji kač!
Torej, ste uspeli popraviti pixle? Juhu! Vas pestijo drugačne težave? Na primer, kako 530 različnih slik, posnetih ob različnih časih in na različnih krajih spraviti v nek poljuben direktorij in jih datumsko urediti? Vse slike posnete včeraj v enem direktoriju, vse slike posnete tri dni nazaj v drugem? Si želite tega? Nič lažjega! Uporabite camfetch!

Hkrati bo program vaše slike opremil tudi z imenom avtorja in imetnika avtorskih pravic. Z mojim imenom. 😉

Še več! Celo timestamp datoteke na datotečnem sistemu se bo ohranil tako kot je treba. Prav tako bodo vse datoteke preimenovane, saj bodo njihova imena zapisana z malimi črkami. Vse to v pičlih 99ih vrsticah ali pa trikrat po 33 vrstic. To je malenkost več kot ena vrstica na mesec!

PS: Tudi tukaj ne odgovarjam za kakršnekoli poškodbe slik, ki bi se morebiti utegnile zgoditi.
DISCLAIMER: Men vse dela! Od mene za vas, z ljubeznijo…

[python]
#!/usr/bin/env python
############################################################################
# Copyright (C) 2008 by David Klasinc
# bigwhale@lubica.net
#
# 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.
############################################################################

import os
import sys
import time
import Image
import shutil
import pyexiv2
from stat import *

def walkTree (top, callback, DST_DIR):

for f in os.listdir (top):
pathname = os.path.join (top, f)
mode = os.stat(pathname)[ST_MODE]
if S_ISDIR (mode):
walkTree (pathname, callback, DST_DIR)
elif S_ISREG (mode):
callback (pathname, DST_DIR)
else:
print ‘Skipping %s’ % pathname

def processFile (srcFile, DST_DIR):
srcFile = srcFile.lower ()
if (not srcFile.endswith (“.jpg”)):
print srcFile, ” is not a JPEG file.”
return False
try:
tmpImage = pyexiv2.Image (srcFile)
tmpImage.readMetadata ()
tmpTime = tmpImage[‘Exif.Image.DateTime’]
except:
print “Skipping: Unable to read meta data for”, srcFile
return False

tmpDir = tmpTime.strftime(‘%Y-%m-%d’)
cYear = tmpTime.strftime (‘%Y’)
tgtDir = DST_DIR + “/” + tmpDir
tgtFile = tgtDir + “/” + os.path.basename (srcFile)
unixTime = time.mktime (tmpTime.timetuple())

if not os.path.isdir (tgtDir):
os.makedirs (tgtDir)
try:
# print “C:”, srcFile, ” ->\n “, tgtDir
if os.path.exists (tgtFile):
tgtFile = tgtDir + “/dup_” + os.path.basename (srcFile)
print “Not overwriting target file, trying to rename\n”, tgtFile
if os.path.exists (tgtFile):
print “Not overwriting duplicate, skipping”, srcFile
return False

shutil.copy2(srcFile, tgtFile)

except:
print “Copy failed for”, srcFile
return False

newImage = pyexiv2.Image (tgtFile)
newImage.readMetadata ()

newImage[‘Exif.Image.Artist’] = “David Klasinc”
newImage[‘Exif.Image.Copyright’] = “David Klasinc (c)” + cYear + “, All rights reserved.”
newImage.writeMetadata ()
os.utime(tgtFile, (unixTime, unixTime))
os.utime(tgtDir, (unixTime, unixTime))

return True

if __name__ == ‘__main__’:

try:
SRC_DIR = sys.argv[1]
DST_DIR = sys.argv[2]
except:
print “Usage: camfetch.py\n”
sys.exit ()
walkTree (SRC_DIR, processFile, DST_DIR)

print “Done.”
[/python]

3 thoughts on “CamFetch!

Comments are closed.

Comments are closed.