module MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule

Constants

HEIGHT
#

HEIGHT

#
NAMESPACE
#

NAMESPACE

#
TITLE
#

TITLE

#
WIDTH
#

WIDTH

#
WORK_DIRECTORY
#

WORK_DIRECTORY

#

Public Class Methods

[](i = '') click to toggle source
#

MultimediaParadise::GUI::Gtk::YoutubeDownloader[]

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 322
def self.[](i = '')
  new
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method
# 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
run() click to toggle source
#

MultimediaParadise::GUI::Gtk::YoutubeDownloaderModule.run

#
# 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?() click to toggle source
#

MultimediaParadise::YoutubeDownloader.title?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 184
def self.title?
  TITLE
end

Public Instance Methods

add_to_widget(i) click to toggle source
#

add_to_widget

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 233
def add_to_widget(i)
  # i = GLib.convert(i, 'iso-8859-1', 'utf-8') # Do a conversion here.
  @textarea.buffer.append(i+N)
end
border_size?() click to toggle source
#

border_size?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 111
def border_size?
  2
end
connect_skeleton() click to toggle source
#

connect_skeleton (connect tag)

#
# 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() click to toggle source
#

create_skeleton

#
# 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 = gtk_button('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() click to toggle source
#

create_the_textarea

#
# 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? ) click to toggle source
#

do_download

For now we will use youtube-dl for the actual download.

#
# 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?)+'`.'
  add_to_widget(file_name?)
  opnn; e 'All done!'
end
ensure_that_the_work_directory_exists() click to toggle source
#

ensure_that_the_work_directory_exists

#
# 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() click to toggle source
#

enter_working_directory

#
# 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?() click to toggle source
#

file_name?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 199
def file_name?
  @file_name
end
input?() click to toggle source
#

input?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 135
def input?
  @input
end
opnn() click to toggle source
#

opnn

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 177
def opnn
  Opn.opn(namespace: NAMESPACE)
end
padding?() click to toggle source
#

padding?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 104
def padding?
  2
end
rename_main_file() click to toggle source
#

rename_main_file

#
# 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() click to toggle source
#

report_what_directory_will_be_the_working_directory

#
# 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() click to toggle source
#

reset (reset tag)

#
# 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() click to toggle source
#

run (run tag)

#
# 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 ) click to toggle source
#

set_default_gui_font_size

#
# 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) click to toggle source
#

set_file_name

#
# 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 = '') click to toggle source
#

set_input

#
# 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?() click to toggle source
#

url?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 142
def url?
  @url_input.text
end
work_directory?()
Alias for: working_directory?
working_directory?() click to toggle source
#

working_directory?

#
# File lib/multimedia_paradise/gui/shared_code/youtube_downloader/youtube_downloader_module.rb, line 170
def working_directory?
  WORK_DIRECTORY
end
Also aliased as: work_directory?