Created
June 23, 2012 10:16
-
-
Save makotom/2977804 to your computer and use it in GitHub Desktop.
CD-DA TOC Parser (outputs in .cue form)
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
<?php | |
if(empty($argv[1])){ | |
exit(); | |
} | |
$fh = fopen($argv[1], "r"); | |
fread($fh, 4); | |
$ret = ""; | |
$i = 0; | |
while($bin = fread($fh, 11)){ | |
if(strlen($bin) < 11 || ord($bin[3]) > 0x99){ | |
continue; | |
} | |
if($i === 0){ | |
$base = array(ord($bin[8]), ord($bin[9]), ord($bin[10])); | |
} | |
$track = array(ord($bin[8]), ord($bin[9]), ord($bin[10])); | |
$track[2] -= $base[2]; | |
if($track[2] < 0){ | |
$track[2] += 75; | |
$track[1] -= 1; | |
} | |
$track[1] -= $base[1]; | |
if($track[1] < 0){ | |
$track[1] += 60; | |
$track[0] -= 1; | |
} | |
$track[0] -= $base[0]; | |
$ret .= " TRACK " . sprintf("%02d", ord($bin[3])) . " AUDIO\n"; | |
$ret .= " INDEX 01 " . sprintf("%02d:%02d:%02d", $track[0], $track[1], $track[2]) . "\n"; | |
$i += 1; | |
} | |
if(!empty($ret)){ | |
$ret = "FILE \"" . (!empty($argv[2]) ? $argv[2] : "") . "\" BINARY\n" . $ret; | |
} | |
echo $ret; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment