Skip to content
This repository has been archived by the owner on Nov 3, 2018. It is now read-only.

Commit

Permalink
DiscordDJ is coming back!
Browse files Browse the repository at this point in the history
  • Loading branch information
Guichaguri committed Mar 8, 2017
1 parent d27983e commit b007a10
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
22 changes: 22 additions & 0 deletions jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"source": {
"include": ["lib"],
"includePattern": ".+\\.js$"
},
"plugins": [],
"templates": {
"cleverLinks": true,
"monospaceLinks": false
},
"opts": {
"template": "templates/default",
"encoding": "utf8",
"destination": "./docs/",
"recurse": true,
"readme": "README.md"
}
}
58 changes: 58 additions & 0 deletions lib/audio/playable/YouTubePlayable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";

const Playable = require('../../interfaces/Playable.js');

const ytdl = require('ytdl-core');

class YouTubePlayable extends Playable {

constructor(url) {
super();
this.url = url;
}

get title() {
return this._title;
}

get artist() {
return this._artist;
}

get description() {
return this._description;
}

loadData() {
return new Promise(function(resolve, reject) {
ytdl.getInfo(this.video, function(err, info) {
if(err) return reject(err);

let title = info.title.split(' - ', 2);
this._artist = title[0];
this._title = title[1];
this._description = null; //TODO?

this.url = info.loaderUrl;
this.emit('data-changed');
resolve();
}.bind(this));
}.bind(this));
}

filterVideo(format) {
return format.container === 'mp4';
}

createStream() {
try {
// Since 2014, video quality does not affect audio quality anymore, so we'll use the lowest quality
return Promise.resolve(ytdl(this.url, {filter: this.filterVideo, quality: 'lowest'}));
} catch(e) {
return Promise.reject(e);
}
}

}

module.exports = YouTubePlayable;
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"license": "LGPL-2.0",
"dependencies": {
"icy": "2.1.0",
"opusscript": "0.0.1",
"opusscript": "0.0.2",
"pako": "1.0.3",
"tweetnacl": "0.14.3",
"ws": "1.1.1",
"ytdl-core": "^0.7.10"
"ytdl-core": "^0.7.24"
},
"repository": {
"type": "git",
Expand All @@ -26,7 +26,8 @@
"discord-dj"
],
"scripts": {
"start": "node ./runtime/DiscordDJ.js"
"start": "node ./runtime/DiscordDJ.js",
"gen-docs": "jsdoc -c jsdoc.json"
},
"bugs": {
"url": "https://github.com/Guichaguri/DiscordDJ/issues"
Expand Down

0 comments on commit b007a10

Please sign in to comment.