Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/spotify

src/exports/get-queue.ts

18 lines · 588 B · TypeScript
import { getQueue, normalizePlaybackItem } from '../lib/spotify-api.ts'
import type { GetQueueParams } from '../lib/export-types.ts'

/**
 * Read the current Spotify playback queue.
 * @example
 * import getQueue from 'kody:@kody/spotify/get-queue'
 * const queue = await getQueue()
 */
export default async function spotifyGetQueue(params: GetQueueParams = {}) {
	const data = await getQueue(params)
	return {
		currentlyPlaying: normalizePlaybackItem(data?.currently_playing),
		queue: Array.isArray(data?.queue)
			? data.queue.map(normalizePlaybackItem).filter(Boolean)
			: [],
	}
}