~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/hydraulophone

An unofficial YouTube Music app for iPhone, iPad, and Mac.

0
0
main
88 lines · 2.8 KB Raw History
import Foundation

public enum SearchScope: String, CaseIterable, Hashable, Sendable, Identifiable {
  case all, artists, albums, songs, playlists
  public var id: String { rawValue }
  public var title: String {
    switch self {
    case .all: "All"
    case .artists: "Artists"
    case .albums: "Albums"
    case .songs: "Songs"
    case .playlists: "Playlists"
    }
  }

  public func includes(_ result: SearchResult) -> Bool {
    switch (self, result) {
    case (.all, _), (.artists, .artist), (.albums, .album), (.songs, .song),
      (.playlists, .playlist):
      true
    default: false
    }
  }
}

/// Opaque values from AuraMusic's pinned SearchFilter adapter. Never assemble
/// protobufs or double-decode these values in feature code.
enum SearchParameters {
  static func value(for scope: SearchScope) -> String? {
    switch scope {
    case .artists: "EgWKAQIgAWoKEAkQChAFEAMQBA%3D%3D"
    case .albums: "EgWKAQIYAWoKEAkQChAFEAMQBA%3D%3D"
    case .songs: "EgWKAQIIAWoKEAkQBRAKEAMQBA%3D%3D"
    // AuraMusic distinguishes featured/community playlists. Keep the broad
    // search for this combined scope rather than silently exclude either.
    case .all, .playlists: nil
    }
  }
}

public protocol ScopedSearchMusicService: MusicService {
  func searchPage(
    query: String, scope: SearchScope, continuation: PaginationToken?,
    policy: CatalogLoadPolicy
  ) async throws -> Page<SearchResult>
}

/// Catalog capabilities are separate from the small playback/fake-service API.
public protocol PaginatedCatalogMusicService: MusicService {
  func searchPage(
    query: String, continuation: PaginationToken?, policy: CatalogLoadPolicy
  ) async throws -> Page<SearchResult>
  func playlistPage(
    continuation: PaginationToken?, policy: CatalogLoadPolicy
  ) async throws -> Page<Playlist>
  func trackPage(
    in playlist: Playlist, continuation: PaginationToken?, policy: CatalogLoadPolicy
  ) async throws -> Page<Song>
  func albumTrackPage(
    in album: Album, continuation: PaginationToken?, policy: CatalogLoadPolicy
  ) async throws -> Page<Song>
  func homePage(
    audience: HomeAudience, filter: HomeFilter?, continuation: PaginationToken?,
    policy: CatalogLoadPolicy
  ) async throws -> HomePage
}

public protocol ArtistBrowsingMusicService: MusicService {
  func artistPage(
    _ artist: Artist, continuation: PaginationToken?, policy: CatalogLoadPolicy
  ) async throws -> HomePage
}

public protocol PaginatedLibraryMusicService: PaginatedCatalogMusicService {
  func libraryPage(
    category: LibraryCategory,
    continuation: PaginationToken?,
    policy: CatalogLoadPolicy
  ) async throws -> Page<LibraryItem>
}

public protocol SessionManagingMusicService: MusicService {
  func setSession(_ session: UserSession?) async
}

public protocol CatalogCacheManaging: Sendable {
  func clearCatalogCache() async
}