This repository was archived by the owner on Mar 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,11 @@ const dayjs = require("dayjs");
55
66const 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
Original file line number Diff line number Diff line change @@ -70,7 +70,16 @@ const writeFile = async (file, data) => {
7070const 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
7685const getOutputInfo = ( ) => {
You can’t perform that action at this time.
0 commit comments