modify lyric time mechanism
This commit is contained in:
24
.env.example
24
.env.example
@@ -1,12 +1,20 @@
|
|||||||
WEBSITE_NAME=MeowEmbeddedMusicServer // Your website name
|
WEBSITE_NAME_CN=MeowEmbeddedMusicServer # Your website name in chinese
|
||||||
WEBSITE_URL=http://127.0.0.1:2233 // Your website URL
|
WEBSITE_NAME_EN=MeowEmbeddedMusicServer # Your website name in English
|
||||||
WEBSITE_DESC=A music server for embedded devices // Your website description
|
WEBSITE_TITLE_CN=MeowEmbeddedMusicServer # Your website title in chinese
|
||||||
WEBSITE_KEYWORDS=music, embedded, server // Your website keywords
|
WEBSITE_TITLE_EN=MeowEmbeddedMusicServer # Your website title in English
|
||||||
WEBSITE_AUTHOR=Yuafeng // Your website author
|
WEBSITE_DESC_CN=A music server for embedded devices # Your website description in chinese
|
||||||
WEBSITE_FAVICON=favicon.ico // Your website favicon
|
WEBSITE_DESC_EN=A music server for embedded devices # Your website description in English
|
||||||
PORT=2233 // Your website port
|
WEBSITE_KEYWORDS_CN=music, embedded, server # Your website keywords in chinese
|
||||||
|
WEBSITE_KEYWORDS_EN=music, embedded, server # Your website keywords in English
|
||||||
|
WEBSITE_FAVICON=/favicon.ico # Your website favicon
|
||||||
|
WEBSITE_BACKGROUND=/background.webp # Your website background image
|
||||||
|
|
||||||
// Yuafeng free API sources
|
WEBSITE_URL=http://127.0.0.1:2233 # Your website URL
|
||||||
|
PORT=2233 # Your website port
|
||||||
|
|
||||||
|
FONTAWESOME_CDN=https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css # Fontawesome CDN
|
||||||
|
|
||||||
|
# Yuafeng free API sources
|
||||||
API_SOURCES=kuwo
|
API_SOURCES=kuwo
|
||||||
API_SOURCES_1=netease
|
API_SOURCES_1=netease
|
||||||
API_SOURCES_2=migu
|
API_SOURCES_2=migu
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,7 +101,7 @@ func YuafengAPIResponseHandler(sources, song, singer string) MusicItem {
|
|||||||
fmt.Println("[Warning] Lyric retrieval failed, skipping lyric file creation and download.")
|
fmt.Println("[Warning] Lyric retrieval failed, skipping lyric file creation and download.")
|
||||||
} else if !strings.HasPrefix(lyricData, "http://") && !strings.HasPrefix(lyricData, "https://") {
|
} else if !strings.HasPrefix(lyricData, "http://") && !strings.HasPrefix(lyricData, "https://") {
|
||||||
// If it is not in link format, write the lyrics to the file line by line
|
// If it is not in link format, write the lyrics to the file line by line
|
||||||
lines := strings.Split(lyricData, "\r\n")
|
lines := strings.Split(lyricData, "\n")
|
||||||
lyricFilePath := filepath.Join(dirName, "lyric.lrc")
|
lyricFilePath := filepath.Join(dirName, "lyric.lrc")
|
||||||
file, err := os.Create(lyricFilePath)
|
file, err := os.Create(lyricFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -108,7 +110,19 @@ func YuafengAPIResponseHandler(sources, song, singer string) MusicItem {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
timeTagRegex := regexp.MustCompile(`^\[(\d+(?:\.\d+)?)\]`)
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
// Check if the line starts with a time tag
|
||||||
|
match := timeTagRegex.FindStringSubmatch(line)
|
||||||
|
if match != nil {
|
||||||
|
// Convert the time tag to [mm:ss.ms] format
|
||||||
|
timeInSeconds, _ := strconv.ParseFloat(match[1], 64)
|
||||||
|
minutes := int(timeInSeconds / 60)
|
||||||
|
seconds := int(timeInSeconds) % 60
|
||||||
|
milliseconds := int((timeInSeconds-float64(seconds))*1000) / 100 % 100
|
||||||
|
formattedTimeTag := fmt.Sprintf("[%02d:%02d.%02d]", minutes, seconds, milliseconds)
|
||||||
|
line = timeTagRegex.ReplaceAllString(line, formattedTimeTag)
|
||||||
|
}
|
||||||
_, err := file.WriteString(line + "\r\n")
|
_, err := file.WriteString(line + "\r\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("[Error] Error writing to lyric file:", err)
|
fmt.Println("[Error] Error writing to lyric file:", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user