This repository has been archived by the owner on Nov 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
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
1 parent
d27983e
commit b007a10
Showing
3 changed files
with
84 additions
and
3 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,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" | ||
} | ||
} |
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,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; |
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