Created
September 23, 2016 23:00
-
-
Save tily/eb339a9452846e339ff2cba7ee78410f to your computer and use it in GitHub Desktop.
Detect data track from XLD logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main | |
Dir["/Users/tily/Music/CDs/*/*.log"].each do |path| | |
f = File.open(path) | |
table_num, track_num = parse(f) | |
if table_num != track_num | |
puts "#{path}: table -> #{table_num}, track -> #{track_num}" | |
end | |
end | |
end | |
def parse(io) | |
lines = io.read.split("\n") | |
iter = lines.each | |
table_num = nil | |
track_num = nil | |
while true | |
begin | |
l = iter.next | |
if l.match(/^TOC of the extracted CD$/) | |
while true | |
l = iter.next | |
if num = l[/^\s+(\d+)/, 1] | |
table_num = num.to_i | |
end | |
if l == "" | |
break | |
end | |
end | |
end | |
if num = l[/^Track (\d+)/, 1] | |
track_num = num.to_i | |
end | |
rescue StopIteration => e | |
break | |
end | |
end | |
return [table_num, track_num] | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment