module MultimediaParadise::GUI::ChangeMetadataWidgetModule

Constants

ARRAY_SUPPORTED_VIDEO_FILES
#

ARRAY_SUPPORTED_VIDEO_FILES

List all supported video files here in this array.

#
HEIGHT
#

HEIGHT

#
SMALLER_FONT
#

SMALLER_FONT

#
TITLE
#

TITLE

#
USE_THIS_FONT
#

USE_THIS_FONT

#
WIDTH
#

WIDTH

#

Public Instance Methods

border_size?() click to toggle source
#

border_size?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 158
def border_size?
  2
end
clear_the_old_entries() click to toggle source
#

clear_the_old_entries

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 495
def clear_the_old_entries
  @entry_comment.set_text('')
  @entry_year.set_text('')
  @entry_title.set_text('')
end
create_skeleton() click to toggle source
#

create_skeleton (create tag, skeleton tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 382
def create_skeleton
  create_the_buttons
  create_the_entries
  create_the_spinner
  create_the_header
  create_the_grid
end
create_the_buttons() click to toggle source
#

create_the_buttons (buttons tag, button tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 61
def create_the_buttons
  # ======================================================================= #
  # === @button_run_the_sys_command
  # ======================================================================= #
  @button_run_the_sys_command = button('_Run')
  @button_run_the_sys_command.remove_background
  #@button_run_the_sys_command.bblack1
  @button_run_the_sys_command.hint = 'This will run the sys-command.'
  @button_run_the_sys_command.on_hover(:lightblue)
  @button_run_the_sys_command.rounded_border(
    '12px', :default, '4px solid royalblue'
  )

  @button_run_the_sys_command.on_clicked {
    work_on_this_file = work_on_which_file?
    unless File.exist? work_on_this_file
      popup_this_text_over_that_widget(
        "The target file at \n\n"\
        "  <b>#{File.absolute_path(work_on_this_file)}</b>\n"\
        "\ndoes not exist.",
        entry_input?
      )
    else # else the file exists, so we can continue here.
      @spinner.start_to_spin if gtk3?
      @button_run_the_sys_command.is_insensitive
      # =================================================================== #
      # The built-up command shall be similar to this:
      #
      #   ffmpeg -i foobar.mp4 -metadata title=foobar -codec copy output.mp4
      #
      # =================================================================== #
      cmd_to_run = 'ffmpeg '.dup
      cmd_to_run << ' -i '+work_on_this_file
      cmd_to_run << ' -metadata '
      cmd_to_run << ' title="'+entry_title?.text?+'"'
      # =================================================================== #
      # Next add comments
      # =================================================================== #
      unless @entry_comment.text?.empty?
        cmd_to_run << ' -metadata '
        cmd_to_run << ' comment='+@entry_comment.text?
      end
      # =================================================================== #
      # Next add the year
      # =================================================================== #
      unless @entry_year.text?.empty?
        cmd_to_run << ' -metadata '
        cmd_to_run << ' year='+@entry_year.text?
      end
      cmd_to_run << ' -codec copy'
      cmd_to_run << ' -y' # To overwrite any existing files at once.
      cmd_to_run << " #{default_output_file?}"
      cmd_to_run.squeeze!(' ')
      Thread.new {
        esystem(cmd_to_run)
        @spinner.stop_spinning if gtk3?
        @button_run_the_sys_command.is_sensitive
        log_this_file_has_been_modified(work_on_this_file)
      }
    end
  }
end
create_the_entries() click to toggle source
#

create_the_entries (entries tag, entry tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 421
def create_the_entries
  # ======================================================================= #
  # === @entry_input_file
  # ======================================================================= #
  @entry_input_file = entry('foobar.mp4')
  @entry_input_file.width_height(600, 30)
  @entry_input_file.very_light_yellowish_background
  @entry_input_file.use_this_font = SMALLER_FONT
  @entry_input_file.enable_scroll_events
  # ======================================================================= #
  # === @entry_output_file
  # ======================================================================= #
  @entry_output_file = entry(File.absolute_path('output.mp4'))
  @entry_output_file.width_height(600, 30)
  @entry_output_file.very_light_yellowish_background
  @entry_output_file.use_this_font = SMALLER_FONT
  # ======================================================================= #
  # === @entry_title
  # ======================================================================= #
  @entry_title = entry
  @entry_title.width_height(600, 30)
  @entry_title.very_light_yellowish_background
  @entry_title.use_this_font = SMALLER_FONT
  # ======================================================================= #
  # === @entry_comment
  # ======================================================================= #
  @entry_comment = entry
  @entry_comment.width_height(600, 30)
  @entry_comment.very_light_yellowish_background
  @entry_comment.use_this_font = SMALLER_FONT
  # ======================================================================= #
  # === @entry_year
  # ======================================================================= #
  @entry_year = entry
  @entry_year.width_height(600, 30)
  @entry_year.very_light_yellowish_background
  @entry_year.use_this_font = SMALLER_FONT
end
create_the_grid() click to toggle source
#

create_the_grid (grid tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 134
def create_the_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = default_grid
end
create_the_header() click to toggle source
#

create_the_header (header tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 300
def create_the_header
  # ======================================================================= #
  # === @header
  # ======================================================================= #
  @header = default_header
  @header.set_title('Change Metadata')
  button_open_file = button('Open file')
  button_open_file.on_clicked {
    do_open_a_local_file
  }
  @header.add_right(button_open_file)
  icon = gtk_icon('media-playback-start')
  button_play_the_video = event_box(icon)
  button_play_the_video.hint = 'Play the video file listed under '\
    '"Input file to use:".'
  button_play_the_video.on_clicked {
    Thread.new {
      esystem "mpv #{work_on_which_file?}"
    }
  }
  @header.add_left(button_play_the_video)
end
create_the_spinner() click to toggle source
#

create_the_spinner

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 283
def create_the_spinner
  if use_gtk3?
    @spinner = return_spinner_widget # Create the spinner before the buttons.
  end
end
default_output_file?() click to toggle source
#

default_output_file?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 165
def default_output_file?
  @entry_output_file.text?
end
do_analyse_this_file(i) click to toggle source
#

do_analyse_this_file (open tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 463
def do_analyse_this_file(i)
  @entry_input_file.set_text(i)
  read_the_title_and_then_assign_it
  read_the_comment_and_then_assign_it
  if is_on_roebe?
    old_value = @entry_output_file.text?.dup
    original_filename = File.basename(i).delete_suffix(File.extname(i))
    old_value.delete_suffix!(File.extname(old_value))
    old_value.sub!(/output/, '')
    old_value << "#{original_filename}_output#{File.extname(i)}"
    @entry_output_file.set_text(old_value)
    # ===================================================================== #
    # We may also infer the title if the entry is empty.
    # ===================================================================== #
    if entry_title? and entry_title?.empty?
      new_name = File.basename(input_file_name?).delete_suffix(
        File.extname(i)
      )
      if new_name.include?('_') and (new_name =~ /^\d+/)
        splitted = new_name.split('_')
        new_name = splitted[1 .. -1].join('_')
      end
      new_name.tr!('_',' ')
      entry_title?.set_text(new_name)
    end
  end
end
do_open_a_local_file() click to toggle source
#

do_open_a_local_file (open tag)

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 393
def do_open_a_local_file
  new_open_file_dialog {{
    name_for_the_file_chooser_dialog: :custom_dialog,
    use_this_as_the_current_folder:   return_pwd,
    filter_for:                       ARRAY_SUPPORTED_VIDEO_FILES,
    additional_folders:
      %w(
        /Depot/j/
        /home/x/video/Realvids/
      )
  }}
  _ = main_file?
  if _ and File.exist?(_)
    # ===================================================================== #
    # First, clear the old entries that contain meta-data.
    # ===================================================================== #
    clear_the_old_entries
    # ===================================================================== #
    # Next proceed by analysing the file.
    # ===================================================================== #
    do_analyse_this_file(_)
    sync_the_output_directory_based_on_this_file(_)
  end
end
do_open_this_file(i)
do_rename_the_newly_created_file_to_the_original_file() click to toggle source
#

do_rename_the_newly_created_file_to_the_original_file

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 213
def do_rename_the_newly_created_file_to_the_original_file
  newly_created_file = @entry_output_file.text?
  original_file      = @entry_input_file.text?
  unless is_still_spinning?
    if File.exist? newly_created_file
      FileUtils.mv(newly_created_file, original_file)
    end
  end
end
entry2?() click to toggle source
#

entry2?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 361
def entry2?
  @entry_output_file
end
entry5?()
Alias for: entry_year?
entry_comment?() click to toggle source
#

entry_comment?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 368
def entry_comment?
  @entry_comment
end
entry_input?() click to toggle source
#

entry_input?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 127
def entry_input?
  @entry_input_file
end
entry_title?() click to toggle source
#

entry_title?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 54
def entry_title?
  @entry_title
end
entry_year?() click to toggle source
#

entry_year?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 375
def entry_year?
  @entry_year
end
Also aliased as: entry5?
file?()
Alias for: input_file_name?
input_file_name?() click to toggle source
#

input_file_name?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 292
def input_file_name?
  @entry_input_file.text?
end
Also aliased as: work_on_which_file?, file?
is_still_spinning?() click to toggle source
#

is_still_spinning?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 226
def is_still_spinning?
  @spinner.is_still_spinning?
end
log_dir?() click to toggle source
#

log_dir?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 233
def log_dir?
  MultimediaParadise.log_dir?
end
log_this_file_has_been_modified(this_file) click to toggle source
#

log_this_file_has_been_modified (log tag)

This method will log which file has been modified. Knowing this information is helpful when we want to copy only those video files that were modified.

What information must we save?

The file name, as well as the time when the file was modified.

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 248
def log_this_file_has_been_modified(this_file)
  what = this_file.dup
  what << ' # '+dd_mm_yyyy?+' '+hh_mm_ss?
  into = log_dir?+'metadata_of_video_files_that_were_modified.md'
  if File.exist? into
    what.prepend(File.read(into))
  end
  if is_on_roebe?
    e "Storing log-information into the file "\
      "at `#{sfile(into)}`."
  end
  write_what_into("#{what}\n", into)
end
menu( i = commandline_arguments? ) click to toggle source
#

menu (menu tag)

#
padding?() click to toggle source
#

padding?

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 151
def padding?
  4
end
read_the_comment_and_then_assign_it() click to toggle source
#

read_the_comment_and_then_assign_it

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 265
def read_the_comment_and_then_assign_it
  _ = file?
  result_from_exiftool = `exiftool #{_}`
  begin
    if result_from_exiftool.include? 'Comment'
      current_comment = result_from_exiftool.split("\n").select {|entry|
        entry.include? 'Comment'
      }.flatten.first.sub(/Comment/,'').strip.delete(':').strip
      @entry_comment.set_text(current_comment)
    end
  rescue ArgumentError => error
    pp error
  end
end
read_the_title_and_then_assign_it() click to toggle source
#

read_the_title_and_then_assign_it

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 179
def read_the_title_and_then_assign_it
  _ = file?
  result_from_exiftool = `exiftool #{_}`
  if result_from_exiftool.include? 'Title'
    begin
      splitted = result_from_exiftool.split("\n")
      current_title = splitted.select {|entry|
        entry.include? 'Title'
      }.flatten.first.sub(/Title/,'').strip.delete(':').strip
      entry_title?.set_text(current_title)
    rescue ArgumentError => error
      pp error
    end 
  end
end
respond_to_scroll_events_of_the_first_entry() click to toggle source
#

respond_to_scroll_events_of_the_first_entry

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 521
def respond_to_scroll_events_of_the_first_entry
  @entry_input_file.on_scroll_event {|widget, event|
    # ===================================================================== #
    # If the user scrolls then a new random file will be selected.
    # ===================================================================== #
    base_dir = File.dirname(
      File.absolute_path(@entry_input_file.text?)
    )+'/'
    this_new_file = Dir["#{base_dir}*"].select {|entry|
      ARRAY_SUPPORTED_VIDEO_FILES.include?(File.extname(entry).delete('.'))
    }.sample
    clear_the_old_entries
    work_on_this_file_now(this_new_file)
    sync_the_output_directory_based_on_this_file(this_new_file)
  }
end
return_spinner_widget() click to toggle source
#

return_spinner_widget

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 144
def return_spinner_widget
  return new_spinner
end
return_text1() click to toggle source
#

return_text1

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 326
def return_text1
  text('Input file to use:')
end
return_text2() click to toggle source
#

return_text2

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 333
def return_text2
  text('Output file to use:')
end
return_text3() click to toggle source
#

return_text3

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 340
def return_text3
  text('Title to use:')
end
return_text4() click to toggle source
#

return_text4

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 347
def return_text4
  text('Comment:')
end
return_text5() click to toggle source
#

return_text5

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 354
def return_text5
  text('Year:')
end
set_output_file_to_use(i) click to toggle source
#

set_output_file_to_use

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 172
def set_output_file_to_use(i)
  @entry_output_file.set_text(i.to_s)
end
sync_the_output_directory_based_on_this_file(_) click to toggle source
#

sync_the_output_directory_based_on_this_file

#
# File lib/multimedia_paradise/gui/shared_code/change_metadata_widget/change_metadata_widget_module.rb, line 504
def sync_the_output_directory_based_on_this_file(_)
  # ======================================================================= #
  # Sync the output directory too:
  # ======================================================================= #
  base_dir = File.dirname(_)

  new_filename = File.basename(_).dup
  new_filename.delete_suffix!(File.extname(new_filename))
  new_filename.sub!(/output/, '')
  new_filename = "#{new_filename}_output#{File.extname(_)}" # This will be like "004_Cube_output.avi"

  set_output_file_to_use("#{base_dir}/#{new_filename}")
end
work_on_this_file_now(i)
work_on_which_file?()
Alias for: input_file_name?