cody-music
Advanced tools
Comparing version 2.6.18 to 2.6.19
@@ -173,2 +173,8 @@ import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature, PlaylistItem, CodyResponse, CodyConfig, PlayerContext } from "./models"; | ||
/** | ||
* Play a specific spotify track by trackId (it can be the URI or the ID) | ||
* @param trackId | ||
* @param deviceId (optional) | ||
*/ | ||
export declare function playSpotifyTrack(trackId: string, deviceId?: string): Promise<CodyResponse>; | ||
/** | ||
* Initiate the play command for a given trackId for a specific player | ||
@@ -175,0 +181,0 @@ * @param player {spotify|spotify-web|itunes} |
@@ -476,2 +476,11 @@ "use strict"; | ||
/** | ||
* Play a specific spotify track by trackId (it can be the URI or the ID) | ||
* @param trackId | ||
* @param deviceId (optional) | ||
*/ | ||
function playSpotifyTrack(trackId, deviceId = "") { | ||
return musicCtr.spotifyWebPlayTrack(trackId, deviceId); | ||
} | ||
exports.playSpotifyTrack = playSpotifyTrack; | ||
/** | ||
* Initiate the play command for a given trackId for a specific player | ||
@@ -478,0 +487,0 @@ * @param player {spotify|spotify-web|itunes} |
@@ -19,2 +19,3 @@ import { PlayerName } from "./models"; | ||
playPauseSpotifyDevice(device_id: string, play: boolean): Promise<import("./models").CodyResponse>; | ||
spotifyWebPlayTrack(trackId: string, deviceId?: string): Promise<import("./models").CodyResponse>; | ||
spotifyWebPlay(options: any): Promise<import("./models").CodyResponse>; | ||
@@ -21,0 +22,0 @@ spotifyWebPause(options: any): Promise<import("./models").CodyResponse>; |
@@ -321,2 +321,24 @@ "use strict"; | ||
} | ||
async spotifyWebPlayTrack(trackId, deviceId = "") { | ||
/** | ||
* to play a track without the play list id | ||
* curl -X "PUT" "https://api.spotify.com/v1/me/player/play?device_id=4f38ae14f61b3a2e4ed97d537a5cb3d09cf34ea1" | ||
* --data "{\"uris\":[\"spotify:track:2j5hsQvApottzvTn4pFJWF\"]}" | ||
*/ | ||
const trackUris = musicUtil.createUrisFromTrackIds([trackId]); | ||
const qsOptions = deviceId ? { device_id: deviceId } : {}; | ||
const payload = { | ||
uris: trackUris | ||
}; | ||
const api = "/v1/me/player/play"; | ||
let response = await musicClient.spotifyApiPut(api, qsOptions, payload); | ||
// check if the token needs to be refreshed | ||
if (response.statusText === "EXPIRED") { | ||
// refresh the token | ||
await musicClient.refreshSpotifyToken(); | ||
// try again | ||
response = await musicClient.spotifyApiPut(api, qsOptions, payload); | ||
} | ||
return response; | ||
} | ||
async spotifyWebPlay(options) { | ||
@@ -333,5 +355,4 @@ const qsOptions = options.device_id | ||
} | ||
payload["offset"] = {}; | ||
if (options.offset) { | ||
payload.offset = options.offset; | ||
payload["offset"] = options.offset; | ||
} | ||
@@ -342,6 +363,13 @@ if (options.context_uri) { | ||
if (payload.context_uri && payload.uris) { | ||
payload["offset"] = { | ||
...payload.offset, | ||
uri: payload.uris[0] | ||
}; | ||
if (payload.offset) { | ||
payload["offset"] = { | ||
...payload.offset, | ||
uri: payload.uris[0] | ||
}; | ||
} | ||
else { | ||
payload["offset"] = { | ||
uri: payload.uris[0] | ||
}; | ||
} | ||
delete payload.uris; | ||
@@ -348,0 +376,0 @@ } |
@@ -526,2 +526,11 @@ "use strict"; | ||
/** | ||
* Play a specific spotify track by trackId (it can be the URI or the ID) | ||
* @param trackId | ||
* @param deviceId (optional) | ||
*/ | ||
export function playSpotifyTrack(trackId: string, deviceId: string = "") { | ||
return musicCtr.spotifyWebPlayTrack(trackId, deviceId); | ||
} | ||
/** | ||
* Initiate the play command for a given trackId for a specific player | ||
@@ -528,0 +537,0 @@ * @param player {spotify|spotify-web|itunes} |
@@ -354,2 +354,27 @@ import { MusicUtil } from "./util"; | ||
public async spotifyWebPlayTrack(trackId: string, deviceId: string = "") { | ||
/** | ||
* to play a track without the play list id | ||
* curl -X "PUT" "https://api.spotify.com/v1/me/player/play?device_id=4f38ae14f61b3a2e4ed97d537a5cb3d09cf34ea1" | ||
* --data "{\"uris\":[\"spotify:track:2j5hsQvApottzvTn4pFJWF\"]}" | ||
*/ | ||
const trackUris = musicUtil.createUrisFromTrackIds([trackId]); | ||
const qsOptions = deviceId ? { device_id: deviceId } : {}; | ||
const payload = { | ||
uris: trackUris | ||
}; | ||
const api = "/v1/me/player/play"; | ||
let response = await musicClient.spotifyApiPut(api, qsOptions, payload); | ||
// check if the token needs to be refreshed | ||
if (response.statusText === "EXPIRED") { | ||
// refresh the token | ||
await musicClient.refreshSpotifyToken(); | ||
// try again | ||
response = await musicClient.spotifyApiPut(api, qsOptions, payload); | ||
} | ||
return response; | ||
} | ||
public async spotifyWebPlay(options: any) { | ||
@@ -368,6 +393,4 @@ const qsOptions = options.device_id | ||
payload["offset"] = {}; | ||
if (options.offset) { | ||
payload.offset = options.offset; | ||
payload["offset"] = options.offset; | ||
} | ||
@@ -380,6 +403,12 @@ | ||
if (payload.context_uri && payload.uris) { | ||
payload["offset"] = { | ||
...payload.offset, | ||
uri: payload.uris[0] | ||
}; | ||
if (payload.offset) { | ||
payload["offset"] = { | ||
...payload.offset, | ||
uri: payload.uris[0] | ||
}; | ||
} else { | ||
payload["offset"] = { | ||
uri: payload.uris[0] | ||
}; | ||
} | ||
delete payload.uris; | ||
@@ -386,0 +415,0 @@ } |
{ | ||
"name": "cody-music", | ||
"version": "2.6.18", | ||
"version": "2.6.19", | ||
"description": "mac osx spotify and itunes music player controller, spotify audio features, itunes and spotify genre, and playlist control", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -321,2 +321,9 @@ # cody-music | ||
/** | ||
* Play a specific spotify track by trackId (it can be the URI or the ID) | ||
* @param trackId | ||
* @param deviceId (optional) | ||
*/ | ||
playSpotifyTrack(trackId: string, deviceId: string = "") | ||
/** | ||
* Initiate the pause command for a specific player | ||
@@ -323,0 +330,0 @@ * @param player {spotify|spotify-web|itunes} |
429199
10516
585