Skip to content

Commit

Permalink
fix(song.ts): changing youtube-sr to ytdl-core in Song.ts makeResource()
Browse files Browse the repository at this point in the history
  • Loading branch information
kzielinski committed Jun 17, 2024
1 parent d785326 commit 6b21834
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"play-dl": "^1.9.7",
"soundcloud-downloader": "^0.2.3",
"string-progressbar": "^1.0.4",
"youtube-sr": "~4.3.0"
"youtube-sr": "~4.3.0",
"ytdl-core": "^4.11.5"
},
"devDependencies": {
"@types/i18n": "^0.13.12",
Expand Down
9 changes: 6 additions & 3 deletions structs/Song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { i18n } from "../utils/i18n";
import { videoPattern, isURL } from "../utils/patterns";

const { stream, video_basic_info } = require("play-dl");
import ytdl from "ytdl-core";

export interface SongData {
url: string;
Expand Down Expand Up @@ -60,18 +61,20 @@ export class Song {
}
}

public async makeResource(): Promise<AudioResource<Song> | void> {
public async makeResource(): Promise<AudioResource | void> {
let playStream;

const source = this.url.includes("youtube") ? "youtube" : "soundcloud";

if (source === "youtube") {
playStream = await stream(this.url);
playStream = ytdl(this.url, { filter: "audioonly", liveBuffer: 0, quality: "lowestaudio" });
}

if (!stream) return;

return createAudioResource(playStream.stream, { metadata: this, inputType: playStream.type, inlineVolume: true });
if (!playStream) throw new Error("No stream found");

return createAudioResource(playStream, { metadata: this, inlineVolume: true });
}

public startMessage() {
Expand Down

0 comments on commit 6b21834

Please sign in to comment.