musical 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "trollop", ">=1.16.2"
4
4
  gem "progressbar", ">=0.9.1"
5
+ gem "rb-appscript", ">=0.6.1"
5
6
 
6
7
  # Add dependencies to develop your gem here.
7
8
  # Include everything needed to run rake, tests, features, etc.
data/README.rdoc CHANGED
@@ -1,12 +1,12 @@
1
1
  = musical
2
2
 
3
3
  Musical is a simple tool for your DVD.
4
- It enables you to rip and convert it to wav data by chapter.
4
+ It enables you to rip data by chapter, encode it with your iTunes setting and add it to your iTunes library automatically.
5
5
 
6
6
 
7
7
  == Install
8
8
 
9
- 1 Install dvdbackup and ffmpeg. For example,
9
+ 1 Musical depends on dvdbackup and ffmpeg. To install them try this for example,
10
10
  brew install dvdbackup
11
11
  brew install ffmpeg
12
12
 
@@ -21,13 +21,18 @@ Set you DVD and type
21
21
  Options:
22
22
  --info, -i: Show your DVD data
23
23
  --ignore-convert-sound, -g: Rip data only, NOT convert them to wav file
24
+ --ignore-use-itunes, -n: NOT add ripped files to iTunes and encode the
24
25
  --dev, -d <s>: Set location of DVD device
25
26
  --title, -t <s>: Set DVD title (default: LIVE)
27
+ --artist, -a <s>: Set DVD artist (default: Artist)
26
28
  --output, -o <s>: Set location of ripped data (default: ripped)
27
29
  --version, -v: Print version and exit
28
30
  --help, -h: Show this message
29
31
 
30
32
 
33
+ When you use iTunes, you should use --title and --artist options. They will help you to manage your music library easily.
34
+
35
+
31
36
  == FAQ
32
37
 
33
38
  === On Mac OS X 10.7.x, I cannot install ffmpeg.
@@ -35,7 +40,7 @@ Options:
35
40
  The latest Xcode doesn't include gcc. Install gcc-4.2[https://github.com/kennethreitz/osx-gcc-installer].
36
41
 
37
42
  And try this.
38
- brew install --use-clang --HEAD --use-gcc ffmpeg
43
+ brew install --use-gcc ffmpeg
39
44
 
40
45
 
41
46
  === I got an error, /bin/sh: /usr/bin/pod2man: Permission denied
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/bin/musical CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'musical'
4
-
5
4
  include Musical
6
5
 
7
- DVD.new
6
+ opts = Musical.setup
7
+ DVD.new opts
data/lib/musical.rb CHANGED
@@ -2,135 +2,39 @@ require 'rubygems'
2
2
  require 'trollop'
3
3
  require 'progressbar'
4
4
  require 'fileutils'
5
+ require 'appscript'
5
6
 
6
- module Musical
7
- class DVD
8
- attr_accessor :opts
9
-
10
- def self.detect
11
- dev_infos = `df -h | awk {'print $1,$5,$6'}`.split("\n")
12
- candidates = []
13
- dev_infos.each do |dev_info|
14
- info = dev_info.split(" ")
15
- file_system = info[0]
16
- capacity = info[1]
17
- mounted = info[2]
18
- if capacity == "100%" && mounted.include?("/Volumes")
19
- candidates << mounted
20
- end
21
- end
22
-
23
- raise "Not detect DVD device" if candidates.empty?
24
- candidates
25
- end
26
-
27
- def initialize
28
- @opts = Trollop::options do
29
- version 'Musical 0.0.1'
30
- opt :info, "Show your DVD data", :type => :boolean
31
- opt :ignore_convert_sound, "Rip data only, NOT convert them to wav file", :type => :boolean
32
- opt :dev, "Set location of DVD device"
33
- opt :title, "Set DVD title", :default => 'LIVE'
34
- opt :output, "Set location of ripped data", :default => 'ripped'
35
- end
36
- run
37
- end
38
-
39
- def run
40
- check_env
41
- return puts info if @opts[:info]
42
- rip_by_chapter
43
- convert_sound unless @opts[:ignore_convert_sound]
44
- end
45
-
46
- def dev
47
- @_dev ||= DVD.detect.first
48
- end
49
-
50
- def info
51
- raise "Not detect DVD device" if dev.empty?
52
- @_info ||= `dvdbackup --input=#{dev} --info 2>/dev/null`
53
- end
54
-
55
- def title_with_chapters
56
- return @_title_chapters unless @_title_chapters.nil?
57
-
58
- @_title_chapters = []
59
- info_str = info.split("\n")
60
- info_str.each_with_index do |line, index|
61
- if line =~ /\s*Title (\d):$/
62
- @_title_chapters << { :title => $1.to_i, :line => index }
63
- end
64
- end
7
+ require 'musical/dvd'
8
+ require 'musical/itunes'
65
9
 
66
- @_title_chapters.each do |title_chapter|
67
- line = title_chapter[:line]
68
- if info_str[line + 1] =~ /\s*Title (\d) has (\d*) chapter/
69
- title_chapter[:chapter] = $2.to_i
70
- title_chapter.delete(:line)
71
- end
72
- end
73
- @_title_chapters
74
- end
75
-
76
- def rip_by_chapter
77
- task_message "Ripping"
78
-
79
- pbar = ProgressBar.new "Ripping", chapter_size
80
- title_with_chapters.each_with_index do |title_chapter, title_index|
81
- ripped_dir_base = "#{@opts[:output]}"
82
- saved_dir = "#{ripped_dir_base}/#{@opts[:title]}/title_#{title_index+1}"
83
- FileUtils.mkdir_p "#{saved_dir}"
84
-
85
- 1.upto title_chapter[:chapter] do |chapter|
86
- `dvdbackup --name=#{@opts[:title]} --input=#{dev} --title=#{title_index+1} --start=#{chapter} --end=#{chapter} --output=#{ripped_dir_base}_#{title_index}_#{chapter} 2>/dev/null`
87
- pbar.inc
88
-
89
- # moved file
90
- vob_path = `find #{ripped_dir_base}_#{title_index}_#{chapter} -name "*.VOB"`.chomp
91
- FileUtils.mv vob_path, "#{saved_dir}/chapter_#{chapter}.VOB"
92
- FileUtils.rm_rf "#{ripped_dir_base}_#{title_index}_#{chapter}"
93
- end
94
- end
95
- pbar.finish
96
- end
97
-
98
- def convert_sound
99
- task_message "Converting"
100
-
101
- pbar = ProgressBar.new "Converting", chapter_size
102
- title_with_chapters.each_with_index do |title_chapter, title_index|
103
- ripped_dir_base = "#{@opts[:output]}"
104
- saved_dir = "#{ripped_dir_base}/#{@opts[:title]}/title_#{title_index+1}"
105
-
106
- 1.upto title_chapter[:chapter] do |chapter|
107
- `ffmpeg -i #{saved_dir}/chapter_#{chapter}.VOB #{saved_dir}/chapter_#{chapter}.wav 2>/dev/null`
108
- FileUtils.rm_f "#{saved_dir}/chapter_#{chapter}.VOB"
109
- pbar.inc
110
- end
10
+ module Musical
11
+ def setup
12
+ # check env
13
+ ['dvdbackup', 'ffmpeg'].each do |app|
14
+ if `which #{app}`.empty?
15
+ raise RuntimeError, "\n\n'#{app}' is not installed.\n\ntry:\n brew install #{app}\n\n"
111
16
  end
112
- pbar.finish
113
17
  end
114
18
 
115
- def task_message(task)
116
- raise "Not found any titles and chapters" if title_with_chapters.size == 0 && chapter_size == 0
117
- puts "#{task} #{title_with_chapters.size} titles, #{chapter_size} chapters to #{@opts[:output]} directory"
118
- end
119
- private :task_message
19
+ version = open(File.join(File.dirname(__FILE__), "..", "VERSION")){ |f| f.gets }
120
20
 
121
- def chapter_size
122
- @_chapter_size ||= title_with_chapters.inject(0){ |count, t| count + t[:chapter]}
21
+ # parse options
22
+ opts = Trollop::options do
23
+ version "Musical #{version}"
24
+ opt :info, "Show your DVD data", :type => :boolean
25
+ opt :ignore_convert_sound, "Rip data only, NOT convert them to wav file", :type => :boolean
26
+ opt :ignore_use_itunes, "NOT add ripped files to iTunes and encode them"
27
+ opt :dev, "Set location of DVD device"
28
+ opt :title, "Set DVD title", :default => 'LIVE'
29
+ opt :artist, "Set DVD artist", :default => 'Artist'
30
+ opt :output, "Set location of ripped data", :default => 'ripped'
123
31
  end
124
- private :chapter_size
125
32
 
126
- def check_env
127
- ['dvdbackup', 'ffmpeg'].each do |app|
128
- if `which #{app}`.empty?
129
- raise RuntimeError, "\n\n'#{app}' is not installed.\n\ntry:\n brew install #{app}\n\n"
130
- end
131
- end
132
- end
133
- private :check_env
33
+ # fix fox dvdbackup
34
+ opts[:trim_title] = opts[:title].gsub(" ", "_")
35
+ opts[:trim_artist] = opts[:artist].gsub(" ", "_")
134
36
 
37
+ opts
135
38
  end
39
+
136
40
  end
@@ -0,0 +1,132 @@
1
+ module Musical
2
+ class DVD
3
+ attr_accessor :opts
4
+
5
+ def self.detect
6
+ dev_infos = `df -h | awk {'print $1,$5,$6'}`.split("\n")
7
+ candidates = []
8
+ dev_infos.each do |dev_info|
9
+ info = dev_info.split(" ")
10
+ file_system = info[0]
11
+ capacity = info[1]
12
+ mounted = info[2]
13
+ if capacity == "100%" && mounted.include?("/Volumes")
14
+ candidates << mounted
15
+ end
16
+ end
17
+
18
+ raise "Not detect DVD device" if candidates.empty?
19
+ candidates
20
+ end
21
+
22
+ def initialize(options={})
23
+ @opts = options
24
+
25
+ return puts info if @opts[:info]
26
+
27
+ # rip_by_chapter
28
+ # convert_sound unless @opts[:ignore_convert_sound]
29
+ to_itunes unless @opts[:ignore_use_itunes]
30
+ end
31
+
32
+ def dev
33
+ @_dev ||= DVD.detect.first
34
+ end
35
+
36
+ def info
37
+ raise "Not detect DVD device" if dev.empty?
38
+ @_info ||= `dvdbackup --input=#{dev} --info 2>/dev/null`
39
+ end
40
+
41
+ def title_with_chapters
42
+ return @_title_chapters unless @_title_chapters.nil?
43
+
44
+ @_title_chapters = []
45
+ info_str = info.split("\n")
46
+ info_str.each_with_index do |line, index|
47
+ if line =~ /\s*Title (\d):$/
48
+ @_title_chapters << { :title => $1.to_i, :line => index }
49
+ end
50
+ end
51
+
52
+ @_title_chapters.each do |title_chapter|
53
+ line = title_chapter[:line]
54
+ if info_str[line + 1] =~ /\s*Title (\d) has (\d*) chapter/
55
+ title_chapter[:chapter] = $2.to_i
56
+ title_chapter.delete(:line)
57
+ end
58
+ end
59
+ @_title_chapters
60
+ end
61
+
62
+ def rip_by_chapter
63
+ task_message "Ripping"
64
+
65
+ pbar = ProgressBar.new "Ripping", chapter_size
66
+ title_with_chapters.each_with_index do |title_chapter, title_index|
67
+ ripped_dir_base = "#{@opts[:output]}"
68
+ saved_dir = "#{ripped_dir_base}/#{@opts[:trim_title]}/title_#{title_index+1}"
69
+ FileUtils.mkdir_p "#{saved_dir}"
70
+
71
+ 1.upto title_chapter[:chapter] do |chapter|
72
+ `dvdbackup --name=#{@opts[:trim_title]} --input=#{dev} --title=#{title_index+1} --start=#{chapter} --end=#{chapter} --output=#{ripped_dir_base}_#{title_index}_#{chapter} 2>/dev/null`
73
+ pbar.inc
74
+ # moved file
75
+ vob_path = `find #{ripped_dir_base}_#{title_index}_#{chapter} -name "*.VOB"`.chomp
76
+ FileUtils.mv vob_path, "#{saved_dir}/chapter_#{chapter}.VOB"
77
+ FileUtils.rm_rf "#{ripped_dir_base}_#{title_index}_#{chapter}"
78
+ end
79
+ end
80
+ pbar.finish
81
+ end
82
+
83
+ def convert_sound
84
+ task_message "Converting"
85
+
86
+ pbar = ProgressBar.new "Converting", chapter_size
87
+ title_with_chapters.each_with_index do |title_chapter, title_index|
88
+ ripped_dir_base = "#{@opts[:output]}"
89
+ saved_dir = "#{ripped_dir_base}/#{@opts[:trim_title]}/title_#{title_index+1}"
90
+
91
+ 1.upto title_chapter[:chapter] do |chapter|
92
+ `ffmpeg -i #{saved_dir}/chapter_#{chapter}.VOB #{saved_dir}/chapter_#{chapter}.wav 2>/dev/null`
93
+ FileUtils.rm_f "#{saved_dir}/chapter_#{chapter}.VOB"
94
+ pbar.inc
95
+ end
96
+ end
97
+ pbar.finish
98
+ end
99
+
100
+ def to_itunes
101
+ task_message "To iTunes"
102
+
103
+ pbar = ProgressBar.new "To iTunes", chapter_size
104
+ its = ITunes.new
105
+
106
+ title_with_chapters.each_with_index do |title_chapter, title_index|
107
+ ripped_dir_base = "#{@opts[:output]}"
108
+ saved_dir = "#{ripped_dir_base}/#{@opts[:trim_title]}/title_#{title_index+1}"
109
+
110
+ options = { :album => @opts[:title], :artist => @opts[:artist], :track_count => title_chapter[:chapter]}
111
+ 1.upto title_chapter[:chapter] do |chapter|
112
+ its.add("#{saved_dir}/chapter_#{chapter}.wav", options.merge(:track_number => chapter))
113
+ pbar.inc
114
+ end
115
+ end
116
+ FileUtils.rm_rf @opts[:output]
117
+ pbar.finish
118
+ end
119
+
120
+ def chapter_size
121
+ @_chapter_size ||= title_with_chapters.inject(0){ |count, t| count + t[:chapter]}
122
+ end
123
+ private :chapter_size
124
+
125
+ def task_message(task)
126
+ raise "Not found any titles and chapters" if title_with_chapters.size == 0 && chapter_size == 0
127
+ puts "#{task} #{title_with_chapters.size} titles, #{chapter_size} chapters"
128
+ end
129
+ private :task_message
130
+
131
+ end
132
+ end
@@ -0,0 +1,31 @@
1
+ module Musical
2
+ include Appscript
3
+
4
+ class ITunes
5
+ attr_accessor :opts
6
+ def initialize(options = {})
7
+ raise "iTunes support works on only Mac OSX" unless RUBY_PLATFORM.include? "darwin"
8
+ @opts = options # not used yet
9
+ end
10
+
11
+ def its
12
+ @_its ||= app "iTunes.app"
13
+ end
14
+
15
+ def add(file_path, options = {})
16
+ wav = its.add MacTypes::FileURL.path(File.expand_path(file_path))
17
+ return if wav.nil?
18
+
19
+ tracks = wav.convert
20
+ sleep 5 # FIXME
21
+ tracks.each do |track|
22
+ [:name, :album, :artist, :track_count, :track_number].each do |key|
23
+ unless options[key].nil?
24
+ track.send(key).set options[key]
25
+ end
26
+ end
27
+ end
28
+ its.delete wav
29
+ end
30
+ end
31
+ end
data/musical.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{musical}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ryo katsuma"]
12
- s.date = %q{2011-11-06}
12
+ s.date = %q{2011-11-26}
13
13
  s.default_executable = %q{musical}
14
14
  s.description = %q{Musical is a simple rip and convert tool for your DVD. It enables you to rip and convert it to wav data by chapter.}
15
15
  s.email = %q{katsuma@gmail.com}
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "bin/musical",
30
30
  "lib/musical.rb",
31
+ "lib/musical/dvd.rb",
32
+ "lib/musical/itunes.rb",
31
33
  "musical.gemspec",
32
34
  "spec/musical_spec.rb",
33
35
  "spec/spec_helper.rb"
@@ -44,6 +46,7 @@ Gem::Specification.new do |s|
44
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
47
  s.add_runtime_dependency(%q<trollop>, [">= 1.16.2"])
46
48
  s.add_runtime_dependency(%q<progressbar>, [">= 0.9.1"])
49
+ s.add_runtime_dependency(%q<rb-appscript>, [">= 0.6.1"])
47
50
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
51
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
52
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -51,6 +54,7 @@ Gem::Specification.new do |s|
51
54
  else
52
55
  s.add_dependency(%q<trollop>, [">= 1.16.2"])
53
56
  s.add_dependency(%q<progressbar>, [">= 0.9.1"])
57
+ s.add_dependency(%q<rb-appscript>, [">= 0.6.1"])
54
58
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
55
59
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
60
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -59,6 +63,7 @@ Gem::Specification.new do |s|
59
63
  else
60
64
  s.add_dependency(%q<trollop>, [">= 1.16.2"])
61
65
  s.add_dependency(%q<progressbar>, [">= 0.9.1"])
66
+ s.add_dependency(%q<rb-appscript>, [">= 0.6.1"])
62
67
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
63
68
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
69
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: musical
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - ryo katsuma
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-06 00:00:00 +09:00
13
+ date: 2011-11-26 00:00:00 +09:00
14
14
  default_executable: musical
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,8 +36,19 @@ dependencies:
36
36
  prerelease: false
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: rspec
39
+ name: rb-appscript
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.1
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &id004 !ruby/object:Gem::Requirement
41
52
  none: false
42
53
  requirements:
43
54
  - - ~>
@@ -45,10 +56,10 @@ dependencies:
45
56
  version: 2.3.0
46
57
  type: :development
47
58
  prerelease: false
48
- version_requirements: *id003
59
+ version_requirements: *id004
49
60
  - !ruby/object:Gem::Dependency
50
61
  name: bundler
51
- requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
52
63
  none: false
53
64
  requirements:
54
65
  - - ~>
@@ -56,10 +67,10 @@ dependencies:
56
67
  version: 1.0.0
57
68
  type: :development
58
69
  prerelease: false
59
- version_requirements: *id004
70
+ version_requirements: *id005
60
71
  - !ruby/object:Gem::Dependency
61
72
  name: jeweler
62
- requirement: &id005 !ruby/object:Gem::Requirement
73
+ requirement: &id006 !ruby/object:Gem::Requirement
63
74
  none: false
64
75
  requirements:
65
76
  - - ~>
@@ -67,10 +78,10 @@ dependencies:
67
78
  version: 1.6.4
68
79
  type: :development
69
80
  prerelease: false
70
- version_requirements: *id005
81
+ version_requirements: *id006
71
82
  - !ruby/object:Gem::Dependency
72
83
  name: rcov
73
- requirement: &id006 !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
74
85
  none: false
75
86
  requirements:
76
87
  - - ">="
@@ -78,7 +89,7 @@ dependencies:
78
89
  version: "0"
79
90
  type: :development
80
91
  prerelease: false
81
- version_requirements: *id006
92
+ version_requirements: *id007
82
93
  description: Musical is a simple rip and convert tool for your DVD. It enables you to rip and convert it to wav data by chapter.
83
94
  email: katsuma@gmail.com
84
95
  executables:
@@ -98,6 +109,8 @@ files:
98
109
  - VERSION
99
110
  - bin/musical
100
111
  - lib/musical.rb
112
+ - lib/musical/dvd.rb
113
+ - lib/musical/itunes.rb
101
114
  - musical.gemspec
102
115
  - spec/musical_spec.rb
103
116
  - spec/spec_helper.rb
@@ -115,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
128
  requirements:
116
129
  - - ">="
117
130
  - !ruby/object:Gem::Version
118
- hash: 785758502750108159
131
+ hash: -3076262886197774611
119
132
  segments:
120
133
  - 0
121
134
  version: "0"