mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-30 12:32:55 +00:00
✨ feat: Audio metadata
This commit is contained in:
@@ -9,7 +9,7 @@ import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
const main = async () => {
|
||||
const videoId = "2gigEGxnsmo";
|
||||
const videoId = "l6gPxDSNbVk";
|
||||
const videoId2 = "oM-JneFEdBk";
|
||||
|
||||
// Providers
|
||||
@@ -21,7 +21,11 @@ const main = async () => {
|
||||
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}`);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Player, createPlayer } from "./player";
|
||||
import { YtDlpProvider } from "./providers";
|
||||
|
||||
export { Player, createPlayer };
|
||||
|
||||
export default {
|
||||
Player,
|
||||
YtDlpProvider,
|
||||
createPlayer,
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ export class Player {
|
||||
this.queue.push(information);
|
||||
}
|
||||
|
||||
console.log("Enqueued", url);
|
||||
return information;
|
||||
}
|
||||
|
||||
public async seek(time: number) {
|
||||
|
||||
@@ -8,6 +8,10 @@ export interface AudioInformation {
|
||||
};
|
||||
bitrate: number;
|
||||
livestream: boolean;
|
||||
metadata: {
|
||||
title: string | null;
|
||||
thumbnail: string | null;
|
||||
};
|
||||
refreshInfoFunction: () => Promise<AudioInformation>;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,24 @@ export class YtDlpProvider extends Provider {
|
||||
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 {
|
||||
url: ytDlpWrapInfo.url,
|
||||
fileSize: ytDlpWrapInfo.filesize,
|
||||
@@ -52,6 +70,10 @@ export class YtDlpProvider extends Provider {
|
||||
bitrate: ytDlpWrapInfo.asr, //bitrate: Math.ceil((ytDlpWrapInfo.tbr || 128) * 1000),
|
||||
livestream: ytDlpWrapInfo.is_live,
|
||||
refreshInfoFunction,
|
||||
metadata: {
|
||||
title: ytDlpWrapInfo.title,
|
||||
thumbnail: bestThumbnail,
|
||||
},
|
||||
} as AudioInformation;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user