Created
February 19, 2011 10:37
-
-
Save iratqq/834989 to your computer and use it in GitHub Desktop.
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
# $ awk -f bin-discid.awk foobar.cue | |
BEGIN { | |
trackno = 0; | |
framesize = 75; | |
bsize = 2352; | |
msf_offset = 150; | |
} | |
/[ \t]*FILE/ { | |
cmd = sprintf("ls -l %s", $2); | |
cmd | getline fileinfo; | |
split(fileinfo, arr, " "); | |
last_off = arr[5]; | |
} | |
/[ \t]*TRACK/ { | |
trackno++; | |
} | |
# INDEX 0 (pregap) will overwrite | |
/[ \t]*INDEX/ { | |
index_time = $3; | |
# get time | |
split($3, arr, ":"); # get | |
# arr[1]: min, arr[2]: sec, arr[3]: frame | |
start_time[trackno] = arr[1] * 60 + arr[2]; | |
start_frames[trackno] = arr[1] * 60 * framesize + arr[2] * framesize + arr[3]; | |
fstr = sprintf("%08d", (start_frames[trackno] + msf_offset) / framesize); | |
sum = 0; | |
for (i = 0; i <= length(fstr); i++) { | |
sum += substr(fstr, i, 1); | |
} | |
magics[trackno] = sum; | |
# printf("track %02d", trackno); | |
# printf(" index %02d:%02d:%02d", arr[1], arr[2], arr[3]); | |
# printf(" starttime %d", start_time[trackno]); | |
# printf(" startframe %d", start_frames[trackno]); | |
# printf(" magic %d\n", magics[trackno]); | |
} | |
END { | |
#last_size = last_off - start_frames[trackno] * bsize; | |
#print int(last_size / bsize / framesize); | |
magic = 0; | |
for (i = 1; i <= trackno; i++) { | |
magic += magics[i]; | |
} | |
#print magic; | |
total_time = int(last_off / bsize / framesize) + msf_offset / framesize - start_time[0]; | |
# print "lastoffset", last_off, "totaltime", total_time | |
# printf("%08x %08x %08x\n", lshift(magic % 255, 24), lshift(total_time, 8), trackno); | |
discid = lshift(magic % 255, 24) + lshift(total_time, 8) + trackno; | |
frames_query = "" | |
for (i = 1; i <= trackno; i++) { | |
frames_query = sprintf("%s %d", frames_query, start_frames[i]); | |
} | |
printf("%08x %d%s %d\n", discid, trackno, frames_query, total_time); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment