From ba7400819b36a0c7b2c7a8be365b36b894a46fe2 Mon Sep 17 00:00:00 2001 From: Cooper Hammond Date: Wed, 12 Jun 2019 22:11:16 -0700 Subject: [PATCH] ripper module finished --- shard.yml | 4 ++-- src/interact/ripper.cr | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/interact/ripper.cr diff --git a/shard.yml b/shard.yml index c54c51d..2862560 100644 --- a/shard.yml +++ b/shard.yml @@ -13,5 +13,5 @@ crystal: 0.28.0 license: MIT dependencies: - spotify: - github: marceloboeira/spotify.cr \ No newline at end of file + ydl_binaries: + github: cooperhammond/ydl-binaries \ No newline at end of file diff --git a/src/interact/ripper.cr b/src/interact/ripper.cr new file mode 100644 index 0000000..eab563a --- /dev/null +++ b/src/interact/ripper.cr @@ -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 \ No newline at end of file