mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-31 14:57:58 +00:00
✨ feat: Audio metadata
This commit is contained in:
@@ -9,7 +9,7 @@ import dotenv from "dotenv";
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const videoId = "2gigEGxnsmo";
|
const videoId = "l6gPxDSNbVk";
|
||||||
const videoId2 = "oM-JneFEdBk";
|
const videoId2 = "oM-JneFEdBk";
|
||||||
|
|
||||||
// Providers
|
// Providers
|
||||||
@@ -21,7 +21,11 @@ const main = async () => {
|
|||||||
player.startCurrentStream();
|
player.startCurrentStream();
|
||||||
});
|
});
|
||||||
|
|
||||||
await player.enqueue(`https://www.youtube.com/watch?v=${videoId}`);
|
const info = await player.enqueue(
|
||||||
|
`https://www.youtube.com/watch?v=${videoId}`,
|
||||||
|
);
|
||||||
|
console.log(info);
|
||||||
|
|
||||||
await player.enqueue(`https://www.youtube.com/watch?v=${videoId2}`);
|
await player.enqueue(`https://www.youtube.com/watch?v=${videoId2}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Player, createPlayer } from "./player";
|
import { Player, createPlayer } from "./player";
|
||||||
|
import { YtDlpProvider } from "./providers";
|
||||||
|
|
||||||
export { Player, createPlayer };
|
export { Player, createPlayer };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Player,
|
Player,
|
||||||
|
YtDlpProvider,
|
||||||
createPlayer,
|
createPlayer,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export class Player {
|
|||||||
this.queue.push(information);
|
this.queue.push(information);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Enqueued", url);
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async seek(time: number) {
|
public async seek(time: number) {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ export interface AudioInformation {
|
|||||||
};
|
};
|
||||||
bitrate: number;
|
bitrate: number;
|
||||||
livestream: boolean;
|
livestream: boolean;
|
||||||
|
metadata: {
|
||||||
|
title: string | null;
|
||||||
|
thumbnail: string | null;
|
||||||
|
};
|
||||||
refreshInfoFunction: () => Promise<AudioInformation>;
|
refreshInfoFunction: () => Promise<AudioInformation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,24 @@ export class YtDlpProvider extends Provider {
|
|||||||
throw new Error("Failed to parse YouTube formats");
|
throw new Error("Failed to parse YouTube formats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bestThumbnail = null;
|
||||||
|
|
||||||
|
type Thumbnail = { url: string; preference: number };
|
||||||
|
const sortedThumbnails = ytDlpWrapInfo.thumbnails.sort(
|
||||||
|
(a: Thumbnail, b: Thumbnail) => b.preference - a.preference,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let thumbnail of sortedThumbnails) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(thumbnail.url);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
bestThumbnail = thumbnail.url;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: ytDlpWrapInfo.url,
|
url: ytDlpWrapInfo.url,
|
||||||
fileSize: ytDlpWrapInfo.filesize,
|
fileSize: ytDlpWrapInfo.filesize,
|
||||||
@@ -52,6 +70,10 @@ export class YtDlpProvider extends Provider {
|
|||||||
bitrate: ytDlpWrapInfo.asr, //bitrate: Math.ceil((ytDlpWrapInfo.tbr || 128) * 1000),
|
bitrate: ytDlpWrapInfo.asr, //bitrate: Math.ceil((ytDlpWrapInfo.tbr || 128) * 1000),
|
||||||
livestream: ytDlpWrapInfo.is_live,
|
livestream: ytDlpWrapInfo.is_live,
|
||||||
refreshInfoFunction,
|
refreshInfoFunction,
|
||||||
|
metadata: {
|
||||||
|
title: ytDlpWrapInfo.title,
|
||||||
|
thumbnail: bestThumbnail,
|
||||||
|
},
|
||||||
} as AudioInformation;
|
} as AudioInformation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user