mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-20 07:54:17 +00:00
Added download current track lyrics
This commit is contained in:
parent
5fe7fe2a30
commit
55c61cc2c3
@ -2,7 +2,7 @@ import React from "react"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import classnames from "classnames"
|
import classnames from "classnames"
|
||||||
|
|
||||||
import { parseLRC } from "../../utils/lrcParser"
|
import { parseLRC, formatToLRC } from "../../utils/lrcParser"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Input,
|
Input,
|
||||||
@ -351,6 +351,17 @@ const LyricsEditor = ({ player }) => {
|
|||||||
app.message.success("Language file loaded")
|
app.message.success("Language file loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleLanguageDownload = () => {
|
||||||
|
const data = formatToLRC(lines)
|
||||||
|
const blob = new Blob([data], { type: "text/plain" })
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
|
||||||
|
const link = document.createElement("a")
|
||||||
|
link.href = url
|
||||||
|
link.download = `${state.track.title} - ${state.selectedLanguage}.txt`
|
||||||
|
link.click()
|
||||||
|
}
|
||||||
|
|
||||||
const followLineTick = () => {
|
const followLineTick = () => {
|
||||||
const currentTime = player.current.audio.current.currentTime
|
const currentTime = player.current.audio.current.currentTime
|
||||||
|
|
||||||
@ -409,6 +420,9 @@ const LyricsEditor = ({ player }) => {
|
|||||||
>
|
>
|
||||||
Load file
|
Load file
|
||||||
</UploadButton>
|
</UploadButton>
|
||||||
|
<Button onClick={() => handleLanguageDownload()}>
|
||||||
|
Download current
|
||||||
|
</Button>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
@ -92,43 +92,22 @@ export const parseLRC = (lrcContent) => {
|
|||||||
* @param {Object} lrcData - Structured LRC data
|
* @param {Object} lrcData - Structured LRC data
|
||||||
* @returns {string} LRC formatted string
|
* @returns {string} LRC formatted string
|
||||||
*/
|
*/
|
||||||
export const formatToLRC = (lrcData) => {
|
export const formatToLRC = (lines) => {
|
||||||
const { metadata = {}, lyrics = [] } = lrcData
|
const data = []
|
||||||
const lines = []
|
|
||||||
|
|
||||||
// Add metadata
|
lines.forEach((line) => {
|
||||||
const metadataMapping = {
|
if (line.time !== null) {
|
||||||
artist: "ar",
|
const timeStr = line.timeStr || formatSecondsToLRC(line.time)
|
||||||
title: "ti",
|
|
||||||
album: "al",
|
|
||||||
author: "au",
|
|
||||||
length: "length",
|
|
||||||
creator: "by",
|
|
||||||
editor: "re",
|
|
||||||
version: "ve",
|
|
||||||
offset: "offset",
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.entries(metadata).forEach(([key, value]) => {
|
if (line.break) {
|
||||||
const tag = metadataMapping[key] || key
|
data.push(`[${timeStr}]`)
|
||||||
lines.push(`[${tag}:${value}]`)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (lines.length > 0) {
|
|
||||||
lines.push("") // Empty line after metadata
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add lyrics
|
|
||||||
lyrics.forEach((lyric) => {
|
|
||||||
if (lyric.time !== null) {
|
|
||||||
const timeStr = lyric.timeStr || formatSecondsToLRC(lyric.time)
|
|
||||||
lines.push(`[${timeStr}]${lyric.text}`)
|
|
||||||
} else {
|
} else {
|
||||||
lines.push(lyric.text)
|
data.push(`[${timeStr}] ${line.text}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return lines.join("\n")
|
return data.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user