Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/services/exif.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const dayjs = require("dayjs");

const exiftool = new ExifTool({});

const updateExifData = async (fileName, creationDateTimeString) => {
const updateExifData = async (
fileName,
creationDateTimeString,
geolocationData
) => {
const extension = extname(fileName);
if (extension === ".mp4") {
// mp4 files are not supported by exiftool
Expand All @@ -14,9 +18,15 @@ const updateExifData = async (fileName, creationDateTimeString) => {
const exifFormattedDate = dayjs
.utc(creationDateTimeString, "YYYY-MM-DD HH:mm:ss Z")
.format("YYYY:MM:DD HH:mm:ss");

await exiftool.write(fileName, {
DateTimeOriginal: exifFormattedDate,
GPSLatitude: geolocationData.latitude,
GPSLongitude: geolocationData.longitude,
GPSLatitudeRef: geolocationData.latitude > 0 ? "North" : "South",
GPSLongitudeRef: geolocationData.longitude > 0 ? "East" : "West",
});

await unlink(`${fileName}_original`);
};

Expand Down
11 changes: 10 additions & 1 deletion src/services/fileServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ const writeFile = async (file, data) => {
const updateFileMetadata = (file, memory) => {
const date = new Date(memory.Date);
fs.utimes(file, date, date, () => {});
return updateExifData(file, memory.Date);

// parse latitude and longitude 'x, y' from `Latitude, Longitude: x, y` string
const geolocationString = memory.Location.split(": ")[1];
const [latitude, longitude] = geolocationString.split(", ");
const geolocationData = {
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
};

return updateExifData(file, memory.Date, geolocationData);
};

const getOutputInfo = () => {
Expand Down