mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-03 08:57:53 +01:00
refactor(lyrics): consolidate lyrics parsing functions names
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
e8a404ac76
commit
48c0173e81
5 changed files with 6 additions and 6 deletions
|
|
@ -20,8 +20,8 @@ var lyricFormats = []struct {
|
||||||
suffixes []string
|
suffixes []string
|
||||||
parse lyricParser
|
parse lyricParser
|
||||||
}{
|
}{
|
||||||
{[]string{".ttml"}, parseTTMLWithDefaultLang},
|
{[]string{".ttml"}, parseTTML},
|
||||||
{[]string{".srt"}, parseSRTWithLanguage},
|
{[]string{".srt"}, parseSRT},
|
||||||
{[]string{".yaml", ".yml"}, parseLyricsfile},
|
{[]string{".yaml", ".yml"}, parseLyricsfile},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ var (
|
||||||
srtBlockSeparatorRegex = regexp.MustCompile(`\n\s*\n`)
|
srtBlockSeparatorRegex = regexp.MustCompile(`\n\s*\n`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseSRTWithLanguage(language string, contents []byte) (LyricList, error) {
|
func parseSRT(language string, contents []byte) (LyricList, error) {
|
||||||
raw := strings.ReplaceAll(string(contents), "\r\n", "\n")
|
raw := strings.ReplaceAll(string(contents), "\r\n", "\n")
|
||||||
raw = strings.ReplaceAll(raw, "\r", "\n")
|
raw = strings.ReplaceAll(raw, "\r", "\n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// parseSRT parses with the default placeholder language, for test ergonomics.
|
// parseSRT parses with the default placeholder language, for test ergonomics.
|
||||||
func parseSRT(contents []byte) (LyricList, error) {
|
func parseSRT(contents []byte) (LyricList, error) {
|
||||||
return parseSRTWithLanguage("xxx", contents)
|
return parseSRT("xxx", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("parseSRT", func() {
|
var _ = Describe("parseSRT", func() {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func isTTMLDocument(contents []byte) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTTMLWithDefaultLang(defaultLang string, contents []byte) (LyricList, error) {
|
func parseTTML(defaultLang string, contents []byte) (LyricList, error) {
|
||||||
contents = xmlEncodingRegex.ReplaceAll(contents, []byte(`<?xml$1encoding="UTF-8"$2?>`))
|
contents = xmlEncodingRegex.ReplaceAll(contents, []byte(`<?xml$1encoding="UTF-8"$2?>`))
|
||||||
|
|
||||||
// Skip non-TTML content so sniffing doesn't run the full TTML parse on plain
|
// Skip non-TTML content so sniffing doesn't run the full TTML parse on plain
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// parseTTML parses with the default placeholder language, for test ergonomics.
|
// parseTTML parses with the default placeholder language, for test ergonomics.
|
||||||
func parseTTML(contents []byte) (LyricList, error) {
|
func parseTTML(contents []byte) (LyricList, error) {
|
||||||
return parseTTMLWithDefaultLang("xxx", contents)
|
return parseTTML("xxx", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("parseTTML", func() {
|
var _ = Describe("parseTTML", func() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue