feat(discord): add song & artist URLs to rich presence (#3737)

Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
lew
2025-09-05 02:32:31 -04:00
committed by GitHub
parent b64e1394ae
commit e6c78dd5e0
2 changed files with 8 additions and 1 deletions

View File

@ -99,7 +99,9 @@ export class DiscordService {
const activityInfo: SetActivity = {
type: ActivityType.Listening,
details: truncateString(songInfo.title, 128), // Song title
detailsUrl: songInfo.url,
state: truncateString(songInfo.artist, 128), // Artist name
stateUrl: songInfo.artistUrl,
largeImageKey: songInfo.imageSrc ?? undefined,
largeImageText: songInfo.album
? truncateString(songInfo.album, 128)

View File

@ -30,6 +30,7 @@ export interface SongInfo {
title: string;
alternativeTitle?: string;
artist: string;
artistUrl?: string;
views: number;
uploadDate?: string;
imageSrc?: string | null;
@ -72,6 +73,7 @@ const handleData = async (
title: '',
alternativeTitle: '',
artist: '',
artistUrl: '',
views: 0,
uploadDate: '',
imageSrc: '',
@ -93,6 +95,9 @@ const handleData = async (
songInfo.url = microformat.urlCanonical?.split('&')[0];
songInfo.playlistId =
new URL(microformat.urlCanonical).searchParams.get('list') ?? '';
if (microformat.pageOwnerDetails?.externalChannelId) {
songInfo.artistUrl = `https://music.youtube.com/channel/${microformat.pageOwnerDetails.externalChannelId}`;
}
// Used for options.resumeOnStart
config.set('url', microformat.urlCanonical);
songInfo.alternativeTitle = microformat.linkAlternates.find(
@ -110,7 +115,7 @@ const handleData = async (
songInfo.elapsedSeconds = videoDetails.elapsedSeconds;
songInfo.isPaused = videoDetails.isPaused;
songInfo.videoId = videoDetails.videoId;
songInfo.album = data?.videoDetails?.album; // Will be undefined if video exist
songInfo.album = videoDetails.album; // Will be undefined if video exist
switch (videoDetails?.musicVideoType) {
case 'MUSIC_VIDEO_TYPE_ATV':