Skip to content

Commit

Permalink
Merge pull request #348 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: resolved lrc mapping
  • Loading branch information
lovegaoshi authored Mar 15, 2024
2 parents 9045725 + 1e274d0 commit 04f2c5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/he": "^1.2.3",
"@types/jest": "^29.5.12",
"@types/md5": "^2.3.5",
"@types/node": "^20.11.26",
"@types/node": "^20.11.27",
"@types/react": "^18.2.65",
"@types/react-native": "^0.73.0",
"@types/react-native-background-timer": "^2.0.2",
Expand Down
29 changes: 15 additions & 14 deletions src/components/player/Lyric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ export const LyricView = ({
logger.debug('[lrc] read local lrc and loading...');
setLrc(readlrc);
return true;
} else if (lrcDetail.lyric.endsWith('.txt')) {
logger.debug('[lrc] local lrc no longer exists, fetching new...');
}
logger.debug('[lrc] local lrc no longer exists, fetching new...');
searchAndSetCurrentLyric(0, await lyricPromise, lrcKey);
return true;
}
Expand Down Expand Up @@ -143,15 +142,19 @@ export const LyricView = ({
return lyricMapping.has(track?.song?.id);
};

const updateLyricMapping = (
newLrcDetail: Partial<NoxMedia.LyricDetail> = {}
) => {
if (lrcOption !== null && lrcOption !== undefined) {
const updateLyricMapping = ({
resolvedLrc = lrcOption,
newLrcDetail = {},
}: {
resolvedLrc?: NoxNetwork.NoxFetchedLyric;
newLrcDetail?: Partial<NoxMedia.LyricDetail>;
}) => {
if (resolvedLrc !== null && resolvedLrc !== undefined) {
const lrcpath = `${track.song.id}.txt`;
writeTxtFile(lrcpath, [newLrcDetail.lyric || lrc], 'lrc/');
const lyricDeatail: NoxMedia.LyricDetail = {
songId: track.song.id,
lyricKey: lrcOption.key,
lyricKey: resolvedLrc.key,
lyricOffset: currentTimeOffset,
...newLrcDetail,
lyric: lrcpath,
Expand All @@ -165,7 +168,7 @@ export const LyricView = ({
? currentTimeOffset + LYRIC_OFFSET_INTERVAL
: currentTimeOffset - LYRIC_OFFSET_INTERVAL;
setCurrentTimeOffset(newTimeOffset);
updateLyricMapping({ lyricOffset: newTimeOffset });
updateLyricMapping({ newLrcDetail: { lyricOffset: newTimeOffset } });
};

const fetchAndSetLyricOptions = async (adhocTitle?: string) => {
Expand Down Expand Up @@ -194,12 +197,10 @@ export const LyricView = ({
console.debug(`lrcoptions: ${JSON.stringify(resolvedLrcOptions)}`);
if (resolvedLrcOptions.length === 0) setLrc('无法找到歌词,请手动搜索...');
else {
const lyric = await searchLyric(
lyricMid || resolvedLrcOptions[index!].songMid,
setLrc
);
setLrcOption(resolvedLrcOptions[index!]);
updateLyricMapping({ lyric });
const resolvedLrc = resolvedLrcOptions[index!];
const lyric = await searchLyric(lyricMid || resolvedLrc.songMid, setLrc);
setLrcOption(resolvedLrc);
updateLyricMapping({ newLrcDetail: { lyric }, resolvedLrc });
}
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3981,10 +3981,10 @@
dependencies:
undici-types "~5.26.4"

"@types/node@^20.11.26":
version "20.11.26"
resolved "https://registry.npmjs.org/@types/node/-/node-20.11.26.tgz#3fbda536e51d5c79281e1d9657dcb0131baabd2d"
integrity sha512-YwOMmyhNnAWijOBQweOJnQPl068Oqd4K3OFbTc6AHJwzweUwwWG3GIFY74OKks2PJUDkQPeddOQES9mLn1CTEQ==
"@types/node@^20.11.27":
version "20.11.27"
resolved "https://registry.npmjs.org/@types/node/-/node-20.11.27.tgz#debe5cfc8a507dd60fe2a3b4875b1604f215c2ac"
integrity sha512-qyUZfMnCg1KEz57r7pzFtSGt49f6RPkPBis3Vo4PbS7roQEDn22hiHzl/Lo1q4i4hDEgBJmBF/NTNg2XR0HbFg==
dependencies:
undici-types "~5.26.4"

Expand Down

0 comments on commit 04f2c5c

Please sign in to comment.