vdj 1.3.0 → 1.4.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.
@@ -17,5 +17,5 @@ export default class YouTubeSong extends Song {
17
17
  constructor(service: YouTubeService, video: Video, playlistID?: string, logger?: Logger, seek?: number);
18
18
  getSongInfo(): Promise<SongInfo>;
19
19
  static extractSeek(url: string): number;
20
- stream(): ReadableStream;
20
+ stream(): ReadableStream | null;
21
21
  }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const ytdl = require("ytdl-core");
12
+ const youtube_dl_exec_1 = require("youtube-dl-exec");
13
13
  const core_1 = require("../../core");
14
14
  class YouTubeSong extends core_1.Song {
15
15
  constructor(service, video, playlistID, logger, seek = 0) {
@@ -60,19 +60,14 @@ class YouTubeSong extends core_1.Song {
60
60
  return 0;
61
61
  }
62
62
  stream() {
63
- const options = {};
64
- if (this.live) {
65
- options.quality = [128, 127, 120, 96, 95, 94, 93];
66
- }
67
- else {
68
- options.filter = 'audioonly';
69
- options.range = {
70
- start: this.seek > 0 ? this.seek : 0
71
- };
72
- }
73
- if (typeof (this.logger) == 'function')
74
- this.logger(`[${this.type}] Fetching stream url for ${this.URL}.`);
75
- return ytdl(this.trackID, options);
63
+ const stream = youtube_dl_exec_1.exec(this.streamURL, {
64
+ output: '-',
65
+ format: 'bestaudio[ext=webm+acodec=opus+tbr>100]/bestaudio[ext=webm+acodec=opus]/bestaudio/best',
66
+ limitRate: '1M',
67
+ rmCacheDir: true,
68
+ verbose: true,
69
+ }, { stdio: ['ignore', 'pipe', 'ignore'] });
70
+ return stream.stdout;
76
71
  }
77
72
  }
78
73
  exports.default = YouTubeSong;
@@ -31,13 +31,13 @@ class YoutubedlService {
31
31
  }
32
32
  canFetch(target, logger) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- var res = yield youtube_dl_exec_1.default(target, { j: true }, {});
34
+ var res = yield youtube_dl_exec_1.default(target, { dumpJson: true }, {});
35
35
  return !!res;
36
36
  });
37
37
  }
38
38
  getSongInfo(url, logger) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
- var res = yield youtube_dl_exec_1.default(url, { j: true, "no-check-certificate": true, "add-metadata": true }, {});
40
+ var res = yield youtube_dl_exec_1.default(url, { dumpJson: true, noCheckCertificate: true, addMetadata: true }, {});
41
41
  return {
42
42
  full: true,
43
43
  metadataType: "youtubedl",
@@ -33,9 +33,14 @@ class YoutubedlSong extends core_1.Song {
33
33
  });
34
34
  }
35
35
  stream() {
36
- if (typeof (this.logger) == 'function')
37
- this.logger(`[${this.type}] Fetching stream for ${this.URL}.`);
38
- return youtube_dl_exec_1.raw(this.streamURL, { _: ['-f', 'bestaudio/best[height<=?480]', '-o', '-'] }, {}).stdout;
36
+ const stream = youtube_dl_exec_1.exec(this.streamURL, {
37
+ output: '-',
38
+ format: 'bestaudio[ext=webm+acodec=opus+tbr>100]/bestaudio[ext=webm+acodec=opus]/bestaudio/best',
39
+ limitRate: '1M',
40
+ rmCacheDir: true,
41
+ verbose: true,
42
+ }, { stdio: ['ignore', 'pipe', 'ignore'] });
43
+ return stream.stdout;
39
44
  }
40
45
  }
41
46
  exports.default = YoutubedlSong;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vdj",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
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",
22
+ "youtube-dl-exec": "^2.1.5",
23
23
  "ytdl-core": "^4.11.2"
24
24
  }
25
25
  }
@@ -1,6 +1,6 @@
1
1
  import { Readable as ReadableStream } from 'stream';
2
2
  import { Video } from 'simple-youtube-api';
3
- import ytdl = require('ytdl-core');
3
+ import { exec as ytdlexec } from 'youtube-dl-exec';
4
4
 
5
5
  import { Song, SongInfo, Logger } from '../../core';
6
6
  import YouTubeService from './service';
@@ -62,20 +62,19 @@ export default class YouTubeSong extends Song {
62
62
  return 0;
63
63
  }
64
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);
65
+ public stream(): ReadableStream | null {
66
+ const stream = ytdlexec(
67
+ this.streamURL,
68
+ {
69
+ output: '-',
70
+ format:
71
+ 'bestaudio[ext=webm+acodec=opus+tbr>100]/bestaudio[ext=webm+acodec=opus]/bestaudio/best',
72
+ limitRate: '1M',
73
+ rmCacheDir: true,
74
+ verbose: true,
75
+ },
76
+ { stdio: ['ignore', 'pipe', 'ignore'] }
77
+ );
78
+ return stream.stdout;
80
79
  }
81
80
  }
@@ -15,12 +15,12 @@ export default class YoutubedlService implements IService {
15
15
  }
16
16
 
17
17
  public async canFetch(target: string, logger?: Logger): Promise<boolean> {
18
- var res = await youtubedl(target, {j: true}, {});
18
+ var res = await youtubedl(target, { dumpJson: true }, {});
19
19
  return !!res;
20
20
  }
21
21
 
22
22
  public async getSongInfo(url: string, logger?: Logger): Promise<SongInfo> {
23
- var res = await youtubedl(url, {j: true, "no-check-certificate": true, "add-metadata": true}, {});
23
+ var res = await youtubedl(url, { dumpJson: true, noCheckCertificate: true, addMetadata: true }, {});
24
24
  return {
25
25
  full: true,
26
26
  metadataType: "youtubedl",
@@ -38,10 +38,10 @@ export default class YoutubedlService implements IService {
38
38
  if (!dateString) {
39
39
  return undefined;
40
40
  }
41
- const year = dateString.slice(0,4);
42
- const month = dateString.slice(4,6);
43
- const day = dateString.slice(6,8);
44
-
41
+ const year = dateString.slice(0, 4);
42
+ const month = dateString.slice(4, 6);
43
+ const day = dateString.slice(6, 8);
44
+
45
45
  return new Date(`${year} ${month} ${day}`)
46
46
  }
47
47
  }
@@ -1,6 +1,6 @@
1
1
  import { Readable as ReadableStream } from 'stream';
2
2
  import { Song, SongInfo, Logger } from '../../core';
3
- import { raw as youtubedl } from 'youtube-dl-exec';
3
+ import { exec as ytdlexec } from 'youtube-dl-exec';
4
4
  import YoutubedlService from './service';
5
5
 
6
6
  export default class YoutubedlSong extends Song {
@@ -30,7 +30,18 @@ export default class YoutubedlSong extends Song {
30
30
  }
31
31
 
32
32
  public stream(): ReadableStream | null {
33
- if (typeof (this.logger) == 'function') this.logger(`[${this.type}] Fetching stream for ${this.URL}.`);
34
- return youtubedl(this.streamURL, { _: ['-f', 'bestaudio/best[height<=?480]', '-o', '-'] }, {}).stdout;
33
+ const stream = ytdlexec(
34
+ this.streamURL,
35
+ {
36
+ output: '-',
37
+ format:
38
+ 'bestaudio[ext=webm+acodec=opus+tbr>100]/bestaudio[ext=webm+acodec=opus]/bestaudio/best',
39
+ limitRate: '1M',
40
+ rmCacheDir: true,
41
+ verbose: true,
42
+ },
43
+ { stdio: ['ignore', 'pipe', 'ignore'] }
44
+ );
45
+ return stream.stdout;
35
46
  }
36
47
  }