cody-music
Control Mac desktop Spotify and iTunes, or Spotify devices via your access and refresh token.
Also provides various Spotify and iTunes search, audio features, and playlist APIs. More coming soon.
Installation
$ npm install cody-music
Running unit tests
$ npm test
Load the module
import * as music from "cody-music";
OR
const music = require("cody-music");
API
playTrack(uri)
Play a track with Music URI uri
.
Specify either "Spotify" or "iTunes" (case-insensitive).
await music.getPlayerState("iTunes").then(state => {
console.log(state);
});
await music
.playTrack("Spotify", "spotify:track:2YarjDYjBJuH63dUIh9OWv")
.then(result => {
});
await music.playTrack("iTunes", 1).then(result => {
});
await music.playTrack("iTunes", 1000000000).then(result => {
if (result.error) {
console.log(`Unable to play track, error: ${result.error}`);
}
});
Full set of APIs
setCredentials(credentials: any)
getAccessToken()
isSpotifyRunning(): Promise<boolean>
isItunesRunning(): Promise<boolean>
isPlayerRunning(player: PlayerName): Promise<boolean>
getPlayerState(player: PlayerName): Promise<TrackState>
getRunningPlayerState(): Promise<TrackState>
getTracksByPlaylistName(player: PlayerName,playListName: string)
playTrackInContext(player: PlayerName, params: any[])
playSpotifyDevice(device_id: string)
play(player: PlayerName, options: any)
playTrack(player: PlayerName, trackId: string)
pause(player: PlayerName, options: any)
playPause(player: PlayerName)
next(player: PlayerName, options: any)
previous(player: PlayerName, options: any)
setRepeat(player: PlayerName, repeat: boolean)
setShuffle(player: PlayerName, shuffle: boolean)
isShuffling(player: PlayerName)
isRepeating(player: PlayerName)
setVolume(player: PlayerName, volume: number)
volumeUp(player: PlayerName, volume: number)
volumeDown(player: PlayerName, volume: number)
mute(player: PlayerName)
unmute(player: PlayerName)
setItunesLoved(loved: boolean)
getPlaylistNames(player: PlayerName)
launchPlayer(playerName: PlayerName, options: any)
getSpotifyDevices(): Promise<PlayerDevice[]>
getGenre(artist: string, songName: string = ""): Promise<string>
getSpotifyGenre(artist: string): Promise<string>
getSpotifyAudioFeatures(ids: string[]): Promise<SpotifyAudioFeature[]>
getCurrentlyRunningTrackState(): Promise<TrackState>
getState(player: PlayerName): Promise<TrackState>
startSpotifyIfNotRunning()
startItunesIfNotRunning()
isRunning(player: PlayerName): Promise<boolean>
repeatOn(player: PlayerName)
repeatOff(player: PlayerName)
unMute(player: PlayerName)
Contributors
License