Class: Taifu::App
- Inherits:
-
Object
- Object
- Taifu::App
- Defined in:
- lib/taifu/app.rb
Constant Summary collapse
- REQUIRED_APPS =
%w(youtube-dl ffmpeg).freeze
Instance Method Summary collapse
- #add_track(wav_path, clean_up = true) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #save_as_wav_with(youtube_url) ⇒ Object
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
6 7 8 9 |
# File 'lib/taifu/app.rb', line 6 def initialize init_working_dir if check_env @logger = Logger.new("#{working_dir}/taifu.log") end |
Instance Method Details
#add_track(wav_path, clean_up = true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/taifu/app.rb', line 29 def add_track(wav_path, clean_up = true) @logger.info 'Add wav file to iTunes' unless File.exist?(wav_path) raise ArgumentError.new 'Not found wav file' end track = Itunes::Player.add(wav_path) converted_track = track.convert converted_track.update_attributes(name: 'Taifu') track.delete! if clean_up FileUtils.rm_f(wav_path) @logger.info "Done. Type 'taifu' on your iTunes" end |
#save_as_wav_with(youtube_url) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/taifu/app.rb', line 11 def save_as_wav_with(youtube_url) url = youtube_url.split('&').first flv_path = "#{working_dir}/taifu.flv" wav_file = 'taifu.wav' wav_path = "#{working_dir}/#{wav_file}" FileUtils.rm_f(wav_path) if File.exist?(wav_path) @logger.info 'Download data' Util.save_flv_from_url(url, flv_path) @logger.info 'Save wav file' Util.convert_flv_to_wav(flv_path, wav_path) FileUtils.rm_f(flv_path) wav_path end |