cody-music
New updates include:
-
More comments for highest used APIs, more to come
-
Interally setting "itunesAccessGranted"
to true if the user has granted access to iTunes.
-
This is accessible via the api:
-
Support to specify which players are enabled for lookup
-
Improved playlist model definition to provide a tree view structure
-
Set or update Spotify access or other settings using the CodyConfig with the following api:
-
You can send all or partial settings updates
Player control support
- Mac Spotify and iTunes desktop
- Spotify Web
Spotify web API support
- Audio features
- Playlists
(create, delete, fetch playlist tracks, replace playlist tracks)
- Genre search
- Spotify devices
- Access token refresh retry
iTunes API support
More coming soon
Installation
$ npm install cody-music
Running unit tests
$ npm test
Load the module
import {
getRunningTrack,
Track,
PlayerType,
TrackStatus,
setConfig } from "cody-music";
...
setConfig({
spotifyAccessToken: <spotify_access_token>,
spotifyRefreshToken: <spotify_refresh_token>;
spotifyClientSecret: <spotify_client_secret>;
spotifyClientId: <spotify_client_id>;
enableItunesDesktop: <enable_itunes_desktop_track_lookup>;
enableSpotifyDesktop: <enable_spotify_desktop_track_lookup>;
enableSpotifyApi: <enable_spotify_api>;
});
const track:Track = await getRunningTrack();
if (track.state === TrackStatus.Playing) {
}
if (track.playerType === PlayerType.WebSpotify) {
}
OR
import * as CodyMusic from "cody-music";
OR
const CodyMusic = require("cody-music");
API
playTrack(uri)
Play a track with Music URI uri
.
Specify either "Spotify" or "iTunes" (case-insensitive).
await CodyMusic.getRunningTrack().then((track: Track) => {
});
await CodyMusic.playTrack(
"spotify",
"spotify:track:2YarjDYjBJuH63dUIh9OWv"
).then(result => {
});
await CodyMusic.playTrack("itunes", 1).then(result => {
});
await CodyMusic.playTrack("spotify", 1000000000).then(result => {
if (result.error) {
console.log(`Unable to play track, error: ${result.error}`);
}
});
await CodyMusic.getRunningTrack().then(result => {
});
Full set of APIs
setConfig(config: CodyConfig)
getSpotifyAccessToken()
isItunesAccessGranted()
isSpotifyRunning(): Promise<boolean>
isItunesRunning(): Promise<boolean>
isPlayerRunning(player: PlayerName): Promise<boolean>
hasActiveTrack(): Promise<boolean>
getTrack(player: PlayerName): Promise<Track>
getSpotifyTrackById(id: string, includeFullArtistData: boolean): Promise<Track>
getRunningTrack(): Promise<Track>
getTracksByPlaylistName(player: PlayerName,
playListName: string): Promise<PlaylistItem[]>
playItunesTrackNumberInPlaylist(playlistName: string,trackNumber: number)
getPlaylistTracks(player: PlayerName,
playlist_id: string,
qsOptions: any = {}): Promise<CodyResponse>
playTrackInContext(player: PlayerName, params: any[]);
quitMacPlayer(player: PlayerName)
playTrackInLibrary(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)
getPlaylists(
player: PlayerName,
qsOptions: any = {}
): Promise<PlaylistItem[]>
getPlaylistNames(player: PlayerName, qsOptions: any = {}):Promise<string[]>
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[]>
createPlaylist(name: string, isPublic: boolean, description: string = "")
deletePlaylist(playlist_id: string)
replacePlaylistTracks(
playlist_id: string,
track_ids: string[]
)
addTracksToPlaylist(
playlist_id: string,
tracks: string[],
position: number = 0
)
removeTracksFromPlaylist(
playlist_id: string,
tracks: string[]
)
requiresSpotifyAccessInfo(): boolean
Deprecated APIs
getAccessToken()
getCurrentlyRunningTrackState(): Promise<Track>
getPlayerState(player: PlayerName): Promise<Track>
getState(player: PlayerName): Promise<Track>
startSpotifyIfNotRunning()
startItunesIfNotRunning()
isRunning(player: PlayerName): Promise<boolean>
repeatOn(player: PlayerName)
repeatOff(player: PlayerName)
unMute(player: PlayerName)
setCredentials(credentials: any)
Contributors
License