class MultimediaParadise::PrepareVideoLecture

Constants

BASE_DIRECTORY
#

BASE_DIRECTORY

This is the directory we will log the output to.

On my system, this will be at:

"/Depot/Temp/MultimediaProject/video_lectures/"
#
BLACK_MP4_VIDEO_FILE
#

BLACK_MP4_VIDEO_FILE

#
COMMAND
#

COMMAND

#
DEFAULT_URLS
#

DEFAULT_URLS

Which URLS to use by default.

#
DELAY_IN_N_SECONDS
#

DELAY_IN_N_SECONDS

Specify the delay that the interval-video will use.

#
NAMESPACE
#

NAMESPACE

#
OUTPUT_FILE
#

OUTPUT_FILE

#
USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
#

USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES

#

Public Class Methods

new( these_urls = nil, run_already = true ) click to toggle source
#

initialize

The first argument is the list of remote URLs.

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 90
def initialize(
    these_urls  = nil,
    run_already = true
  )
  reset
  set_work_on_these_urls(these_urls)
  run if run_already
end

Public Instance Methods

create_base_directory() click to toggle source
#

create_base_directory

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 134
def create_base_directory
  mkdir(download_dir?)
end
create_black_image() click to toggle source
#

create_black_image

We will use ImageMagick convert to create a black .png file.

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 157
def create_black_image
  _ = 'convert -size 320x240 xc:black black.png'
  system _
end
create_black_mp4_video_file() click to toggle source
#

create_black_mp4_video_file

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 165
def create_black_mp4_video_file
  output_file = BLACK_MP4_VIDEO_FILE
  _ = 'ffmpeg -f lavfi -i color=color=black -t '+DELAY_IN_N_SECONDS.to_s+' '+output_file
  system _ unless File.exist? output_file
end
download_dir?() click to toggle source
#

download_dir?

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 141
def download_dir?
  BASE_DIRECTORY
end
download_the_videos() click to toggle source
#

download_the_videos

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 225
def download_the_videos
  @array_downloaded_files = [] # Reset to empty always.
  opnn; e 'Now downloading the URLs. The download directory will be at:'+
          sdir(download_dir?)
  urls?.each {|remote_url|
    opnn; e 'Now working on the URL `'+sfancy(remote_url)+'` via '+
             simp(COMMAND)+'.'
    cmd = COMMAND+' '+remote_url
    # e cmd # Don't want to display it really.
    result = `#{cmd}` # <- This is the part where we download the file finally.
    File.delete('gmon.out') if File.exist? 'gmon.out' # We don't need gmon.out
    regex = /Merging formats into "(.*)"/
    result =~ regex
    this_file = $1.to_s.dup
    if File.exist? this_file
      new_filename = this_file.tr(' ','_').tr("'",'').tr('-','_').
                     tr('(','').tr(')','').tr('&','')
      new_filename.squeeze! '_'
      opnn; rename(this_file, new_filename)
      this_file = new_filename # Reassign.
    end
    @array_downloaded_files << this_file
    opnn; e 'The final file result is: `'+sfile(this_file)+'`.'
  }
end
enter_base_directory() click to toggle source
#

enter_base_directory

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 148
def enter_base_directory
  cd download_dir?
end
input?()
Alias for: work_on_these_urls?
merge_the_videos() click to toggle source
#

merge_the_videos

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 202
def merge_the_videos
  n_videos = @array_downloaded_files.size.to_s
  opnn; e 'These videos ('+simp(n_videos)+') will next be merged.'
  # ======================================================================= #
  # Sneakily insert the delay-video into the Array.
  # ======================================================================= #
  if USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
    _ = @array_downloaded_files
    array = Array.new(_.size, BLACK_MP4_VIDEO_FILE)
    _ = _.zip(array).flatten
    # ===================================================================== #
    # Last one should not be black, hence we remove it.
    # ===================================================================== #
    _.pop if _.last == BLACK_MP4_VIDEO_FILE
    @array_downloaded_files = _
  end
  pp @array_downloaded_files
  ::MultimediaParadise.merge(@array_downloaded_files)
end
remove_base_directory() click to toggle source
#

empty_base_directory

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 183
def remove_base_directory
  FileUtils.rm_rf(download_dir?) unless download_dir? == '/'
end
report_everything_has_finished() click to toggle source
#

report_everything_has_finished

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 190
def report_everything_has_finished
  result = 'Everything has now finished.'
  if File.exist? OUTPUT_FILE
    result << ' It may be available here: '+
              sfile((Dir.pwd+'/'+OUTPUT_FILE).squeeze('/'))
  end
  opnn; e result
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 102
def reset
  super()
  @array_downloaded_files = []
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 254
def run
  show_welcome_message
  remove_base_directory
  create_base_directory
  enter_base_directory
  # create_black_image
  if USE_DELAY_WHEN_MERGING_THE_VIDEO_FILES
    create_black_mp4_video_file
  end
  download_the_videos
  merge_the_videos
  report_everything_has_finished
end
set_work_on_these_urls(i = DEFAULT_URLS) click to toggle source
#

set_work_on_these_urls

Pass here the remote URLS to use.

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 116
def set_work_on_these_urls(i = DEFAULT_URLS)
  i = [i] unless i.is_a? Array
  i = DEFAULT_URLS if i.empty?
  @work_on_these_urls = i # Must be an Array.
end
show_welcome_message() click to toggle source
#

show_welcome_message

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 174
def show_welcome_message
  unless input?.empty?
    opnn; e 'Welcome! We will next work on the given URLs.'
  end
end
urls?()
Alias for: work_on_these_urls?
work_on_these_urls()
Alias for: work_on_these_urls?
work_on_these_urls?() click to toggle source
#

work_on_these_urls?

#
# File lib/multimedia_paradise/video/prepare_video_lecture.rb, line 125
def work_on_these_urls?
  @work_on_these_urls
end
Also aliased as: work_on_these_urls, urls?, input?