Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 8abf8f2

Browse files
authored
Memory Geolocation (#81)
1 parent 9b63ec9 commit 8abf8f2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/services/exif.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const dayjs = require("dayjs");
55

66
const exiftool = new ExifTool({});
77

8-
const updateExifData = async (fileName, creationDateTimeString) => {
8+
const updateExifData = async (
9+
fileName,
10+
creationDateTimeString,
11+
geolocationData
12+
) => {
913
const extension = extname(fileName);
1014
if (extension === ".mp4") {
1115
// mp4 files are not supported by exiftool
@@ -14,9 +18,15 @@ const updateExifData = async (fileName, creationDateTimeString) => {
1418
const exifFormattedDate = dayjs
1519
.utc(creationDateTimeString, "YYYY-MM-DD HH:mm:ss Z")
1620
.format("YYYY:MM:DD HH:mm:ss");
21+
1722
await exiftool.write(fileName, {
1823
DateTimeOriginal: exifFormattedDate,
24+
GPSLatitude: geolocationData.latitude,
25+
GPSLongitude: geolocationData.longitude,
26+
GPSLatitudeRef: geolocationData.latitude > 0 ? "North" : "South",
27+
GPSLongitudeRef: geolocationData.longitude > 0 ? "East" : "West",
1928
});
29+
2030
await unlink(`${fileName}_original`);
2131
};
2232

src/services/fileServices.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,16 @@ const writeFile = async (file, data) => {
7070
const updateFileMetadata = (file, memory) => {
7171
const date = new Date(memory.Date);
7272
fs.utimes(file, date, date, () => {});
73-
return updateExifData(file, memory.Date);
73+
74+
// parse latitude and longitude 'x, y' from `Latitude, Longitude: x, y` string
75+
const geolocationString = memory.Location.split(": ")[1];
76+
const [latitude, longitude] = geolocationString.split(", ");
77+
const geolocationData = {
78+
latitude: parseFloat(latitude),
79+
longitude: parseFloat(longitude),
80+
};
81+
82+
return updateExifData(file, memory.Date, geolocationData);
7483
};
7584

7685
const getOutputInfo = () => {

0 commit comments

Comments
 (0)