Skip to content

Commit

Permalink
Set timestamps of downloaded files to media creation timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
SijmenHuizenga committed Sep 11, 2020
1 parent fc2db69 commit ea4b9dc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,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 availabe, 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 {
log.Printf("Warning: Could not write timestamp to '%v': %v", filePath, err)
}
}

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 ea4b9dc

Please sign in to comment.