Permalink
Browse files

Finishing a previous commit that converted from 16 character track an…

…d artist IDs to incremental IDs
  • Loading branch information...
jhurliman committed Apr 9, 2013
1 parent a736fca commit edf0cb8208babd4e8ac9bd258e386995f4baf62c
Showing with 40 additions and 33 deletions.
  1. +17 −18 controllers/fingerprinter.js
  2. +14 −6 models/mysql.js
  3. +4 −4 mysql.sql
  4. +5 −5 package.json
@@ -158,6 +158,8 @@ function bestMatchForQuery(fp, threshold, callback) {
if (matches.length === 1) {
if (matches[0].ascore / fp.codes.length >= MIN_MATCH_PERCENT) {
// Fetch metadata for the single match
+ log.debug('Single good match with actual score ' + matches[0].ascore +
+ '/' + fp.codes.length);
return getTrackMetadata(matches[0], matches,
'SINGLE_GOOD_MATCH_HISTOGRAM_DECREASED', callback);
} else {
@@ -302,11 +304,13 @@ function getActualScore(fp, match, threshold, slop) {
function ingest(fp, callback) {
var MAX_DURATION = 60 * 60 * 4;
+ fp.codever = fp.codever || fp.version;
+
log.info('Ingesting track "' + fp.track + '" by artist "' + fp.artist +
- '", ' + fp.length + ' seconds, ' + fp.codes.length + ' codes');
+ '", ' + fp.length + ' seconds, ' + fp.codes.length + ' codes (' + fp.codever + ')');
- if (!fp.codes.length || typeof fp.length !== 'number' || !fp.codever)
- return callback('Missing required track fields', null);
+ if (!fp.codes.length || typeof fp.length !== 'number' || !fp.codever || !fp.track || !fp.artist)
+ return callback('Missing required fields', null);
fp = cutFPLength(fp, MAX_DURATION);
@@ -326,7 +330,7 @@ function ingest(fp, callback) {
match.artist + '"');
var checkUpdateArtist = function() {
- if (!match.artist && fp.artist) {
+ if (!match.artist) {
// Existing artist is unnamed but we have a name now. Check if this
// artist name already exists in the database
log.debug('Updating track artist');
@@ -397,20 +401,15 @@ function ingest(fp, callback) {
log.debug('Track does not exist in the database yet, status ' +
res.status);
- // Check if we were given an artist name
- if (fp.artist) {
- // Does this artist already exist in the database?
- database.getArtistByName(fp.artist, function(err, artist) {
- if (err) { gMutex.release(); return callback(err, null); }
-
- if (!artist)
- createArtistAndTrack();
- else
- createTrack(artist.artist_id, artist.name);
- });
- } else {
- createArtistAndTrack();
- }
+ // Does this artist already exist in the database?
+ database.getArtistByName(fp.artist, function(err, artist) {
+ if (err) { gMutex.release(); return callback(err, null); }
+
+ if (!artist)
+ createArtistAndTrack();
+ else
+ createTrack(artist.artist_id, artist.name);
+ });
}
// Function for creating a new artist and new track
View
@@ -142,22 +142,30 @@ function addTrack(artistID, fp, callback) {
length = parseInt(length, 10);
// Sanity checks
- if (!artistID || artistID.length !== 16 || isNaN(length))
- return callback('Attempted to add track with missing fields', null);
+ if (!artistID)
+ return callback('Attempted to add track with missing artistID', null);
+ if (isNaN(length) || !length)
+ return callback('Attempted to add track with invalid duration "' + length + '"', null);
+ if (!fp.codever)
+ return callback ('Attempted to add track with missing code version (codever field)', null);
var sql = 'INSERT INTO tracks ' +
- '(name,artist_id,length,import_date) ' +
- 'VALUES (?,?,?,?)';
- client.query(sql, [fp.track, artistID, length, new Date()],
+ '(codever,name,artist_id,length,import_date) ' +
+ 'VALUES (?,?,?,?,NOW())';
+ client.query(sql, [fp.codever, fp.track, artistID, length],
function(err, info)
{
if (err) return callback(err, null);
if (info.affectedRows !== 1) return callback('Track insert failed', null);
var trackID = info.insertId;
- // Write out the codes to a file for bulk insertion into MySQL
var tempName = temp.path({ prefix: 'echoprint-' + trackID, suffix: '.csv' });
+ // HACK: Work around permission problem with temporary paths on OSX
+ if (tempName.indexOf('/var/folders/') === 0)
+ tempName = '/tmp/' + require('path').basename(tempName);
+
+ // Write out the codes to a file for bulk insertion into MySQL
writeCodesToFile(tempName, fp, trackID, function(err) {
if (err) return callback(err, null);
View
@@ -4,7 +4,7 @@
--
CREATE TABLE IF NOT EXISTS `artists` (
- `id` char(16) NOT NULL DEFAULT '',
+ `id` MEDIUMINT NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
@@ -16,10 +16,10 @@ CREATE TABLE IF NOT EXISTS `artists` (
--
CREATE TABLE IF NOT EXISTS `tracks` (
- `id` char(16) NOT NULL,
+ `id` MEDIUMINT NOT NULL AUTO_INCREMENT,
`codever` char(4) NOT NULL,
`name` varchar(255) DEFAULT NULL,
- `artist_id` char(16) NOT NULL,
+ `artist_id` MEDIUMINT NOT NULL,
`length` int(5) NOT NULL,
`import_date` datetime NOT NULL,
PRIMARY KEY (`id`,`codever`),
@@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `tracks` (
CREATE TABLE IF NOT EXISTS `codes` (
`code` int(7) NOT NULL,
`time` int(7) NOT NULL,
- `track_id` char(16) NOT NULL,
+ `track_id` MEDIUMINT NOT NULL,
PRIMARY KEY (`code`,`time`,`track_id`),
FOREIGN KEY (`track_id`) REFERENCES `tracks`(`id`) ON DELETE CASCADE
) DEFAULT CHARSET=utf8;
View
@@ -2,10 +2,10 @@
"name": "echoprint-server",
"version": "0.1.0",
"dependencies": {
- "mysql": "0.9.5",
- "winston": "0.5.9",
- "jade": "0.20.3",
- "async": "0.1.16",
- "temp": "0.4.0"
+ "mysql": "0.9.6",
+ "winston": "0.6.2",
+ "jade": "0.28.2",
+ "async": "0.2.6",
+ "temp": "0.5.0"
}
}

0 comments on commit edf0cb8

Please sign in to comment.