Class: MultimediaParadise::Video::RenameVideoFile

Inherits:
Base
  • Object
show all
Defined in:
lib/multimedia_paradise/video/rename_video_file.rb

Overview

MultimediaParadise::Video::RenameVideoFile

Constant Summary

Constants inherited from Base

Base::ERROR, Base::ERROR_LINE, Base::NAMESPACE, Base::USE_THIS_NAMESPACE_FOR_THE_COLOURS, Base::USE_THIS_NAMESPACE_FOR_THE_CORE_COLOURS

Instance Method Summary collapse

Methods inherited from Base

[], #actions, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #cartoons_directory?, #clear_the_internal_hash, #cliner, #cliner_with_time_stamp, #colourized_comment, #copy_file, #crimson, #dataset_from_file_video_collection, #dd_mm_yyyy, #debug?, #default_readlines, #directory_to_realvids?, #do_not_use_opn, #dodgerblue, #does_the_video_player_support_this_commandline?, #e, #ecomment, #ecrimson, #efancy, #enable_debug, #ensure_main_encoding, #ensure_that_the_output_directory_exists, #eparse, #erev, #esystem, #ewarn, #file_video_collection?, #filter_for_audio_files, #filter_for_video_files, #forestgreen, #gold, #grey, #hh_mm_ss, #home_x_video?, #indianred, #infer_the_namespace, #internal_hash?, #is_audio_file?, #is_mkv?, #is_mp3?, #is_mp4?, #is_multimedia_file?, #is_on_roebe?, #is_video_file?, #konsole_colour_peru, #lightblue, #lightgreen, #load_yaml, #local_audio_directory?, #log_dir?, #map_symbol_to_locally_existing_file, #mediumorchid, #mediumpurple, #mediumslateblue, #mkdir, #move_file, #namespace?, #no_file_exists, #no_file_exists_at, #olive, #olivedrab, #opne, #opnecomment, #opnn, #orange, #palegoldenrod, #palegreen, #powderblue, #project_base_directory?, #rds, #register_sigint, #remove_file, #report_pwd, #reset_the_internal_hash, #return_all_video_files, #return_pwd, #return_random_video, #rev, #royalblue, #save_what_into, #sdir, #seagreen, #seconds_to_time_format, #select_only_video_files_from, #set_be_verbose, #set_use_colours, #sfancy, #sfile, #simp, #skyblue, #slateblue, #springgreen, #steelblue, #swarn, #teal, #time_right_now, #to_hh_mm_ss, #tomato, #true_rev, #try_to_rename_kde_konsole_tab, #ucliner, #use_colours?, #use_opn?, #use_which_video_player?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel

Methods included from CommandlineArgumentsModule

#all_input_starts_with_a_number?, #commandline_arguments?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?, #set_commandline_arguments

Constructor Details

#initialize(i, run_already = true) ⇒ RenameVideoFile

#

initialize

#


28
29
30
31
32
33
34
35
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 28

def initialize(
    i, run_already = true
  )
  reset
  register_sigint
  set_file(i)
  run if run_already
end

Instance Method Details

#determine_extension_nameObject

#

determine_extension_name

#


58
59
60
61
62
63
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 58

def determine_extension_name
  i = @file
  i = File.extname(i)
  i.prepend '.' unless i.start_with? '.'
  @extension_name = i
end

#extension_name?Boolean

#

extension_name?

#

Returns:

  • (Boolean)


68
69
70
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 68

def extension_name?
  @extension_name
end

#file?Boolean Also known as: old_filename?

#

file?

#

Returns:

  • (Boolean)


112
113
114
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 112

def file?
  @file
end

#resetObject

#

reset

#


40
41
42
43
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 40

def reset
  super()
  @search_term = nil
end

#runObject

#

run

#


140
141
142
143
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 140

def run
  set_search_term
  try_to_find_corresponding_video_file
end

#sanitize_search_term(i = @search_term) ⇒ Object

#

sanitize_search_term

This method is ultimately not needed, but I wanted to just chop down the input file to make it smaller.

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 78

def sanitize_search_term(i = @search_term)
  if i
    i.downcase!
    i.gsub!(/\.x264/,'') if i.include? '.x264'
    i.gsub!(/\.extended/,'') if i.include? '.extended'
    i.gsub!(/\.remastered/,'') if i.include? '.remastered'
    i.gsub!(/\.2000\.720p\.brrip\.bokutox\.yify/,'')
    # ===================================================================== #
    # Chop off file Extensions.
    # ===================================================================== #
    i.gsub!(/\.mp4$/,'') if i.end_with? '.mp4'
    @search_term = i
  end
end

#search_term?Boolean

#

search_term?

#

Returns:

  • (Boolean)


96
97
98
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 96

def search_term?
  @search_term
end

#set_file(i) ⇒ Object

#

set_file

#


48
49
50
51
52
53
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 48

def set_file(i)
  i = i.first if i.is_a? Array
  i = i.to_s
  @file = i
  determine_extension_name
end

#set_search_term(i = @file) ⇒ Object

#

set_search_term

#


103
104
105
106
107
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 103

def set_search_term(i = @file)
  i = i.to_s.dup
  @search_term = i
  sanitize_search_term
end

#try_to_find_corresponding_video_fileObject

#

try_to_find_corresponding_video_file

#


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/multimedia_paradise/video/rename_video_file.rb', line 119

def try_to_find_corresponding_video_file
  results = MultimediaParadise::FindVideo[search_term?]
  unless results.empty?
    new_file_name = results.first.first
    position = results.first.last
    opn; e 'We found a result, thus we will rename.'
    new_file_name = position+'_'+new_file_name+extension_name?
    opn; e 'The new file name will be:'
    rename_file(old_filename?, new_file_name)
    _ = realvids_directory?
    if File.directory?(_) and !File.exist?(_+File.basename(new_file_name))
      target = _+File.basename(new_file_name)
      opn; e 'Also copying to '+sfile(target)+' next.'
      copy_file(new_file_name, target)
    end
  end
end