class Musical::DVD
Constants
- DETECT_ERROR_MESSAGE
- DRIVE_NOT_FOUND_MESSAGE
- DVD_NOT_INSERTED_MESSAGE
Attributes
artist[RW]
title[RW]
year[RW]
Public Class Methods
detect()
click to toggle source
# File lib/musical/dvd.rb, line 18 def self.detect drutil_out = execute_command('drutil status') raise RuntimeError.new DRIVE_NOT_FOUND_MESSAGE unless drutil_out raise RuntimeError.new DVD_NOT_INSERTED_MESSAGE unless drutil_out.include?('Name:') file_system = drutil_out.split("\n").select do |line| line.include?('Name:') end.first.match(/Name: (.+)/)[1] end
load(options = {}) { |dvd| ... }
click to toggle source
# File lib/musical/dvd.rb, line 37 def self.load(options = {}) if @@path.nil? || options[:forcibly] @@path = options[:path] || self.detect end dvd = DVD.instance dvd.title = options[:title] || Musical.configuration.title dvd.artist = options[:artist] || Musical.configuration.artist dvd.year = options[:year] || Musical.configuration.year if block_given? yield(dvd) end dvd.info end
path()
click to toggle source
# File lib/musical/dvd.rb, line 33 def self.path @@path end
path=(path)
click to toggle source
# File lib/musical/dvd.rb, line 29 def self.path=(path) @@path = path end
Public Instance Methods
info()
click to toggle source
# File lib/musical/dvd.rb, line 54 def info raise RuntimeError.new DETECT_ERROR_MESSAGE unless @@path return @info if @info @info = execute_command("dvdbackup --info --input='#{@@path}'", true) raise RuntimeError.new DETECT_ERROR_MESSAGE if @info.empty? @info end
rip() { || ... }
click to toggle source
# File lib/musical/dvd.rb, line 83 def rip raise RuntimeError.new DETECT_ERROR_MESSAGE unless @@path save_dir = Musical.configuration.output FileUtils.mkdir_p save_dir chapters = [] title_sets.each do |title_set| chapters << (1..title_set[:chapter]).map do |chapter_index| commands = [] commands << 'dvdbackup' commands << "--input='#{@@path}'" commands << "--title='#{title_set[:title]}'" commands << "--start=#{chapter_index}" commands << "--end=#{chapter_index}" commands << "--output='#{Musical.configuration.working_dir}'" execute_command(commands.join(' '), true) vob_save_path = "#{save_dir}/TITLE_#{title_set[:title]}_#{chapter_index}.VOB" FileUtils.mv(vob_path, vob_save_path) yield if block_given? Chapter.new(vob_save_path, title_number: title_set[:title], chapter_number: chapter_index) end end chapters.flatten end
title_sets()
click to toggle source
# File lib/musical/dvd.rb, line 64 def title_sets return @title_sets if @title_sets @title_sets = [].tap do |sets| sets_regexp = /\s*Title (\d) has (\d*) chapter/ info.split("\n").each do |line| if line =~ sets_regexp sets << { title: $1.to_i, chapter: $2.to_i } end end end end
Private Instance Methods
vob_path()
click to toggle source
# File lib/musical/dvd.rb, line 77 def vob_path find_command = "find '#{Musical.configuration.working_dir}' -name '*.VOB'" execute_command(find_command).split("\n").first end