vdj 1.1.3 → 1.1.4

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, { "o": true, "f": "bestvideo[height<=?480]+bestaudio/best[height<=480]", _: ['-'] }, {}).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.4",
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
  });