Skip to content

Commit

Permalink
fix: thumbnails not being present sometimes & types (#25)
Browse files Browse the repository at this point in the history
- fixes current track being undefined for some reason
- removes debug logs (youtube.js class changes)
- other fixes
  • Loading branch information
Faf4a authored Oct 11, 2024
1 parent 3ede0d6 commit 2c04659
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 30 deletions.
15 changes: 13 additions & 2 deletions lib/newstruct/aoiVoice.js

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

2 changes: 1 addition & 1 deletion lib/newstruct/aoiVoice.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/newstruct/audioPlayer.js

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

2 changes: 1 addition & 1 deletion lib/newstruct/audioPlayer.js.map

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions lib/newstruct/manager.js

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

2 changes: 1 addition & 1 deletion lib/newstruct/manager.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/newutils/request.js

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

2 changes: 1 addition & 1 deletion lib/newutils/request.js.map

Large diffs are not rendered by default.

19 changes: 3 additions & 16 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aoijs/aoi.music",
"version": "1.2.3",
"version": "1.2.4",
"description": "Addition of the Music properties and foundation for aoi.js",
"author": {
"name": "Leref"
Expand Down
16 changes: 12 additions & 4 deletions src/newstruct/aoiVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,13 @@ export class AoiVoice<T> extends Manager {
return d.aoiError.fnError(d, "custom", {}, "Player Not Found.");

if (
!["relative", "youtube", "soundcloud", "spotify", "none"].includes(
type.toLowerCase()
)
![
"relative",
"youtube",
"soundcloud",
"spotify",
"none",
].includes(type.toLowerCase())
) {
return d.aoiError.fnError(
d,
Expand Down Expand Up @@ -1180,7 +1184,11 @@ export class AoiVoice<T> extends Manager {
const parsedPos = position
? parseInt(position)
: player.currentPosition();
data.result = eval(`player.queue[${parsedPos}].${type}`);
try {
data.result = eval(`player.queue[${parsedPos}].${type}`);
} catch (error) {
data.result = null;
}
return {
code: d.util.setCode(data),
};
Expand Down
1 change: 1 addition & 0 deletions src/newstruct/audioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class AudioPlayer {
async play(emit = true) {
let resource: AudioResource;
const current = this.queue[this.#modes.currentTrack];
if (!current) return;
let stream: Readable | FFmpeg | PassThrough;
//@ts-ignore
stream = await requestStream(
Expand Down
12 changes: 11 additions & 1 deletion src/newstruct/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@discordjs/voice";
import { Snowflake, VoiceBasedChannel } from "discord.js";
import { TypedEmitter } from "tiny-typed-emitter/lib/index";
import { Innertube, UniversalCache, Utils } from "youtubei.js";
import { Innertube, UniversalCache, Log } from "youtubei.js";
import IT from "youtubei.js";
import {
Credentials,
Expand Down Expand Up @@ -133,6 +133,9 @@ export class Manager extends TypedEmitter<ManagerEvents> {

generateYoutubePoToken();
}
// prevent future class changes from being logged to console
// so people don't get confused about those *absolutely* irrelevant logs
Log.setLevel(Log.Level.NONE);
const youtubeOptions: any = {
cache: new UniversalCache(true),
};
Expand Down Expand Up @@ -347,6 +350,13 @@ export class Manager extends TypedEmitter<ManagerEvents> {
>(adapter ? adapter : <unknown>voiceChannel.guild?.voiceAdapterCreator ?? adapter),
group: voiceChannel.client.user.id,
};
// destory player if already exists to prevent memory leaks
if (this.players.has(data.guildId)) {
const player = this.players.get(data.guildId);
player?._destroy();
this.players.delete(data.guildId);
player.options.connection.destroy();
}
const connection = joinVoiceChannel(data);
connection.on("error", console.error);
try {
Expand Down
2 changes: 1 addition & 1 deletion src/newutils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export async function requestInfo<T extends keyof typeof PlatformType>(id: strin
} else if (type === "Youtube") {
const ytData: any = await (await manager.platforms.youtube).getBasicInfo(id, manager.configs.searchOptions?.youtubeClient ?? "TV_EMBEDDED").catch((_) => undefined);
if (!ytData) return;
console.log(JSON.stringify(ytData.basic_info, null, 2));
return <Track<T>>(<unknown>{
title: ytData.basic_info.title,
channelId: ytData.basic_info.channel_id,
Expand Down Expand Up @@ -309,6 +308,7 @@ export async function requestInfo<T extends keyof typeof PlatformType>(id: strin
}

export async function requestStream<T extends keyof typeof PlatformType>(track: Track<T>, type: T, manager: Manager) {
if (!track) return;
if (manager.plugins.has(PluginName.Cacher) && (<Plugin<PluginName.Cacher>>manager.plugins.get(PluginName.Cacher)).has(track.id)) {
return (<Plugin<PluginName.Cacher>>manager.plugins.get(PluginName.Cacher)).get(track.id);
} else if (type === "SoundCloud") {
Expand Down

0 comments on commit 2c04659

Please sign in to comment.