mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
fix(song-info-front): fix nullable issue
This commit is contained in:
@ -2,7 +2,7 @@ import { singleton } from './decorators';
|
|||||||
|
|
||||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||||
import type { GetState } from '@/types/datahost-get-state';
|
import type { GetState } from '@/types/datahost-get-state';
|
||||||
import type { AlbumDetails, VideoDataChangeValue } from '@/types/player-api-events';
|
import type { AlbumDetails, PlayerOverlays, VideoDataChangeValue } from '@/types/player-api-events';
|
||||||
|
|
||||||
import type { SongInfo } from './song-info';
|
import type { SongInfo } from './song-info';
|
||||||
import type { VideoDataChanged } from '@/types/video-data-changed';
|
import type { VideoDataChanged } from '@/types/video-data-changed';
|
||||||
@ -208,28 +208,35 @@ export default (api: YoutubePlayer) => {
|
|||||||
list: playlistId
|
list: playlistId
|
||||||
} = api.getVideoData();
|
} = api.getVideoData();
|
||||||
|
|
||||||
const { playerOverlays } = api.getWatchNextResponse();
|
const watchNextResponse = api.getWatchNextResponse();
|
||||||
|
|
||||||
sendSongInfo(<VideoDataChangeValue>{
|
sendSongInfo({
|
||||||
title, author, videoId, playlistId,
|
title, author, videoId, playlistId,
|
||||||
|
|
||||||
isUpcoming: false,
|
isUpcoming: false,
|
||||||
lengthSeconds: video.duration,
|
lengthSeconds: video.duration,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
|
||||||
uhhh: { playerOverlays }
|
ytmdWatchNextResponse: watchNextResponse,
|
||||||
});
|
} satisfies VideoDataChangeValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendSongInfo(videoData: VideoDataChangeValue) {
|
function sendSongInfo(videoData: VideoDataChangeValue) {
|
||||||
const data = api.getPlayerResponse();
|
const data = api.getPlayerResponse();
|
||||||
|
|
||||||
data.videoDetails.album = (
|
let playerOverlay: PlayerOverlays | undefined;
|
||||||
Object.entries(videoData).find(
|
|
||||||
([, value]) => value && Object.hasOwn(value, 'playerOverlays'),
|
if (!videoData.ytmdWatchNextResponse) {
|
||||||
) as [string, AlbumDetails | undefined]
|
playerOverlay = (
|
||||||
)?.[1]?.playerOverlays?.playerOverlayRenderer?.browserMediaSession?.browserMediaSessionRenderer?.album?.runs?.at(
|
Object.entries(videoData).find(
|
||||||
|
([, value]) => value && Object.hasOwn(value, 'playerOverlays'),
|
||||||
|
) as [string, AlbumDetails | undefined]
|
||||||
|
)?.[1]?.playerOverlays;
|
||||||
|
} else {
|
||||||
|
playerOverlay = videoData.ytmdWatchNextResponse?.playerOverlays;
|
||||||
|
}
|
||||||
|
data.videoDetails.album = playerOverlay?.playerOverlayRenderer?.browserMediaSession?.browserMediaSessionRenderer?.album?.runs?.at(
|
||||||
0,
|
0,
|
||||||
)?.text;
|
)?.text;
|
||||||
data.videoDetails.elapsedSeconds = 0;
|
data.videoDetails.elapsedSeconds = 0;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import type { WatchNextResponse } from '@/types/youtube-music-desktop-internal';
|
||||||
|
|
||||||
export interface AlbumDetails {
|
export interface AlbumDetails {
|
||||||
responseContext: ResponseContext;
|
responseContext: ResponseContext;
|
||||||
contents: Contents;
|
contents: Contents;
|
||||||
@ -252,6 +254,11 @@ export type VideoDataChangeValue = Record<string, unknown> & {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
|
||||||
lengthSeconds: number;
|
lengthSeconds: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* YouTube Music Desktop internal variable (for album data)
|
||||||
|
**/
|
||||||
|
ytmdWatchNextResponse?: WatchNextResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PlayerAPIEvents {
|
export interface PlayerAPIEvents {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { QueueItem } from '@/types/datahost-get-state';
|
import type { QueueItem } from '@/types/datahost-get-state';
|
||||||
|
import type { PlayerOverlays } from '@/types/player-api-events';
|
||||||
|
|
||||||
export interface QueueResponse {
|
export interface QueueResponse {
|
||||||
items?: QueueItem[];
|
items?: QueueItem[];
|
||||||
@ -7,15 +8,5 @@ export interface QueueResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WatchNextResponse {
|
export interface WatchNextResponse {
|
||||||
playerOverlays: {
|
playerOverlays?: PlayerOverlays;
|
||||||
playerOverlayRenderer: {
|
|
||||||
browserMediaSession: {
|
|
||||||
browserMediaSessionRenderer: {
|
|
||||||
album: {
|
|
||||||
runs: { text: string; }[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user