diff --git a/CUETools.CTDB/Web/about.php b/CUETools.CTDB/Web/about.php new file mode 100644 index 0000000..b0e7d47 --- /dev/null +++ b/CUETools.CTDB/Web/about.php @@ -0,0 +1,35 @@ + +

What's it for?

+You probably heard about AccurateRip, a wonderfull database of CD rip checksums, which helps you make sure your CD rip is an exact copy of original CD. What it can tell you is how many other people got the same data when copying this CD. + +CUETools Database is an extension of this idea. + +

What are the advantages?

+ +

What are the downsides and limitations?

+ +

How many errors can a rip contain and still be repairable?

+ +

What information does the database contain per each submission?

+ + + diff --git a/CUETools.CTDB/Web/img/bg_bottom.jpg b/CUETools.CTDB/Web/img/bg_bottom.jpg new file mode 100644 index 0000000..668b9a1 Binary files /dev/null and b/CUETools.CTDB/Web/img/bg_bottom.jpg differ diff --git a/CUETools.CTDB/Web/img/bg_left_border.jpg b/CUETools.CTDB/Web/img/bg_left_border.jpg new file mode 100644 index 0000000..90756df Binary files /dev/null and b/CUETools.CTDB/Web/img/bg_left_border.jpg differ diff --git a/CUETools.CTDB/Web/img/bg_right_border.jpg b/CUETools.CTDB/Web/img/bg_right_border.jpg new file mode 100644 index 0000000..4fed854 Binary files /dev/null and b/CUETools.CTDB/Web/img/bg_right_border.jpg differ diff --git a/CUETools.CTDB/Web/img/bg_top_border.jpg b/CUETools.CTDB/Web/img/bg_top_border.jpg new file mode 100644 index 0000000..d3528eb Binary files /dev/null and b/CUETools.CTDB/Web/img/bg_top_border.jpg differ diff --git a/CUETools.CTDB/Web/img/bottom_left_corner.jpg b/CUETools.CTDB/Web/img/bottom_left_corner.jpg new file mode 100644 index 0000000..229d9d1 Binary files /dev/null and b/CUETools.CTDB/Web/img/bottom_left_corner.jpg differ diff --git a/CUETools.CTDB/Web/img/bottom_right_corner.jpg b/CUETools.CTDB/Web/img/bottom_right_corner.jpg new file mode 100644 index 0000000..46e68c3 Binary files /dev/null and b/CUETools.CTDB/Web/img/bottom_right_corner.jpg differ diff --git a/CUETools.CTDB/Web/img/top_left_corner.jpg b/CUETools.CTDB/Web/img/top_left_corner.jpg new file mode 100644 index 0000000..0e6c0b3 Binary files /dev/null and b/CUETools.CTDB/Web/img/top_left_corner.jpg differ diff --git a/CUETools.CTDB/Web/img/top_right_corner.jpg b/CUETools.CTDB/Web/img/top_right_corner.jpg new file mode 100644 index 0000000..0f3332d Binary files /dev/null and b/CUETools.CTDB/Web/img/top_right_corner.jpg differ diff --git a/CUETools.CTDB/Web/index.php b/CUETools.CTDB/Web/index.php index 054632d..b652e88 100644 --- a/CUETools.CTDB/Web/index.php +++ b/CUETools.CTDB/Web/index.php @@ -1,77 +1,49 @@ - $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 (--$n <= 0) - break; -} -fclose($fp); -printf("

Recent additions:

"); -include 'table_start.php'; -?> - - -$imgs = ''; -if ($lines) foreach(array_reverse($lines) as $line) { - $ctdb = new phpCTDB($line); - $disc = $ctdb->db['discs'][0]; - $ctdb->ParseToc(); - //$id = @$disc['MBID']['value']; - $artist = @$disc['ART ']['value']; - $title = @$disc['nam ']['value']; - $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($ctdb->mbid) ); - foreach ( $rresults as $key => $rr ) { - $rr = $rr->getRelease(); - $artist = $rr->getArtist()->getName(); - $title = $rr->getTitle(); - $imgs = $imgs . ''; - } - } - catch ( ResponseError $e ) { - // echo $e->getMessage() . " "; - } - } - printf('', htmlspecialchars($artist), htmlspecialchars($title), $ctdb->mbid, $discid, $discid, $ctdbid, $ctdbid); -} -printf('', $count * floor(($start - 1) / $count)); -printf("
ArtistAlbumDisc IdCTDB Id
%s%s%s%08x
More
"); -include 'table_end.php' ; -//printf('%s', $imgs); -printf("
"); -?> - - + pg_num_rows($result)) + $count = pg_num_rows($result); +if ($start == '') $start = pg_num_rows($result) - $count; + +printf("

Recent additions:

"); +include 'list.php'; +pg_free_result($result); +printf("
"); +?> + + diff --git a/CUETools.CTDB/Web/list.php b/CUETools.CTDB/Web/list.php new file mode 100644 index 0000000..7d81a05 --- /dev/null +++ b/CUETools.CTDB/Web/list.php @@ -0,0 +1,13 @@ + + += $start; $i--) { + $record = pg_fetch_array($result, $i); + printf('', urlencode($record['artist']), $record['artist'], $record['title'], $record['discid'], $record['discid'], $record['discid'], $record['ctdbid'], $record['ctdbid'], $record['confidence']); +} +if ($start > 0) printf('', $count * floor(($start - 1) / $count), $url); +printf("
ArtistAlbumDisc IdCTDB IdAR
%s%s%s%08x%d
More
"); +include 'table_end.php' ; +?> diff --git a/CUETools.CTDB/Web/logo_start.php b/CUETools.CTDB/Web/logo_start.php index 525bc13..79897f1 100644 --- a/CUETools.CTDB/Web/logo_start.php +++ b/CUETools.CTDB/Web/logo_start.php @@ -1,62 +1,81 @@ - - - -CUETools DB - - - - - - - - - - - - - - - -
- -
AboutCUETools
-
+ + + +CUETools DB + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
HomePopularAboutCUETools
+ +
+
diff --git a/CUETools.CTDB/Web/phpctdb/ctdb.php b/CUETools.CTDB/Web/phpctdb/ctdb.php index 135c7c7..afa7820 100644 --- a/CUETools.CTDB/Web/phpctdb/ctdb.php +++ b/CUETools.CTDB/Web/phpctdb/ctdb.php @@ -3,88 +3,267 @@ class phpCTDB{ private $fp; - private $fpstats; - private $atoms; - public $db; - public $fulltoc; - public $mbid; + private $fpstats; + private $atoms; + public $db; + public $fulltoc; function __construct($target_file) { - $this->fp = fopen($target_file, 'rb'); + $this->fp = fopen($target_file, 'rb'); $this->fpstats = fstat($this->fp); $this->atoms = $this->parse_container_atom(0, $this->fpstats['size']); - $this->db = false; + $this->db = false; foreach ($this->atoms as $entry) if($entry['name'] == 'CTDB') $this->db = $entry; } - function __destruct() { + function __destruct() { fclose($this->fp); - } + } function ParseTOC() { $disc = $this->db['discs'][0]; $this->fulltoc = ''; - $mbtoc = ''; + $totalcount = 0; + $firstaudio = 0; + $lastaudio = 0; 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; - } + $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)); + if ($isaudio == 0 && $totalcount!=0) + $pos += 11400; + $this->fulltoc = sprintf('%s %d', $this->fulltoc, $pos); + $pos += $length; + $totalcount ++; + if ($isaudio != 0) + $lastaudio = $totalcount; + if ($isaudio != 0 && $firstaudio == 0) + $firstaudio = $totalcount; + } } - $this->fulltoc = sprintf('1 %d %d%s', $trackcount, $pos, $this->fulltoc); - $mbtoc = sprintf('01%02X%08X%s', $trackcount, $pos, $mbtoc); + if ($trackcount != $totalcount) + die('wrong trackcount'); + $this->fulltoc = sprintf('%d %d %d %d%s', $firstaudio, $lastaudio, $totalcount, $pos, $this->fulltoc); + } + + static function toc2mbtoc($fulltoc) + { + $ids = explode(' ', $fulltoc); + $mbtoc = sprintf('%d %d', $ids[0], $ids[1]); + if ($ids[1] == $ids[2]) + { + for ($tr = 3; $tr < count($ids); $tr++) + $mbtoc = sprintf('%s %d', $mbtoc, $ids[$tr]); + } else // Enhanced CD + { + $mbtoc = sprintf('%s %d', $mbtoc, $ids[$ids[1] + 4] - 11400); + for ($tr = 4; $tr < $ids[1] + 4; $tr++) + $mbtoc = sprintf('%s %d', $mbtoc, $ids[$tr]); + } + return $mbtoc; + } + + static function toc2mbid($fulltoc) + { + $ids = explode(' ', $fulltoc); + $mbtoc = sprintf('%02X%02X', $ids[0], $ids[1]); + if ($ids[1] == $ids[2]) + { + for ($tr = 3; $tr < count($ids); $tr++) + $mbtoc = sprintf('%s%08X', $mbtoc, $ids[$tr]); + } else // Enhanced CD + { + $mbtoc = sprintf('%s%08X', $mbtoc, $ids[$ids[1] + 4] - 11400); + for ($tr = 4; $tr < $ids[1] + 4; $tr++) + $mbtoc = sprintf('%s%08X', $mbtoc, $ids[$tr]); + } +// echo $fulltoc . ':' . $mbtoc . '
'; $mbtoc = str_pad($mbtoc,804,'0'); - $this->mbid = str_replace('+', '.', str_replace('/', '_', str_replace('=', '-', base64_encode(pack("H*" , sha1($mbtoc)))))); + $mbid = str_replace('+', '.', str_replace('/', '_', str_replace('=', '-', base64_encode(pack("H*" , sha1($mbtoc)))))); + return $mbid; + } + + static function mblookup($mbid) + { + $mbconn = pg_connect("dbname=musicbrainz_db user=musicbrainz_user"); + if (!$mbconn) + return false; + $mbresult = pg_query_params('SELECT DISTINCT album' + . ' FROM album_cdtoc, cdtoc' + . ' WHERE album_cdtoc.cdtoc = cdtoc.id' + . ' AND cdtoc.discid = $1', + array($mbid) + ); + $mbmeta = false; + while(true == ($mbrecord = pg_fetch_array($mbresult))) + { + $mbresult2 = pg_query_params('SELECT a.name as albumname, ar.name as artistname, coverarturl' + . ' FROM album a INNER JOIN albummeta m ON m.id = a.id, artist ar' + . ' WHERE a.id = $1' + . ' AND ar.id = a.artist', + array($mbrecord[0])); + $mbmeta[] = pg_fetch_array($mbresult2); + pg_free_result($mbresult2); + } + pg_free_result($mbresult); + return $mbmeta; + } + + function ctdb2pg($discid) + { + $disc = $this->db['discs'][0]; + $record = false; + $record['discid'] = $discid; + $record['ctdbid'] = $disc['CRC ']['int']; + $record['confidence'] = $disc['CONF']['int']; + $record['parity'] = base64_encode($this->read($disc['PAR ']['offset'], 16)); + $record['fulltoc'] = $this->fulltoc; + $record['userid'] = $disc['USER']['value']; + $record['agent'] = $disc['TOOL']['value']; + $record['time'] = date ("Y-m-d H:i:s"); + $record['artist'] = @$disc['ART ']['value']; + $record['title'] = @$disc['nam ']['value']; + return $record; + } + + static function pg2ctdb($dbconn, $id) + { + $target_path = phpCTDB::discid2path($id); + + $result = pg_query_params($dbconn, "SELECT * FROM submissions WHERE discid=$1", array($id)) + or die('Query failed: ' . pg_last_error()); + if (pg_num_rows($result) < 1) die('not found'); + + $totalconf = 0; + $newctdb = false; + $newctdb['name'] = 'CTDB'; + $newhead = false; + $newhead['name'] = 'HEAD'; + $newtotal = false; + $newtotal['name'] = 'TOTL'; + $newtotal['value'] = phpCTDB::BigEndian2String($totalconf,4); + $newhead['subatoms'][] = $newtotal; + $newctdb['subatoms'][] = $newhead; + + while (TRUE == ($record = pg_fetch_array($result))) + { + $totalconf += $record['confidence']; + $newdisc = false; + $newdisc['name'] = 'DISC'; + + $newatom = false; + $newatom['name'] = 'CRC '; + $newatom['value'] = phpCTDB::Hex2String(sprintf('%08x',$record['ctdbid'])); + $newdisc['subatoms'][] = $newatom; + + $newatom = false; + $newatom['name'] = 'NPAR'; + $newatom['value'] = phpCTDB::BigEndian2String(8,4); + $newdisc['subatoms'][] = $newatom; + + $newatom = false; + $newatom['name'] = 'CONF'; + $newatom['value'] = phpCTDB::BigEndian2String((int)($record['confidence']),4); + $newdisc['subatoms'][] = $newatom; + + $newatom = false; + $newatom['name'] = 'PAR '; + $newatom['value'] = base64_decode($record['parity']); + $newdisc['subatoms'][] = $newatom; + + $newctdb['subatoms'][] = $newdisc; + } + + pg_free_result($result); + + $newctdb['subatoms'][0]['subatoms'][0]['value'] = phpCTDB::BigEndian2String($totalconf,4); + + $ftyp=false; + $ftyp['name'] = 'ftyp'; + $ftyp['value'] = 'CTDB'; + + $tname = sprintf("%s/ctdb.tmp", $target_path); + $tfp = fopen($tname, 'wb'); + phpCTDB::unparse_atom($tfp,$ftyp); + phpCTDB::unparse_atom($tfp,$newctdb); + fclose($tfp); + if(!rename($tname,sprintf("%s/ctdb.bin", $target_path))) + die('error uploading file ' . $target_path); + } + + static function Hex2Int($hex_word, $signed = false) + { + $int_value = 0; + $byte_wordlen = strlen($hex_word); + for ($i = 0; $i < $byte_wordlen; $i++) { + sscanf($hex_word{$i}, "%x", $digit); + $int_value += $digit * pow(16, ($byte_wordlen - 1 - $i)); + } + if ($signed) { + $sign_mask_bit = 0x80 << 24; + if ($int_value & $sign_mask_bit) { + $int_value = 0 - ($int_value & ($sign_mask_bit - 1)); + } + } + return $int_value; } static function BigEndian2Int($byte_word, $signed = false) { - $int_value = 0; - $byte_wordlen = strlen($byte_word); + $int_value = 0; + $byte_wordlen = strlen($byte_word); - for ($i = 0; $i < $byte_wordlen; $i++) { - $int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i)); - } + for ($i = 0; $i < $byte_wordlen; $i++) { + $int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i)); + } - if ($signed) { - $sign_mask_bit = 0x80 << (8 * ($byte_wordlen - 1)); - if ($int_value & $sign_mask_bit) { - $int_value = 0 - ($int_value & ($sign_mask_bit - 1)); - } - } + if ($signed) { + $sign_mask_bit = 0x80 << (8 * ($byte_wordlen - 1)); + if ($int_value & $sign_mask_bit) { + $int_value = 0 - ($int_value & ($sign_mask_bit - 1)); + } + } - return $int_value; + return $int_value; + } + + static function Hex2String($number) + { + $intstring = ''; + $hex_word = str_pad($number, 8, '0', STR_PAD_LEFT); + for ($i = 0; $i < 4; $i++) { + sscanf(substr($hex_word, $i*2, 2), "%x", $number); + $intstring = $intstring.chr($number); + } + return $intstring; } static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { - $intstring = ''; - while ($number > 0) { - if ($synchsafe) { - $intstring = $intstring.chr($number & 127); - $number >>= 7; - } else { - $intstring = $intstring.chr($number & 255); - $number >>= 8; - } - } - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); + $intstring = ''; + while ($number > 0) { + if ($synchsafe) { + $intstring = $intstring.chr($number & 127); + $number >>= 7; + } else { + $intstring = $intstring.chr($number & 255); + $number >>= 8; + } + } + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); } static function BigEndian2String($number, $minbytes=1, $synchsafe=false) { - return strrev(phpCTDB::LittleEndian2String($number, $minbytes, $synchsafe)); + return strrev(phpCTDB::LittleEndian2String($number, $minbytes, $synchsafe)); } - static function discid2path($id) + 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); @@ -105,85 +284,87 @@ class phpCTDB{ static function unparse_atom($fp, $atom) { -// printf('unparse_atom(%s)
', $atom['name']); - $offset = ftell($fp); - fwrite($fp, phpCTDB::BigEndian2String(0, 4)); - fwrite($fp, $atom['name']); - if (@$atom['subatoms']) - foreach ($atom['subatoms'] as $subatom) - phpCTDB::unparse_atom($fp, $subatom); - else if ($atom['value']) - fwrite($fp, $atom['value']); - else - die(sprintf("couldn't write long atom %s: size %d", $atom['name'], $atom['size'])); - $pos = ftell($fp); - fseek($fp, $offset, SEEK_SET); - fwrite($fp, phpCTDB::BigEndian2String($pos - $offset, 4)); - fseek($fp, $pos, SEEK_SET); +// printf('unparse_atom(%s)
', $atom['name']); + $offset = ftell($fp); + fwrite($fp, phpCTDB::BigEndian2String(0, 4)); + fwrite($fp, $atom['name']); + if (@$atom['subatoms']) + foreach ($atom['subatoms'] as $subatom) + phpCTDB::unparse_atom($fp, $subatom); + else if ($atom['value']) + fwrite($fp, $atom['value']); + else + die(sprintf("couldn't write long atom %s: size %d", $atom['name'], $atom['size'])); + $pos = ftell($fp); + fseek($fp, $offset, SEEK_SET); + fwrite($fp, phpCTDB::BigEndian2String($pos - $offset, 4)); + fseek($fp, $pos, SEEK_SET); } - function read($offset, $len) - { - fseek($this->fp, $offset, SEEK_SET); - return fread($this->fp, $len); - } + function read($offset, $len) + { + fseek($this->fp, $offset, SEEK_SET); + return fread($this->fp, $len); + } function parse_container_atom($offset, $len) { -// printf('parse_container_atom(%d, %d)
', $offset, $len); - $atoms = false; - $fin = $offset + $len; - while ($offset < $fin) { - fseek($this->fp, $offset, SEEK_SET); - $atom_header = fread($this->fp, 8); - $atom_size = phpCTDB::BigEndian2Int(substr($atom_header, 0, 4)); - $atom_name = substr($atom_header, 4, 4); - $atom['name'] = $atom_name; - $atom['size'] = $atom_size - 8; - $atom['offset'] = $offset + 8; - if ($atom_size - 8 <= 256) - $atom['value'] = fread($this->fp, $atom_size - 8); - else - $atom['value'] = false; -// echo $len, ':', $offset, ":", $atom_size, ":", $atom_name, '
'; - if ($atom_name == 'CTDB' || $atom_name == 'DISC' || $atom_name == 'TOC ' || ($atom_name == 'HEAD' && ($atom_size != 28 || 256 != phpCTDB::BigEndian2Int(substr($atom['value'],0,4))))) - { - $atom['subatoms'] = $this->parse_container_atom($offset + 8, $atom_size - 8); - foreach ($atom['subatoms'] as $param) - switch ($param['name']) { - case 'HEAD': - case 'TOC ': - case 'CRC ': - case 'MBID': - case 'ART ': - case 'nam ': - case 'NPAR': - case 'CONF': - case 'TOTL': - case 'PAR ': - $atom[$param['name']] = $param; - break; - case 'DISC': - $atom['discs'][] = $param; - break; - } - } else - $atom['subatoms'] = false; - switch ($atom_name) - { - case 'CRC ': - case 'NPAR': - case 'CONF': - case 'TOTL': - $atom['int'] = phpCTDB::BigEndian2Int($atom['value']); - break; - } - $offset += $atom_size; - $atoms[] = $atom; - } - if ($offset > $fin) - die(printf("bad atom: offset=%d, fin=%d", $offset, $fin)); - return $atoms; +// printf('parse_container_atom(%d, %d)
', $offset, $len); + $atoms = false; + $fin = $offset + $len; + while ($offset < $fin) { + fseek($this->fp, $offset, SEEK_SET); + $atom_header = fread($this->fp, 8); + $atom_size = phpCTDB::BigEndian2Int(substr($atom_header, 0, 4)); + $atom_name = substr($atom_header, 4, 4); + $atom['name'] = $atom_name; + $atom['size'] = $atom_size - 8; + $atom['offset'] = $offset + 8; + if ($atom_size - 8 <= 256) + $atom['value'] = fread($this->fp, $atom_size - 8); + else + $atom['value'] = false; +// echo $len, ':', $offset, ":", $atom_size, ":", $atom_name, '
'; + if ($atom_name == 'CTDB' || $atom_name == 'DISC' || $atom_name == 'TOC ' || ($atom_name == 'HEAD' && ($atom_size != 28 || 256 != phpCTDB::BigEndian2Int(substr($atom['value'],0,4))))) + { + $atom['subatoms'] = $this->parse_container_atom($offset + 8, $atom_size - 8); + foreach ($atom['subatoms'] as $param) + switch ($param['name']) { + case 'HEAD': + case 'TOC ': + case 'CRC ': + case 'USER': + case 'TOOL': + case 'MBID': + case 'ART ': + case 'nam ': + case 'NPAR': + case 'CONF': + case 'TOTL': + case 'PAR ': + $atom[$param['name']] = $param; + break; + case 'DISC': + $atom['discs'][] = $param; + break; + } + } else + $atom['subatoms'] = false; + switch ($atom_name) + { + case 'CRC ': + case 'NPAR': + case 'CONF': + case 'TOTL': + $atom['int'] = phpCTDB::BigEndian2Int($atom['value']); + break; + } + $offset += $atom_size; + $atoms[] = $atom; + } + if ($offset > $fin) + die(printf("bad atom: offset=%d, fin=%d", $offset, $fin)); + return $atoms; } } ?> diff --git a/CUETools.CTDB/Web/robots.txt b/CUETools.CTDB/Web/robots.txt new file mode 100644 index 0000000..6072cbb --- /dev/null +++ b/CUETools.CTDB/Web/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Disallow: /show.php +Disallow: /top.php +Disallow: /parity/ diff --git a/CUETools.CTDB/Web/show.php b/CUETools.CTDB/Web/show.php index 8eb0cfc..3358fbd 100644 --- a/CUETools.CTDB/Web/show.php +++ b/CUETools.CTDB/Web/show.php @@ -1,55 +1,98 @@ -db['discs'][0]; -//$id = @$disc['MBID']['value']; -$ctdb->ParseTOC(); -$artist = @$disc['ART ']['value']; -$title = @$disc['nam ']['value']; -$link = ''; -$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('
'); -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('', $imgurl); - include 'table_end.php'; - printf('

'); -} -include 'table_start.php'; -?> - -', $ctdb->fulltoc); -printf('', $artist); -if ($mbrr && $mbrr->getArtist()->getName() != $artist) -printf('', $mbrr->getArtist()->getName()); -printf('', $title); -if ($mbrr && $mbrr->getTitle() != $title) -printf('', $mbrr->getTitle()); -printf('', $link, $ctdb->mbid); -?> -
Full TOC%s
Artist%s
Artist (MB)%s
Title%s
Title (MB)%s
MusicbrainzId%s%s
- -
- - + 1) die('not unique'); +$record = pg_fetch_array($result); +pg_free_result($result); + +$mbid = phpCTDB::toc2mbid($record['fulltoc']); +$mbmeta = phpCTDB::mblookup($mbid); + +printf('
'); +$imgfound = false; +if ($mbmeta) + foreach ($mbmeta as $mbr) + if ($mbr['coverarturl']) + { + if (!$imgfound) include 'table_start.php'; + printf('', $mbr['coverarturl']); + $imgfound = true; + } +if ($imgfound) { + include 'table_end.php'; + printf('

'); +} +include 'table_start.php'; +?> + +', $discid); +printf('', $ctdbid); +printf('', phpCTDB::toc2mbtoc($record['fulltoc']), $mbid, $mbmeta ? count($mbmeta) : "-"); +//printf('', $record['fulltoc']); +printf(''); +if ($record['artist'] != '') + printf('', $record['artist']); +if ($mbmeta) + foreach ($mbmeta as $mbr) + if ($mbr['artistname'] != $record['artist']) + printf('', $mbr['artistname']); +if ($record['title'] != '') + printf('', $record['title']); +if ($mbmeta) + foreach ($mbmeta as $mbr) + if ($mbr['albumname'] != $record['title']) + printf('', $mbr['albumname']); +?> +
Disc ID%s
CTDB ID%s
Musicbrainz ID%s (%s)
Full TOC%s
'); +?> + +', $trno, $trstartmsf, $trlenmsf, $trstart, $trend); +} +printf("
TrackStartLengthStart sectorEnd sector
%d%s%s%d%d
"); +printf('
Artist%s
Artist (MB)%s
Title%s
Title (MB)%s
+ +
+ + diff --git a/CUETools.CTDB/Web/submit.php b/CUETools.CTDB/Web/submit.php index 1320a14..a7e28ff 100644 --- a/CUETools.CTDB/Web/submit.php +++ b/CUETools.CTDB/Web/submit.php @@ -74,86 +74,27 @@ if ($size == 0) { return; } +$dbconn = pg_connect("dbname=ctdb user=ctdb_user") + or die('Could not connect: ' . pg_last_error()); + $id = $_POST['id']; $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; -$merging = $ctdb1 ? true : false; - -$ftyp['name'] = 'ftyp'; -$ftyp['value'] = 'CTDB'; - -$newctdb['name'] = 'CTDB'; - $newhead['name'] = 'HEAD'; - $newtotal['name'] = 'TOTL'; - $newtotal['value'] = $ctdb1 ? phpCTDB::BigEndian2String($ctdb1->db['HEAD']['TOTL']['int'] + 1,4) : $ctdb->db['HEAD']['TOTL']['value']; - $newhead['subatoms'][] = $newtotal; -$newctdb['subatoms'][] = $newhead; - -if ($ctdb1) -foreach ($ctdb1->db['subatoms'] as $disc) - if ($disc['name'] == 'DISC') - { - if ($crc == $disc['CRC ']['value']) - die("duplicate entry"); - - $newdisc = false; - $newdisc['name'] = 'DISC'; - $newdisc['subatoms'][] = $disc['CRC ']; - $newdisc['subatoms'][] = $disc['NPAR']; - $newdisc['subatoms'][] = $disc['CONF']; - $newpar['name'] = 'PAR '; - $newpar['value'] = $ctdb1->read($disc['PAR ']['offset'], 16); - $newdisc['subatoms'][] = $newpar; - $newctdb['subatoms'][] = $newdisc; - } - -$discs = 0; -foreach ($ctdb->db['subatoms'] as $disc) - if ($disc['name'] == 'DISC') - { - $crc = $disc['CRC ']['value']; - - $newdisc = false; - $newdisc['name'] = 'DISC'; - $newdisc['subatoms'][] = $disc['CRC ']; - $newdisc['subatoms'][] = $disc['NPAR']; - $newdisc['subatoms'][] = $disc['CONF']; - $newpar['name'] = 'PAR '; - $newpar['value'] = $ctdb->read($disc['PAR ']['offset'], 16); - $newdisc['subatoms'][] = $newpar; - $newctdb['subatoms'][] = $newdisc; - $discs++; - } -if ($discs > 1) - die('One disc at a time, please'); -if ($discs < 1) - die('No disc records found'); - -$tname = sprintf("%s/ctdb.tmp", $target_path); -$tfp = fopen($tname, 'wb'); -phpCTDB::unparse_atom($tfp,$ftyp); -phpCTDB::unparse_atom($tfp,$newctdb); -fclose($tfp); +$merging = @file_exists($target_file); +$ctdb->ParseTOC(); +$record = $ctdb->ctdb2pg($id); unset($ctdb); -unset($ctdb1); -$crca = phpCTDB::BigEndian2Int(substr($crc,0,2)); -$crcb = phpCTDB::BigEndian2Int(substr($crc,2,2)); -$destname = sprintf("%s/%04x%04x.bin", $target_path, $crca, $crcb); +$destname = sprintf("%s/%08x.bin", $target_path, $record['ctdbid']); if(!move_uploaded_file($tmpname, $destname)) die('error uploading file ' . $tmpname . ' to ' . $destname); -if(!rename($tname,sprintf("%s/ctdb.bin", $target_path))) - die('error uploading file ' . $target_path); +$subres = pg_insert($dbconn, 'submissions', $record); -$listfp = fopen("parity/list.txt", 'a'); -fwrite($listfp, $destname); -fwrite($listfp, "\n"); -fclose($listfp); +phpCTDB::pg2ctdb($dbconn, $id); if ($merging) printf("%s has been updated", $id); diff --git a/CUETools.CTDB/Web/table_end.php b/CUETools.CTDB/Web/table_end.php index 520a0e5..ebe80f2 100644 --- a/CUETools.CTDB/Web/table_end.php +++ b/CUETools.CTDB/Web/table_end.php @@ -1,9 +1,9 @@ - - - - - - - - - + + + + + + + + + diff --git a/CUETools.CTDB/Web/table_start.php b/CUETools.CTDB/Web/table_start.php index 0a32d34..b39065d 100644 --- a/CUETools.CTDB/Web/table_start.php +++ b/CUETools.CTDB/Web/table_start.php @@ -1,10 +1,10 @@ - - - - - - - - -
- + + + + + + + + +
+ diff --git a/CUETools.CTDB/Web/top.php b/CUETools.CTDB/Web/top.php new file mode 100644 index 0000000..ce0de21 --- /dev/null +++ b/CUETools.CTDB/Web/top.php @@ -0,0 +1,48 @@ +=100"; + $term = ' AND '; +} +$query = $query . " ORDER BY confidence"; +$result = pg_query($query) or die('Query failed: ' . pg_last_error()); +$start = @$_GET['start']; +if (pg_num_rows($result) == 0) + die('nothing found'); +if ($count > pg_num_rows($result)) + $count = pg_num_rows($result); +if ($start == '') $start = pg_num_rows($result) - $count; + +printf("

Popular discs:

"); +include 'list.php'; +pg_free_result($result); +printf("
"); +?> + +