Yandex Music client for Apple TV
tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations with feedback, library, search, artist and album pages, synced lyrics, and system Now Playing integration.
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ArtistView: View {
|
||||
let artist: Artist
|
||||
@EnvironmentObject private var player: PlayerController
|
||||
|
||||
@State private var info: ArtistBriefInfo?
|
||||
@State private var isLoading = true
|
||||
@State private var showAllTracks = false
|
||||
|
||||
private var resolved: Artist { info?.artist ?? artist }
|
||||
private var popular: [Track] { info?.popularTracks ?? [] }
|
||||
private var albums: [Album] { info?.albums ?? [] }
|
||||
private var alsoAlbums: [Album] { info?.alsoAlbums ?? [] }
|
||||
private var similar: [Artist] { info?.similarArtists ?? [] }
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 50) {
|
||||
header
|
||||
|
||||
if isLoading {
|
||||
LoadingState(text: "Загружаем исполнителя…").frame(height: 300)
|
||||
} else {
|
||||
if !popular.isEmpty { popularSection }
|
||||
if !albums.isEmpty { albumShelf("Альбомы", albums) }
|
||||
if !alsoAlbums.isEmpty { albumShelf("Сборники и участие", alsoAlbums) }
|
||||
if !similar.isEmpty { similarSection }
|
||||
if let text = resolved.description?.text, !text.isEmpty { about(text) }
|
||||
}
|
||||
}
|
||||
.padding(.top, 120)
|
||||
.padding(.bottom, 60)
|
||||
}
|
||||
.background(backdrop)
|
||||
.task { await load() }
|
||||
}
|
||||
|
||||
// MARK: - Header
|
||||
|
||||
private var backdrop: some View {
|
||||
BlurredBackdrop(url: resolved.coverURL(size: 200))
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack(alignment: .center, spacing: 50) {
|
||||
CoverImage(url: resolved.coverURL(size: 400), corner: 160)
|
||||
.frame(width: 320, height: 320)
|
||||
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
Text(resolved.name)
|
||||
.font(.system(size: 60, weight: .bold))
|
||||
.lineLimit(2)
|
||||
|
||||
if let genres = resolved.genres, !genres.isEmpty {
|
||||
Text(genres.prefix(3).joined(separator: " · ").capitalized)
|
||||
.font(.title3)
|
||||
.foregroundStyle(Color.ymAccent)
|
||||
}
|
||||
if let counts = resolved.countsLine {
|
||||
Text(counts)
|
||||
.font(.body)
|
||||
.foregroundStyle(.white.opacity(0.6))
|
||||
}
|
||||
|
||||
HStack(spacing: 20) {
|
||||
Button {
|
||||
play(popular, title: resolved.name)
|
||||
} label: {
|
||||
Label("Слушать", systemImage: "play.fill")
|
||||
}
|
||||
.disabled(popular.isEmpty)
|
||||
|
||||
Button {
|
||||
player.startRotor(
|
||||
station: "artist:\(resolved.id.value)",
|
||||
name: "Волна: \(resolved.name)"
|
||||
)
|
||||
} label: {
|
||||
Label("Волна артиста", systemImage: "dot.radiowaves.left.and.right")
|
||||
}
|
||||
|
||||
Button {
|
||||
playAllTracks()
|
||||
} label: {
|
||||
Label("Все треки", systemImage: "music.note.list")
|
||||
}
|
||||
}
|
||||
.padding(.top, 10)
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Sections
|
||||
|
||||
private var popularSection: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text("Популярные треки").font(.title2.weight(.semibold))
|
||||
Spacer()
|
||||
if popular.count > 8 {
|
||||
Button(showAllTracks ? "Свернуть" : "Показать все") {
|
||||
showAllTracks.toggle()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.font(.callout)
|
||||
}
|
||||
}
|
||||
|
||||
let shown = showAllTracks ? popular : Array(popular.prefix(8))
|
||||
LazyVStack(spacing: 6) {
|
||||
ForEach(Array(shown.enumerated()), id: \.offset) { pair in
|
||||
TrackRow(
|
||||
track: pair.element,
|
||||
isCurrent: player.current?.trackID == pair.element.trackID
|
||||
) {
|
||||
play(popular, startAt: pair.offset, title: resolved.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func albumShelf(_ title: String, _ list: [Album]) -> some View {
|
||||
Shelf(title: title) {
|
||||
ForEach(list, id: \.id) { album in
|
||||
PosterLink(
|
||||
title: album.displayTitle,
|
||||
subtitle: album.subtitleLine,
|
||||
imageURL: album.coverURL(size: 200),
|
||||
route: .album(album)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var similarSection: some View {
|
||||
Shelf(title: "Похожие исполнители") {
|
||||
ForEach(similar, id: \.id) { other in
|
||||
PosterLink(
|
||||
title: other.name,
|
||||
subtitle: nil,
|
||||
imageURL: other.coverURL(size: 200),
|
||||
route: .artist(other),
|
||||
circular: true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func about(_ text: String) -> some View {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
Text("Об исполнителе").font(.title2.weight(.semibold))
|
||||
Text(text)
|
||||
.font(.body)
|
||||
.foregroundStyle(.white.opacity(0.7))
|
||||
.frame(maxWidth: 1200, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
private func play(_ list: [Track], startAt: Int = 0, title: String) {
|
||||
guard !list.isEmpty else { return }
|
||||
player.play(tracks: list, startAt: startAt, source: .collection(title))
|
||||
}
|
||||
|
||||
private func playAllTracks() {
|
||||
Task {
|
||||
do {
|
||||
let all = try await YMClient.shared.artistTracks(artistID: resolved.id.value)
|
||||
play(all, title: resolved.name)
|
||||
} catch {
|
||||
log.error("\(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func load() async {
|
||||
isLoading = true
|
||||
defer { isLoading = false }
|
||||
do {
|
||||
info = try await YMClient.shared.artistBriefInfo(artistID: artist.id.value)
|
||||
} catch {
|
||||
log.error("\(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user