导出的Google+照片,如何将JSON数据转换为EXIF?

时间:2015-03-19 23:23:10

标签: json google-plus exif photos exiftool

最近使用Google Takeout从Google +下载60GB以上的照片和视频。

这导致了大量文件 - 但有价值的元数据(包括照片的原始日期和位置)存储在每个相册的单独metadata.json文件中,而不是存储在EXIF中。

这意味着我无法将其导入任何其他照片服务,而基本上不会根据G +对照片进行自动编辑来加扰所有日期。

无法在任何地方找到答案 - 解决这个问题应该可以帮助那些希望将照片从谷歌服务转移到其他地方的人。

2 个答案:

答案 0 :(得分:1)

我在将 Google 照片导出到 Synology NAS 后编写了这个 bash 脚本。 你可以试试这个

    #!/bin/bash
    tmpFileName="filelist.txt"
    startPath="/google_drive_sync"
    exifToolPath="./Image-ExifTool-12.29/"
    showCorrectFiles="False"
    debugOutput="False"
    
   if [[ -f $tmpFileName ]]; then
    echo "FileList is exist"
else    
    echo "Creatig FileList"
    find $startPath -name "*.jpg"  >> $tmpFileName
    find $startPath -name "*.png"  >> $tmpFileName
    find $startPath -name "*.PNG"  >> $tmpFileName
    find $startPath -name "*.JPG"  >> $tmpFileName
fi

filesCount=`wc filelist.txt -l | awk '{print $1}'`
currentFile=0
needRefresh="True"
tmpCount=0
processedByJson=0
processedByFilename=0
skippedFiles=0
echo "Parsing FileList"
echo "Total files (including eaDir): $filesCount"
while read fullPathToPhoto
do
    currentFile=$((currentFile + 1))
    tmpCount=$((tmpCount + 1))
    
    if [[ "$tmpCount" -gt "100" ]]; then
    tmpCount=0
    needRefresh="True"
    fi

    if [[ "$needRefresh" == "True" ]]; then
    clear
    needRefresh="False"
    echo "Processing: $currentFile of $filesCount"
    echo "Processed by JSON: $processedByJson"
    echo "Processed by FileName: $processedByFilename"
    echo "Skipped: $skippedFiles"
    fi
    photoFileName="$fullPathToPhoto"
    if [[ "$photoFileName" == *"eaDir"* ]]; then
    isEaDir="True"
    skippedFiles=$((skippedFiles + 1))
    else
    jsonFileName="$photoFileName.json"
        modifyDate=`stat "$photoFileName" | grep "Modify:" | cut -c9-18`
    checkJson="False"
        if [[ -f $jsonFileName ]]; then
            jsonDateTime=`cat "$jsonFileName" | grep -A1 "photoTakenTime" | grep "timestamp" | awk '{print $2}' | cut -c2-11`
        jsonDateTimeFormatted=`date -d @$jsonDateTime +"%Y-%m-%d %H:%M:%S"`
        jsonDate=`date -d @$jsonDateTime +"%Y-%m-%d"`
        checkJson="True"
    fi
    isAndroidWhatsAppImage="False"
    if [[ -n $modifyDate ]]; then
        isAndroidWhatsAppImageTmp=`echo $photoFileName | grep "WA" | grep "IMG"`
        if [[ -n $isAndroidWhatsAppImageTmp ]]; then
            isAndroidWhatsAppImage="True"
            modifyDateFromFileNameTmp=`echo $photoFileName | sed 's|.*IMG||' | sed 's/WA.*//' | sed 's/[^0-9]//g'`
            yearTmp=`echo $modifyDateFromFileNameTmp | cut -c1-4`
            monthTmp=`echo $modifyDateFromFileNameTmp | cut -c5-6`
            dayTmp=`echo $modifyDateFromFileNameTmp | cut -c7-8`
            modifyDateFromFileName=`echo $yearTmp-$monthTmp-$dayTmp`
        else
            isAndroidWhatsAppImage="False"
        fi
    fi
    if [[ "$isAndroidWhatsAppImage" == "True" ]]; then
        if [[ "$modifyDateFromFileName" != "$jsonDate" ]]; then
        checkJson="False"
        fi
    fi    
    if [[ "$checkJson" == "True" ]]; then
        if [[ "$modifyDate" != "$jsonDate" ]]; then
        echo "Change dt for $photoFileName" 
        echo "from $modifyDate to $jsonDateTimeFormatted by JSON"
        perl "$exifToolPath/exiftool" "-AllDates=$jsonDateTimeFormatted" "$photoFileName" -overwrite_original
        perl "$exifToolPath/exiftool" "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" "$photoFileName"
        processedByJson=$((processedByJson + 1))
        tmpCount=$((tmpCount + 45))
        else
        if [[ "$showCorrectFiles" == "True" ]]; then
            echo "Date is correct for $photoFileName by JSON"
            tmpCount=$((tmpCount + 45))
        fi
        skippedFiles=$((skippedFiles + 1))
        fi
    else
        if [[ -n $modifyDate ]]; then
        if [[ "$isAndroidWhatsAppImage" == "True" ]]; then
            if [[ "$debugOutput" == "True" ]]; then
            echo "Find WhatsApp image in $photoFileName"
            fi
            if [[ "$modifyDateFromFileName" == "$modifyDate" ]]; then
            if [[ "$showCorrectFiles" == "True" ]]; then
                echo "Date is correct for $photoFileName"
                echo "date is $modifyDate FileName date is $modifyDateFromFileName"
                tmpCount=$((tmpCount + 45))
            fi
            skippedFiles=$((skippedFiles + 1))
            else
            echo "Change dt for $photoFileName" 
            echo "from $modifyDate to $modifyDateFromFileName by FileName"
            perl "$exifToolPath/exiftool" "-AllDates=$modifyDateFromFileName 06:00:00" "$photoFileName" -overwrite_original
            perl "$exifToolPath/exiftool" "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" "$photoFileName"
            processedByFilename=$((processedByFilename + 1))
            tmpCount=$((tmpCount + 45))
            fi
        else
            if [[ "$debugOutput" == "True" ]]; then
            echo "$isAndroidWhatsAppImage"
            echo "Skip image check in $photoFileName"
            tmpCount=$((tmpCount + 45))
            fi
            skippedFiles=$((skippedFiles + 1))
        fi
        fi
    fi
    fi  
    done < $tmpFileName

答案 1 :(得分:0)

http://www.sno.phy.queensu.ca/~phil/exiftool/

有一个Exif工具

那里有很多文档,但有一些例子:

这样叫 exiftool -json=picture.json picture.jpg

exiftool -filename -imagesize -exif:fnumber -xmp:all image.jpg