Crystal library and CLI tool for Catbox.moe
Revision | 3c5ff3d4a8cb37b9eb529d0b709413e0bdde95a0 (tree) |
---|---|
Time | 2023-03-30 23:53:39 |
Author | Remilia Scarlet <remilia@post...> |
Commiter | Remilia Scarlet |
Update to a newer libremiliacr version. Update copyright headers.
@@ -1,6 +1,6 @@ | ||
1 | 1 | version: 2.0 |
2 | 2 | shards: |
3 | 3 | libremiliacr: |
4 | - git: https://gitlab.com/remiliascarlet/libremiliacr.git | |
5 | - version: 0.4.7 | |
4 | + fossil: https://chiselapp.com/user/MistressRemilia/repository/libremiliacr | |
5 | + version: 0.9.0 | |
6 | 6 |
@@ -12,5 +12,5 @@ | ||
12 | 12 | |
13 | 13 | dependencies: |
14 | 14 | libremiliacr: |
15 | - gitlab: RemiliaScarlet/libremiliacr | |
16 | - version: ~> 0.4.7 | |
15 | + fossil: https://chiselapp.com/user/MistressRemilia/repository/libremiliacr | |
16 | + version: ~> 0.9.0 |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #### RemiCatbox - A library to interact with Catbox. |
2 | -#### Copyright (C) 2021 Remilia Scarlet | |
2 | +#### Copyright (C) 2021-2023 Remilia Scarlet | |
3 | 3 | #### |
4 | 4 | #### This program is free software: you can redistribute it and/or modify it |
5 | 5 | #### under the terms of the GNU Affero General Public License as published by |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #### CatboxTool - A CLI tool to interact with Catbox. |
2 | -#### Copyright (C) 2021 Remilia Scarlet | |
2 | +#### Copyright (C) 2021-2023 Remilia Scarlet | |
3 | 3 | #### |
4 | 4 | #### This program is free software: you can redistribute it and/or modify it |
5 | 5 | #### under the terms of the GNU Affero General Public License as published by |
@@ -14,8 +14,7 @@ | ||
14 | 14 | #### You should have received a copy of the GNU Affero General Public License |
15 | 15 | #### along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | require "../src/remicatbox" |
17 | -require "libremiliacr/remiargparser" | |
18 | -require "libremiliacr/remilog" | |
17 | +require "libremiliacr" | |
19 | 18 | require "json" |
20 | 19 | |
21 | 20 | module CatboxTool |
@@ -35,7 +34,7 @@ | ||
35 | 34 | end |
36 | 35 | |
37 | 36 | class Program |
38 | - getter args = RemiArgParser::ArgParser.new("catboxtool", VERSION) | |
37 | + getter args = RemiLib::Args::ArgParser.new("catboxtool", VERSION) | |
39 | 38 | @userHash : String? = nil |
40 | 39 | @files = [] of String |
41 | 40 |
@@ -47,9 +46,9 @@ | ||
47 | 46 | # Load config and get a user hash |
48 | 47 | config = loadConfig |
49 | 48 | @userHash = config.userHash |
50 | - if args["user-hash"].called | |
49 | + if args["user-hash"].called? | |
51 | 50 | @userHash = args["user-hash"].str |
52 | - elsif args["no-user-hash"].called | |
51 | + elsif args["no-user-hash"].called? | |
53 | 52 | @userHash = nil |
54 | 53 | end |
55 | 54 |
@@ -57,23 +56,23 @@ | ||
57 | 56 | |
58 | 57 | # We'll need a user hash for certain operations |
59 | 58 | unless @userHash |
60 | - if args["album-edit"].called || args["album-delete"].called | |
61 | - RemiLog.log.fatal("A user hash is required to edit or delete albums") | |
59 | + if args["album-edit"].called? || args["album-delete"].called? | |
60 | + RemiLib.log.fatal("A user hash is required to edit or delete albums") | |
62 | 61 | end |
63 | 62 | end |
64 | 63 | |
65 | 64 | # Do one of the possible operations. |
66 | - if args["album"].called | |
65 | + if args["album"].called? | |
67 | 66 | case |
68 | - when args["album-delete"].called then deleteAlbum | |
69 | - when args["album-edit"].called then editAlbum | |
70 | - when args["album-add"].called then albumAdd | |
71 | - when args["album-remove"].called then albumRemove | |
67 | + when args["album-delete"].called? then deleteAlbum | |
68 | + when args["album-edit"].called? then editAlbum | |
69 | + when args["album-add"].called? then albumAdd | |
70 | + when args["album-remove"].called? then albumRemove | |
72 | 71 | end |
73 | 72 | else |
74 | 73 | case |
75 | - when args["delete"].called then deleteFiles | |
76 | - when args["album-title"].called then uploadToAlbum | |
74 | + when args["delete"].called? then deleteFiles | |
75 | + when args["album-title"].called? then uploadToAlbum | |
77 | 76 | else uploadStuff |
78 | 77 | end |
79 | 78 | end |
@@ -90,7 +89,7 @@ | ||
90 | 89 | if File.exists?(file) |
91 | 90 | puts "Uploading #{Path[file].basename}..." |
92 | 91 | else |
93 | - RemiLog.log.error("File not found: #{file}") | |
92 | + RemiLib.log.error("File not found: #{file}") | |
94 | 93 | next |
95 | 94 | end |
96 | 95 | end |
@@ -100,7 +99,7 @@ | ||
100 | 99 | if code == 200 |
101 | 100 | uploaded << result |
102 | 101 | else |
103 | - RemiLog.log.error("Could not upload #{file}: #{result}") | |
102 | + RemiLib.log.error("Could not upload #{file}: #{result}") | |
104 | 103 | end |
105 | 104 | end |
106 | 105 |
@@ -115,7 +114,7 @@ | ||
115 | 114 | |
116 | 115 | # Uploads things into a new album |
117 | 116 | private def uploadToAlbum |
118 | - albumDesc = args["album-desc"].called ? args["album-desc"].str : nil | |
117 | + albumDesc = args["album-desc"].called? ? args["album-desc"].str : nil | |
119 | 118 | |
120 | 119 | puts "Uploading things to new album..." |
121 | 120 | begin |
@@ -123,7 +122,7 @@ | ||
123 | 122 | |
124 | 123 | # Print any URLs that were generated during the initial file upload |
125 | 124 | if newUrls.empty? |
126 | - RemiLog.log.fatal("No files could be uploaded") | |
125 | + RemiLib.log.fatal("No files could be uploaded") | |
127 | 126 | else |
128 | 127 | puts "URLs: " |
129 | 128 | newUrls.each { |url| puts " #{url}" } |
@@ -133,10 +132,10 @@ | ||
133 | 132 | if code == 200 |
134 | 133 | puts "Album: #{result}" |
135 | 134 | else |
136 | - RemiLog.log.error("Could not create an album from the uploads: #{result}") | |
135 | + RemiLib.log.error("Could not create an album from the uploads: #{result}") | |
137 | 136 | end |
138 | 137 | rescue err : Exception |
139 | - RemiLog.log.error("#{err}") | |
138 | + RemiLib.log.error("#{err}") | |
140 | 139 | end |
141 | 140 | end |
142 | 141 |
@@ -148,7 +147,7 @@ | ||
148 | 147 | if code == 200 |
149 | 148 | puts "Success" |
150 | 149 | else |
151 | - RemiLog.log.fatal("Could not delete album: #{result}") | |
150 | + RemiLib.log.fatal("Could not delete album: #{result}") | |
152 | 151 | end |
153 | 152 | end |
154 | 153 |
@@ -162,46 +161,46 @@ | ||
162 | 161 | if code == 200 |
163 | 162 | puts "Success: #{result}" |
164 | 163 | else |
165 | - RemiLog.log.fatal("Could not edit album: #{result}") | |
164 | + RemiLib.log.fatal("Could not edit album: #{result}") | |
166 | 165 | end |
167 | 166 | end |
168 | 167 | |
169 | 168 | # Adds files already uploaded to Catbox to an existing album |
170 | 169 | private def albumAdd |
171 | - RemiLog.log.fatal("No files specified to add to an album") if @files.empty? | |
170 | + RemiLib.log.fatal("No files specified to add to an album") if @files.empty? | |
172 | 171 | puts "Adding #{@files.size} file#{@files.size == 1 ? "" : "s"} to album #{args["album"].str}..." |
173 | 172 | result, code = RemiCatbox.addToAlbum(args["album"].str, @userHash.not_nil!, @files) |
174 | 173 | |
175 | 174 | if code == 200 |
176 | 175 | puts "Success: #{result}" |
177 | 176 | else |
178 | - RemiLog.log.fatal("Could not add files to album: #{result}") | |
177 | + RemiLib.log.fatal("Could not add files to album: #{result}") | |
179 | 178 | end |
180 | 179 | end |
181 | 180 | |
182 | 181 | # Removes files from an album |
183 | 182 | private def albumRemove |
184 | - RemiLog.log.fatal("No files specified to remove from an album") if @files.empty? | |
183 | + RemiLib.log.fatal("No files specified to remove from an album") if @files.empty? | |
185 | 184 | puts "Removing #{@files.size} file#{@files.size == 1 ? "" : "s"} from album #{args["album"].str}..." |
186 | 185 | result, code = RemiCatbox.removeFromAlbum(args["album"].str, @userHash.not_nil!, @files) |
187 | 186 | |
188 | 187 | if code == 200 |
189 | 188 | puts "Success: #{result}" |
190 | 189 | else |
191 | - RemiLog.log.fatal("Could not remove files from album: #{result}") | |
190 | + RemiLib.log.fatal("Could not remove files from album: #{result}") | |
192 | 191 | end |
193 | 192 | end |
194 | 193 | |
195 | 194 | # Deletes files from Catbox |
196 | 195 | private def deleteFiles |
197 | 196 | puts "Deleting #{@files.size} file#{@files.size == 1 ? "" : "s"}..." |
198 | - RemiLog.log.fatal("No files specified for deletion") if @files.empty? | |
197 | + RemiLib.log.fatal("No files specified for deletion") if @files.empty? | |
199 | 198 | result, code = RemiCatbox.deleteFiles(@userHash.not_nil!, @files) |
200 | 199 | |
201 | 200 | if code == 200 |
202 | 201 | puts "Success: #{result}" |
203 | 202 | else |
204 | - RemiLog.log.fatal("Could not delete files: #{result}") | |
203 | + RemiLib.log.fatal("Could not delete files: #{result}") | |
205 | 204 | end |
206 | 205 | end |
207 | 206 |
@@ -230,16 +229,16 @@ | ||
230 | 229 | # Add the arguments |
231 | 230 | args.addFlag("delete", 'D', help: "Deletes files instead of uploading them. A userhash is required.") |
232 | 231 | |
233 | - args.addString("user-hash", 'u', "Users", "Use a userhash for the upload") | |
234 | - args.addFlag("no-user-hash", 'A', "Users", "Do not use the userhash in the config file if it exists") | |
232 | + args.addString("user-hash", 'u', group: "Users", help: "Use a userhash for the upload") | |
233 | + args.addFlag("no-user-hash", 'A', group: "Users", help: "Do not use the userhash in the config file if it exists") | |
235 | 234 | |
236 | - args.addString("album", 'a', "Albums", "Manage an existing album with the given short code") | |
237 | - args.addString("album-title", 't', "Albums", "Sets an album's title") | |
238 | - args.addString("album-desc", 'd', "Albums", "Sets an album's description") | |
239 | - args.addFlag("album-add", nil, "Albums", "Adds the files to the album referenced with --album") | |
240 | - args.addFlag("album-remove", nil, "Albums", "Removes the files from the album referenced with --album") | |
241 | - args.addFlag("album-delete", nil, "Albums", "Deletes the album referenced with --album") | |
242 | - args.addFlag("album-edit", nil, "Albums", "Modifies the album referenced with --album") | |
235 | + args.addString("album", 'a', group: "Albums", help: "Manage an existing album with the given short code") | |
236 | + args.addString("album-title", 't', group: "Albums", help: "Sets an album's title") | |
237 | + args.addString("album-desc", 'd', group: "Albums", help: "Sets an album's description") | |
238 | + args.addFlag("album-add", nil, group: "Albums", help: "Adds the files to the album referenced with --album") | |
239 | + args.addFlag("album-remove", nil, group: "Albums", help: "Removes the files from the album referenced with --album") | |
240 | + args.addFlag("album-delete", nil, group: "Albums", help: "Deletes the album referenced with --album") | |
241 | + args.addFlag("album-edit", nil, group: "Albums", help: "Modifies the album referenced with --album") | |
243 | 242 | |
244 | 243 | args.postHelpText = %{ |
245 | 244 | If a user hash is specified in the configuration file, then it is used for all |
@@ -254,38 +253,38 @@ | ||
254 | 253 | # Parse command line |
255 | 254 | begin |
256 | 255 | args.parse |
257 | - rescue err : RemiArgParser::ArgumentError | |
258 | - RemiLog.log.fatal("#{err}") | |
256 | + rescue err : RemiLib::Args::ArgumentError | |
257 | + RemiLib.log.fatal("#{err}") | |
259 | 258 | end |
260 | 259 | |
261 | 260 | # Check argument combinations and other conditions |
262 | - if args.positionalArgs.empty? && !(args["album-delete"].called || args["album-edit"].called) | |
263 | - RemiLog.log.fatal("Nothing to upload or manage") | |
261 | + if args.positionalArgs.empty? && !(args["album-delete"].called? || args["album-edit"].called?) | |
262 | + RemiLib.log.fatal("Nothing to upload or manage") | |
264 | 263 | end |
265 | 264 | |
266 | - if args["no-user-hash"].called | |
267 | - RemiLog.log.fatal("Cannot use --user-hash and --no-user-hash together") if args["user-hash"].called | |
268 | - RemiLog.log.fatal("Cannot use --delete and --no-user-hash together") if args["delete"].called | |
269 | - RemiLog.log.fatal("Cannot use --album-edit and --no-user-hash together") if args["album-edit"].called | |
270 | - RemiLog.log.fatal("Cannot use --album-delete and --no-user-hash together") if args["album-delete"].called | |
265 | + if args["no-user-hash"].called? | |
266 | + RemiLib.log.fatal("Cannot use --user-hash and --no-user-hash together") if args["user-hash"].called? | |
267 | + RemiLib.log.fatal("Cannot use --delete and --no-user-hash together") if args["delete"].called? | |
268 | + RemiLib.log.fatal("Cannot use --album-edit and --no-user-hash together") if args["album-edit"].called? | |
269 | + RemiLib.log.fatal("Cannot use --album-delete and --no-user-hash together") if args["album-delete"].called? | |
271 | 270 | end |
272 | 271 | |
273 | - unless args["album"].called | |
274 | - RemiLog.log.fatal("--album-edit requires an album short code") if args["album-edit"].called | |
275 | - RemiLog.log.fatal("--album-delete requires an album short code") if args["album-delete"].called | |
276 | - RemiLog.log.fatal("--album-add requires an album short code") if args["album-add"].called | |
277 | - RemiLog.log.fatal("--album-remove requires an album short code") if args["album-remove"].called | |
272 | + unless args["album"].called? | |
273 | + RemiLib.log.fatal("--album-edit requires an album short code") if args["album-edit"].called? | |
274 | + RemiLib.log.fatal("--album-delete requires an album short code") if args["album-delete"].called? | |
275 | + RemiLib.log.fatal("--album-add requires an album short code") if args["album-add"].called? | |
276 | + RemiLib.log.fatal("--album-remove requires an album short code") if args["album-remove"].called? | |
278 | 277 | end |
279 | 278 | |
280 | - if args["album-desc"].called | |
281 | - unless (args["album"].called && args["album-edit"].called) || args["album-title"].called | |
282 | - RemiLog.log.fatal("--album-desc can only be used when creating or editing an album") | |
279 | + if args["album-desc"].called? | |
280 | + unless (args["album"].called? && args["album-edit"].called?) || args["album-title"].called? | |
281 | + RemiLib.log.fatal("--album-desc can only be used when creating or editing an album") | |
283 | 282 | end |
284 | 283 | end |
285 | 284 | |
286 | - if args["delete"].called | |
287 | - RemiLog.log.fatal("Cannot use --delete with --album") if args["album"].called | |
288 | - RemiLog.log.fatal("Cannot use --delete with --album-title") if args["album-title"].called | |
285 | + if args["delete"].called? | |
286 | + RemiLib.log.fatal("Cannot use --delete with --album") if args["album"].called? | |
287 | + RemiLib.log.fatal("Cannot use --delete with --album-title") if args["album-title"].called? | |
289 | 288 | end |
290 | 289 | end |
291 | 290 |