vdj 1.6.10 → 1.7.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.
@@ -5,6 +5,7 @@ export default class YouTubeService implements IService {
5
5
  readonly api: API;
6
6
  canSearch: boolean;
7
7
  type: string;
8
+ private innertubePromise;
8
9
  constructor(key: string);
9
10
  fetch(targets: string[], logger?: Logger): Promise<YouTubeSong[]>;
10
11
  search(queries: string[], searchType: SearchType, logger?: Logger): Promise<YouTubeSong[]>;
@@ -13,12 +13,13 @@ 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("@distube/ytdl-core");
16
+ const youtubei_js_1 = require("youtubei.js");
17
17
  const song_1 = __importDefault(require("./song"));
18
18
  class YouTubeService {
19
19
  constructor(key) {
20
20
  this.canSearch = true;
21
21
  this.type = 'youtube';
22
+ this.innertubePromise = youtubei_js_1.Innertube.create();
22
23
  this.api = new API(key);
23
24
  }
24
25
  fetch(targets, logger) {
@@ -78,17 +79,24 @@ class YouTubeService {
78
79
  }
79
80
  getSongInfo(url, logger) {
80
81
  return __awaiter(this, void 0, void 0, function* () {
82
+ var _a, _b, _c, _d;
83
+ function url_parser(url) {
84
+ var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
85
+ var match = url.match(regExp);
86
+ return (match && match[7].length == 11) ? match[7] : url;
87
+ }
81
88
  try {
82
- const result = yield ytdl.getInfo(url);
89
+ const innertube = yield this.innertubePromise;
90
+ const result = yield innertube.getBasicInfo(url_parser(url));
83
91
  return {
84
92
  full: true,
85
93
  metadataType: "youtube",
86
- imgURL: result.player_response.videoDetails.thumbnail.thumbnails[0].url,
87
- title: result.videoDetails.title,
88
- duration: Number(result.videoDetails.lengthSeconds),
89
- url: result.videoDetails.video_url,
90
- artist: [result.videoDetails.author.name],
91
- date: new Date(result.videoDetails.publishDate),
94
+ imgURL: (_c = (_b = (_a = result.basic_info) === null || _a === void 0 ? void 0 : _a.thumbnail) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.url,
95
+ title: result.basic_info.title,
96
+ duration: result.basic_info.duration ? Number(result.basic_info.duration) : undefined,
97
+ url: (_d = result.basic_info.url_canonical) !== null && _d !== void 0 ? _d : url,
98
+ artist: result.basic_info.author ? [result.basic_info.author] : undefined,
99
+ date: undefined,
92
100
  custom: result
93
101
  };
94
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vdj",
3
- "version": "1.6.10",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -15,11 +15,11 @@
15
15
  "typescript": "^5.7.3"
16
16
  },
17
17
  "dependencies": {
18
- "@distube/ytdl-core": "^4.16.12",
19
18
  "@types/node": "^12.19.2",
20
19
  "got": "^13.0.0",
21
20
  "mocha": "^10.7.3",
22
21
  "simple-youtube-api": "^5.2.1",
23
- "youtube-dl-exec": "^3.0.22"
22
+ "youtube-dl-exec": "^3.0.30",
23
+ "youtubei.js": "^16.0.1"
24
24
  }
25
25
  }
@@ -1,14 +1,17 @@
1
1
  import API = require('simple-youtube-api');
2
- import ytdl = require("@distube/ytdl-core");
2
+ import { Innertube, Generator } from 'youtubei.js';
3
3
 
4
4
  import { IService, SearchType, SongInfo, Logger } from '../../core/';
5
5
  import YouTubeSong from './song';
6
+ import { VideoInfo } from 'youtubei.js/dist/src/parser/youtube';
6
7
 
7
8
  export default class YouTubeService implements IService {
8
9
  public readonly api: API;
9
10
  public canSearch: boolean = true;
10
11
  public type: string = 'youtube';
11
12
 
13
+ private innertubePromise = Innertube.create();
14
+
12
15
  constructor(key: string) {
13
16
  this.api = new API(key);
14
17
  }
@@ -67,18 +70,25 @@ export default class YouTubeService implements IService {
67
70
  return parsed.video != undefined || parsed.playlist != undefined;
68
71
  }
69
72
 
70
- public async getSongInfo(url: string, logger?: Logger): Promise<SongInfo> {
73
+ public async getSongInfo(url: string, logger?: Logger): Promise<SongInfo> {
74
+ function url_parser(url: string): string {
75
+ var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
76
+ var match = url.match(regExp);
77
+ return (match && match[7].length == 11) ? match[7] : url;
78
+ }
79
+
71
80
  try {
72
- const result: ytdl.videoInfo = await ytdl.getInfo(url);
81
+ const innertube = await this.innertubePromise;
82
+ const result: VideoInfo = await innertube.getBasicInfo(url_parser(url));
73
83
  return {
74
84
  full: true,
75
85
  metadataType: "youtube",
76
- imgURL: ((result.player_response.videoDetails as any).thumbnail as ytdl.VideoDetails).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),
86
+ imgURL: result.basic_info?.thumbnail?.[0]?.url,
87
+ title: result.basic_info.title,
88
+ duration: result.basic_info.duration ? Number(result.basic_info.duration) : undefined,
89
+ url: result.basic_info.url_canonical ?? url,
90
+ artist: result.basic_info.author ? [result.basic_info.author] : undefined,
91
+ date: undefined,
82
92
  custom: result
83
93
  };
84
94
  } catch (e) {
package/test/test.js CHANGED
@@ -152,7 +152,7 @@ describe("Playlist", function () {
152
152
  title: "楽園ベイベー - RIP SLYME(Cover) / KMNZ",
153
153
  duration: 282,
154
154
  artist: ["KMNZ"],
155
- date: new Date(1566991937000),
155
+ date: undefined,
156
156
  };
157
157
  const result = await youtubeService.getSongInfo(input, console.log);
158
158
  sortOfDeepEqual(result, expected);