From 100623fe7d3b91b7c0537e8320a806d52f7822f2 Mon Sep 17 00:00:00 2001 From: Chris Walter Date: Sat, 23 Dec 2023 13:11:33 -0500 Subject: [PATCH] Programmatically upload to Google Photos with XMP Title Extract the XMP title using exiftools and then add it to the uploaded item. This change adds an ImageTitle entry to the uploadedItem struct. It then fills it using an exiftools wrapper and the info is uploaded to google photos via the API with the AlbumID and UploadToken. Note, this ignores any batching and will only work with single thread uploads (`--transfers 1`) --- backend/googlephotos/googlephotos.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/googlephotos/googlephotos.go b/backend/googlephotos/googlephotos.go index df031b606..5733b5b86 100644 --- a/backend/googlephotos/googlephotos.go +++ b/backend/googlephotos/googlephotos.go @@ -36,6 +36,8 @@ import ( "github.com/rclone/rclone/lib/rest" "golang.org/x/oauth2" "golang.org/x/oauth2/google" + + "github.com/barasher/go-exiftool" ) var ( @@ -992,6 +994,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read // input to the batcher type uploadedItem struct { AlbumID string // desired album + ImageTitle string // Title taken from the EXIF XMP Title UploadToken string // upload ID } @@ -1009,6 +1012,7 @@ func (f *Fs) commitBatchAlbumID(ctx context.Context, items []uploadedItem, resul for i := range items { if items[i].AlbumID == albumID { request.NewMediaItems = append(request.NewMediaItems, api.NewMediaItem{ + Description: items[i].ImageTitle, SimpleMediaItem: api.SimpleMediaItem{ UploadToken: items[i].UploadToken, }, @@ -1125,8 +1129,13 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op return errors.New("empty upload token") } + et, err := exiftool.NewExiftool() + fileInfos := et.ExtractMetadata(fileName) + exifTitle, err := fileInfos[0].GetString("Title") + uploaded := uploadedItem{ AlbumID: albumID, + ImageTitle: exifTitle, UploadToken: uploadToken, }