mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-31 04:42:51 +00:00
✨ feat: Audio metadata
This commit is contained in:
@@ -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