iPhoto est bien sympa mais il a des limites, à commencer par le fait qu’il n’exporte pas dans des dossiers. Si on utilise les outils d’exportation on se retrouve avec toutes les photos dans un seul dossier !
grace aux commentaires sur cette page j’ai utilisé le script python suivant qui a fonctionné sur ma configuration :
- Mac OS 10.6.3 (Snow Leopard), avec le python intégré
- iPhoto 8.1.2
Je l’ai enregistré dans un fichier nommé “export-iphoto.py” dans le dossier “documents” de l’utilisateur “chris”, puis en lançant le terminal pour l’executer (en réalité je crois qu’on peut se contenter de double cliquer dessus, mais j’aime bien le mode ligne de commande 🙂 ) :
cd /Users/chris/Documents
python export-iphoto.py
Voici le contenu du fichier export-iphoto où il faut bien prendre soint de changer ces 2 lignes
albumDataXml="/Users/YOURUSERNAME/Pictures/iPhoto Library/AlbumData.xml"
targetDir="/Volumes/share/pictures"
export-iphoto.py :
from xml.dom.minidom import parse, parseString, Node
import os, time, stat, shutil, sys
def findChildElementsByName(parent, name):
result = []
for child in parent.childNodes:
if child.nodeName == name:
result.append(child)
return result
def getElementText(element):
if element is None: return None
if len(element.childNodes) == 0: return None
else: return element.childNodes[0].nodeValue
def getValueElementForKey(parent, keyName):
for key in findChildElementsByName(parent, "key"):
if getElementText(key) == keyName:
sib = key.nextSibling
while(sib is not None and sib.nodeType != Node.ELEMENT_NODE):
sib = sib.nextSibling
return sib
albumDataXml="/Users/chris/Pictures/iPhoto Library/AlbumData.xml"
targetDir="/Volumes/FAT/pictures"
copyImg=True #set to false to run with out copying files or creating directories
print "Parsing AlbumData.xml"
albumDataDom = parse(albumDataXml)
topElement = albumDataDom.documentElement
topMostDict = topElement.getElementsByTagName('dict')[0]
listOfRollsArray = getValueElementForKey(topMostDict, "List of Rolls")
masterImageListDict = getValueElementForKey(topMostDict, "Master Image List")
#walk through all the rolls (events)
for rollDict in findChildElementsByName(listOfRollsArray, 'dict'):
rollName = getElementText(getValueElementForKey(rollDict, "RollName"))
print "\n\nProcessing Roll: %s" % (rollName)
#walk through all the images in this roll/event
imageIdArray = getValueElementForKey(rollDict, "KeyList")
for imageIdElement in findChildElementsByName(imageIdArray, 'string'):
imageId = getElementText(imageIdElement)
imageDict = getValueElementForKey(masterImageListDict, imageId)
modifiedFilePath = getElementText(getValueElementForKey(imageDict, "ImagePath"))
originalFilePath = getElementText(getValueElementForKey(imageDict, "OriginalPath"))
sourceImageFilePath = modifiedFilePath
modifiedStat = os.stat(sourceImageFilePath)
basename = os.path.basename(sourceImageFilePath)
year = str(time.gmtime(modifiedStat[stat.ST_CTIME])[0])
targetFileDir = targetDir + "/" + year + "/" + rollName
if not os.path.exists(targetFileDir):
print "Directory did not exist - Creating: %s" % targetFileDir
if copyImg:
os.makedirs(targetFileDir)
targetFilePath = targetFileDir + "/" + basename
iPhotoFileIsNewer = False
if os.path.exists(targetFilePath):
targetStat = os.stat(targetFilePath)
#print "modified: %d %d" % (modifiedStat[stat.ST_MTIME], modifiedStat[stat.ST_SIZE])
#print "target : %d %d" % (targetStat[stat.ST_MTIME], targetStat[stat.ST_SIZE])
#why oh why is modified time not getting copied over exactly the same?
if abs(targetStat[stat.ST_MTIME] - modifiedStat[stat.ST_MTIME]) > 10 or targetStat[stat.ST_SIZE] != modifiedStat[stat.ST_SIZE]:
iPhotoFileIsNewer = True
else:
iPhotoFileIsNewer = True
if iPhotoFileIsNewer:
msg = "copy from:%s to:%s" % (sourceImageFilePath, targetFilePath)
if copyImg:
print msg
shutil.copy2(sourceImageFilePath, targetFilePath)
else:
print "test - %s" % (msg)
else:
sys.stdout.write(".")
sys.stdout.flush()
albumDataDom.unlink()