mirror of
https://github.com/whoeevee/EeveeSpotifyReborn.git
synced 2026-01-09 00:23:20 +01:00
fix for #263
This commit is contained in:
@@ -101,12 +101,11 @@ struct LrcLibLyricsRepository: LyricsRepository {
|
||||
}
|
||||
|
||||
if let syncedLyrics = song.syncedLyrics {
|
||||
let lines = Array(syncedLyrics.components(separatedBy: "\n").dropLast())
|
||||
return LyricsDto(
|
||||
lines: mapSyncedLyricsLines(
|
||||
syncedLyrics.components(separatedBy: "\n").dropLast()
|
||||
),
|
||||
lines: mapSyncedLyricsLines(lines),
|
||||
timeSynced: true,
|
||||
romanization: syncedLyrics.canBeRomanized ? .canBeRomanized : .original
|
||||
romanization: lines.canBeRomanized ? .canBeRomanized : .original
|
||||
)
|
||||
}
|
||||
|
||||
@@ -114,13 +113,12 @@ struct LrcLibLyricsRepository: LyricsRepository {
|
||||
throw LyricsError.DecodingError
|
||||
}
|
||||
|
||||
let lines = Array(plainLyrics.components(separatedBy: "\n").dropLast())
|
||||
|
||||
return LyricsDto(
|
||||
lines: plainLyrics
|
||||
.components(separatedBy: "\n")
|
||||
.dropLast()
|
||||
.map { content in LyricsLineDto(content: content) },
|
||||
lines: lines.map { content in LyricsLineDto(content: content) },
|
||||
timeSynced: false,
|
||||
romanization: plainLyrics.canBeRomanized ? .canBeRomanized : .original
|
||||
romanization: lines.canBeRomanized ? .canBeRomanized : .original
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,20 +116,19 @@ struct PetitLyricsRepository: LyricsRepository {
|
||||
)
|
||||
},
|
||||
timeSynced: true,
|
||||
romanization: lyrics.lines.map { $0.linestring }.joined().canBeRomanized
|
||||
romanization: lyrics.lines.map { $0.linestring }.canBeRomanized
|
||||
? .canBeRomanized
|
||||
: .original
|
||||
)
|
||||
|
||||
case .plain:
|
||||
let stringLyrics = String(data: lyricsData, encoding: .utf8)!
|
||||
let lines = stringLyrics.components(separatedBy: "\n")
|
||||
|
||||
return LyricsDto(
|
||||
lines: stringLyrics
|
||||
.components(separatedBy: "\n")
|
||||
.map { LyricsLineDto(content: $0) },
|
||||
lines: lines.map { LyricsLineDto(content: $0) },
|
||||
timeSynced: false,
|
||||
romanization: stringLyrics.canBeRomanized ? .canBeRomanized : .original
|
||||
romanization: lines.canBeRomanized ? .canBeRomanized : .original
|
||||
)
|
||||
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
import NaturalLanguage
|
||||
|
||||
extension Array where Element == String {
|
||||
var canBeRomanized: Bool {
|
||||
var languageList: [NLLanguage] = []
|
||||
|
||||
for line in self {
|
||||
if let language = NLLanguageRecognizer.dominantLanguage(for: line) {
|
||||
languageList.append(language)
|
||||
}
|
||||
}
|
||||
|
||||
let canBeRomanizedLanguageCount = languageList.filter {
|
||||
[.japanese, .korean, .simplifiedChinese, .traditionalChinese].contains($0)
|
||||
}.count
|
||||
|
||||
return Double(canBeRomanizedLanguageCount) / Double(languageList.count) > 0.15
|
||||
}
|
||||
}
|
||||
@@ -50,17 +50,6 @@ extension String {
|
||||
["ja", "ko", "z1"].contains(self) || self.contains("zh")
|
||||
}
|
||||
|
||||
var canBeRomanized: Bool {
|
||||
let languageRecognizer = NLLanguageRecognizer()
|
||||
languageRecognizer.processString(self)
|
||||
|
||||
if let code = languageRecognizer.dominantLanguage?.rawValue {
|
||||
return code.isCanBeRomanizedLanguage
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
var hexadecimal: Data? {
|
||||
var data = Data(capacity: count / 2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user