-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgps2file.py
executable file
·73 lines (60 loc) · 2.21 KB
/
gps2file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
# -*- coding: utf-8 -*-
#=================DESCRIPTION IS MISSING!========================================#
#System environment
import sys
import os
import datetime
import subprocess
#exiftool bindings for python (git://github.com/smarnach/pyexiftool.git)
from lib.pyexiftool_settags import exiftool
#
import shutil
#SETTINGS:
file_exts=('.tif','.nef','.jpg','.png', '.xmp')
photo_exts=('.tif','.nef','.jpg','.png')
#minimum length of counter:
n_zfill=3
def tags_to_file(filepath, xmppath):
print filepath
print xmppath
try:
subprocess.check_call(["exiftool", "-overwrite_original", "-tagsfromfile", xmppath, filepath])
except subprocess.CalledProcessError:
print "Exiftool meldete einen Fehler beim Verarbeiten von '"+xmppath+"'."
return
#Path should be an argument
if len(sys.argv) > 1:
path = sys.argv[1]
#Check folder
if not (os.path.exists(path)):
print "Ordner "+path+" existiert nicht"
sys.exit(0)
print "Starte Kopiere von xmp zu Bild..."
#Check if path exists
if os.path.exists(path):
#rename all tiff to tif
files_tiff = [ f for f in os.listdir(path) if f[-4:].lower() == 'tiff']
if len(files_tiff)>0:
print "Umbenennen von *.tiff nach *.tif"
for t in files_tiff:
name=os.path.splitext(t)[0]
os.rename(os.path.join(path, t), os.path.join(path,name+".tif"))
#create a list of file names from image files in our folder
files=[ f for f in os.listdir(path) if f[-4:].lower() in ['.xmp']]
for i, f in enumerate(files):
files[i] = os.path.splitext(f)[0]
for f in files:
for ext in photo_exts:
#check if image.ext exists:
if os.path.exists(os.path.join(path, f+ext.lower())):
tags_to_file(os.path.join(path, f+ext.lower()), os.path.join(path, f+'.xmp'))
else:
if os.path.exists(os.path.join(path, f+ext.upper())):
tags_to_file(os.path.join(path, f+ext.upper()), os.path.join(path, f+'.xmp'))
else:
print "Keine xmp-Metadata für Datei '"+f+ext+"'."
print "Kopieren abgeschlossen."
else:
print "Kein Pfad angeben."
sys.exit(0)