class MultimediaParadise::GUI::Libui::YoutubeDownloader
Public Class Methods
new()
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/libui/youtube_downloader/youtube_downloader.rb, line 25 def initialize @main_window = ui_main_window('Youtube Downloader', 1200, 200, 0) outer_vbox = ui_vbox hbox = ui_hbox hbox << ui_text( 'Input the youtube URL on the left side, then click '\ 'the download-button to download this URL via youtube-dl.' ) hbox.is_padded outer_vbox << hbox hbox = ui_hbox @entry_URL_to_use_for_the_youtube_video = ui_entry hbox << @entry_URL_to_use_for_the_youtube_video @button_download = ui_button('Download the video') @button_download.on_clicked { do_download_the_video } hbox << @button_download outer_vbox << hbox @main_window.child = outer_vbox @main_window.intelligent_exit end
Public Instance Methods
do_download_the_video( i = @entry_URL_to_use_for_the_youtube_video.text? )
click to toggle source
#¶ ↑
do_download_the_video
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/libui/youtube_downloader/youtube_downloader.rb, line 54 def do_download_the_video( i = @entry_URL_to_use_for_the_youtube_video.text? ) if i.empty? ui_error_msg( @main_window, 'Please provide a remote URL.' ) else Dir.chdir('/tmp/') e "Downloading `#{::Colours.sfancy(i)}` into the directory "\ "#{Dir.pwd} using youtube-dl." result = 'youtube-dl '+i e result result = `#{result}` # ======================================================================= # # Next, we will search for [ffmpeg] entries. # ======================================================================= # _ = result.split("\n").select {|line| line.include? '[ffmpeg] Merging formats' } _ = _.first regex = /\[ffmpeg\] Merging formats into "(.+)"/ # See: http://rubular.com/r/YYVCi91eTb _.match(regex) new_filename = $1.to_s if File.exist? new_filename if new_filename.include? ' ' old_filename = new_filename.dup new_filename = new_filename.tr(' ','_') FileUtils.mv(old_filename, new_filename) end if File.exist? new_filename # Do it again because of the above renaming. message_to_the_user(main_window, "The downloaded file should now be available at:\n\n"+ " #{new_filename.to_s}\n" ) e 'All done!' else error_message_to_the_user(main_window, 'Something did not work - nothing is at : '+ new_filename.to_s+"\n\nPlease make sure that "\ "/tmp/ exists and that ffmpeg as well as youtube-dl "\ "are installed locally.\n" ) end end end end