vdj 1.1.6 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Playlist, PlaylistSettings, IService, Song } from './core';
|
|
2
|
-
import YouTubeService from './default_implementations/youtube/service';
|
|
3
|
-
import YouTubeSong from './default_implementations/youtube/song';
|
|
4
2
|
import YoutubedlService from './default_implementations/youtubedl/service';
|
|
5
3
|
import YoutubedlSong from './default_implementations/youtubedl/song';
|
|
6
|
-
export { Playlist, PlaylistSettings, IService, Song,
|
|
4
|
+
export { Playlist, PlaylistSettings, IService, Song, YoutubedlService, YoutubedlSong, };
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.YoutubedlSong = exports.YoutubedlService = exports.
|
|
6
|
+
exports.YoutubedlSong = exports.YoutubedlService = exports.Song = exports.Playlist = void 0;
|
|
7
7
|
const core_1 = require("./core");
|
|
8
8
|
Object.defineProperty(exports, "Playlist", { enumerable: true, get: function () { return core_1.Playlist; } });
|
|
9
9
|
Object.defineProperty(exports, "Song", { enumerable: true, get: function () { return core_1.Song; } });
|
|
10
|
-
const service_1 = __importDefault(require("./default_implementations/
|
|
11
|
-
exports.
|
|
12
|
-
const song_1 = __importDefault(require("./default_implementations/
|
|
13
|
-
exports.
|
|
14
|
-
const service_2 = __importDefault(require("./default_implementations/youtubedl/service"));
|
|
15
|
-
exports.YoutubedlService = service_2.default;
|
|
16
|
-
const song_2 = __importDefault(require("./default_implementations/youtubedl/song"));
|
|
17
|
-
exports.YoutubedlSong = song_2.default;
|
|
10
|
+
const service_1 = __importDefault(require("./default_implementations/youtubedl/service"));
|
|
11
|
+
exports.YoutubedlService = service_1.default;
|
|
12
|
+
const song_1 = __importDefault(require("./default_implementations/youtubedl/song"));
|
|
13
|
+
exports.YoutubedlSong = song_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vdj",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"@types/node": "^12.19.2",
|
|
20
20
|
"got": "^11.8.0",
|
|
21
21
|
"simple-youtube-api": "^5.2.1",
|
|
22
|
-
"youtube-dl-exec": "^1.2.13"
|
|
23
|
-
"ytdl-core": "^4.11.0"
|
|
22
|
+
"youtube-dl-exec": "^1.2.13"
|
|
24
23
|
}
|
|
25
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Playlist, PlaylistSettings, IService, Song } from './core';
|
|
2
|
-
import YouTubeService from './default_implementations/youtube/service'
|
|
3
|
-
import YouTubeSong from './default_implementations/youtube/song'
|
|
4
2
|
import YoutubedlService from './default_implementations/youtubedl/service';
|
|
5
3
|
import YoutubedlSong from './default_implementations/youtubedl/song';
|
|
6
4
|
|
|
@@ -11,9 +9,6 @@ export {
|
|
|
11
9
|
IService,
|
|
12
10
|
Song,
|
|
13
11
|
|
|
14
|
-
YouTubeService,
|
|
15
|
-
YouTubeSong,
|
|
16
|
-
|
|
17
12
|
YoutubedlService,
|
|
18
13
|
YoutubedlSong,
|
|
19
14
|
};
|
package/test/test.js
CHANGED
|
@@ -3,7 +3,6 @@ const assert = require('chai').assert;
|
|
|
3
3
|
const vdj = require('../dist');
|
|
4
4
|
|
|
5
5
|
var playlist,
|
|
6
|
-
youtubeService = new vdj.YouTubeService(process.env.GOOGLE_API_KEY),
|
|
7
6
|
youtubedlService = new vdj.YoutubedlService();
|
|
8
7
|
|
|
9
8
|
function sortOfDeepEqual(actual, expected) {
|
|
@@ -30,89 +29,6 @@ describe('Playlist', function () {
|
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
describe('Youtube', function () {
|
|
34
|
-
before(function () {
|
|
35
|
-
playlist = new vdj.Playlist({
|
|
36
|
-
services: [youtubeService]
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('#add', function () {
|
|
42
|
-
it('should return a YouTubeSong from working youtube video link', async function () {
|
|
43
|
-
const input = ['https://www.youtube.com/watch?v=FtsefkeIE7k'];
|
|
44
|
-
const expected = {
|
|
45
|
-
"added": [
|
|
46
|
-
{
|
|
47
|
-
"URL": input[0],
|
|
48
|
-
"info": {
|
|
49
|
-
"duration": 282,
|
|
50
|
-
"full": false,
|
|
51
|
-
"metadataType": "youtube",
|
|
52
|
-
"title": "楽園ベイベー - RIP SLYME(Cover) / KMNZ",
|
|
53
|
-
"url": input[0]
|
|
54
|
-
},
|
|
55
|
-
"live": false,
|
|
56
|
-
"logger": undefined,
|
|
57
|
-
"loop": false,
|
|
58
|
-
"playlistID": undefined,
|
|
59
|
-
"seek": 0,
|
|
60
|
-
"service": playlist.services[0],
|
|
61
|
-
"streamURL": input[0],
|
|
62
|
-
"title": "楽園ベイベー - RIP SLYME(Cover) / KMNZ",
|
|
63
|
-
"trackID": "FtsefkeIE7k",
|
|
64
|
-
"type": "youtube",
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
"notFound": []
|
|
68
|
-
};
|
|
69
|
-
const result = await playlist.add(input);
|
|
70
|
-
assert.deepEqual(result, expected);
|
|
71
|
-
});
|
|
72
|
-
it('should return multiple YouTubeSongs from multiple working youtube video links', async function () {
|
|
73
|
-
const input = ['https://www.youtube.com/watch?v=fmrA-gxJxgQ', 'https://www.youtube.com/watch?v=DDjcqu9uvUE', 'https://www.youtube.com/watch?v=lBnAY4VH9T4'];
|
|
74
|
-
const expected = input.length;
|
|
75
|
-
const result = (await playlist.add(input)).added.length;
|
|
76
|
-
assert.equal(result, expected);
|
|
77
|
-
});
|
|
78
|
-
it('should return a YouTubeSong from working shortened youtube video link', async function () {
|
|
79
|
-
const input = ['https://youtu.be/LoK17z6xDwI'];
|
|
80
|
-
const expected = "https://www.youtube.com/watch?v=LoK17z6xDwI";
|
|
81
|
-
const result = (await playlist.add(input)).added[0].URL;
|
|
82
|
-
assert.deepEqual(result, expected);
|
|
83
|
-
});
|
|
84
|
-
it('should return a YouTubeSong from live youtube video link', async function () {
|
|
85
|
-
const input = ['https://www.youtube.com/watch?v=5qap5aO4i9A'];
|
|
86
|
-
const result = (await playlist.add(input)).added[0].live;
|
|
87
|
-
assert.isTrue(result);
|
|
88
|
-
});
|
|
89
|
-
it('should return a YouTubeSong with seek from working youtube video link with timestamp parameter', async function () {
|
|
90
|
-
const input = ['https://www.youtube.com/watch?v=tMKrECxEpq8&t=64'];
|
|
91
|
-
const expected = 64;
|
|
92
|
-
const result = (await playlist.add(input)).added[0].seek;
|
|
93
|
-
assert.equal(result, expected);
|
|
94
|
-
});
|
|
95
|
-
it('should return multiple YouTubeSongs from youtube playlist link', async function () {
|
|
96
|
-
const input = ['https://www.youtube.com/playlist?list=PLFJU3fqbXA2e1_wAqOn7IoRB02nCfsAVh'];
|
|
97
|
-
const result = (await playlist.add(input)).added.length;
|
|
98
|
-
assert.isAbove(result, 1);
|
|
99
|
-
});
|
|
100
|
-
it('should return one YouTubeSong from youtube video link with playlist parameter', async function () {
|
|
101
|
-
const input = ['https://www.youtube.com/watch?v=wSCEC0lYTzk&list=PLFJU3fqbXA2e1_wAqOn7IoRB02nCfsAVh&index=67'];
|
|
102
|
-
const expected = 1;
|
|
103
|
-
const result = (await playlist.add(input)).added.length;
|
|
104
|
-
assert.equal(result, expected);
|
|
105
|
-
});
|
|
106
|
-
it('should return YouTubeSongs from search queries', async function () {
|
|
107
|
-
const input = ['globglogabgalab', 'yooooooooo'];
|
|
108
|
-
const expected = 2;
|
|
109
|
-
const result = (await playlist.add(input, {
|
|
110
|
-
playlistAddType: 'searches'
|
|
111
|
-
})).added.length;
|
|
112
|
-
assert.equal(result, expected);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
32
|
describe('Youtubedl', function () {
|
|
117
33
|
before(function () {
|
|
118
34
|
playlist = new vdj.Playlist({
|
|
@@ -150,27 +66,24 @@ describe('Playlist', function () {
|
|
|
150
66
|
|
|
151
67
|
|
|
152
68
|
describe('Service', function () {
|
|
153
|
-
describe('
|
|
69
|
+
describe('Youtubedl', function () {
|
|
154
70
|
describe('#getSongInfo', function () {
|
|
155
|
-
|
|
156
|
-
|
|
71
|
+
this.timeout(5000);
|
|
72
|
+
it('should return a lot more information from working youtube link', async function () {
|
|
73
|
+
const input = 'https://www.youtube.com/watch?v=232fF5ECnGo';
|
|
157
74
|
const expected = {
|
|
158
75
|
full: true,
|
|
159
|
-
metadataType: "
|
|
76
|
+
metadataType: "youtubedl",
|
|
160
77
|
url: input,
|
|
161
|
-
title: "
|
|
162
|
-
duration:
|
|
163
|
-
artist: [
|
|
164
|
-
|
|
165
|
-
],
|
|
166
|
-
date: new Date(1566950400000)
|
|
78
|
+
title: "Rap God in the style of @Linkin Park (Feat. @Jonathan Young)",
|
|
79
|
+
duration: 371,
|
|
80
|
+
artist: [],
|
|
81
|
+
date: new Date(1660773600000)
|
|
167
82
|
};
|
|
168
|
-
const result = await
|
|
83
|
+
const result = await youtubedlService.getSongInfo(input, console.log);
|
|
169
84
|
sortOfDeepEqual(result, expected);
|
|
170
85
|
});
|
|
171
86
|
});
|
|
172
|
-
});
|
|
173
|
-
describe('Youtubedl', function () {
|
|
174
87
|
describe('#getSongInfo', function () {
|
|
175
88
|
this.timeout(5000);
|
|
176
89
|
it('should return a lot more information from working soundcloud link', async function () {
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import API = require('simple-youtube-api');
|
|
2
|
-
import ytdl = require('ytdl-core');
|
|
3
|
-
|
|
4
|
-
import { IService, SearchType, SongInfo, Logger } from '../../core/';
|
|
5
|
-
import YouTubeSong from './song';
|
|
6
|
-
|
|
7
|
-
export default class YouTubeService implements IService {
|
|
8
|
-
public readonly api: API;
|
|
9
|
-
public canSearch: boolean = true;
|
|
10
|
-
public type: string = 'youtube';
|
|
11
|
-
|
|
12
|
-
constructor(key: string) {
|
|
13
|
-
this.api = new API(key);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async fetch(targets: string[], logger?: Logger): Promise<YouTubeSong[]> {
|
|
17
|
-
const fetched: YouTubeSong[] = [];
|
|
18
|
-
|
|
19
|
-
for (const target of targets) {
|
|
20
|
-
var parsed = API.util.parseURL(target);
|
|
21
|
-
if (parsed.video) {
|
|
22
|
-
typeof(logger) == 'function' && logger(`[${this.type}] Fetching video from target ${target}.`);
|
|
23
|
-
|
|
24
|
-
const video = await this.api.getVideoByID(parsed.video);
|
|
25
|
-
const seek = YouTubeSong.extractSeek(target);
|
|
26
|
-
if (video) fetched.push(new YouTubeSong(this, video, undefined, logger, seek));
|
|
27
|
-
} else if (parsed.playlist) {
|
|
28
|
-
typeof(logger) == 'function' && logger(`[${this.type}] Fetching playlist from target ${target}.`);
|
|
29
|
-
|
|
30
|
-
const playlist = await this.api.getPlaylistByID(parsed.playlist);
|
|
31
|
-
if (!playlist) continue;
|
|
32
|
-
await playlist.getVideos();
|
|
33
|
-
fetched.push(...playlist.videos.map((v) => new YouTubeSong(this, v, parsed.playlist, logger)));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return fetched;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async search(queries: string[], searchType: SearchType, logger?: Logger): Promise<YouTubeSong[]> {
|
|
41
|
-
const fetched: YouTubeSong[] = [];
|
|
42
|
-
|
|
43
|
-
if (!this.canSearch) return fetched;
|
|
44
|
-
for (const query of queries) {
|
|
45
|
-
if (searchType === 'playlist') {
|
|
46
|
-
typeof(logger) == 'function' && logger(`[${this.type}] Searching for a playlist with the input ${query}.`);
|
|
47
|
-
|
|
48
|
-
const results = await this.api.searchPlaylists(query, 1);
|
|
49
|
-
if (results.length) {
|
|
50
|
-
const list = results[0];
|
|
51
|
-
const videos = await list.getVideos();
|
|
52
|
-
fetched.push(...videos.map((v) => new YouTubeSong(this, v, list.id, logger)));
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
typeof(logger) == 'function' && logger(`[${this.type}] Searching for a song with the input ${query}.`);
|
|
56
|
-
|
|
57
|
-
const results = await this.api.searchVideos(query, 1);
|
|
58
|
-
if (results.length) fetched.push(new YouTubeSong(this, results[0], undefined, logger));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return fetched;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public async canFetch(target: string, logger?: Logger): Promise<boolean> {
|
|
66
|
-
const parsed = API.util.parseURL(target);
|
|
67
|
-
return parsed.video != undefined || parsed.playlist != undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public async getSongInfo(url: string, logger?: Logger): Promise<SongInfo> {
|
|
71
|
-
try {
|
|
72
|
-
const result: ytdl.videoInfo = await ytdl.getInfo(url);
|
|
73
|
-
return {
|
|
74
|
-
full: true,
|
|
75
|
-
metadataType: "youtube",
|
|
76
|
-
imgURL: result.player_response.videoDetails.thumbnail.thumbnails[0].url,
|
|
77
|
-
title: result.videoDetails.title,
|
|
78
|
-
duration: Number(result.videoDetails.lengthSeconds),
|
|
79
|
-
url: result.videoDetails.video_url,
|
|
80
|
-
artist: [result.videoDetails.author.name],
|
|
81
|
-
date: new Date(result.videoDetails.publishDate),
|
|
82
|
-
custom: result
|
|
83
|
-
};
|
|
84
|
-
} catch(e) {
|
|
85
|
-
typeof(logger) == 'function' && logger(`Failed to get song info for url '${url}', error ${e}`);
|
|
86
|
-
return {
|
|
87
|
-
full: true,
|
|
88
|
-
metadataType: "youtube",
|
|
89
|
-
imgURL: "",
|
|
90
|
-
title: url,
|
|
91
|
-
duration: 0,
|
|
92
|
-
url: url,
|
|
93
|
-
artist: [],
|
|
94
|
-
date: new Date(),
|
|
95
|
-
custom: {}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Readable as ReadableStream } from 'stream';
|
|
2
|
-
import { Video } from 'simple-youtube-api';
|
|
3
|
-
import ytdl = require('ytdl-core');
|
|
4
|
-
|
|
5
|
-
import { Song, SongInfo, Logger } from '../../core';
|
|
6
|
-
import YouTubeService from './service';
|
|
7
|
-
|
|
8
|
-
export default class YouTubeSong extends Song {
|
|
9
|
-
public readonly type: string = 'youtube';
|
|
10
|
-
public readonly title: string;
|
|
11
|
-
public readonly playlistID?: string;
|
|
12
|
-
public readonly trackID: string;
|
|
13
|
-
public readonly streamURL: string;
|
|
14
|
-
public readonly URL: string;
|
|
15
|
-
public readonly live: boolean;
|
|
16
|
-
public info: SongInfo;
|
|
17
|
-
public seek: number;
|
|
18
|
-
public logger?: Logger;
|
|
19
|
-
|
|
20
|
-
constructor(service: YouTubeService, video: Video, playlistID?: string, logger?: Logger, seek: number = 0) {
|
|
21
|
-
super(service);
|
|
22
|
-
this.title = video.title;
|
|
23
|
-
this.trackID = video.id;
|
|
24
|
-
this.streamURL = video.url;
|
|
25
|
-
this.URL = video.url;
|
|
26
|
-
this.playlistID = playlistID;
|
|
27
|
-
this.live = video.raw.snippet.liveBroadcastContent == "live";
|
|
28
|
-
this.seek = seek;
|
|
29
|
-
this.info = {
|
|
30
|
-
full: false,
|
|
31
|
-
metadataType: this.type,
|
|
32
|
-
title: this.title,
|
|
33
|
-
url: this.URL,
|
|
34
|
-
duration: video.durationSeconds
|
|
35
|
-
}
|
|
36
|
-
this.logger = logger;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public async getSongInfo(): Promise<SongInfo> {
|
|
40
|
-
if (this.info.full) return this.info;
|
|
41
|
-
this.info = await this.service.getSongInfo(this.URL);
|
|
42
|
-
return this.info;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public static extractSeek(url: string): number {
|
|
46
|
-
var lookFor = ["&t=", "?t="];
|
|
47
|
-
for (var i in lookFor) {
|
|
48
|
-
var key = lookFor[i];
|
|
49
|
-
var start = url.indexOf(key);
|
|
50
|
-
if (start === -1) continue;
|
|
51
|
-
start += key.length;
|
|
52
|
-
var time = "";
|
|
53
|
-
var char = "";
|
|
54
|
-
for (var j = start; j < url.length; j++) {
|
|
55
|
-
char = url[j];
|
|
56
|
-
if (isNaN(Number(char)))
|
|
57
|
-
break;
|
|
58
|
-
time += char;
|
|
59
|
-
}
|
|
60
|
-
return Number(time);
|
|
61
|
-
}
|
|
62
|
-
return 0;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public stream(): ReadableStream {
|
|
66
|
-
const options: any = {};
|
|
67
|
-
|
|
68
|
-
if(this.live) {
|
|
69
|
-
options.quality = [128,127,120,96,95,94,93];
|
|
70
|
-
} else {
|
|
71
|
-
options.filter = 'audioonly';
|
|
72
|
-
|
|
73
|
-
options.range = {
|
|
74
|
-
start: this.seek > 0 ? this.seek : 0
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (typeof(this.logger) == 'function') this.logger(`[${this.type}] Fetching stream url for ${this.URL}.`);
|
|
79
|
-
return ytdl(this.trackID, options);
|
|
80
|
-
}
|
|
81
|
-
}
|