vdj 1.5.0 → 1.6.1

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Readable as ReadableStream } from 'stream';
3
2
  import { IService, SongInfo } from '.';
4
3
  export default abstract class Song {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IService, Song } from ".";
3
2
  export type SongInfo = {
4
3
  full: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference path="../../../src/typings/simple-youtube-api.d.ts" />
2
1
  import API = require('simple-youtube-api');
3
2
  import { IService, SearchType, SongInfo, Logger } from '../../core/';
4
3
  import YouTubeSong from './song';
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const API = require("simple-youtube-api");
16
- const ytdl = require("ytdl-core");
16
+ const ytdl = require("@distube/ytdl-core");
17
17
  const song_1 = __importDefault(require("./song"));
18
18
  class YouTubeService {
19
19
  constructor(key) {
@@ -1,5 +1,3 @@
1
- /// <reference path="../../../src/typings/simple-youtube-api.d.ts" />
2
- /// <reference types="node" />
3
1
  import { Readable as ReadableStream } from 'stream';
4
2
  import { Video } from 'simple-youtube-api';
5
3
  import { Song, SongInfo, Logger } from '../../core';
@@ -66,7 +66,10 @@ class YouTubeSong extends core_1.Song {
66
66
  limitRate: '1M',
67
67
  rmCacheDir: true,
68
68
  verbose: true,
69
- }, { stdio: ['ignore', 'pipe', 'ignore'] });
69
+ }, { stdio: ['ignore', 'pipe', 'ignore'], });
70
+ stream.on('error', (err) => {
71
+ this.logger && this.logger(`[${this.type}] Error while streaming: ${err}`);
72
+ });
70
73
  return stream.stdout;
71
74
  }
72
75
  }
@@ -38,6 +38,19 @@ class YoutubedlService {
38
38
  getSongInfo(url, logger) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  var res = yield (0, youtube_dl_exec_1.default)(url, { dumpSingleJson: true, noCheckCertificates: true, addMetadata: true }, {});
41
+ if (typeof res === 'string') {
42
+ return {
43
+ full: true,
44
+ metadataType: "youtubedl",
45
+ imgURL: "",
46
+ title: url,
47
+ duration: 0,
48
+ url: url,
49
+ artist: [],
50
+ date: new Date(),
51
+ custom: {}
52
+ };
53
+ }
41
54
  return {
42
55
  full: true,
43
56
  metadataType: "youtubedl",
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Readable as ReadableStream } from 'stream';
3
2
  import { Song, SongInfo, Logger } from '../../core';
4
3
  import YoutubedlService from './service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vdj",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -12,14 +12,14 @@
12
12
  "devDependencies": {
13
13
  "chai": "^4.2.0",
14
14
  "dotenv": "^8.2.0",
15
- "typescript": "^3.9.7"
15
+ "typescript": "^5.7.3"
16
16
  },
17
17
  "dependencies": {
18
+ "@distube/ytdl-core": "^4.16.4",
18
19
  "@types/node": "^12.19.2",
19
20
  "got": "^13.0.0",
20
21
  "mocha": "^10.7.3",
21
22
  "simple-youtube-api": "^5.2.1",
22
- "youtube-dl-exec": "^3.0.7",
23
- "ytdl-core": "^4.11.5"
23
+ "youtube-dl-exec": "^3.0.15"
24
24
  }
25
25
  }
@@ -1,5 +1,5 @@
1
1
  import API = require('simple-youtube-api');
2
- import ytdl = require('ytdl-core');
2
+ import ytdl = require("@distube/ytdl-core");
3
3
 
4
4
  import { IService, SearchType, SongInfo, Logger } from '../../core/';
5
5
  import YouTubeSong from './song';
@@ -71,8 +71,11 @@ export default class YouTubeSong extends Song {
71
71
  rmCacheDir: true,
72
72
  verbose: true,
73
73
  },
74
- { stdio: ['ignore', 'pipe', 'ignore'] }
74
+ { stdio: ['ignore', 'pipe', 'ignore'], }
75
75
  );
76
+ stream.on('error', (err) => {
77
+ this.logger && this.logger(`[${this.type}] Error while streaming: ${err}`);
78
+ });
76
79
  return stream.stdout;
77
80
  }
78
81
  }
@@ -20,7 +20,20 @@ export default class YoutubedlService implements IService {
20
20
  }
21
21
 
22
22
  public async getSongInfo(url: string, logger?: Logger): Promise<SongInfo> {
23
- var res = await youtubedl(url, { dumpSingleJson: true, noCheckCertificates: true, addMetadata: true }, {});
23
+ var res = await youtubedl(url, { dumpSingleJson: true, noCheckCertificates: true, addMetadata: true }, {});
24
+ if(typeof res === 'string') {
25
+ return {
26
+ full: true,
27
+ metadataType: "youtubedl",
28
+ imgURL: "",
29
+ title: url,
30
+ duration: 0,
31
+ url: url,
32
+ artist: [],
33
+ date: new Date(),
34
+ custom: {}
35
+ };
36
+ }
24
37
  return {
25
38
  full: true,
26
39
  metadataType: "youtubedl",
package/test/test.js CHANGED
@@ -15,13 +15,17 @@ function sortOfDeepEqual(actual, expected) {
15
15
  return assert.deepEqual(strippedActual, expected);
16
16
  }
17
17
 
18
- describe("Playlist", function () {
18
+ describe("Playlist", function () {
19
19
  before(function () {
20
20
  playlist = new vdj.Playlist({
21
21
  services: [],
22
22
  });
23
23
  });
24
24
 
25
+ beforeEach(function () {
26
+ playlist.clear();
27
+ });
28
+
25
29
  describe("#add", function () {
26
30
  it("should return the not found targets", async function () {
27
31
  const input = ["first", "second"];
@@ -118,6 +122,26 @@ describe("Playlist", function () {
118
122
  assert.equal(result, expected);
119
123
  });
120
124
  });
125
+ describe("#next", function () {
126
+
127
+ it("should go to next song", async function () {
128
+ const input = [
129
+ "https://www.youtube.com/watch?v=fmrA-gxJxgQ",
130
+ "https://www.youtube.com/watch?v=DDjcqu9uvUE",
131
+ "https://www.youtube.com/watch?v=lBnAY4VH9T4",
132
+ ];
133
+ await playlist.add(input);
134
+ const current1 = playlist.current;
135
+ await playlist.next();
136
+ const current2 = playlist.current;
137
+ await playlist.next();
138
+ const current3 = playlist.current;
139
+ assert.equal(current1.URL, input[0]);
140
+ assert.equal(current2.URL, input[1]);
141
+ assert.equal(current3.URL, input[2]);
142
+ });
143
+ });
144
+
121
145
  describe("#getSongInfo", function () {
122
146
  it("should return a lot more information from working youtube video link", async function () {
123
147
  const input = "https://www.youtube.com/watch?v=FtsefkeIE7k";
@@ -142,7 +166,7 @@ describe("Playlist", function () {
142
166
  });
143
167
  });
144
168
  describe("#add", function () {
145
- this.timeout(5000);
169
+ this.timeout(10000);
146
170
  it("should return a YoutubedlSong from working ogg link", async function () {
147
171
  const input = ["https://upload.wikimedia.org/wikipedia/commons/d/de/Lorem_ipsum.ogg"];
148
172
  const expected = {
@@ -170,31 +194,24 @@ describe("Playlist", function () {
170
194
  });
171
195
  });
172
196
  describe("#getSongInfo", function () {
173
- this.timeout(5000);
174
- console.log("hey");
197
+ this.timeout(10000);
175
198
  it("should return a lot more information from working youtube link", async function () {
176
- try {
177
- const input = "https://www.youtube.com/watch?v=232fF5ECnGo";
178
- const expected = {
179
- full: true,
180
- metadataType: "youtubedl",
181
- url: input,
182
- title: "Rap God in the style of @LinkinPark​ (Feat. @jonathanymusic)",
183
- duration: 371,
184
- artist: [],
185
- date: new Date(1660773600000),
186
- };
187
- var tes = new vdj.YoutubedlService();
188
- const result = await tes.getSongInfo(input, console.log);
189
- sortOfDeepEqual(result, expected);
190
- }
191
- catch (e) {
192
- console.log(e);
193
- }
199
+ const input = "https://www.youtube.com/watch?v=232fF5ECnGo";
200
+ const expected = {
201
+ full: true,
202
+ metadataType: "youtubedl",
203
+ url: input,
204
+ title: "Rap God in the style of @LinkinPark​ (Feat. @jonathanymusic)",
205
+ duration: 371,
206
+ artist: [],
207
+ date: new Date(1660773600000),
208
+ };
209
+ const result = await youtubedlService.getSongInfo(input, console.log);
210
+ sortOfDeepEqual(result, expected);
194
211
  });
195
212
  });
196
213
  describe("#getSongInfo", function () {
197
- this.timeout(5000);
214
+ this.timeout(10000);
198
215
  it("should return a lot more information from working soundcloud link", async function () {
199
216
  const input = "https://soundcloud.com/bionicelcor/wakusei-abnormal";
200
217
  const expected = {