Skip to content

Commit

Permalink
Merge 2cfb842 into 7f6bfca
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Jun 26, 2015
2 parents 7f6bfca + 2cfb842 commit 5763e03
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 92 deletions.
50 changes: 50 additions & 0 deletions lib/ChangeTip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var rest = require('restler');
var moment = require('moment');

var ChangeTip = function(token) {
this.token = token;
this.base = 'https://api.changetip.com/v2/';
};

ChangeTip.prototype.get = function(url, params, cb) {
var self = this;

if (typeof params === 'function') {
cb = params;
params = {};
}

var qs = Object.keys( params ).map(function(k) {
return k + '=' + params[k];
});

rest.get( self.base + url + '?' + qs.join('&') , {
headers: {
'Authorization': 'Bearer ' + self.token
}
}).on('complete', function(data) {
cb( null , data );
});
};

ChangeTip.prototype.post = function(url, params, cb) {
var self = this;

if (typeof params === 'function') {
cb = params;
params = {};
}

console.log('posting...');

rest.post( self.base + url , {
headers: {
'Authorization': 'Bearer ' + self.token
},
data: params
}).on('complete', function(data) {
cb( null , data );
}).on('error', cb );
};

module.exports = ChangeTip;
6 changes: 6 additions & 0 deletions models/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ var PersonSchema = new Schema({
token: String,
updated: Date,
playlists: []
},
changetip: {
id: String,
username: String,
token: String,
updated: Date
}
}
, preferences: {
Expand Down
62 changes: 34 additions & 28 deletions models/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RoomSchema.methods.bind = function( soundtrack ) {
};
RoomSchema.methods.broadcast = function( msg , GLOBAL ) {
if (GLOBAL) return this.soundtrack.broadcast( msg );

var room = this;
var app = room.soundtrack.app;

Expand All @@ -52,10 +52,10 @@ RoomSchema.methods.broadcast = function( msg , GLOBAL ) {
};
RoomSchema.methods.queueTrack = function( track , curator , callback ) {
var room = this;

Track.findOne({ _id: track._id }).populate('_artist _credits').exec(function(err, realTrack) {
if (err || !realTrack) return callback('Could not acquire that track.');

var playlistItem = realTrack.toObject();

playlistItem._artist = {
Expand All @@ -71,27 +71,33 @@ RoomSchema.methods.queueTrack = function( track , curator , callback ) {
delete playlistItem.sources[ source ][ i ].data;
}
}

if (!playableSources) {
return callback({
status: 'error'
, message: 'No playable sources.'
});
}


var curatorObj = {
_id: curator._id
, username: curator.username
, slug: curator.slug
};

if (curator.profiles && curator.profiles.changetip && curator.profiles.changetip.username) {
curatorObj.changetip = curator.profiles.changetip.username;
}

room.playlist.push( _.extend( playlistItem , {
score: 0
, votes: {} // TODO: auto-upvote?
, timestamp: new Date()
, curator: {
_id: curator._id
, username: curator.username
, slug: curator.slug
}
, curator: curatorObj
} ) );

room.sortPlaylist();

room.savePlaylist(function() {
room.broadcast({
type: 'playlist:add',
Expand Down Expand Up @@ -121,9 +127,9 @@ RoomSchema.methods.savePlaylist = function( saved ) {
//console.log('as stringified', JSON.stringify( self.playlist ));

app.redis.set( app.config.database.name + ':rooms:' + self.slug + ':playlist', JSON.stringify( self.playlist ) );

app.rooms[ self.slug ] = self;

saved();
};

Expand All @@ -136,7 +142,7 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
var gain = 0;
var failpoint = MAXIMUM_PLAY_AGE;
}

if (typeof(failpoint) === 'function') {
var cb = failpoint;
var failpoint = MAXIMUM_PLAY_AGE;
Expand All @@ -146,7 +152,7 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
if (!failpoint) var failpoint = MAXIMUM_PLAY_AGE;

var query = {};

// must be queued by a real person
query._curator = { $exists: true };
// must have been played in this room
Expand Down Expand Up @@ -174,7 +180,7 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
timestamp: { $gte: (new Date()) - 3600 * 3 * 1000 }
}).exec(function(err, exclusions) {
query.exclusionIDs = exclusions.map(function(x) { return x._track.toString(); });

plays = plays.filter(function(x) {
//console.log('filtering ', x );
//console.log('exclusions checker,', x._track.toString() , 'in' , query.exclusionIDs , '?');
Expand All @@ -187,9 +193,9 @@ RoomSchema.methods.generatePool = function( gain , failpoint , cb ) {
if ((!plays) && (gain > failpoint)) return cb('init');

return cb( err , plays , query );

});

});
});

Expand Down Expand Up @@ -221,7 +227,7 @@ RoomSchema.methods.ensureQueue = function(callback) {
room.playlist.push( track );
return callback();
});

};
RoomSchema.methods.nextSong = function( done ) {
if (!done) var done = new Function();
Expand Down Expand Up @@ -265,11 +271,11 @@ RoomSchema.methods.startMusic = function( cb ) {

var now = Date.now();
var seekTo = (now - room.playlist[0].startTime) / 1000;

Track.findOne({ _id: room.track._id }).populate('_artist _artists').lean().exec(function(err, track) {
if (err || !track) return cb('no such track (severe error)');

// temporary collect exact matches...
// temporary collect exact matches...
// testing for future merging of track data for advances
var query = { _artist: track._artist._id , title: track.title, _id: { $ne: track._id } };
Track.find( query ).lean().exec(function(err, tracks) {
Expand All @@ -286,14 +292,14 @@ RoomSchema.methods.startMusic = function( cb ) {
sources: sources,
seekTo: seekTo
});

clearTimeout( room.trackTimer );
clearTimeout( room.permaTimer );

room.trackTimer = setTimeout(function() {
room.nextSong();
}, (room.track.duration - seekTo) * 1000 );

if (room.soundtrack.app.lastfm) {
room.setListeningActive( room.track , new Function() );
}
Expand All @@ -303,15 +309,15 @@ RoomSchema.methods.startMusic = function( cb ) {
var scrobbleTime = (room.track.duration > FOUR_MINUTES) ? FOUR_MINUTES : room.track.duration / 2;

room.permaTimer = setTimeout(function() {

async.parallel([
insertIntoPlayHistory,
scrobbleIfEnabled
], function(err, results) {
if (err) console.log(err);
console.log('play history updated and lastfm scrobbled!');
});

function insertIntoPlayHistory( done ) {
var play = new Play({
_track: room.track._id,
Expand All @@ -321,7 +327,7 @@ RoomSchema.methods.startMusic = function( cb ) {
});
play.save( done );
}

function scrobbleIfEnabled( done ) {
if (!room.soundtrack.app.lastfm) return done();
room.scrobbleActive( room.track , done );
Expand All @@ -331,7 +337,7 @@ RoomSchema.methods.startMusic = function( cb ) {
}

return cb();

});
});
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"mongoose-agency": "0.0.0",
"mongoose-slug": "~1.3.0",
"passport": "~0.1.17",
"passport-changetip": "0.0.1",
"passport-google-oauth": "^0.2.0",
"passport-local": "~0.1.6",
"passport-local-mongoose": "~0.2.4",
Expand Down
27 changes: 16 additions & 11 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ footer {

@media (max-width: 979px) {
body {padding:0;}

.container {
width: 100%;
margin-left:0;
margin-right:0;
}

footer {margin:0;}

#chat-form .input-block-level {
width: 275px;
}
Expand Down Expand Up @@ -363,42 +363,42 @@ footer {
margin-left:0;
margin-right:0;
}

footer {margin:0;}

}

@media (max-width:979px) and (min-width:768px){
#chat-form .input-block-level {
width: 85%;
}
}
}

@media (max-width: 979px) and (min-width: 945px) {
.row-fluid [class*="span"].padded-left {
padding-left:0;
width:290px;
}
}

@media (max-width: 944px) {
.row-fluid [class*="span"].padded-left {
width:100%;
padding-left:12px;
padding-right:12px;
}

#playlist {
height:auto;
max-height:200px;
}

.row-fluid [class*="span"].unpadded {
width:100%;
padding:0 12px;
margin:0;
}

#search-form .input-block-level {
width: 90%;
}
Expand All @@ -419,3 +419,8 @@ footer {
opacity: 1 !important;
transition-duration: 0s!important;
}

/* pointer patch from @chrisinajar */
.tooltip {
pointer-events: none;
}
Binary file added public/img/changetip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,16 @@ $(window).load(function() {
return false;
});

$(document).on('click', '*[data-action=tip-current-curator]', function(e) {
e.preventDefault();

$.post('/tips', function(data) {
if (data.errors) alert( data.errors );
});

return false;
});

$(document).on('click', '*[data-action=remove-queued-track]', function(e) {
e.preventDefault();
var self = this;
Expand Down
Loading

0 comments on commit 5763e03

Please sign in to comment.