Skip to content

Commit

Permalink
fix(lyrics-plus): copy converted Japanese lyrics (spicetify#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie25 authored Dec 30, 2022
1 parent 5d2384a commit 902aad6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
42 changes: 2 additions & 40 deletions CustomApps/lyrics-plus/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,7 @@ const SyncedLyricsPage = react.memo(({ lyrics = [], provider, copyright, isKara
offset += -(activeLineEle.current.offsetTop + activeLineEle.current.clientHeight / 2);
}

const rawLyrics = lyrics
.map(line => {
if (!line.startTime) return line.text;
let startTimeString = "";

if (!isNaN(line.startTime)) {
let minutes = Math.trunc(line.startTime / 60000),
seconds = ((line.startTime - minutes * 60000) / 1000).toFixed(2);

if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;

startTimeString = `${minutes}:${seconds}`;
} else {
startTimeString = line.startTime.toString();
}

return `[${startTimeString}]${line.text}`;
})
.join("\n");
const rawLyrics = Utils.convertParsedToLRC(lyrics);

return react.createElement(
"div",
Expand Down Expand Up @@ -387,26 +368,7 @@ const SyncedExpandedLyricsPage = react.memo(({ lyrics, provider, copyright, isKa
}
}

const rawLyrics = lyrics
.map(line => {
if (!line.startTime) return line.text;
let startTimeString = "";

if (!isNaN(line.startTime)) {
let minutes = Math.trunc(line.startTime / 60000),
seconds = ((line.startTime - minutes * 60000) / 1000).toFixed(2);

if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;

startTimeString = `${minutes}:${seconds}`;
} else {
startTimeString = line.startTime.toString();
}

return `[${startTimeString}]${line.text}`;
})
.join("\n");
const rawLyrics = Utils.convertParsedToLRC(lyrics);

useEffect(() => {
if (activeLineRef.current && (!intialScroll[0] || isInViewport(activeLineRef.current))) {
Expand Down
36 changes: 36 additions & 0 deletions CustomApps/lyrics-plus/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,40 @@ class Utils {

return react.createElement("p1", null, reactChildren);
}

static convertParsedToLRC(lyrics) {
return lyrics
.map(line => {
// Process converted Japanese lyrics
if (line.text.props?.children) {
line.rawText = line.text.props.children
.map(child => {
if (typeof child === "string") {
return child;
} else if (child.props?.children) {
return child.props?.children[0];
}
})
.join("");
}
if (!line.startTime) return line.text;
let startTimeString = "";

// Convert milliseconds to mm:ss format
if (!isNaN(line.startTime)) {
let minutes = Math.trunc(line.startTime / 60000),
seconds = ((line.startTime - minutes * 60000) / 1000).toFixed(2);

if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;

startTimeString = `${minutes}:${seconds}`;
} else {
startTimeString = line.startTime.toString();
}

return `[${startTimeString}]${line.rawText || line.text}`;
})
.join("\n");
}
}

0 comments on commit 902aad6

Please sign in to comment.