mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix(synced-lyric): fix album_name
This commit is contained in:
@ -19,13 +19,6 @@ export const [differentDuration, setDifferentDuration] = createSignal(false);
|
|||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
export let foundPlainTextLyrics = false;
|
export let foundPlainTextLyrics = false;
|
||||||
|
|
||||||
export type SongData = {
|
|
||||||
title: string;
|
|
||||||
artist: string;
|
|
||||||
album: string;
|
|
||||||
songDuration: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const extractTimeAndText = (
|
export const extractTimeAndText = (
|
||||||
line: string,
|
line: string,
|
||||||
index: number,
|
index: number,
|
||||||
@ -33,7 +26,7 @@ export const extractTimeAndText = (
|
|||||||
const groups = /\[(\d+):(\d+)\.(\d+)\](.+)/.exec(line);
|
const groups = /\[(\d+):(\d+)\.(\d+)\](.+)/.exec(line);
|
||||||
if (!groups) return null;
|
if (!groups) return null;
|
||||||
|
|
||||||
const [_, rMinutes, rSeconds, rMillis, text] = groups;
|
const [, rMinutes, rSeconds, rMillis, text] = groups;
|
||||||
const [minutes, seconds, millis] = [
|
const [minutes, seconds, millis] = [
|
||||||
parseInt(rMinutes),
|
parseInt(rMinutes),
|
||||||
parseInt(rSeconds),
|
parseInt(rSeconds),
|
||||||
@ -46,7 +39,7 @@ export const extractTimeAndText = (
|
|||||||
return {
|
return {
|
||||||
index,
|
index,
|
||||||
timeInMs,
|
timeInMs,
|
||||||
time: `${minutes}:${seconds}:${millis}`,
|
time: `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}:${millis}`,
|
||||||
text: text?.trim() ?? config()!.defaultTextString,
|
text: text?.trim() ?? config()!.defaultTextString,
|
||||||
status: 'upcoming',
|
status: 'upcoming',
|
||||||
duration: 0,
|
duration: 0,
|
||||||
@ -55,7 +48,7 @@ export const extractTimeAndText = (
|
|||||||
|
|
||||||
export const makeLyricsRequest = async (extractedSongInfo: SongInfo) => {
|
export const makeLyricsRequest = async (extractedSongInfo: SongInfo) => {
|
||||||
setLineLyrics([]);
|
setLineLyrics([]);
|
||||||
const songData: SongData = {
|
const songData: Parameters<typeof getLyricsList>[0] = {
|
||||||
title: `${extractedSongInfo.title}`,
|
title: `${extractedSongInfo.title}`,
|
||||||
artist: `${extractedSongInfo.artist}`,
|
artist: `${extractedSongInfo.artist}`,
|
||||||
album: `${extractedSongInfo.album}`,
|
album: `${extractedSongInfo.album}`,
|
||||||
@ -67,7 +60,7 @@ export const makeLyricsRequest = async (extractedSongInfo: SongInfo) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getLyricsList = async (
|
export const getLyricsList = async (
|
||||||
songData: SongData,
|
songData: Pick<SongInfo, 'title' | 'artist' | 'album' | 'songDuration'>,
|
||||||
): Promise<LineLyrics[] | null> => {
|
): Promise<LineLyrics[] | null> => {
|
||||||
setIsFetching(true);
|
setIsFetching(true);
|
||||||
setIsInstrumental(false);
|
setIsInstrumental(false);
|
||||||
@ -80,7 +73,7 @@ export const getLyricsList = async (
|
|||||||
track_name: songData.title,
|
track_name: songData.title,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (songData.album?.length ?? 0 > 1) {
|
if (songData.album) {
|
||||||
query.set('album_name', songData.album);
|
query.set('album_name', songData.album);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,14 +167,14 @@ export const getLyricsList = async (
|
|||||||
// Add a blank line at the beginning
|
// Add a blank line at the beginning
|
||||||
raw.unshift('[0:0.0] ');
|
raw.unshift('[0:0.0] ');
|
||||||
|
|
||||||
const syncedLyricList = [];
|
const syncedLyricList = raw.reduce<LineLyrics[]>((acc, line, index) => {
|
||||||
|
const syncedLine = extractTimeAndText(line, index);
|
||||||
for (let idx = 0; idx < raw.length; idx++) {
|
|
||||||
const syncedLine = extractTimeAndText(raw[idx], idx);
|
|
||||||
if (syncedLine) {
|
if (syncedLine) {
|
||||||
syncedLyricList.push(syncedLine);
|
acc.push(syncedLine);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
|
||||||
for (const line of syncedLyricList) {
|
for (const line of syncedLyricList) {
|
||||||
const next = syncedLyricList[line.index + 1];
|
const next = syncedLyricList[line.index + 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user