-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathripcd.rb
147 lines (131 loc) · 3.86 KB
/
ripcd.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'tempfile'
require 'optparse'
require 'yaml'
ARGV.options do |opts|
opts.on("-o", "--output-dir=val", String) { |val| ProjectDir = val.tr("\\", "/") }
opts.on("-d", "--discs=val", String) { |val| @discTotal = val.to_i }
opts.on("-b", "--burst") { @mode = '-B' }
opts.on("-s", "--secure") { @mode = '-S' }
opts.on("-p", "--paranoid") { @mode = '-P' }
opts.parse!
end
#confirm inputs
if defined?(ProjectDir).nil?
puts "Please enter a valid output directory for rip!"
exit
elsif ! File.exist?(ProjectDir)
puts "Please enter a valid output directory for rip!"
exit
end
if defined?(@discTotal).nil?
puts "Please enter the amount of discs to be ripped!"
exit
end
if defined?(@mode).nil?
puts "Defaulting to secure rip"
@mode = '-S'
else
ripOptions = ['-B', '-S', '-P']
if ! ripOptions.include? @mode
puts 'Non-valid option entered for rip mode - using default of Secure'
@mode = '-S'
end
end
scriptPath = __dir__
configPath = scriptPath + "/ripcd.config"
configOptions = YAML.load_file(configPath)
CLI_Tools_Path = configOptions['CLI_Tools_Path']
CueToolsPath = configOptions['CueToolsPath']
LoadPath = CLI_Tools_Path + configOptions['LoadPath']
UnloadPath = CLI_Tools_Path + configOptions['UnloadPath']
Drive = configOptions['Drive']
def loadDisc()
tempFile1 = Tempfile.new('batchRipping')
tempFile2 = Tempfile.new('batchRipping')
system(LoadPath, "--drive=#{Drive}", '--rejectifnodisc' "--logfile=#{tempFile1.path}", "--passerrorsback=#{tempFile2.path}")
puts "\n"
end
def unloadDisc()
tempFile1 = Tempfile.new('batchRipping')
tempFile2 = Tempfile.new('batchRipping')
system(UnloadPath, "--drive=#{Drive}", '--rejectifnodisc' "--logfile=#{tempFile1.path}", "--passerrorsback=#{tempFile2.path}")
puts "\n"
end
def ripDisc()
puts "Ripping disc: #{@discNumber}"
`powershell "Start-Transcript -Append #{ProjectDir}/cdimage.consolelog ; #{CueToolsPath} -D #{Drive} #{@mode} ; Stop-Transcript"`
end
def checkRipError()
ripLog = File.readlines("#{ProjectDir}/cdimage.consolelog")
if ripLog.any? {|line| line.include?('Results')}
ripExit = 5
else
ripExit = 1
end
end
def updateCue(cuePath,outputFile)
oldCue = File.readlines(cuePath)
temp = Tempfile.new
newCuePath = outputFile
newWavPath = File.basename(outputFile, ".*") + '.wav'
oldCue.each do|line|
if (line.include?('FILE') && line.include?('WAVE'))
newLine = "FILE " + '"' + newWavPath + '"' + " WAVE\n"
temp << newLine
else
temp << line
end
end
temp.rewind
temp.close
FileUtils.mv(temp.path,newCuePath)
if ! File.readlines(newCuePath).empty?
FileUtils.rm(cuePath)
end
end
def renameOutput(file,time,status)
outName = 'cdrip-'
outName.prepend('FAIL_') if status == 'fail'
dir = File.dirname(file)
ext = File.extname(file)
outputFile = dir + '/' + outName + time + ext
if ext == '.cue'
updateCue(file,outputFile)
else
File.rename(file,outputFile)
end
end
# Start process
@discNumber = 1
Dir.chdir(ProjectDir)
while @discNumber <= @discTotal do
ripAttempt = 1
loadDisc()
while ripAttempt <=5
ripDisc()
ripAttempt += checkRipError()
sleep 5
end
time = Time.now.strftime("%m%d%H%M%S")
outputFiles = Dir.glob("#{ProjectDir}/cdimage*")
if outputFiles.length == 4
ripLog = File.readlines("#{ProjectDir}/cdimage.consolelog")
ripResults = ripLog["#{ripLog.count - 5}".to_i]
puts ripResults
outputFiles.each {|file| renameOutput(file, time, 'pass')}
csvLine = "#{@discNumber}, cdrip-#{time}, #{ripResults}"
open("#{ProjectDir}/rip-log.txt", 'a') { |f| f.puts csvLine}
@discNumber += 1
else
sleep 20
csvLine = "#{@discNumber}, FAIL, FAIL"
puts "Rip Failed!"
outputFiles.each {|file| renameOutput(file, time, 'fail')}
@discNumber += 1
open("#{ProjectDir}/rip-log.txt", 'a') { |f| f.puts csvLine}
end
unloadDisc()
sleep 5
end
sleep 5
puts "All done!!"