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
110 changed files
with
21,333 additions
and
3,699 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,47 @@ | ||
# soundtrack.io | ||
soundtrack.io | ||
============= | ||
[![Build Status](https://img.shields.io/travis/martindale/soundtrack.io.svg?branch=soundtrack.io&style=flat-square)](https://travis-ci.org/martindale/soundtrack.io) | ||
[![Coverage Status](https://img.shields.io/coveralls/martindale/soundtrack.io/soundtrack.io.svg?style=flat-square)](https://coveralls.io/r/martindale/soundtrack.io) | ||
|
||
soundtrack.io is a collaborative online jukebox. | ||
soundtrack.io is a collaborative online jukebox. It is an experimental Internet radio platform. Vote on what plays next, like Reddit for music. Aggregates streams from sources like YouTube and SoundCloud, so when a song is queued, it has multiple locations to play from if any one source fails for any particular reason. | ||
|
||
## Getting Started | ||
|
||
Before you begin you will need to have nodejs, redis, and mongodb installed. | ||
Homebrew is recommended for OS X users. | ||
|
||
brew install nodejs mongodb redis | ||
redis-server & | ||
mongod & | ||
``` | ||
brew install nodejs mongodb redis | ||
``` | ||
|
||
Once you have them installed, go ahead and clone the repository. | ||
In the logged output, you'll find some instructions for starting both mongodb and redis – you can follow those instructions, or execute once with `redis-server & mongod &` | ||
|
||
git clone git@github.com:fractaloop/soundtrack.io.git | ||
Once you have them installed (and running!), go ahead and clone the repository. | ||
|
||
git clone git@github.com:martindale/soundtrack.io.git | ||
cd soundtrack.io | ||
|
||
You will need to fetch the dependencies and then you can start up the server. | ||
|
||
npm install | ||
node soundtrack.js | ||
|
||
### Testing Rooms | ||
Now that soundtrack has multiple rooms, you'll need to configure your local hostname lookups to point at the appropriate locations. In `/etc/hosts` (or equivalent for your OS): | ||
|
||
``` | ||
127.0.0.1 localhost.localdomain | ||
127.0.0.1 test.localhost.localdomain | ||
``` | ||
|
||
You'll need to add an entry for each subdomain you want to test. Also, the `.localdomain` component is important for sessions, as some browsers expect a top level domain for cookies to work correctly! | ||
|
||
## API | ||
|
||
Deleting tracks: | ||
`$.ajax('/playlist/520e6bda3cb680003700049c', { type: 'DELETE', data: { index: 1 } });` | ||
|
||
## Contributing | ||
Want to help? Claim something in [the "ready" column on our Waffle.io](https://waffle.io/martindale/soundtrack.io) by assigning it to yourself. | ||
|
||
[Fork. Commit. Pull request.](https://help.github.com/articles/fork-a-repo) |
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.