Skip to content

Commit

Permalink
imp
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Jul 18, 2024
1 parent c233289 commit c0a5310
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Sources/EeveeSpotify/Lyrics/Models/Genius/GeniusSong.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import Foundation

struct GeniusSong: Decodable {
var lyrics: GeniusLyrics
}
var language: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,14 @@ struct GeniusLyricsRepository: LyricsRepository {
)

let songInfo = try getSongInfo(song.id)
let plainLyrics = songInfo.lyrics.plain
let plainLines = plainLyrics.components(separatedBy: "\n")
let plainLines = songInfo.lyrics.plain.components(separatedBy: "\n")

var romanization = LyricsRomanizationStatus.original

if hasFoundRomanizedLyrics {
romanization = .romanized
}
else if plainLyrics.canBeRomanized {
else if songInfo.language.isCanBeRomanizedLanguage {
romanization = .canBeRomanized
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class MusixmatchLyricsRepository: LyricsRepository {
if romanized {
romanization = .romanized
}
else if lyricsLines.map({ $0.content }).joined().canBeRomanized {
else if subtitleLanguage.isCanBeRomanizedLanguage {
romanization = .canBeRomanized
}

Expand All @@ -256,6 +256,7 @@ class MusixmatchLyricsRepository: LyricsRepository {

if let lyricsBody = lyricsMessage["body"] as? [String: Any],
let lyrics = lyricsBody["lyrics"] as? [String: Any],
let lyricsLanguage = lyrics["lyrics_language"] as? String,
let plainLyrics = lyrics["lyrics_body"] as? String {

if let restricted = lyrics["restricted"] as? Bool, restricted {
Expand All @@ -268,7 +269,7 @@ class MusixmatchLyricsRepository: LyricsRepository {
.dropLast()
.map { LyricsLineDto(content: $0.lyricsNoteIfEmpty) },
timeSynced: false,
romanization: plainLyrics.canBeRomanized ? .canBeRomanized : .original
romanization: lyricsLanguage.isCanBeRomanizedLanguage ? .canBeRomanized : .original
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ extension String {
)
}

var isCanBeRomanizedLanguage: Bool {
["ja", "ko", "z1"].contains(self) || self.contains("zh")
}

var canBeRomanized: Bool {
let languageRecognizer = NLLanguageRecognizer()
languageRecognizer.processString(self)

if let code = languageRecognizer.dominantLanguage?.rawValue {
return ["ja", "ko"].contains(code) || code.contains("zh")
return code.isCanBeRomanizedLanguage
}

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ extension UserDefaults {
return LyricsSource(rawValue: rawValue)!
}

if Locale.isInRegion("JP", orHasLanguage: "ja") {
return .petit
}

return .lrclib
}
set (newSource) {
Expand Down

0 comments on commit c0a5310

Please sign in to comment.