Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Magnet Streaming #189

Open
wants to merge 1 commit into
base: soundtrack.io
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/soundtrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var util = require('../util');
var rest = require('restler');
var async = require('async');
var slug = require('speakingurl');
var meta = require('musicmetadata');

var YouTube = require('./YouTube');

Expand Down Expand Up @@ -142,6 +143,28 @@ Soundtrack.prototype.trackFromSource = function(source, id, data, sourceCallback
default:
sourceCallback('Unknown source: ' + source);
break;
case 'magnet':
Track.findOne({ 'sources.magnet.id': id }).populate('_artist').exec(function(err, track) {
if (track) return sourceCallback(err, track);

var track = new Track({
title: data.title || 'Unknown',
duration: data.duration || 300
});

var artistName = data.artist || 'unknown';

Artist.findOne({ slug: slug(artistName) }).exec(function(err, artist) {
track._artist = (artist && artist._id) ? artist._id : new Artist({ name: artistName });
track.sources.magnet = [{ id: id }];
track.save(function(err) {
console.log('TRACK SAVED', err);
sourceCallback(err, track);
});
});

});
break;
case 'direct':
Track.findOne({ 'sources.direct.uri': id }).populate('_artist').exec(function(err, track) {
if (track) return sourceCallback(err, track);
Expand All @@ -158,7 +181,7 @@ Soundtrack.prototype.trackFromSource = function(source, id, data, sourceCallback
track.sources.direct = [{ uri: id }];
track.save(function(err) {
console.log('TRACK SAVED', err);
sourceCallback(err, track);
sourceCallback(err, track);
});
});

Expand Down
8 changes: 7 additions & 1 deletion models/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ var TrackSchema = new Schema({
duration: { type: Number },
data: {}
})],
magnet: [ new Schema({
id: { type: String , required: true , index: true },
duration: { type: Number },
data: {}
})],
lastfm: [ new Schema({
id: { type: String , required: true , index: true }
, duration: { type: Number }
Expand Down Expand Up @@ -83,10 +88,11 @@ TrackSchema.pre('save', function(next) {
});
}

['direct', 'youtube', 'soundcloud'].forEach(function(source) {
['direct', 'magnet', 'youtube', 'soundcloud'].forEach(function(source) {

switch (source) {
case 'direct': var type = 'video/mp4'; break;
case 'magnet': var type = 'video/mp4'; break;
case 'youtube': var type = 'video/youtube'; break;
case 'soundcloud': var type = 'audio/mp3'; break;
}
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": "~3.6.14",
"mongoose-agency": "0.0.0",
"mongoose-slug": "~1.3.0",
"musicmetadata": "^2.0.2",
"passport": "~0.1.17",
"passport-changetip": "0.0.1",
"passport-google-oauth": "^0.2.0",
Expand Down
1 change: 1 addition & 0 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ html(lang="en-US", ng-app="soundtrack-io")
script(src="/video-js/video.dev.js")
script(src="/js/youtube.js")
script(src="/js/sockjs-0.3.min.js")
script(src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js")
script(src="/js/app.js")

base
Expand Down