Class: MultimediaParadise::AnalyseMultimediaFile

Inherits:
Base
  • Object
show all
Defined in:
lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb

Overview

MultimediaParadise::AnalyseMultimediaFile

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect

Constants inherited from Base

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

Class Method Summary collapse

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, #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(commandline_arguments = nil, run_already = true) ⇒ AnalyseMultimediaFile

#

initialize

#


31
32
33
34
35
36
37
38
39
40
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 31

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

MultimediaParadise::AnalyseMultimediaFile[]

#


174
175
176
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 174

def self.[](i = '')
  new(i)
end

Instance Method Details

#analyze_this_result(i) ⇒ Object

#

analyze_this_result

This method will analyse the result that “ffmpeg -i” gave us.

#


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 101

def analyze_this_result(i)
  # debug_this(i) # This can be enabled/disabled.
  if i.include? 'encoder         :'
    i =~ /encoder         : (.+)$/
    @encoder = $1.to_s.dup
    e 'The encoder is: '.ljust(@left_pad_n_times)+lightgreen(@encoder)
  end
  # ======================================================================= #
  # === Duration
  # ======================================================================= #
  if i.include? 'Duration: '
    i =~ /Duration: ([0-9:.]{2,12}),/ # See: https://rubular.com/r/Rq5lAuQnJUfiZd
    @duration = $1.to_s.dup
    n_seconds = return_this_duration_in_seconds(@duration)
    e rev+'The duration is: '.ljust(@left_pad_n_times)+
       lightgreen(@duration)+
       rev+
       " (#{olive(n_seconds.to_s)} #{rev}seconds)"
  end
  # ======================================================================= #
  # === Stream #0:0:
  # ======================================================================= #
  if i.include? 'Stream #0:0:'
    if i.include?('x') and (i =~ / (\d{1,3})x(\d{1,3}) /) 
      results = i.scan(/ (\d{1,3})x(\d{1,3}) /)
      e rev+'Video resolution is: '.ljust(@left_pad_n_times)+
         lightgreen(results.flatten.join('x').to_s)
    end
    # if i.include? 'Video:'
    #   e 'Codec: '.ljust(@left_pad_n_times)+
    #     'mpeg4'
    # end
  end
  if i.include? 'ENCODER   '
    # ===================================================================== #
    # ENCODER         : Lavf58.29.100
    # ===================================================================== #
    scanned_result = i.scan(/ENCODER\s*: (.+)/).flatten.first
    e rev+'The encoder is: '.ljust(@left_pad_n_times)+
       lightgreen(scanned_result)
  end
  if i.include? ': Audio: mp3, '
    e rev+'The file includes an audio stream '\
      "(#{royalblue('mp3 format')}#{rev})."
  end
end

#debug_this(i) ⇒ Object

#

debug_this

#


91
92
93
94
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 91

def debug_this(i)
  e crimson('Debugging:')
  pp i
end

#opnn(&block) ⇒ Object

#

opnn

#


57
58
59
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 57

def opnn(&block)
  super(namespace?, &block)
end

#process_the_input(i = commandline_arguments? ) ⇒ Object

#

process_the_input

#


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 64

def process_the_input(
    i = commandline_arguments?
  )
  i.each {|this_file|
    if is_a_multimedia_file?(this_file)
      opnn { :no_colon }
      e
      e
      e "The multimedia file #{sfile(this_file)}#{rev} "\
        "will be analysed"
      e "next, via #{orange('ffmpeg')}#{rev}."
      e
      cmd = "ffmpeg -i #{this_file} 2>&1"
      e slateblue("  #{cmd}")
      e
      result = `#{cmd}`
      analyze_this_result(result)
    else
      opne sfile(this_file)+rev+' can not be analysed as it is not a (registered)'
      opne 'audio/video (multimedia) file.'
    end
  }
end

#resetObject

#

reset (reset tag)

#


45
46
47
48
49
50
51
52
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 45

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @left_pad_n_times
  # ======================================================================= #
  @left_pad_n_times = 25
end

#return_this_duration_in_seconds(i = '00:03:52.15') ⇒ Object

#

return_this_duration_in_seconds

#


151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 151

def return_this_duration_in_seconds(
    i = '00:03:52.15'
  )
  result = 0.0
  if i.include? ':'
    splitted = i.split(':')
    result += (splitted[0].to_f * 60 * 60)
    result += (splitted[1].to_f * 60) # These is the entry for minutes.
    result += splitted[2].to_f
  end
  result
end

#runObject

#

run (run tag)

#


167
168
169
# File 'lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb', line 167

def run
  process_the_input
end