Class: DVDConverter::Movie
- Inherits:
-
Object
- Object
- DVDConverter::Movie
- Defined in:
- lib/dvd_converter/movie.rb
Constant Summary collapse
- AUDIO_INFO_REGEX =
/scan: id=(.+)bd, lang=(.+), 3cc=(.+) ext=(\d+)/.freeze
- AUDIO_REGEX =
/scan: checking audio (\d+)/.freeze
- DURATION_REGEX =
/scan: duration is (.+) \((\d+) ms\)/- IGNORE_TITLE_REGEX =
/scan: ignoring title/.freeze
- TITLE_REGEX =
/scan: scanning title (\d+)/.freeze
- SUBTITLE_INFO_REGEX =
/scan: id=(.+)bd, lang=(.+), 3cc=(.+)/.freeze
- SUBTITLE_REGEX =
/scan: checking subtitle (\d+)/.freeze
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
Instance Method Summary collapse
- #convert(options = {}) ⇒ Object
- #convert_everything(options = {}) ⇒ Object
-
#initialize(source) ⇒ Movie
constructor
A new instance of Movie.
- #print_description ⇒ Object
- #scan_titles ⇒ Object
Constructor Details
#initialize(source) ⇒ Movie
Returns a new instance of Movie.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dvd_converter/movie.rb', line 16 def initialize(source) # Does the given source exist? unless File.exists? source raise ArgumentError, 'Movie source is not a valid path' end # Scan the movie for information @source = source self.tracks = {} end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
13 14 15 |
# File 'lib/dvd_converter/movie.rb', line 13 def source @source end |
#tracks ⇒ Object
Returns the value of attribute tracks.
14 15 16 |
# File 'lib/dvd_converter/movie.rb', line 14 def tracks @tracks end |
Instance Method Details
#convert(options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/dvd_converter/movie.rb', line 27 def convert( = {}) track = self.tracks[[:track]] track.convert end |
#convert_everything(options = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/dvd_converter/movie.rb', line 32 def convert_everything( = {}) self.tracks.keys.sort.each do |k| self.tracks[k].convert_everything() unless [:exclude].include?(k) end end |
#print_description ⇒ Object
38 39 40 41 42 43 |
# File 'lib/dvd_converter/movie.rb', line 38 def print_description self.tracks.keys.sort.each do |id| track = self.tracks[id] track.print_description end end |
#scan_titles ⇒ Object
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 |
# File 'lib/dvd_converter/movie.rb', line 45 def scan_titles # Set some defaults audio_id = nil id = nil subtitle_id = nil # Run the command to pull information f = IO.popen("#{HANDBRAKECLI_PATH} -i \"#{@source}\" -t 0 2>&1") f.each_line do |line| # Did we read a title? match = TITLE_REGEX.match(line) if match id = match[1].to_i self.tracks[id] = Track.new id, self audio_id = nil subtitle_id = nil next end # Did we read a duration match = DURATION_REGEX.match(line) if match && id self.tracks[id].duration = match[1] next end # Do we ignore the title? match = IGNORE_TITLE_REGEX.match(line) if match && id self.tracks.delete(id) id = nil audio_id = nil subtitle_id = nil next end # Did we read a subtitle? match = SUBTITLE_REGEX.match(line) if match && self.tracks[id] subtitle_id = match[1].to_i next end # Did we read a subtitle info? match = SUBTITLE_INFO_REGEX.match(line) if match && subtitle_id self.tracks[id].subtitles[subtitle_id] = Subtitle.new subtitle_id, match[1], match[2], match[3] subtitle_id = nil next end # Did we read an audio channel match = AUDIO_REGEX.match(line) if match && self.tracks[id] audio_id = match[1].to_i next end # Did we read an audio channel info? match = AUDIO_INFO_REGEX.match(line) if match && audio_id self.tracks[id].audio[audio_id] = Audio.new audio_id, match[1], match[2], match[3], match[4] audio_id = nil next end end end |