class VineDl::Video
Attributes
client_video[R]
user[R]
Public Class Methods
new(_user, _client_video)
click to toggle source
# File lib/vine_dl/video.rb, line 8 def initialize(_user, _client_video) @user = _user @client_video = _client_video end
Public Instance Methods
download(path, options = {})
click to toggle source
# File lib/vine_dl/video.rb, line 13 def download(path, options = {}) create_directory = options.fetch(:create_directory, false) # TODO: Find the dir more robustly. directory = File.join(path.split("/")[0..-2]) if create_directory && !File.directory?(directory) Dir.mkdir(directory) end write_to_file(path) path end
file_name()
click to toggle source
# File lib/vine_dl/video.rb, line 32 def file_name # TODO: Get the video name more robustly. @file_name ||= video_url.split("videos_h264high/")[1] end
video_url()
click to toggle source
# File lib/vine_dl/video.rb, line 27 def video_url # TODO: Get the url without the query more robustly. @video_url ||= client_video.videoUrl.split("?")[0] end
Private Instance Methods
download_and_write_to_stream(write_stream)
click to toggle source
# File lib/vine_dl/video.rb, line 47 def download_and_write_to_stream(write_stream) open(video_url, "rb") do |read_stream| write_stream.write(read_stream.read) end end
write_to_file(path)
click to toggle source
# File lib/vine_dl/video.rb, line 41 def write_to_file(path) File.open(path, "wb") do |write_stream| download_and_write_to_stream(write_stream) end end