Module: FLVTool2

Defined in:
lib/flvtool2.rb,
lib/flvtool2/base.rb,
lib/flvtool2/version.rb

Defined Under Namespace

Modules: Base

Constant Summary collapse

SHELL_COMMAND_NAME =
(RUBY_PLATFORM =~ /win32/) ? 'flvtool2.exe' : 'flvtool2'
SWITCHES =
%w{ s v r p x c i o k t n l a }
COMMANDS =
%w{ U C P D A V }
PROGRAMM_VERSION =
[1, 0, 6]
PROGRAMM_VERSION_EXTENSION =
''

Class Method Summary collapse

Class Method Details

.execute!(options) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/flvtool2.rb', line 164

def self.execute!(options)
  if options[:commands].include? :help
    show_usage
  else
    FLVTool2::Base::execute!( options )
  end
end

.parse_argumentsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
# File 'lib/flvtool2.rb', line 35

def self.parse_arguments
  options = {}
  options[:commands] = []
  options[:metadatacreator] = "inlet media FLVTool2 v#{PROGRAMM_VERSION.join('.')} - http://www.inlet-media.de/flvtool2"
  options[:metadata] = {}
  options[:in_path] = nil
  options[:in_pipe] = false
  options[:out_path] = nil
  options[:out_pipe] = false
  options[:simulate] = false
  options[:verbose] = false
  options[:recursive] = false
  options[:preserve] = false
  options[:xml] = false
  options[:compatibility_mode] = false
  options[:in_point] = nil
  options[:out_point] = nil
  options[:keyframe_mode] = false
  options[:tag_file] = nil
  options[:tag_number] = nil
  options[:stream_log] = false
  options[:collapse] = false

  while (arg = ARGV.shift)
    case arg
    when /^-([a-zA-Z0-9]+?):(.+)$/
      options[:metadata][$1] = $2
    when /^-([a-zA-Z0-9]+?)#([0-9]+)$/
      options[:metadata][$1] = $2.to_f
    when /^-([a-zA-Z0-9]+?)@(\d{4,})-(\d{2,})-(\d{2,}) (\d{2,}):(\d{2,}):(\d{2,})$/
      options[:metadata][$1] = Time.local($2, $3, $4, $5, $6, $7)
    when /^-(.+)$/
      $1.split(//).flatten.each do |switch|  
        case switch
        when 's'
          options[:simulate] = true
        when 'v'
          options[:verbose] = true
        when 'r'
          options[:recursive] = true
        when 'p'
          options[:preserve] = true
        when 'x'
          options[:xml] = true
        when 'c'
          options[:compatibility_mode] = true
        when 'i'
          options[:in_point] = ARGV.shift.to_i
        when 'o'
          options[:out_point] = ARGV.shift.to_i
        when 'k'
          options[:keyframe_mode] = true
        when 't'
          options[:tag_file] = ARGV.shift
        when 'n'
          options[:tag_number] = ARGV.shift.to_i
        when 'l'
          options[:stream_log] = true
        when 'a'
          options[:collapse] = true
        when 'U'
          options[:commands] << :update
        when 'P'
          options[:commands] << :print
        when 'C'
          options[:commands] << :cut
        when 'D'
          options[:commands] << :debug
        when 'A'
          options[:commands] << :add
        when 'H'
          options[:commands] << :help
        when 'V'
          options[:commands] << :version
        end
      end
    when /^([^-].*)$/
      if options[:in_path].nil? 
        options[:in_path] = $1
        if options[:in_path].downcase =~ /stdin|pipe/
          options[:in_pipe] = true
          options[:in_path] = 'pipe'
        else
          options[:in_path] = File.expand_path( options[:in_path] )
        end
      else
        options[:out_path] = $1
        if options[:out_path].downcase =~ /stdout|pipe/
          options[:out_pipe] = true
          options[:out_path] = 'pipe'
        else
          options[:out_path] = File.expand_path( options[:out_path] )
        end
      end
    end
  end
  
  return options
end

.show_usageObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/flvtool2.rb', line 176

def self.show_usage
  self.show_version
  puts "Copyright (c) 2005-2007 Norman Timmler (inlet media e.K., Hamburg, Germany)\n"
  puts "Get the latest version from http://www.inlet-media.de/flvtool2\n"
  puts "This program is published under the BSD license.\n"
  puts "\n"
  puts "Usage: #{SHELL_COMMAND_NAME} [-#{COMMANDS.sort.join}#{SWITCHES.sort.join}]... [-key:value]... in-path|stdin [out-path|stdout]\n"
  puts "\n"
  puts "If out-path is omitted, in-path will be overwritten.\n"
  puts "In-path can be a single file, or a directory. If in-path is a directory,\n"
  puts "out-path has to be likewise, or can be omitted. Directory recursion\n"
  puts "is controlled by the -r switch. You can use stdin and stdout keywords\n"
  puts "as in- and out-path for piping or redirecting.\n"
  puts "\n"
  puts "Chain commands like that: -UP (updates FLV file than prints out meta data)\n"
  puts "\n"
  puts "Commands:\n"
  puts "  -A            Adds tags from -t tags-file\n"
  puts "  -C            Cuts file using -i inpoint and -o outpoint\n"
  puts "  -D            Debugs file (writes a lot to stdout)\n"
  puts "  -H            Helpscreen will be shown\n"
  puts "  -P            Prints out meta data to stdout\n"
  puts "  -U            Updates FLV with an onMetaTag event\n"
  puts "\n"
  puts "Switches:\n"
  puts "  -a            Collapse space between cutted regions\n"
  puts "  -c            Compatibility mode calculates some onMetaTag values different\n"
  puts "  -key:value    Key-value-pair for onMetaData tag (overwrites generated values)\n"
  puts "  -i timestamp  Inpoint for cut command in miliseconds\n"
  puts "  -k            Keyframe mode slides onCuePoint(navigation) tags added by the\n"
  puts "                add command to nearest keyframe position\n"
  puts "  -l            Logs FLV stream reading to stream.log in current directory\n"
  puts "  -n            Number of tag to debug\n"
  puts "  -o timestamp  Outpoint for cut command in miliseconds\n"
  puts "  -p            Preserve mode only updates FLVs that have not been processed\n"
  puts "                before\n"
  puts "  -r            Recursion for directory processing\n"
  puts "  -s            Simulation mode never writes FLV data to out-path\n"
  puts "  -t path       Tagfile (MetaTags written in XML)\n"
  puts "  -v            Verbose mode\n"
  puts "  -x            XML mode instead of YAML mode\n"
  puts "\n"
  puts "REPORT BUGS at http://projects.inlet-media.de/flvtool2"
  puts "Powered by Riva VX, http://rivavx.com\n"
end

.show_versionObject



172
173
174
# File 'lib/flvtool2.rb', line 172

def self.show_version
  puts "FLVTool2 #{version}"
end

.throw_error(error) ⇒ Object



222
223
224
# File 'lib/flvtool2.rb', line 222

def self.throw_error(error)
  puts "ERROR: #{error}"
end

.validate_options(options) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/flvtool2.rb', line 135

def self.validate_options( options )
  if options[:commands].empty?
    show_usage
    exit 0
  end
  
  options[:commands].each do |command|  
    case command
    when :print
      if options[:out_pipe]
        throw_error "Could not use print command in conjunction with output piping or redirection"
        exit 1
      end
    when :debug
      if options[:out_pipe]
        throw_error "Could not use debug command in conjunction with output piping or redirection"
        exit 1
      end
    when :help
      show_usage
      exit 0
    when :version
      show_version
      exit 0
    end
  end
  options
end

.versionObject



6
7
8
# File 'lib/flvtool2/version.rb', line 6

def self.version
  "#{PROGRAMM_VERSION.join('.')}#{PROGRAMM_VERSION_EXTENSION}"
end