Module: MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule
- Includes:
- Gtk::BaseModule
- Included in:
- YoutubeDownloader
- Defined in:
- lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- WORK_DIRECTORY =
#
WORK_DIRECTORY
#
'/home/Temp/MultimediaParadise/'
- TITLE =
#
TITLE
#
'Youtube Downloader'
- WIDTH =
#
WIDTH
#
'90%'
- HEIGHT =
#
HEIGHT
#
200
Class Method Summary collapse
-
.[](i = '') ⇒ Object
# === MultimediaParadise::GUI::Gtk::YoutubeDownloader[] ========================================================================= #.
-
.run ⇒ Object
# === MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule.run ========================================================================= #.
-
.title? ⇒ Boolean
# === MultimediaParadise::YoutubeDownloader.title? ========================================================================= #.
Instance Method Summary collapse
-
#add_to_widget(i) ⇒ Object
# === add_to_widget ========================================================================= #.
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton (connect tag) ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton ========================================================================= #.
-
#create_the_textarea ⇒ Object
# === create_the_textarea ========================================================================= #.
-
#do_download(_ = url? ) ⇒ Object
# === do_download.
-
#ensure_that_the_work_directory_exists ⇒ Object
# === ensure_that_the_work_directory_exists ========================================================================= #.
-
#enter_working_directory ⇒ Object
# === enter_working_directory ========================================================================= #.
-
#file_name? ⇒ Boolean
# === file_name? ========================================================================= #.
-
#initialize(i = nil, run_already = true) ⇒ Object
# === initialize ========================================================================= #.
-
#input? ⇒ Boolean
# === input? ========================================================================= #.
-
#opnn ⇒ Object
# === opnn ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#rename_main_file ⇒ Object
# === rename_main_file ========================================================================= #.
-
#report_what_directory_will_be_the_working_directory ⇒ Object
# === report_what_directory_will_be_the_working_directory ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_default_gui_font_size(use_this_size = 22) ⇒ Object
# === set_default_gui_font_size ========================================================================= #.
-
#set_file_name(i = nil) ⇒ Object
# === set_file_name ========================================================================= #.
-
#set_input(i = '') ⇒ Object
# === set_input ========================================================================= #.
-
#url? ⇒ Boolean
# === url? ========================================================================= #.
-
#working_directory? ⇒ Boolean
(also: #work_directory?)
# === working_directory? ========================================================================= #.
Class Method Details
.[](i = '') ⇒ Object
#
MultimediaParadise::GUI::Gtk::YoutubeDownloader[]
#
322 323 324 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 322 def self.[](i = '') new end |
.run ⇒ Object
#
MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule.run
#
329 330 331 332 333 334 335 336 337 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 329 def self.run require 'gtk_paradise/run' _ = ::MultimediaParadise::GUI::Gtk::YoutubeDownloader.new(ARGV) r = ::Gtk.run r << _ r.set_size_request(_.width?,_.height?) r.automatic_title r.top_left_then_run end |
.title? ⇒ Boolean
#
MultimediaParadise::YoutubeDownloader.title?
#
184 185 186 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 184 def self.title? TITLE end |
Instance Method Details
#add_to_widget(i) ⇒ Object
#
add_to_widget
#
233 234 235 236 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 233 def (i) # i = GLib.convert(i, 'iso-8859-1', 'utf-8') # Do a conversion here. @textarea.buffer.append(i+N) end |
#border_size? ⇒ Boolean
#
border_size?
#
111 112 113 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 111 def border_size? 2 end |
#connect_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
118 119 120 121 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 118 def connect_skeleton abort_on_exception add(@box_xyz) end |
#create_skeleton ⇒ Object
#
create_skeleton
#
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 253 def create_skeleton create_the_textarea @url_input = gtk_input @url_input.set_size_request(220, 40) _ = 'https://youtube.com/watch?v=...' @url_input.set_placeholder_text(_) @url_input.hint = 'Provide the URL here, which may start like <b>'+_+'</b>.' @button_do_download = ('Download remote URL') @button_do_download.lightblue @button_do_download.clear_background @button_do_download.bblack1 @button_do_download.on_hover(:mintcream) @button_do_download.hint = '<b>Clicking</b> on this button will download the remote URL '\ 'given. Provide the remote URL in the input-field to '\ 'the <b>left side</b> of this button.' @button_do_download.on_clicked { do_download } hbox = gtk_hbox hbox.maximal(@url_input, 2) hbox.maximal(@button_do_download, 2) minimal(hbox) minimal(@textarea) end |
#create_the_textarea ⇒ Object
#
create_the_textarea
#
241 242 243 244 245 246 247 248 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 241 def create_the_textarea # ======================================================================= # # === @textarea # ======================================================================= # @textarea = gtk_textarea @textarea.bblack1 @textarea.set_size_request(300, 50) end |
#do_download(_ = url? ) ⇒ Object
#
do_download
For now we will use youtube-dl for the actual download.
#
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 285 def do_download( _ = url? ) opnn; e "Downloading `#{sfancy(_)}` using youtube-dl." _ = 'youtube-dl '+_ opnn; e _ 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) set_file_name($1) rename_main_file opnn; e 'The file name is: `'+sfile(file_name?)+'`.' (file_name?) opnn; e 'All done!' end |
#ensure_that_the_work_directory_exists ⇒ Object
#
ensure_that_the_work_directory_exists
#
156 157 158 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 156 def ensure_that_the_work_directory_exists ::MultimediaParadise.mkdir(WORK_DIRECTORY) unless File.directory? WORK_DIRECTORY end |
#enter_working_directory ⇒ Object
#
enter_working_directory
#
149 150 151 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 149 def enter_working_directory ::MultimediaParadise.cd(work_directory?) end |
#file_name? ⇒ Boolean
#
file_name?
#
199 200 201 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 199 def file_name? @file_name end |
#initialize(i = nil, run_already = true) ⇒ Object
#
initialize
#
63 64 65 66 67 68 69 70 71 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 63 def initialize( i = nil, run_already = true ) super(:vertical) reset set_input(i) run if run_already end |
#input? ⇒ Boolean
#
input?
#
135 136 137 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 135 def input? @input end |
#opnn ⇒ Object
#
opnn
#
177 178 179 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 177 def opnn Opn.opn(namespace: NAMESPACE) end |
#padding? ⇒ Boolean
#
padding?
#
104 105 106 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 104 def padding? 2 end |
#rename_main_file ⇒ Object
#
rename_main_file
#
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 206 def rename_main_file _ = file_name? if file_name?.include? ' ' _.tr!(' ','_') end _.squeeze!('_') if _.include? '__' _.delete!('ó') if _.include? 'ó' _.delete!('(') if _.include? '(' _.delete!(')') if _.include? ')' unless _ == file_name? mv(file_name?, _) set_file_name(_) end end |
#report_what_directory_will_be_the_working_directory ⇒ Object
#
report_what_directory_will_be_the_working_directory
#
163 164 165 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 163 def report_what_directory_will_be_the_working_directory opnn; e 'The working directory will be `'+::Colours.sdir(working_directory?)+'`.' end |
#reset ⇒ Object
#
reset (reset tag)
#
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 76 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] set_file_name set_use_this_font(:dejavu_condensed_22) # ======================================================================= # # === @title # ======================================================================= # @title = TITLE # ======================================================================= # # === @width # ======================================================================= # set_width(WIDTH) # ======================================================================= # # === @height # ======================================================================= # set_height(HEIGHT) use_gtk_paradise_project_css_file append_project_css_file increase_font_size end |
#run ⇒ Object
#
run (run tag)
#
311 312 313 314 315 316 317 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 311 def run ensure_that_the_work_directory_exists report_what_directory_will_be_the_working_directory enter_working_directory create_skeleton set_default_gui_font_size end |
#set_default_gui_font_size(use_this_size = 22) ⇒ Object
#
set_default_gui_font_size
#
224 225 226 227 228 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 224 def set_default_gui_font_size( use_this_size = 22 ) set_font('Sans '+use_this_size.to_s) end |
#set_file_name(i = nil) ⇒ Object
#
set_file_name
#
191 192 193 194 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 191 def set_file_name(i = nil) i = i.dup if i @file_name = i end |
#set_input(i = '') ⇒ Object
#
set_input
#
126 127 128 129 130 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 126 def set_input(i = '') i = i.first if i.is_a? Array i = i.to_s.dup @input = i end |
#url? ⇒ Boolean
#
url?
#
142 143 144 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 142 def url? @url_input.text end |
#working_directory? ⇒ Boolean Also known as: work_directory?
#
working_directory?
#
170 171 172 |
# File 'lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb', line 170 def working_directory? WORK_DIRECTORY end |