Skip to content

Commit bd6f4d6

Browse files
committed
Set the Flickr Date Posted on upload
When uploading to Flickr, if `upload.set_date_posted` is true, then set the date posted to the date that the picture was taken.
1 parent 193d9de commit bd6f4d6

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ flickr:
115115
user_nsid: "{user's id}"
116116
username: "{user's name}"
117117

118+
# Configuration for `rodeo upload`
119+
upload:
120+
set_date_posted: false
121+
118122
# Configuration for `rodeo resize`
119123
resize:
120124
method: "catrom"
@@ -151,7 +155,7 @@ rules:
151155
### Resize configuration
152156
153157
If these do not exist in `rodeo.yaml`, then they are added automatically on first
154-
run of `rodeo resize`
158+
run of `rodeo`
155159

156160
| Property | What it does |
157161
| --------- | ----------------------------------------------------------------------- |
@@ -162,6 +166,15 @@ run of `rodeo resize`
162166
[im]: https://imagemagick.org/script/command-line-options.php#interpolate
163167
[cl]: https://imagemagick.org/script/command-line-options.php#quality
164168

169+
### Upload configuration
170+
171+
If these do not exist in `rodeo.yaml`, then they are added automatically on first
172+
run of `rodeo`
173+
174+
| Property | What it does |
175+
| ----------------- | ------------------------------------------------------------------------------------ |
176+
| `set_date_posted` | If set to true, then the date posted is set to the date captured. Default is `false` |
177+
165178
### Upload rules
166179

167180
For each rules there are up to four conditions and two actions:

commands/upload.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/spf13/viper"
2020
"gopkg.in/masci/flickr.v2"
2121
"gopkg.in/masci/flickr.v2/photosets"
22+
"gopkg.in/masci/flickr.v2/photos"
2223
"os"
2324
"os/exec"
2425
"path/filepath"
@@ -256,6 +257,17 @@ func uploadFile(filename string) string {
256257
photoId := response.ID
257258
fmt.Printf("Uploaded photo '%s'\n", title)
258259

260+
// set date posted to the date that the photo was taken so that it's in the right place
261+
// in the Flickr photo stream
262+
setDatePosted := config.Upload.SetDatePosted
263+
if setDatePosted == true && info.Date != nil {
264+
datePosted := fmt.Sprintf("%d", info.Date.Unix())
265+
respSetDate, err := photos.SetDates(client, photoId, datePosted, "")
266+
if err == nil {
267+
fmt.Printf("Failed update photo %v's date posted: %v\n%v\n: ", photoId, err, respSetDate.ErrorMsg())
268+
}
269+
}
270+
259271
if len(albumsToAddTo) > 0 {
260272
// assign photo to each photoset in the list
261273
for _, album := range albumsToAddTo {

internal/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ type Flickr struct {
2222
Username string `mapstructure:"username"`
2323
}
2424

25+
type Upload struct {
26+
SetDatePosted bool `mapstructure:"set_date_posted"`
27+
}
28+
2529
type Resize struct {
2630
Method string
2731
Quality string
@@ -55,6 +59,7 @@ type Rules struct {
5559
type Config struct {
5660
Cmd Command
5761
Flickr Flickr
62+
Upload Upload
5863
Resize Resize
5964
Rules []Rules
6065
}
@@ -78,6 +83,9 @@ func GetConfig() *Config {
7883

7984
func setDefaults() {
8085

86+
if viper.IsSet("upload.set_date_posted") == false {
87+
viper.Set("upload.set_date_posted", false)
88+
}
8189

8290
if viper.IsSet("cmd.convert") == false {
8391
viper.Set("cmd.convert", "/usr/local/bin/convert")

0 commit comments

Comments
 (0)