CUERipper revamp

This commit is contained in:
chudov
2010-02-28 21:04:34 +00:00
parent 31048cb63c
commit 749f96ed8a
92 changed files with 6410 additions and 440 deletions

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex" />
</head>
<body>disc not present in database
</body>
</html>

BIN
CUETools.CTDB/Web/ctdb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -1,65 +1,77 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CUETools DB</title>
<style type="text/css">
.style1 {
font-size: x-small;
font-family: Arial, Helvetica, sans-serif;
}
.style_fixed {
#font-size: x-small;
font-family: Courier;
}
</style>
</head>
<body>
<H1>CUETools Database</H1>
<?php
$listfile="parity/list.txt";
$last_modified_time = filemtime($listfile);
$etag = md5_file($listfile);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
header("ETag: $etag");
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}
include 'logo_start.php';
require_once( 'phpmb/mbQuery.php' );
require_once( 'phpctdb/ctdb.php' );
$lines=false;
$fp = fopen('parity/list.txt','r');
$totaldiscs=filesize($listfile)/57;
$fp = fopen($listfile,'r');
$count = 10;
fseek($fp, -57 * $count, SEEK_END);
$start = @$_GET['start'];
if ($start == "" || $start > $totaldiscs || $start < 0) $start = $totaldiscs - $count;
fseek($fp, 57 * $start, SEEK_SET);
$n = $count;
while($line=fgets($fp)) {
$name = trim($line);
if (file_exists($name))
$lines[]=$name;
if (--$count <= 0)
if (--$n <= 0)
break;
}
fclose($fp);
printf("<h3>Recent additions:</h3>");
printf("<table border=3><tr><th>Artist</th><th>Album</th><th>Disc Id</th><th>CTDB Id</th></tr>");
printf("<center><h3>Recent additions:</h3>");
include 'table_start.php';
?>
<table class=classy_table cellpadding=3 cellspacing=0><tr bgcolor=#D0D0D0><th>Artist</th><th>Album</th><th>Disc Id</th><th>CTDB Id</th></tr>
<?php
//<tr background="img/bg_top_border.jpg"><td></td><td width=8 rowspan=12 bgcolor=#FFFFFF></td><td background="img/bg_right_border.jpg" width=4 rowspan=12></td><td></td><td></td><td></td></tr>
$imgs = '';
if ($lines) foreach(array_reverse($lines) as $line) {
$ctdb = new phpCTDB($line);
$disc = $ctdb->db['discs'][0];
$id = @$disc['MBID']['value'];
$ctdb->ParseToc();
//$id = @$disc['MBID']['value'];
$artist = @$disc['ART ']['value'];
$title = @$disc['nam ']['value'];
$link = $id == "" ? "<a>" : '<a href="http://musicbrainz.org/bare/cdlookup.html?id=' . $id . '">';
//echo $line . ':' . $id . '<br>';
if ($artist == "" && $title == "" && $id != "") {
$discid = substr($line,13,30);
$ctdbid = $ctdb->db['discs'][0]['CRC ']['int'];
if ($artist == "" && $title == "")
{
//$q = new MusicBrainzQuery(new WebService('db4.cuetools.net'));
$q = new MusicBrainzQuery();
$rf = new ReleaseFilter();
try {
$rresults = $q->getReleases( $rf->discId($id) );
$rresults = $q->getReleases( $rf->discId($ctdb->mbid) );
foreach ( $rresults as $key => $rr ) {
$rr = $rr->getRelease();
$artist = $rr->getArtist()->getName();
$title = $rr->getTitle();
$imgs = $imgs . '<img src="http://ec1.images-amazon.com/images/P/' . $rr->getAsin() . '.01.MZZZZZZZ.jpg">';
}
}
catch ( ResponseError $e ) {
// echo $e->getMessage() . " ";
}
}
printf("<tr><td>%s</td><td>%s</td><td class=style_fixed>%s%s</a></td><td class=style_fixed>%x</td></tr>", $artist, $title, $link, substr($line,13,30), $ctdb->db['discs'][0]['CRC ']['int']);
printf('<tr><td class=td_artist>%s</td><td class=td_album>%s</td><td class=td_discid><a href="http://musicbrainz.org/bare/cdlookup.html?id=%s">%s</a></td><td class=td_ctdbid><a href=show.php?discid=%s&ctdbid=%08x>%08x</a></td></tr>', htmlspecialchars($artist), htmlspecialchars($title), $ctdb->mbid, $discid, $discid, $ctdbid, $ctdbid);
}
printf('<tr><td colspan=4 align=right><a class=style1 href="?start=%d">More</a></td></tr>', $count * floor(($start - 1) / $count));
printf("</table>");
printf("<h5>Status: %d unique discs.</h5>", filesize("parity/list.txt")/57);
include 'table_end.php' ;
//printf('%s', $imgs);
printf("</center>");
?>
</body>
</html>

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CUETools DB</title>
<style type="text/css">
.style1 {
font-size: x-small;
font-family: Arial, Helvetica, sans-serif;
}
.style_fixed {
#font-size: x-small;
font-family: Courier;
}
.style_logo {
font-size: x-large;
font-family: Arial, Helvetica, sans-serif;
}
.td_status {
font-size: x-small;
text-align: center;
font-family: sans-serif;
}
.td_artist {
padding: 1px 10px;
}
.td_album {
padding: 1px 10px;
}
.td_discid {
padding: 1px 5px;
font-family: Courier;
}
.td_ctdbid {
padding: 1px 5px;
font-family: Courier;
}
.classy_table {
border-style:none;
# border-color-right: #D0D0D0
# border-color-left: #D0D0D0
}
</style>
</head>
<body>
<table border=0 cellspacing=0 cellpadding=3 align=center>
<tr>
<td rowspan=3><img src=ctdb.png></td>
<td colspan=2 class=td_status>
<?php
printf("%d unique discs", filesize("parity/list.txt")/57);
?>
</td>
</tr>
<tr>
<td class=style_logo colspan=2>CUETools Database</td>
</tr>
<tr align=center>
<td>About</td>
<td><a href=http://www.cuetools.net>CUETools</a></td>
</tr>
</table>
<br clear=all>

View File

@@ -6,6 +6,8 @@ class phpCTDB{
private $fpstats;
private $atoms;
public $db;
public $fulltoc;
public $mbid;
function __construct($target_file) {
$this->fp = fopen($target_file, 'rb');
@@ -19,6 +21,32 @@ class phpCTDB{
fclose($this->fp);
}
function ParseTOC()
{
$disc = $this->db['discs'][0];
$this->fulltoc = '';
$mbtoc = '';
foreach ($disc['TOC ']['subatoms'] as $track)
{
if ($track['name']=='INFO') {
$trackcount = phpCTDB::BigEndian2Int(substr($track['value'],0,4));
$pregap = phpCTDB::BigEndian2Int(substr($track['value'],4,4));
$pos = $pregap + 150;
}
if ($track['name']=='TRAK') {
$isaudio = phpCTDB::BigEndian2Int(substr($track['value'],0,4));
$length = phpCTDB::BigEndian2Int(substr($track['value'],4,4));
$this->fulltoc = sprintf('%s %d', $this->fulltoc, $pos);
$mbtoc = sprintf('%s%08X', $mbtoc, $pos);
$pos += $length;
}
}
$this->fulltoc = sprintf('1 %d %d%s', $trackcount, $pos, $this->fulltoc);
$mbtoc = sprintf('01%02X%08X%s', $trackcount, $pos, $mbtoc);
$mbtoc = str_pad($mbtoc,804,'0');
$this->mbid = str_replace('+', '.', str_replace('/', '_', str_replace('=', '-', base64_encode(pack("H*" , sha1($mbtoc))))));
}
static function BigEndian2Int($byte_word, $signed = false) {
$int_value = 0;
@@ -56,6 +84,25 @@ class phpCTDB{
return strrev(phpCTDB::LittleEndian2String($number, $minbytes, $synchsafe));
}
static function discid2path($id)
{
$err = sscanf($id, "%03d-%04x%04x-%04x%04x-%04x%04x", $tracks, $id1a, $id1b, $id2a, $id2b, $cddbida, $cddbidb);
$parsedid = sprintf("%03d-%04x%04x-%04x%04x-%04x%04x", $tracks, $id1a, $id1b, $id2a, $id2b, $cddbida, $cddbidb);
if ($id != $parsedid)
die("bad id ". $id);
return sprintf("parity/%x/%x/%x/%s", $id1b & 15, ($id1b >> 4) & 15, ($id1b >> 8) & 15, $parsedid);
}
static function ctdbid2path($discid, $ctdbid)
{
$path = phpCTDB::discid2path($discid);
sscanf($ctdbid, "%04x%04x", $ctdbida, $ctdbidb);
$parsedctdbid = sprintf("%04x%04x", $ctdbida, $ctdbidb);
if ($ctdbid != $parsedctdbid)
die("bad id ". $ctdbid);
return sprintf("%s/%s.bin", $path, $ctdbid);
}
static function unparse_atom($fp, $atom)
{
// printf('unparse_atom(%s)<br>', $atom['name']);
@@ -105,6 +152,7 @@ class phpCTDB{
foreach ($atom['subatoms'] as $param)
switch ($param['name']) {
case 'HEAD':
case 'TOC ':
case 'CRC ':
case 'MBID':
case 'ART ':

View File

@@ -0,0 +1,55 @@
<?php
include 'logo_start.php';
require_once( 'phpmb/mbQuery.php' );
require_once( 'phpctdb/ctdb.php' );
$discid = $_GET['discid'];
$ctdbid = $_GET['ctdbid'];
$path = phpCTDB::ctdbid2path($discid, $ctdbid);
$ctdb = new phpCTDB($path);
$disc = $ctdb->db['discs'][0];
//$id = @$disc['MBID']['value'];
$ctdb->ParseTOC();
$artist = @$disc['ART ']['value'];
$title = @$disc['nam ']['value'];
$link = '<a href="http://musicbrainz.org/bare/cdlookup.html?id=' . $ctdb->mbid . '">';
$q = new MusicBrainzQuery();
$rf = new ReleaseFilter();
$mbrr = false;
try {
$rresults = $q->getReleases( $rf->discId($ctdb->mbid) );
foreach ( $rresults as $key => $rr ) {
$mbrr = $rr->getRelease();
}
}
catch ( ResponseError $e ) {
// echo $e->getMessage() . " ";
}
printf('<center>');
if ($mbrr && $mbrr->getAsin())
{
include 'table_start.php';
$imgurl = 'http://ec1.images-amazon.com/images/P/' . $mbrr->getAsin() . '.01.MZZZZZZZ.jpg';
#$imgurl = 'http://images.amazon.com/images/P/' . $mbrr->getAsin() . '.01._SCLZZZZZZZ_PU_PU-5_.jpg';
printf('<img src="%s">', $imgurl);
include 'table_end.php';
printf('<br><br>');
}
include 'table_start.php';
?>
<table border=0 cellspacing=0 cellpadding=6>
<?php
printf('<tr><td>Full TOC</td><td>%s</td></tr>', $ctdb->fulltoc);
printf('<tr><td>Artist</td><td>%s</td></tr>', $artist);
if ($mbrr && $mbrr->getArtist()->getName() != $artist)
printf('<tr><td>Artist (MB)</td><td>%s</td></tr>', $mbrr->getArtist()->getName());
printf('<tr><td>Title</td><td>%s</td></tr>', $title);
if ($mbrr && $mbrr->getTitle() != $title)
printf('<tr><td>Title (MB)</td><td>%s</td></tr>', $mbrr->getTitle());
printf('<tr><td>MusicbrainzId</td><td>%s%s</a></tr>', $link, $ctdb->mbid);
?>
</table>
<?php include 'table_end.php'; ?>
</center>
</body>
</html>

View File

@@ -75,15 +75,9 @@ if ($size == 0) {
}
$id = $_POST['id'];
$err = sscanf($id, "%03d-%04x%04x-%04x%04x-%04x%04x", $tracks, $id1a, $id1b, $id2a, $id2b, $cddbida, $cddbidb);
$parsedid = sprintf("%03d-%04x%04x-%04x%04x-%04x%04x", $tracks, $id1a, $id1b, $id2a, $id2b, $cddbida, $cddbidb);
if ($id != $parsedid)
die("bad id ". $id);
$target_path = sprintf("parity/%x/%x/%x/%s", $id1b & 15, ($id1b >> 4) & 15, ($id1b >> 8) & 15, $parsedid);
$target_file = sprintf("%s/ctdb.bin", $target_path, $parsedid);
$target_path = phpCTDB::discid2path($id);
@mkdir($target_path, 0777, true);
$target_file = sprintf("%s/ctdb.bin", $target_path);
$ctdb = new phpCTDB($tmpname);
$ctdb1 = @file_exists($target_file) ? new phpCTDB($target_file) : false;
@@ -162,7 +156,7 @@ fwrite($listfp, "\n");
fclose($listfp);
if ($merging)
printf("%s has been updated", $parsedid);
printf("%s has been updated", $id);
else
printf("%s has been uploaded", $parsedid);
printf("%s has been uploaded", $id);
?>

View File

@@ -0,0 +1,9 @@
</td>
<td background="img/bg_right_border.jpg"></td>
</tr>
<tr>
<td width="4" height="4"><img src="img/bottom_left_corner.jpg" width="4" height="4"></td>
<td background="img/bg_bottom.jpg"></td>
<td width="4" height="4"><img src="img/bottom_right_corner.jpg" width="4" height="4"></td>
</tr>
</table>

View File

@@ -0,0 +1,10 @@
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4" height="4"><img src="img/top_left_corner.jpg" width="4" height="4"></td>
<td background="img/bg_top_border.jpg"></td>
<td width="4" height="4"><img src="img/top_right_corner.jpg" width="4" height="4"></td>
</tr>
<tr>
<td width="4" background="img/bg_left_border.jpg"></td>
<td align="center" valign="middle">