vdj 1.1.3 → 1.1.6

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.
@@ -7,4 +7,5 @@ export default class YoutubedlService implements IService {
7
7
  search(): Promise<YoutubedlSong[]>;
8
8
  canFetch(target: string, logger?: Logger): Promise<boolean>;
9
9
  getSongInfo(url: string, logger?: Logger): Promise<SongInfo>;
10
+ private parseDate;
10
11
  }
@@ -37,19 +37,28 @@ class YoutubedlService {
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 }, {});
40
+ var res = yield youtube_dl_exec_1.default(url, { j: true, "no-check-certificate": true, "add-metadata": true }, {});
41
41
  return {
42
42
  full: true,
43
43
  metadataType: "youtubedl",
44
44
  imgURL: res.thumbnail,
45
45
  title: res.title || url,
46
- duration: 0,
46
+ duration: res.duration,
47
47
  url: url,
48
- artist: [res.artist],
49
- date: res.upload_date,
48
+ artist: res.artist ? [res.artist] : [],
49
+ date: this.parseDate(res.upload_date),
50
50
  custom: {}
51
51
  };
52
52
  });
53
53
  }
54
+ parseDate(dateString) {
55
+ if (!dateString) {
56
+ return undefined;
57
+ }
58
+ const year = dateString.slice(0, 4);
59
+ const month = dateString.slice(4, 6);
60
+ const day = dateString.slice(6, 8);
61
+ return new Date(`${year} ${month} ${day}`);
62
+ }
54
63
  }
55
64
  exports.default = YoutubedlService;
@@ -35,7 +35,7 @@ class YoutubedlSong extends core_1.Song {
35
35
  stream() {
36
36
  if (typeof (this.logger) == 'function')
37
37
  this.logger(`[${this.type}] Fetching stream for ${this.URL}.`);
38
- return youtube_dl_exec_1.raw(this.streamURL, { "o": true, _: ['-'] }, {}).stdout;
38
+ return youtube_dl_exec_1.raw(this.streamURL, { _: ['-f', 'bestaudio/best[height<=?480]', '-o', '-'] }, {}).stdout;
39
39
  }
40
40
  }
41
41
  exports.default = YoutubedlSong;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vdj",
3
- "version": "1.1.3",
3
+ "version": "1.1.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,6 +20,6 @@
20
20
  "got": "^11.8.0",
21
21
  "simple-youtube-api": "^5.2.1",
22
22
  "youtube-dl-exec": "^1.2.13",
23
- "ytdl-core": "^4.9.1"
23
+ "ytdl-core": "^4.11.0"
24
24
  }
25
25
  }
@@ -20,17 +20,28 @@ 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, {j: true}, {});
23
+ var res = await youtubedl(url, {j: true, "no-check-certificate": true, "add-metadata": true}, {});
24
24
  return {
25
25
  full: true,
26
26
  metadataType: "youtubedl",
27
27
  imgURL: res.thumbnail,
28
28
  title: res.title || url,
29
- duration: 0,
29
+ duration: res.duration,
30
30
  url: url,
31
- artist: [res.artist],
32
- date: res.upload_date,
31
+ artist: res.artist ? [res.artist] : [],
32
+ date: this.parseDate(res.upload_date),
33
33
  custom: {}
34
34
  };
35
35
  }
36
+
37
+ private parseDate(dateString: string): Date | undefined {
38
+ if (!dateString) {
39
+ return undefined;
40
+ }
41
+ const year = dateString.slice(0,4);
42
+ const month = dateString.slice(4,6);
43
+ const day = dateString.slice(6,8);
44
+
45
+ return new Date(`${year} ${month} ${day}`)
46
+ }
36
47
  }
@@ -29,8 +29,8 @@ export default class YoutubedlSong extends Song {
29
29
  return this.info;
30
30
  }
31
31
 
32
- public stream(): ReadableStream | null{
32
+ public stream(): ReadableStream | null {
33
33
  if (typeof (this.logger) == 'function') this.logger(`[${this.type}] Fetching stream for ${this.URL}.`);
34
- return youtubedl(this.streamURL, {"o": true, _: ['-']}, {}).stdout;
34
+ return youtubedl(this.streamURL, { _: ['-f', 'bestaudio/best[height<=?480]', '-o', '-'] }, {}).stdout;
35
35
  }
36
36
  }
package/test/test.js CHANGED
@@ -93,13 +93,12 @@ describe('Playlist', function () {
93
93
  assert.equal(result, expected);
94
94
  });
95
95
  it('should return multiple YouTubeSongs from youtube playlist link', async function () {
96
- const input = ['https://www.youtube.com/playlist?list=PL4649F0DBF0FC09E3'];
97
- const expected = 62;
96
+ const input = ['https://www.youtube.com/playlist?list=PLFJU3fqbXA2e1_wAqOn7IoRB02nCfsAVh'];
98
97
  const result = (await playlist.add(input)).added.length;
99
- assert.equal(result, expected);
98
+ assert.isAbove(result, 1);
100
99
  });
101
100
  it('should return one YouTubeSong from youtube video link with playlist parameter', async function () {
102
- const input = ['https://www.youtube.com/watch?v=uS52j0IU1D0&list=PL4649F0DBF0FC09E3&index=3'];
101
+ const input = ['https://www.youtube.com/watch?v=wSCEC0lYTzk&list=PLFJU3fqbXA2e1_wAqOn7IoRB02nCfsAVh&index=67'];
103
102
  const expected = 1;
104
103
  const result = (await playlist.add(input)).added.length;
105
104
  assert.equal(result, expected);
@@ -171,4 +170,42 @@ describe('Service', function () {
171
170
  });
172
171
  });
173
172
  });
173
+ describe('Youtubedl', function () {
174
+ describe('#getSongInfo', function () {
175
+ this.timeout(5000);
176
+ it('should return a lot more information from working soundcloud link', async function () {
177
+ const input = 'https://soundcloud.com/bionicelcor/wakusei-abnormal';
178
+ const expected = {
179
+ full: true,
180
+ metadataType: "youtubedl",
181
+ url: input,
182
+ title: "ふこうぶつ -- Wakusei Abnormal",
183
+ duration: 164.638,
184
+ artist: [],
185
+ date: new Date(1512946800000)
186
+ };
187
+ const result = await youtubedlService.getSongInfo(input, console.log);
188
+ sortOfDeepEqual(result, expected);
189
+ });
190
+ });
191
+ /* TODO: figure this out
192
+ describe('#getSongInfo', function () {
193
+ this.timeout(5000);
194
+ it('should return a lot more information from working mp3 link with metadata', async function () {
195
+ const input = 'https://yourgi.ga/bCy/adUdC.mp3';
196
+ const expected = {
197
+ full: true,
198
+ metadataType: "youtubedl",
199
+ url: input,
200
+ title: "ふこうぶつ -- Wakusei Abnormal",
201
+ duration: 164.638,
202
+ artist: [],
203
+ date: new Date(1512946800000)
204
+ };
205
+ const result = await youtubedlService.getSongInfo(input, console.log);
206
+ sortOfDeepEqual(result, expected);
207
+ });
208
+ });
209
+ */
210
+ });
174
211
  });
@@ -1,10 +0,0 @@
1
- import { IService, SongInfo, Logger } from '../../core/';
2
- import YoutubedlSong from './song';
3
- export default class YoutubedlService implements IService {
4
- canSearch: boolean;
5
- type: string;
6
- fetch(targets: string[], logger?: Logger): Promise<YoutubedlSong[]>;
7
- search(): Promise<YoutubedlSong[]>;
8
- canFetch(target: string, logger?: Logger): Promise<boolean>;
9
- getSongInfo(url: string, logger?: Logger): Promise<SongInfo>;
10
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const song_1 = __importDefault(require("./song"));
15
- const youtube_dl_1 = __importDefault(require("youtube-dl"));
16
- class YoutubedlService {
17
- constructor() {
18
- this.canSearch = false;
19
- this.type = 'youtubedl';
20
- }
21
- fetch(targets, logger) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- return targets.map(x => new song_1.default(this, x, logger));
24
- });
25
- }
26
- search() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return [];
29
- });
30
- }
31
- canFetch(target, logger) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise(resolve => {
34
- youtube_dl_1.default.exec(target, ['-j'], {}, (err) => resolve(!!err));
35
- });
36
- });
37
- }
38
- getSongInfo(url, logger) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- return {
41
- full: true,
42
- metadataType: "unknown",
43
- imgURL: "",
44
- title: url,
45
- duration: 0,
46
- url: url,
47
- artist: [],
48
- date: new Date(),
49
- custom: {}
50
- };
51
- });
52
- }
53
- }
54
- exports.default = YoutubedlService;
@@ -1,14 +0,0 @@
1
- /// <reference types="node" />
2
- import { Readable as ReadableStream } from 'stream';
3
- import { Song, SongInfo, Logger } from '../../core';
4
- import YoutubedlService from './service';
5
- export default class YoutubedlSong extends Song {
6
- readonly type: string;
7
- readonly streamURL: string;
8
- readonly URL: string;
9
- info: SongInfo;
10
- logger?: Logger;
11
- constructor(service: YoutubedlService, url: string, logger?: Logger);
12
- getSongInfo(): Promise<SongInfo>;
13
- stream(): ReadableStream;
14
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const core_1 = require("../../core");
15
- const youtube_dl_1 = __importDefault(require("youtube-dl"));
16
- class YoutubedlSong extends core_1.Song {
17
- constructor(service, url, logger) {
18
- super(service);
19
- this.type = 'youtubedl';
20
- this.streamURL = url;
21
- this.URL = url;
22
- this.info = {
23
- full: false,
24
- metadataType: this.type,
25
- url: this.URL
26
- };
27
- this.logger = logger;
28
- }
29
- getSongInfo() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- if (!this.info.full) {
32
- this.info = yield this.service.getSongInfo(this.URL);
33
- }
34
- return this.info;
35
- });
36
- }
37
- stream() {
38
- if (typeof (this.logger) == 'function')
39
- this.logger(`[${this.type}] Fetching stream for ${this.URL}.`);
40
- return youtube_dl_1.default(this.streamURL, [], {});
41
- }
42
- }
43
- exports.default = YoutubedlSong;