-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_cd_meta.rb
More file actions
39 lines (37 loc) · 1010 Bytes
/
get_cd_meta.rb
File metadata and controls
39 lines (37 loc) · 1010 Bytes
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
require 'json'
prior_drive_info = ''
cd_iterator = 1
Output_dir = ARGV[0].tr("\\","/")
Drive = ARGV[1]
if (Output_dir.nil? || ! File.exist?(Output_dir))
puts "Please use valid output directory!"
exit
end
loop do
drive_info = `mediainfo --Output=JSON #{Drive}:/`
if drive_info == "\n"
puts "Waiting for disc"
elsif prior_drive_info == drive_info
puts "Same Disc Still Present!"
else
parsed_data = JSON.parse(drive_info)
track_lengths = []
if parsed_data.count > 1
parsed_data.each do |track|
track_lengths << track['media']['track'][0]['Duration'].to_f
end
else
track_lengths << parsed_data['media']['track'][0]['Duration'].to_f
end
time_info = {"total_length" => track_lengths.sum}
log_file = "#{Output_dir}/CD_#{cd_iterator.to_s}.log"
puts "Writing: #{log_file}"
File.open(log_file,"w") do |f|
f.write(time_info.to_json)
f.close
end
cd_iterator += 1
prior_drive_info = drive_info
end
sleep 60
end