updated README

This commit is contained in:
WALTERS
2019-08-19 07:30:00 -05:00
parent d32dd0c47d
commit 66a344d35a
6 changed files with 164 additions and 19 deletions

View File

@@ -1,14 +1,13 @@
# from libxmp import file_to_dict
import os, sys, re
ext_filter = lambda file : file.endswith('.NEF')
mainPattern = r'<dc:subject>\n\s+<rdf:Bag>\n(?: <rdf:li>.+<\/rdf:li>\n)*\s+<\/rdf:Bag>\n\s+<\/dc:subject>\n'
subPattern = r'<rdf:li>(.*)</rdf:li>\n'
subFormatPattern = ' <rdf:li>{}</rdf:li>\n'
def writeTags(inputPath, outputPath, tags):
# Write tags to an XMP file, using regex patterns
def writeXMP(inputPath, outputPath, tags):
data = open(inputPath, 'r').read()
# Detect and find the <dc:Subject: part
match = re.search(mainPattern, data)
# If it's not found, we just add the tags area right below the creator tag
@@ -17,17 +16,13 @@ def writeTags(inputPath, outputPath, tags):
look = data.find('</dc:creator>') + 13
data = data[:look] + addition + data[look:]
match = re.search(mainPattern, data)
# Get last matching tag
submatch = None
for submatch in re.finditer(subPattern, match.group(0)):
pass
# Calculate very end
spanend = match.span()[0] + (submatch.span()[1] if submatch else 0)
# add tags to end
data = data[:spanend] + ''.join(subFormatPattern.format(tag) for tag in tags) + data[spanend:]
# Write file to disk
open(outputPath, 'w+').write( data)