@@ -50,8 +50,8 @@ fn cli() -> Command {
50
50
Command :: new ( "logout" )
51
51
. about ( "Logout of your account" )
52
52
. long_about (
53
- "Logs out of your Put.io account by removing the auth token saved on your device." ,
54
- ) ,
53
+ "Logs out of your Put.io account by removing the auth token saved on your device." ,
54
+ ) ,
55
55
)
56
56
. subcommand (
57
57
Command :: new ( "files" )
@@ -99,25 +99,25 @@ fn cli() -> Command {
99
99
. arg_required_else_help ( true )
100
100
. arg (
101
101
Arg :: new ( "parent_id" )
102
- . short ( 'p' )
103
- . long ( "parent" )
104
- . help ( "ID of a Put folder to upload to instead of the root folder" )
105
- . required ( false )
102
+ . short ( 'p' )
103
+ . long ( "parent" )
104
+ . help ( "ID of a Put folder to upload to instead of the root folder" )
105
+ . required ( false )
106
106
)
107
107
. arg (
108
108
Arg :: new ( "file_name" )
109
- . short ( 'n' )
110
- . long ( "name" )
111
- . help ( "Override file name" )
112
- . required ( false )
109
+ . short ( 'n' )
110
+ . long ( "name" )
111
+ . help ( "Override file name" )
112
+ . required ( false )
113
113
)
114
114
. arg (
115
115
Arg :: new ( "is_silent" )
116
- . short ( 's' )
117
- . long ( "silent" )
118
- . help ( "Run CURL in silent mode" )
119
- . required ( false )
120
- . num_args ( 0 )
116
+ . short ( 's' )
117
+ . long ( "silent" )
118
+ . help ( "Run CURL in silent mode" )
119
+ . required ( false )
120
+ . num_args ( 0 )
121
121
)
122
122
. arg (
123
123
arg ! ( <PATH > ... "Valid paths of files to upload" )
@@ -198,7 +198,17 @@ fn cli() -> Command {
198
198
"Clears all finshed transfers on your account. Does not remove files." ,
199
199
) ,
200
200
)
201
- ,
201
+ ,
202
+ )
203
+ . subcommand (
204
+ Command :: new ( "play" )
205
+ . about ( "Stream a video file" )
206
+ . long_about (
207
+ "Plays a video file using MPV.\n \
208
+ If you do not have MPV installed, visit https://mpv.io/installation/.",
209
+ )
210
+ . arg_required_else_help ( true )
211
+ . arg ( arg ! ( <FILE_ID > "ID of a file (required)" ) ) ,
202
212
)
203
213
. subcommand (
204
214
Command :: new ( "whoami" )
@@ -271,6 +281,33 @@ fn main() {
271
281
confy:: store ( APP_NAME , None , cfg) . expect ( "updating config file" ) ;
272
282
println ! ( "Signed out successfully!" )
273
283
}
284
+ Some ( ( "play" , sub_matches) ) => {
285
+ require_auth ( & config) ;
286
+
287
+ let file_id = sub_matches
288
+ . get_one :: < String > ( "FILE_ID" )
289
+ . expect ( "missing file ID argument" )
290
+ . parse :: < u32 > ( )
291
+ . expect ( "parsing file_id" ) ;
292
+
293
+ let file_info =
294
+ put:: files:: list ( config. api_token . clone ( ) , file_id) . expect ( "fetching file info" ) ;
295
+
296
+ if file_info. parent . file_type != "VIDEO" {
297
+ println ! ( "File type must be video." ) ;
298
+ return ;
299
+ }
300
+
301
+ let download_url = put:: files:: url ( config. api_token , file_id) . expect ( "generating url" ) ;
302
+
303
+ ProcessCommand :: new ( "mpv" )
304
+ . arg ( download_url. url )
305
+ . stdout ( Stdio :: piped ( ) )
306
+ . spawn ( )
307
+ . expect ( "error while spawning mpv (is it installed?)" )
308
+ . wait ( )
309
+ . expect ( "error while running MPV" ) ;
310
+ }
274
311
Some ( ( "whoami" , _sub_matches) ) => {
275
312
let account = require_auth ( & config) ;
276
313
println ! (
@@ -295,9 +332,12 @@ fn main() {
295
332
None => 0 ,
296
333
} ;
297
334
let files = put:: files:: list ( config. api_token , folder_id) . expect ( "fetching files" ) ;
335
+
298
336
if files. parent . file_type != "FOLDER" {
299
- panic ! ( "the ID provided should be for a folder and not a file" )
337
+ println ! ( "The ID provided should be for a folder and not a file" ) ;
338
+ return ;
300
339
}
340
+
301
341
let table = Table :: new ( & files. files ) . with ( Style :: markdown ( ) ) . to_string ( ) ;
302
342
println ! ( "\n # {}\n " , & files. parent. name) ;
303
343
println ! ( "{}\n " , table) ;
@@ -331,9 +371,12 @@ fn main() {
331
371
let query = sub_matches
332
372
. get_one :: < String > ( "QUERY" )
333
373
. expect ( "missing query argument" ) ;
374
+
334
375
let files = put:: files:: search ( config. api_token , query. to_string ( ) )
335
376
. expect ( "querying files" ) ;
377
+
336
378
let table = Table :: new ( files. files ) . with ( Style :: markdown ( ) ) . to_string ( ) ;
379
+
337
380
println ! ( "\n # Results for `{}`\n " , & query) ;
338
381
println ! ( "{}\n " , table) ;
339
382
}
@@ -362,7 +405,7 @@ fn main() {
362
405
. arg ( url_response. url )
363
406
. stdout ( Stdio :: piped ( ) )
364
407
. spawn ( )
365
- . expect ( "running CURL command " )
408
+ . expect ( "error while spawning curl " )
366
409
. wait_with_output ( )
367
410
. expect ( "running CURL command" ) ;
368
411
0 commit comments