forked from FabricLabs/soundtrack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
100 changed files
with
20,473 additions
and
3,680 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
service_name: travis-ci |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ logs | |
results | ||
|
||
npm-debug.log | ||
config.js | ||
|
||
config.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
services: | ||
- mongodb | ||
- redis-server | ||
after_script: istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var config = require('./config'); | ||
|
||
var Monq = require('monq'); | ||
var monq = Monq('mongodb://localhost:27017/' + config.database.name ); | ||
var jobs = monq.queue( config.database.name ); | ||
|
||
/**/jobs.enqueue('artist:update', { id: '52166226a1d626d547000338' } , function(err, job) { | ||
/*/jobs.enqueue('test', { id: '5390073d1559212f560012b4' } , function(err, job) {/**/ | ||
console.log('enqueued: ' , job ); | ||
process.exit(); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,192 @@ | ||
var rest = require('restler') | ||
, _ = require('underscore'); | ||
, _ = require('underscore') | ||
, async = require('async'); | ||
|
||
module.exports = { | ||
list: function(req, res, next) { | ||
Artist.find({}).sort('name').exec(function(err, artists) { | ||
res.render('artists', { | ||
artists: artists | ||
var limit = (req.param('limit')) ? req.param('limit') : 100; | ||
var query = (req.param('q')) ? { name: new RegExp('(.*)'+req.param('q')+'(.*)', 'i') } : undefined; | ||
|
||
async.parallel([ | ||
function(done) { | ||
Artist.count().exec( done ); | ||
}, | ||
function(done) { | ||
Artist.find( query ).sort('name').limit( limit ).exec( function(err, artists) { | ||
async.map( artists , function(x, countComplete) { | ||
Track.count({ $or: [ | ||
{ _artist: x._id } | ||
, { _credits: x._id } | ||
] }).exec( function(err, trackCount) { | ||
x = x.toObject(); | ||
x.tracks = trackCount; | ||
countComplete( err, x ); | ||
}); | ||
}, done ); | ||
}); | ||
} | ||
], function(err, results) { | ||
res.format({ | ||
json: function() { | ||
res.send( results[1].map(function(x) { | ||
if (typeof(x.toObject) == 'function') { | ||
x = x.toObject(); | ||
} | ||
//x.value = x._id; | ||
x.value = x.name; | ||
return x; | ||
}) ); | ||
}, | ||
html: function() { | ||
res.render('artists', { | ||
count: results[0] | ||
, limit: limit | ||
, artists: results[1] | ||
}); | ||
} | ||
}); | ||
}); | ||
}, | ||
view: function(req, res, next) { | ||
delete: function(req, res, next) { | ||
Artist.findOne({ slug: req.param('artistSlug') }).exec(function(err, artist) { | ||
if (!artist) { return next(); } | ||
|
||
Track.find({ $or: [ | ||
{ _artist: artist._id } | ||
, { _credits: artist._id } | ||
] }).exec(function(err, tracks) { | ||
|
||
res.send(tracks.length); | ||
|
||
}); | ||
|
||
}); | ||
}, | ||
edit: function(req, res, next) { | ||
Artist.findOne({ $or: [ | ||
{ _id: req.param('artistID') } | ||
, { slug: req.param('artistSlug') } | ||
, { slugs: req.param('artistSlug') } | ||
] }).sort('_id').exec(function(err, artist) { | ||
if (!artist) { return next(); } | ||
|
||
artist.name = req.param('name') || artist.name; | ||
artist.bio = req.param('bio') || artist.bio; | ||
|
||
// reset updated field, for re-crawl | ||
artist.tracking.tracks.updated = undefined; | ||
|
||
Artist.find({ $or: [ | ||
{ _id: req.param('artistID') } | ||
, { slug: req.param('artistSlug') } | ||
, { slugs: req.param('artistSlug') } | ||
] }).exec(function(err, artists) { | ||
|
||
var allArtistIDs = artists.map(function(x) { return x._id; }); | ||
|
||
artists.forEach(function(a) { | ||
artist.slugs = _.union( artist.slugs , a.slugs ); | ||
}); | ||
artist.slugs = _.uniq( artist.slugs ); | ||
|
||
async.parallel([ | ||
function(done) { | ||
Track.update({ _artist: { $in: allArtistIDs } }, { | ||
_artist: artist._id.toString() | ||
}, { multi: true }, done ); | ||
}, | ||
function(done) { | ||
Track.update({ '_credits.$': { $in: allArtistIDs } }, { | ||
$addToSet: { _credits: artist._id } | ||
}, { multi: true }, done ); | ||
} | ||
], function(err, results) { | ||
if (err) { console.log(err); } | ||
|
||
artist.save(function(err) { | ||
if (err) { console.log(err); } | ||
|
||
res.format({ | ||
json: function() { | ||
res.send({ | ||
status: 'success' | ||
, message: 'artist edited successfully' | ||
}); | ||
}, | ||
html: function() { | ||
res.redirect('/' + artist.slug ); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
view: function(req, res, next) { | ||
Person.count({ slug: req.param('artistSlug') }).exec(function(err, num) { | ||
if (num) return next(); | ||
|
||
var limit = (req.param('limit')) ? req.param('limit') : 100; | ||
|
||
Track.find({ _artist: artist._id }).exec(function(err, tracks) { | ||
Artist.findOne({ $or: [ | ||
{ slug: req.param('artistSlug') } | ||
, { slugs: req.param('artistSlug') } | ||
] }).exec(function(err, artist) { | ||
if (!artist) { return next(); } | ||
|
||
// handle artist renames | ||
if (req.param('artistSlug') !== artist.slug) { | ||
return res.redirect('/' + artist.slug); | ||
} | ||
|
||
Play.aggregate([ | ||
{ $match: { _track: { $in: tracks.map(function(x) { return x._id; }) } } }, | ||
{ $group: { _id: '$_track', count: { $sum: 1 } } }, | ||
{ $sort: { 'count': -1 } } | ||
], function(err, trackScores) { | ||
Track.find({ $or: [ | ||
{ _artist: artist._id } | ||
, { _credits: artist._id } | ||
] }).populate('_artist').exec(function(err, tracks) { | ||
|
||
res.render('artist', { | ||
artist: artist | ||
, tracks: tracks.map(function(track) { | ||
var plays = _.find( trackScores , function(x) { return x._id.toString() == track._id.toString() } ); | ||
track.plays = (plays) ? plays.count : 0; | ||
return track; | ||
}) | ||
Play.aggregate([ | ||
{ $match: { _track: { $in: tracks.map(function(x) { return x._id; }) } } }, | ||
{ $group: { _id: '$_track', count: { $sum: 1 } } }, | ||
{ $sort: { 'count': -1 } } | ||
], function(err, trackScores) { | ||
|
||
tracks = tracks.map(function(track) { | ||
var plays = _.find( trackScores , function(x) { return x._id.toString() == track._id.toString() } ); | ||
track.plays = (plays) ? plays.count : 0; | ||
return track; | ||
}).sort(function(a, b) { | ||
return b.plays - a.plays; | ||
}); | ||
|
||
var trackCount = tracks.length; | ||
|
||
tracks = tracks.slice( 0 , limit - 1 ); | ||
|
||
res.format({ | ||
json: function() { | ||
res.send( artist ); | ||
}, | ||
html: function() { | ||
res.render('artist', { | ||
artist: artist | ||
, tracks: tracks | ||
, trackCount: trackCount | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
if (req.app.config.jobs && req.app.config.jobs.enabled) { | ||
req.app.agency.publish('artist:update', { | ||
id: artist._id | ||
, timeout: 3 * 60 * 1000 | ||
}, function(err, job) { | ||
console.log('update artist completed'); | ||
}); | ||
} | ||
|
||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.