mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 11:51:47 +00:00
feat(discord): add song & artist URLs to rich presence (#3737)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -99,7 +99,9 @@ export class DiscordService {
|
|||||||
const activityInfo: SetActivity = {
|
const activityInfo: SetActivity = {
|
||||||
type: ActivityType.Listening,
|
type: ActivityType.Listening,
|
||||||
details: truncateString(songInfo.title, 128), // Song title
|
details: truncateString(songInfo.title, 128), // Song title
|
||||||
|
detailsUrl: songInfo.url,
|
||||||
state: truncateString(songInfo.artist, 128), // Artist name
|
state: truncateString(songInfo.artist, 128), // Artist name
|
||||||
|
stateUrl: songInfo.artistUrl,
|
||||||
largeImageKey: songInfo.imageSrc ?? undefined,
|
largeImageKey: songInfo.imageSrc ?? undefined,
|
||||||
largeImageText: songInfo.album
|
largeImageText: songInfo.album
|
||||||
? truncateString(songInfo.album, 128)
|
? truncateString(songInfo.album, 128)
|
||||||
|
|||||||
@ -30,6 +30,7 @@ export interface SongInfo {
|
|||||||
title: string;
|
title: string;
|
||||||
alternativeTitle?: string;
|
alternativeTitle?: string;
|
||||||
artist: string;
|
artist: string;
|
||||||
|
artistUrl?: string;
|
||||||
views: number;
|
views: number;
|
||||||
uploadDate?: string;
|
uploadDate?: string;
|
||||||
imageSrc?: string | null;
|
imageSrc?: string | null;
|
||||||
@ -72,6 +73,7 @@ const handleData = async (
|
|||||||
title: '',
|
title: '',
|
||||||
alternativeTitle: '',
|
alternativeTitle: '',
|
||||||
artist: '',
|
artist: '',
|
||||||
|
artistUrl: '',
|
||||||
views: 0,
|
views: 0,
|
||||||
uploadDate: '',
|
uploadDate: '',
|
||||||
imageSrc: '',
|
imageSrc: '',
|
||||||
@ -93,6 +95,9 @@ const handleData = async (
|
|||||||
songInfo.url = microformat.urlCanonical?.split('&')[0];
|
songInfo.url = microformat.urlCanonical?.split('&')[0];
|
||||||
songInfo.playlistId =
|
songInfo.playlistId =
|
||||||
new URL(microformat.urlCanonical).searchParams.get('list') ?? '';
|
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
|
// Used for options.resumeOnStart
|
||||||
config.set('url', microformat.urlCanonical);
|
config.set('url', microformat.urlCanonical);
|
||||||
songInfo.alternativeTitle = microformat.linkAlternates.find(
|
songInfo.alternativeTitle = microformat.linkAlternates.find(
|
||||||
@ -110,7 +115,7 @@ const handleData = async (
|
|||||||
songInfo.elapsedSeconds = videoDetails.elapsedSeconds;
|
songInfo.elapsedSeconds = videoDetails.elapsedSeconds;
|
||||||
songInfo.isPaused = videoDetails.isPaused;
|
songInfo.isPaused = videoDetails.isPaused;
|
||||||
songInfo.videoId = videoDetails.videoId;
|
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) {
|
switch (videoDetails?.musicVideoType) {
|
||||||
case 'MUSIC_VIDEO_TYPE_ATV':
|
case 'MUSIC_VIDEO_TYPE_ATV':
|
||||||
|
|||||||
Reference in New Issue
Block a user