ripper module finished

This commit is contained in:
Cooper Hammond 2019-06-12 22:11:16 -07:00
parent 45f4d998a4
commit 253efd1e11
2 changed files with 39 additions and 2 deletions

View file

@ -13,5 +13,5 @@ crystal: 0.28.0
license: MIT
dependencies:
spotify:
github: marceloboeira/spotify.cr
ydl_binaries:
github: cooperhammond/ydl-binaries

37
src/interact/ripper.cr Normal file
View file

@ -0,0 +1,37 @@
module Ripper
extend self
BIN_LOC = Path["~/.irs/bin".sub("~", Path.home)]
# Downloads the video from the given *video_url* using the youtube-dl binary
# Will create any directories that don't exist specified in *output_filename*
#
# ```
# Ripper.download_mp3("https://youtube.com/watch?v=0xnciFWAqa0",
# "Queen/A Night At The Opera/Bohemian Rhapsody.mp3")
# ```
def download_mp3(video_url : String, output_filename : String)
ydl_loc = BIN_LOC.join("youtube-dl")
# remove the extension that will be added on by ydl
output_filename = output_filename.split(".")[..-2].join(".")
options = {
"--output" => %("#{output_filename}.%(ext)s"), # auto-add correct ext
# "--quiet" => "",
"--ffmpeg-location" => BIN_LOC,
"--extract-audio" => "",
"--audio-format" => "mp3",
"--audio-quality" => "0",
}
command = ydl_loc.to_s + " " + video_url
options.keys.each do |option|
command += " #{option} #{options[option]}"
end
system(command)
end
end