summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@inventati.org>2020-03-14 13:11:52 +0530
committerAndinus <andinus@inventati.org>2020-03-14 13:11:52 +0530
commitea8a01e9ae40f5478167abcf4563682adc77efb6 (patch)
treed1392b8cfe51d3105bc8bd3b84820de66488b8d9
parent79f249d1db5843f2966330ddc75a8c71bb8a9ca0 (diff)
downloadcetus-ea8a01e9ae40f5478167abcf4563682adc77efb6.tar.gz
Add photoID support
photo-id flag can be used to set a specific photo as background
-rw-r--r--cmd/cetus/cetus.go37
-rw-r--r--pkg/background.go2
-rw-r--r--pkg/unsplash/unsplash.go37
3 files changed, 75 insertions, 1 deletions
diff --git a/cmd/cetus/cetus.go b/cmd/cetus/cetus.go
index 2618245..35afd01 100644
--- a/cmd/cetus/cetus.go
+++ b/cmd/cetus/cetus.go
@@ -14,4 +14,39 @@
 
 package main
 
-func main() {}
+import (
+	"flag"
+	"log"
+
+	"framagit.org/andinus/cetus/pkg/unsplash"
+)
+
+func main() {
+	var (
+		photoID string
+
+		width  int
+		height int
+
+		err error
+	)
+
+	flag.StringVar(&photoID, "photo-id", "", "Unsplash Photo ID to set as background")
+
+	flag.IntVar(&width, "width", 1920, "Width of the image")
+	flag.IntVar(&height, "height", 1080, "Height of the image")
+
+	flag.Parse()
+
+	if len(photoID) != 0 {
+		err = unsplash.SetFromID(photoID, width, height)
+		errChk(err)
+		return
+	}
+}
+
+func errChk(err error) {
+	if err != nil {
+		log.Fatal(err)
+	}
+}
diff --git a/pkg/background.go b/pkg/background.go
index 44e455c..c6000ff 100644
--- a/pkg/background.go
+++ b/pkg/background.go
@@ -14,6 +14,8 @@
 
 package background
 
+import "os/exec"
+
 // Set calls feh to set the background
 func Set(path string) error {
 	feh, err := exec.LookPath("feh")
diff --git a/pkg/unsplash/unsplash.go b/pkg/unsplash/unsplash.go
new file mode 100644
index 0000000..3070716
--- /dev/null
+++ b/pkg/unsplash/unsplash.go
@@ -0,0 +1,37 @@
+// Copyright (c) 2020, Andinus <andinus@inventati.org>
+
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+package unsplash
+
+import (
+	"fmt"
+
+	"framagit.org/andinus/cetus/pkg"
+)
+
+// SetFromID sets background from Unsplash Photo ID
+func SetFromID(photoID string, width int, height int) error {
+	var (
+		path string
+		size string
+
+		err error
+	)
+
+	size = fmt.Sprintf("%sx%s", width, height)
+	path = fmt.Sprintf("%s/%s/%s", "https://source.unsplash.com", photoID, size)
+	err = background.Set(path)
+
+	return err
+}
'author hut <hut@lavabit.com> 2011-10-02 18:38:54 +0200 committer hut <hut@lavabit.com> 2011-10-02 18:38:54 +0200 CHANGELOG: sorted items' href='/akspecs/ranger/commit/CHANGELOG?h=v1.7.0-emacs&id=fc0c76f9fa577cb8e5db2ba75963864c6ef67b33'>fc0c76f9 ^
ef2b1e37 ^
2ed2d4f7 ^




b7b8f3a0 ^




c8f870cb ^



ef2b1e37 ^















81f5ac9e ^
efd7c0c1 ^






cbcd3325 ^






81f5ac9e ^
cbcd3325 ^
d3bcb234 ^

cbcd3325 ^
81f5ac9e ^











cbcd3325 ^
90018274 ^




cbcd3325 ^
95e021ae ^

c928a9eb ^
95e021ae ^
cbcd3325 ^
95e021ae ^















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230