File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ module Teletube
71
71
@client .create_file
72
72
when " upload"
73
73
@client .upload_file
74
+ when " download"
75
+ @client .download_file
74
76
else
75
77
@client .get_files
76
78
end
Original file line number Diff line number Diff line change @@ -154,6 +154,24 @@ module Teletube
154
154
handle_response(@http .get(path: " /api/v1/videos/#{ @context .params[" video_id" ]} /files" ))
155
155
end
156
156
157
+ def download_file
158
+ response = @http .get(path: " /api/v1/videos/#{ @context .params[" video_id" ]} /files" )
159
+ STDERR .puts " ⚡️ #{ response.status } (#{ response.status_code } )"
160
+ if response.status_code == 200
161
+ files = JSON .parse(response.body).as_a
162
+ if files.empty?
163
+ puts " 🙁 The video does not have any files."
164
+ else
165
+ filename = files[0 ][" filename" ] ? files[0 ][" filename" ].as_s : " original.mov"
166
+ File .open(filename, " w" ) do |file |
167
+ HTTP ::Client .get(files[0 ][" url" ].as_s) do |response |
168
+ IO .copy(response.body_io, file)
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+
157
175
def get_videos
158
176
handle_response(@http .get(path: " /api/v1/channels/#{ @context .params[" channel_id" ]} /videos" ))
159
177
end
Original file line number Diff line number Diff line change @@ -94,6 +94,12 @@ module Teletube
94
94
parser.on(" upload" , " Uploads a file." ) do
95
95
context.command = " upload"
96
96
end
97
+ parser.on(" download" , " Download the latest upload." ) do
98
+ context.command = " download"
99
+ parser.on(" --video-id ID" , " The identifier of the video." ) do |video_id |
100
+ context.params[" video_id" ] = JSON ::Any .new(video_id)
101
+ end
102
+ end
97
103
end
98
104
99
105
parser.on(" videos" , " Interact with videos." ) do
You can’t perform that action at this time.
0 commit comments