diff --git a/src/YTMusic.ts b/src/YTMusic.ts index 6eb5f13..e8791c4 100644 --- a/src/YTMusic.ts +++ b/src/YTMusic.ts @@ -254,9 +254,12 @@ export default class YTMusic { * @returns Song Data */ public async getSong(videoId: string): Promise { + if (!videoId.match(/^[a-zA-Z0-9-_]{11}$/)) throw new Error("Invalid videoId") const data = await this.constructRequest("player", { videoId }) - return SongParser.parse(data) + const song = SongParser.parse(data) + if (song.videoId !== videoId) throw new Error("Invalid videoId") + return song } /** @@ -266,9 +269,12 @@ export default class YTMusic { * @returns Video Data */ public async getVideo(videoId: string): Promise { + if (!videoId.match(/^[a-zA-Z0-9-_]{11}$/)) throw new Error("Invalid videoId") const data = await this.constructRequest("player", { videoId }) - return VideoParser.parse(data) + const video = VideoParser.parse(data) + if (video.videoId !== videoId) throw new Error("Invalid videoId") + return video } /**