mirror of
https://git.gay/lucida/lucida
synced 2025-12-11 20:15:14 +01:00
add playlist
This commit is contained in:
parent
1381c203f2
commit
901d326c8b
@ -1,5 +1,12 @@
|
||||
import Librespot, { LibrespotOptions } from 'librespot'
|
||||
import { parseArtist, parseAlbum, parseTrack, parseEpisode, parsePodcast } from './parse.js'
|
||||
import {
|
||||
parseArtist,
|
||||
parseAlbum,
|
||||
parseTrack,
|
||||
parseEpisode,
|
||||
parsePodcast,
|
||||
parsePlaylist
|
||||
} from './parse.js'
|
||||
import {
|
||||
GetByUrlResponse,
|
||||
ItemType,
|
||||
@ -41,7 +48,9 @@ class Spotify implements StreamerWithLogin {
|
||||
if (this.storedCredential) return await this.client.loginWithStoredCreds(username, password)
|
||||
else return await this.client.login(username, password)
|
||||
}
|
||||
#getUrlParts(url: string): ['artist' | 'album' | 'track' | 'episode' | 'show', string] {
|
||||
#getUrlParts(
|
||||
url: string
|
||||
): ['artist' | 'album' | 'track' | 'episode' | 'show' | 'playlist', string] {
|
||||
const urlObj = new URL(url)
|
||||
const parts = urlObj.pathname.slice(1).split('/')
|
||||
if (parts.length > 2) throw new Error('Unknown Spotify URL')
|
||||
@ -50,7 +59,8 @@ class Spotify implements StreamerWithLogin {
|
||||
parts[0] != 'track' &&
|
||||
parts[0] != 'album' &&
|
||||
parts[0] != 'show' &&
|
||||
parts[0] != 'episode'
|
||||
parts[0] != 'episode' &&
|
||||
parts[0] != 'playlist'
|
||||
) {
|
||||
throw new Error(`Spotify type "${parts[0]}" unsupported`)
|
||||
}
|
||||
@ -132,6 +142,14 @@ class Spotify implements StreamerWithLogin {
|
||||
episodes: metadata.episodes?.map((e) => parseEpisode(e)) ?? []
|
||||
}
|
||||
}
|
||||
case 'playlist': {
|
||||
const metadata = await this.client.get.playlist(id)
|
||||
return {
|
||||
type: 'playlist',
|
||||
metadata: parsePlaylist(metadata),
|
||||
tracks: metadata.tracks?.map((e) => parseTrack(e)) ?? []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async search(query: string): Promise<SearchResults> {
|
||||
|
||||
@ -4,9 +4,10 @@ import type {
|
||||
SpotifyThumbnail,
|
||||
SpotifyTrack,
|
||||
SpotifyEpisode,
|
||||
SpotifyPodcast
|
||||
SpotifyPodcast,
|
||||
SpotifyPlaylist
|
||||
} from 'librespot/types'
|
||||
import { Album, Artist, Episode, Podcast, Track } from '../../types.js'
|
||||
import { Album, Artist, Episode, Playlist, Podcast, Track } from '../../types.js'
|
||||
|
||||
function parseThumbnails(raw: SpotifyThumbnail[]) {
|
||||
return raw
|
||||
@ -92,3 +93,14 @@ export function parsePodcast(raw: SpotifyPodcast) {
|
||||
|
||||
return podcast
|
||||
}
|
||||
|
||||
export function parsePlaylist(raw: SpotifyPlaylist) {
|
||||
const playlist: Playlist = {
|
||||
id: raw.id,
|
||||
title: raw.name,
|
||||
url: raw.externalUrl,
|
||||
trackCount: raw.totalTracks
|
||||
}
|
||||
|
||||
return playlist
|
||||
}
|
||||
|
||||
@ -97,8 +97,7 @@ export function parsePlaylist(raw: RawPlaylist): Playlist {
|
||||
id: raw.uuid,
|
||||
title: raw.title,
|
||||
url: raw.url,
|
||||
trackCount: raw.numberOfTracks,
|
||||
tracks: []
|
||||
trackCount: raw.numberOfTracks
|
||||
}
|
||||
|
||||
playlist.coverArtwork = [
|
||||
|
||||
@ -36,7 +36,6 @@ export interface Playlist {
|
||||
url: string
|
||||
coverArtwork?: CoverArtwork[]
|
||||
trackCount?: number
|
||||
tracks: Track[]
|
||||
}
|
||||
|
||||
export interface Album {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user