Skip to content

Commit

Permalink
redesigned settings, musixmatch lyrics romanization and translation
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Jul 10, 2024
1 parent 742909e commit 9dde89f
Show file tree
Hide file tree
Showing 22 changed files with 799 additions and 532 deletions.
55 changes: 34 additions & 21 deletions Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EncoreButtonHook: ClassHook<UIButton> {

//

private var lastLyricsLanguageLabel: String? = nil
private var lastLyricsError: LyricsError? = nil

private var hasShownRestrictedPopUp = false
Expand All @@ -51,10 +52,6 @@ class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {

orig.viewDidLoad()

if !UserDefaults.fallbackReasons {
return
}

guard
let lyricsHeaderViewController = target.parent?.children.first
else {
Expand Down Expand Up @@ -83,18 +80,19 @@ class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {
encoreLabel.text().firstObject
]

if let description = lastLyricsError?.description {

let attributes = Dynamic.SPTEncoreAttributes
.alloc(interface: SPTEncoreAttributes.self)
.`init`({ attributes in
attributes.setForegroundColor(.white.withAlphaComponent(0.5))
})

let typeStyle = type(
of: Dynamic.SPTEncoreTypeStyle.alloc(interface: SPTEncoreTypeStyle.self)
).bodyMediumBold()

let attributes = Dynamic.SPTEncoreAttributes
.alloc(interface: SPTEncoreAttributes.self)
.`init`({ attributes in
attributes.setForegroundColor(.white.withAlphaComponent(0.5))
})

let typeStyle = type(
of: Dynamic.SPTEncoreTypeStyle.alloc(interface: SPTEncoreTypeStyle.self)
).bodyMediumBold()

//

if UserDefaults.fallbackReasons, let description = lastLyricsError?.description {
text.append(
Dynamic.SPTEncoreAttributedString.alloc(interface: SPTEncoreAttributedString.self)
.initWithString(
Expand All @@ -103,10 +101,21 @@ class LyricsOnlyViewControllerHook: ClassHook<UIViewController> {
attributes: attributes
)
)

if #unavailable(iOS 15.0) {
encoreLabel.setNumberOfLines(2)
}
}

if let languageLabel = lastLyricsLanguageLabel {
text.append(
Dynamic.SPTEncoreAttributedString.alloc(interface: SPTEncoreAttributedString.self)
.initWithString(
"\n\(languageLabel)",
typeStyle: typeStyle,
attributes: attributes
)
)
}

if #unavailable(iOS 15.0) {
encoreLabel.setNumberOfLines(text.count)
}

encoreLabel.setText(text as NSArray)
Expand All @@ -133,7 +142,7 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {
var repository: LyricsRepository = switch source {
case .genius: GeniusLyricsRepository()
case .lrclib: LrcLibLyricsRepository()
case .musixmatch: MusixmatchLyricsRepository()
case .musixmatch: MusixmatchLyricsRepository.shared
}

let lyricsDto: LyricsDto
Expand Down Expand Up @@ -192,6 +201,10 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {

lyricsDto = try repository.getLyrics(searchQuery, options: options)
}

lastLyricsLanguageLabel = lyricsDto.romanized
? "Romanized"
: Locale.current.localizedString(forLanguageCode: lyricsDto.translatedTo ?? "")

let lyrics = Lyrics.with {
$0.colors = getLyricsColors()
Expand Down
2 changes: 2 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/LyricsDto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Foundation
struct LyricsDto {
var lines: [LyricsLineDto]
var timeSynced: Bool
var romanized: Bool = false
var translatedTo: String? = nil

func toLyricsData(source: String) -> LyricsData {
return LyricsData.with {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct LyricsOptions: Codable, Equatable {
var geniusRomanizations: Bool
var musixmatchRomanizations: Bool
var romanization: Bool
var musixmatchLanguage: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ struct GeniusLyricsRepository: LyricsRepository {
private func mostRelevantHitResult(
hits: [GeniusHit],
strippedTitle: String,
romanized: Bool
romanized: Bool,
hasFoundRomanizedLyrics: inout Bool
) -> GeniusHitResult {
let results = hits.map { $0.result }

Expand All @@ -102,6 +103,7 @@ struct GeniusLyricsRepository: LyricsRepository {
if romanized, let romanizedSong = matchingByTitle.first(
where: { $0.artistNames == "Genius Romanizations" }
) {
hasFoundRomanizedLyrics = true
return romanizedSong
}

Expand Down Expand Up @@ -131,18 +133,22 @@ struct GeniusLyricsRepository: LyricsRepository {
throw LyricsError.NoSuchSong
}

var hasFoundRomanizedLyrics = false

let song = mostRelevantHitResult(
hits: hits,
strippedTitle: strippedTitle,
romanized: options.geniusRomanizations
romanized: options.romanization,
hasFoundRomanizedLyrics: &hasFoundRomanizedLyrics
)

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

return LyricsDto(
lines: mapLyricsLines(plainLines).map { line in LyricsLineDto(content: line) },
timeSynced: false
timeSynced: false,
romanized: hasFoundRomanizedLyrics
)
}
}
Loading

0 comments on commit 9dde89f

Please sign in to comment.