mkv2m4v 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ module Mkv2m4v
10
10
 
11
11
  def run
12
12
  if @options[:info]
13
- each_file(&:print)
13
+ each_file(&:print_info)
14
14
  else
15
15
  each_file(&:transcode)
16
16
  end
@@ -25,17 +25,20 @@ module Mkv2m4v
25
25
  end
26
26
 
27
27
  def parse_options
28
- usage = usage
29
28
  @options = Trollop::options do
30
29
  version Mkv2m4v::VersionDescription
31
30
  banner [Mkv2m4v::Description, Mkv2m4v::Usage].join("\n")
32
31
  opt :info, "Print media info only"
33
- opt :lang, "Preferred languages", :type => :strings, :default => ["English"]
32
+ opt :lang, "Preferred languages, comma separated", :type => :string, :default => "English"
34
33
  opt :dir, "Destination directory", :type => :string
35
- opt :verbose, "More output", :type => :boolean
36
34
  end
37
- @options[:languages] = @options[:lang].map { |lang| Iso639[lang] }.compact
35
+ parse_languages
38
36
  @filenames = ARGV
39
37
  end
38
+
39
+ def parse_languages
40
+ @options[:languages] =
41
+ @options[:lang].split(/\s*,\s*/).map { |lang| Iso639[lang] }.compact
42
+ end
40
43
  end
41
44
  end
@@ -11,7 +11,8 @@ module Mkv2m4v
11
11
  extend Forwardable
12
12
 
13
13
  attr_reader :info, :video_tracks, :audio_tracks, :text_tracks
14
- attr_reader :ideal_video_track, :ideal_audio_track
14
+ attr_reader :info, :filtered_video_tracks, :filtered_audio_tracks, :filtered_text_tracks
15
+ attr_reader :ideal_video_track, :ideal_audio_track, :ideal_text_track
15
16
  def_delegator :info, :filename, :name
16
17
  def_delegator :info, :full_filename, :filename
17
18
 
@@ -26,19 +27,17 @@ module Mkv2m4v
26
27
  info.general.format
27
28
  end
28
29
 
29
- def print
30
- puts "#{format}: #{name}".black.on_yellow
31
- video_tracks.filter.each(&:print) if @options[:verbose]
32
- audio_tracks.filter.each(&:print) if @options[:verbose]
33
- text_tracks.filter.each(&:print) if @options[:verbose]
34
- print_ideal_tracks
35
- puts
30
+ def print_info
31
+ process do
32
+ print_filtered_tracks
33
+ end
36
34
  end
37
35
 
38
36
  def transcode
39
- puts "#{format}: #{name}".black.on_yellow
40
- Transcoder.new(self, @options).run
41
- puts
37
+ process do
38
+ print_ideal_tracks
39
+ Transcoder.new(self, @options).run
40
+ end
42
41
  end
43
42
 
44
43
  def self.each(filenames, options = {})
@@ -53,20 +52,59 @@ module Mkv2m4v
53
52
 
54
53
  private
55
54
 
55
+ def process
56
+ preamble
57
+ yield
58
+ postamble
59
+ end
60
+
61
+ def preamble
62
+ print "#{format}: #{name}".black.on_yellow
63
+ langs = @languages.empty? ? "all languages" : @languages.join(", ")
64
+ puts " (matching #{langs})".yellow.on_black
65
+ end
66
+
67
+ def postamble
68
+ puts
69
+ end
70
+
71
+ def print_all_tracks
72
+ video_tracks.each(&:print)
73
+ audio_tracks.each(&:print)
74
+ text_tracks.each(&:print)
75
+ end
76
+
77
+ HIGHLIGHT_COLOR = { :background => :cyan }
78
+
79
+ def print_filtered_tracks
80
+ filtered_video_tracks.each do |t|
81
+ t.print t == ideal_video_track && HIGHLIGHT_COLOR
82
+ end
83
+ filtered_audio_tracks.each do |t|
84
+ t.print t == ideal_audio_track && HIGHLIGHT_COLOR
85
+ end
86
+ filtered_text_tracks.each do |t|
87
+ t.print t == ideal_text_track && HIGHLIGHT_COLOR
88
+ end
89
+ end
90
+
56
91
  def print_ideal_tracks
57
- puts "==> Ideal video track"
58
- @ideal_video_track.print
59
- puts "==> Ideal audio track"
60
- @ideal_audio_track.print
92
+ ideal_video_track.print HIGHLIGHT_COLOR
93
+ ideal_audio_track.print HIGHLIGHT_COLOR
61
94
  end
62
95
 
63
96
  def init_tracks
64
- @video_tracks = tracks_by_type(:video)
65
- @audio_tracks = tracks_by_type(:audio)
66
- @text_tracks = tracks_by_type(:text)
97
+ @video_tracks = tracks_by_type(:video).rank
98
+ @audio_tracks = tracks_by_type(:audio).rank
99
+ @text_tracks = tracks_by_type(:text).rank
100
+
101
+ @filtered_video_tracks = video_tracks.filter
102
+ @filtered_audio_tracks = audio_tracks.filter
103
+ @filtered_text_tracks = text_tracks.filter
67
104
 
68
- @ideal_video_track = video_tracks.filter.rank.first
69
- @ideal_audio_track = audio_tracks.filter.rank.first
105
+ @ideal_video_track = filtered_video_tracks.first
106
+ @ideal_audio_track = filtered_audio_tracks.first
107
+ @ideal_text_track = filtered_text_tracks.first
70
108
  end
71
109
 
72
110
  def tracks_by_type(type)
@@ -32,8 +32,8 @@ module Mkv2m4v
32
32
  "#{frame_size}#{interlaced? ? "i" : "p"}"
33
33
  end
34
34
 
35
- def print
36
- puts "Track #{id}: (video)"
35
+ def print(color = nil)
36
+ puts "Video Track ##{id}:".colorize(color)
37
37
  puts " Format: #{format_description}"
38
38
  puts " Resolution: #{resolution}"
39
39
  puts " FPS: #{fps}"
@@ -61,8 +61,8 @@ module Mkv2m4v
61
61
  "#{bit_rate_kbps}k (#{info.bit_rate_mode})"
62
62
  end
63
63
 
64
- def print
65
- puts "Track #{id}: (audio)"
64
+ def print(color = nil)
65
+ puts "Audio Track ##{id}:".colorize(color)
66
66
  puts " Format: #{format_description}"
67
67
  puts " Channels: #{channel_description}"
68
68
  puts " Bit rate: #{bit_rate_description}"
@@ -76,8 +76,8 @@ module Mkv2m4v
76
76
  "#{format} (#{info.codec_id})"
77
77
  end
78
78
 
79
- def print
80
- puts "Track #{id}: (text)"
79
+ def print(color = nil)
80
+ puts "Text Track ##{id}:".colorize(color)
81
81
  puts " Format: #{format_description}"
82
82
  puts " Language: #{language}"
83
83
  puts " Title: #{title}"
@@ -17,7 +17,7 @@ module Mkv2m4v
17
17
  end
18
18
 
19
19
  def rank
20
- ranked_tracks = @tracks.sort_by { |t| score(t) }.reverse
20
+ ranked_tracks = @tracks.sort_by { |t| -score(t) }
21
21
  self.class.new(ranked_tracks, @options)
22
22
  end
23
23
 
@@ -57,8 +57,11 @@ module Mkv2m4v
57
57
  end
58
58
 
59
59
  class TextRanker < TrackRanker
60
- # scoring not implemented yet
61
- # def score(track)
62
- # end
60
+ def score(track)
61
+ score = 0
62
+ score += 3 if track == first
63
+ score += 4 if language_match?(track)
64
+ score
65
+ end
63
66
  end
64
67
  end
@@ -1,5 +1,5 @@
1
1
  module Mkv2m4v
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
 
4
4
  VersionDescription = "mkv2m4v #{VERSION} (c) 2012 Ryan McGeary"
5
5
  Description = <<EOS
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: mkv2m4v
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan McGeary
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-25 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement