Skip to content

Commit

Permalink
updated lyrics architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Jul 3, 2024
1 parent 88a7ea6 commit 00920de
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 267 deletions.
40 changes: 23 additions & 17 deletions Sources/EeveeSpotify/Lyrics/CustomLyrics.x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,28 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {
throw LyricsError.NoCurrentTrack
}

//

let searchQuery = LyricsSearchQuery(
title: track.trackTitle(),
primaryArtist: track.artistTitle(),
spotifyTrackId: track.URI().spt_trackIdentifier()
)

var source = UserDefaults.lyricsSource

let plainLyrics: PlainLyrics?
var repository: LyricsRepository = switch source {
case .genius: GeniusLyricsRepository()
case .lrclib: LrcLibLyricsRepository()
case .musixmatch: MusixmatchLyricsRepository()
}

let lyricsDto: LyricsDto

//

do {
plainLyrics = try LyricsRepository.getLyrics(
title: track.trackTitle(),
artist: track.artistTitle(),
spotifyTrackId: track.URI().spt_trackIdentifier(),
source: source
)

lyricsDto = try repository.getLyrics(searchQuery)
lastLyricsError = nil
}

Expand Down Expand Up @@ -175,25 +185,21 @@ func getCurrentTrackLyricsData(originalLyrics: Lyrics? = nil) throws -> Data {
}

NSLog("[EeveeSpotify] Unable to load lyrics from \(source): \(error), trying Genius as fallback")

source = .genius
repository = GeniusLyricsRepository()

plainLyrics = try LyricsRepository.getLyrics(
title: track.trackTitle(),
artist: track.artistTitle(),
spotifyTrackId: track.URI().spt_trackIdentifier(),
source: source
)
lyricsDto = try repository.getLyrics(searchQuery)
}

let lyrics = try Lyrics.with {
let lyrics = Lyrics.with {
$0.colors = getLyricsColors()
$0.data = try LyricsHelper.composeLyricsData(plainLyrics!, source: source)
$0.data = lyricsDto.toLyricsData(source: source.description)
}

return try lyrics.serializedData()

func getLyricsColors() -> LyricsColors {

let lyricsColorsSettings = UserDefaults.lyricsColors

if lyricsColorsSettings.displayOriginalColors, let originalLyrics = originalLyrics {
Expand Down

This file was deleted.

114 changes: 0 additions & 114 deletions Sources/EeveeSpotify/Lyrics/Helpers/LyricsHelper.swift

This file was deleted.

57 changes: 0 additions & 57 deletions Sources/EeveeSpotify/Lyrics/LyricsRepository.swift

This file was deleted.

20 changes: 20 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/LyricsDto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation

struct LyricsDto {
var lines: [LyricsLineDto]
var timeSynced: Bool

func toLyricsData(source: String) -> LyricsData {
return LyricsData.with {
$0.timeSynchronized = timeSynced
$0.restriction = .unrestricted
$0.providedBy = "\(source) (EeveeSpotify)"
$0.lines = lines.map { line in
LyricsLine.with {
$0.content = line.content
$0.offsetMs = Int32(line.offsetMs ?? 0)
}
}
}
}
}
6 changes: 6 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/LyricsLineDto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

struct LyricsLineDto {
var content: String
var offsetMs: Int?
}
7 changes: 7 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Models/LyricsSearchQuery.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

struct LyricsSearchQuery {
var title: String
var primaryArtist: String
var spotifyTrackId: String
}
6 changes: 0 additions & 6 deletions Sources/EeveeSpotify/Lyrics/Models/PlainLyrics.swift

This file was deleted.

5 changes: 5 additions & 0 deletions Sources/EeveeSpotify/Lyrics/Protocols/LyricsRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

protocol LyricsRepository {
func getLyrics(_ query: LyricsSearchQuery) throws -> LyricsDto
}
Loading

0 comments on commit 00920de

Please sign in to comment.