Contains scripts to modify exif metadata on media files. Generally, I used them for the synology photostation.
Another good reference with exif tricks: https://gist.github.com/rjames86/33b9af12548adf091a26
All of the commands or scripts require ExifTool by Phil Harvey.
Recommended Order of Running the Commands and Scripts
- Set CreateDate for Video-Media
- Set 'CreateDate' Based on FileName Supporting Different Formats
- Rename Files based on 'CreateDate'
- Copy All Files Without 'CreateDate' to SubDir
exiftool -a -s -G1 -time:all .
Sets DateTimeOriginal based on CreateDate if the DateTimeOriginal is not present and CreateDate is present.
exiftool -r -if '(not $DateTimeOriginal)' -if '($CreateDate)' "-DateTimeOriginal<CreateDate" -overwrite_original .
Renames all files which have a CreateDate tag to the following format: YYYY-MM-DD-HHMMSS, e.g. 2019-02-25-180220.jpg.
exiftool -d %Y-%m-%d-%H%M%S%%-c.%%e -r "-filename<CreateDate" .
exiftool -r -if '(not $createdate)' "-filename=%d/no_createDate/%f.%e" .
Renames image.jpeg to image.jpg.
exiftool '-filename<%f.$fileTypeExtension' .
Uses the filename to set the CreateDate.
exiftool -r "-createDate<filename" .
Sets the CreateDate metadata tag based on the filename. It supports different types of filenames, e.g. WhatsApp and Signal mobile app patterns.
#!/bin/sh
echo "~~~~~~~~~ Fix No 'Create Date' Script ~~~~~~~~~"
echo ""
path=$1
if [ -z "$path" ]
then
echo "Please specify first argument: directory to fix"
exit
else
echo "Fixing dates in directory: $path"
fi
script_execution_directory=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "Script execution directory: $script_execution_directory"
echo ""
echo "Switching to path: $path"
cd $path
for filename in *.jpg; do
[ -e "$filename" ] || continue
echo ""
if [[ "$filename" =~ WA ]]
then
echo "WhatsApp match: $filename"
exiftool -overwrite_original '-CreateDate<${filename;$_=substr($_,4,12)} 00:00:00' "$filename"
elif [[ "$filename" =~ signal ]]
then
echo "Signal match: $filename"
exiftool -overwrite_original '-CreateDate<${filename;$_=substr($_,7,17)}' "$filename"
else
echo "No match: $filename"
fi
done
exiftool -d %Y-%m-%d-%H%M%S%%-c.%%e -r "-filename<CreateDate" .
The Synology photostation uses specific metadata per file type and date sort option (e.g. date taken, date created) to sort the files. These metadata is not always available or changed by the photostation for uploaded media files leading to an incorrect sorting for date options. Albums containing images and videos end up in an incorrect sorted variant.
For example, for video files and sorting option date taken the photostation uses the metadata FileModifyDate. But if the video files are uploaded to the photostation, this metadata tag is set to the upload time. The sorting will be completely off.
As the photostation uses different media metadata to sort the media depending on the file type and not all systems (e.g. cameras or the photostation itself) use or correctly create these files, a modification to the metadata of these files is necessary.
The script does the following:
- looks for video files of defined video formats in the specified path
- copies these files to the directory where the script is executed
- updates the FileModifyDate
- moves the files back to the specified path
It is important to copy the files and overwrite the source files later for the photostation to start the indexing automatically again.
#!/bin/sh
echo "~~~~~~~~~ Set CreateDate Script ~~~~~~~~~"
echo ""
path=$1
if [ -z "$path" ]
then
echo "Please specify first argument: directory to fix"
exit
else
echo "Fixing dates in directory: $path"
fi
script_execution_directory=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "Script execution directory: $script_execution_directory"
echo ""
echo "Switching to path: $path"
cd $path
for filename in *.mp4 *.m4v *.mov; do
[ -e "$filename" ] || continue
echo ""
echo "Working on $filename"
filename_CreateDate=$(exiftool '-CreateDate' '-s' '-s' '-s' "$filename")
filename_FileModifyDate=$(exiftool '-FileModifyDate' '-s' '-s' '-s' "$filename")
filename_FileModifyDateWithoutTimeZone=$(echo $filename_FileModifyDate | cut -d'+' -f 1)
if [ "$filename_CreateDate" = "$filename_FileModifyDateWithoutTimeZone" ]
then
echo " IGNORE: CreateDate and FileModifyDate are equal."
else
filename_temp="$script_execution_directory/$filename"
echo " Copy NAS => LOCAL: $filename to $filename_temp"
cp "$filename" "$filename_temp"
echo " Modifying Exif Metada"
exiftool -q -overwrite_original -if '$ContentCreateDate' '-ContentCreateDate>CreateDate' "$filename_temp"
echo " Copy CreateDate to FileModifyDate"
exiftool -q -overwrite_original '-CreateDate>FileModifyDate' "$filename_temp"
echo " Move NAS <= LOCAL: $filename_temp to $filename"
mv "$filename_temp" "$filename"
fi
done
The scripts are written for Photostation 6 but may also work for other versions.
The official documentation does not provide any information about the tags used by the Synology photostation for each date sorting option.
The photostation uses different media metadata tags to sort the media depending the file type.
- date taken:
- mp4, m4v, mov
- FileModifyDate without timezone suffix
- jpg
- DateTimeOriginal
- Filename (if DateTimeOriginal is not present)
- mp4, m4v, mov
The following metadata is used to fix the sorting.
- date taken
- mp4, m4v, mov
- ContentCreateDate (if available)
- CreateDate
- mp4, m4v, mov