Skip to content

Commit

Permalink
Merge pull request #17 from SijmenHuizenga/timstamps
Browse files Browse the repository at this point in the history
Set timestamps of downloaded files to media creation timestamp
  • Loading branch information
dtylman authored Dec 13, 2020
2 parents a1ffb1c + fa6259b commit df34cc7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -233,6 +234,18 @@ func (d *Downloader) downloadImage(item *LibraryItem, filePath string) error {
return err
}

// close file to prevent conflicts with writing new timestamp in next step
output.Close()

//If timestamp is available, set access time to current timestamp and set modified time to the time the item was first created (not when it was uploaded to Google Photos)
t, err := time.Parse(time.RFC3339, item.MediaMetadata.CreationTime)
if err == nil {
err = os.Chtimes(filePath, time.Now(), t)
if err != nil {
return errors.New("failed writing timestamp to file: " + err.Error())
}
}

log.Printf("Downloaded '%v' [saved as '%v'] (%v)", item.FileName, item.UsedFileName, humanize.Bytes(uint64(n)))

d.stats.UpdateStatsDownloaded(uint64(n), 1)
Expand Down

0 comments on commit df34cc7

Please sign in to comment.