cody-music
Advanced tools
Comparing version 2.1.6 to 2.1.7
export * from "./lib/apis"; | ||
export { PlayerName, Track, TrackStatus, PlayerDevice, PlayerContext, SpotifyAudioFeature, PlayerType } from "./lib/models"; | ||
export { CodyResponse, CodyResponseType, PlayerName, Track, TrackStatus, PlayerDevice, PlayerContext, PlaylistItem, SpotifyAudioFeature, PlayerType } from "./lib/models"; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var models_1 = require("./lib/models"); | ||
exports.CodyResponse = models_1.CodyResponse; | ||
exports.CodyResponseType = models_1.CodyResponseType; | ||
exports.PlayerName = models_1.PlayerName; | ||
@@ -14,3 +16,4 @@ exports.Track = models_1.Track; | ||
exports.PlayerContext = models_1.PlayerContext; | ||
exports.PlaylistItem = models_1.PlaylistItem; | ||
exports.SpotifyAudioFeature = models_1.SpotifyAudioFeature; | ||
exports.PlayerType = models_1.PlayerType; |
@@ -55,5 +55,15 @@ import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature, PlaylistItem } from "./models"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export declare function getTracksByPlaylistName(player: PlayerName, playListName: string): Promise<any>; | ||
export declare function getTracksByPlaylistName(player: PlayerName, playListName: string, playlist_id?: string, qsOptions?: any): Promise<any>; | ||
/** | ||
* Returns the tracks that are found by the given playlist name | ||
* - currently spofity-web support only | ||
* @param player {spotify-web} | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export declare function getPlaylistTracks(player: PlayerName, playlist_id: string, qsOptions?: any): Promise<import("./models").CodyResponse>; | ||
/** | ||
* Plays a specific track on the Spotify or iTunes desktop | ||
@@ -162,9 +172,11 @@ * @param player | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param (optional) {limit, offset} | ||
*/ | ||
export declare function getPlaylists(player: PlayerName): Promise<PlaylistItem[]>; | ||
export declare function getPlaylists(player: PlayerName, qsOptions?: any): Promise<PlaylistItem[]>; | ||
/** | ||
* Get the full list of the playlist names for a given player | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param qsOptions (optional) {limit, offset} | ||
*/ | ||
export declare function getPlaylistNames(player: PlayerName): Promise<string[]>; | ||
export declare function getPlaylistNames(player: PlayerName, qsOptions?: any): Promise<string[]>; | ||
/** | ||
@@ -171,0 +183,0 @@ * Launches a player device |
@@ -157,4 +157,6 @@ "use strict"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
async function getTracksByPlaylistName(player, playListName) { | ||
async function getTracksByPlaylistName(player, playListName, playlist_id = "", qsOptions = {}) { | ||
const params = null; | ||
@@ -177,2 +179,13 @@ const argv = [playListName]; | ||
/** | ||
* Returns the tracks that are found by the given playlist name | ||
* - currently spofity-web support only | ||
* @param player {spotify-web} | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
async function getPlaylistTracks(player, playlist_id, qsOptions = {}) { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
} | ||
exports.getPlaylistTracks = getPlaylistTracks; | ||
/** | ||
* Plays a specific track on the Spotify or iTunes desktop | ||
@@ -365,7 +378,8 @@ * @param player | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param (optional) {limit, offset} | ||
*/ | ||
async function getPlaylists(player) { | ||
async function getPlaylists(player, qsOptions = {}) { | ||
let playlists = []; | ||
if (player === models_1.PlayerName.SpotifyWeb) { | ||
playlists = await playlist.getPlaylists(); | ||
playlists = await playlist.getPlaylists(qsOptions); | ||
} | ||
@@ -389,6 +403,7 @@ else { | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param qsOptions (optional) {limit, offset} | ||
*/ | ||
async function getPlaylistNames(player) { | ||
async function getPlaylistNames(player, qsOptions = {}) { | ||
if (player === models_1.PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistNames(); | ||
return playlist.getPlaylistNames(qsOptions); | ||
} | ||
@@ -395,0 +410,0 @@ // result will string of playlist names separated by a comma |
@@ -25,5 +25,5 @@ import { CodyResponse } from "./models"; | ||
spotifyApiDelete(api: string, qsOptions?: any, payload?: any): Promise<CodyResponse>; | ||
addQueryStringToApi(api: string, qsOptions?: any): void; | ||
addQueryStringToApi(api: string, qsOptions?: any): string; | ||
buildSuccessResponse(resp: any): CodyResponse; | ||
buildErrorResponse(err: any): CodyResponse; | ||
} |
@@ -150,3 +150,3 @@ "use strict"; | ||
spotifyApiGet(api, qsOptions = {}) { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${musicStore.spotifyAccessToken}`; | ||
@@ -164,3 +164,3 @@ return spotifyClient | ||
spotifyApiPut(api, qsOptions = {}, payload = {}) { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${musicStore.spotifyAccessToken}`; | ||
@@ -178,3 +178,3 @@ return spotifyClient | ||
spotifyApiPost(api, qsOptions = {}, payload = {}) { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${musicStore.spotifyAccessToken}`; | ||
@@ -192,3 +192,3 @@ return spotifyClient | ||
spotifyApiDelete(api, qsOptions = {}, payload = {}) { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${musicStore.spotifyAccessToken}`; | ||
@@ -210,2 +210,3 @@ return spotifyClient | ||
} | ||
return api; | ||
} | ||
@@ -212,0 +213,0 @@ buildSuccessResponse(resp) { |
@@ -6,4 +6,5 @@ import { CodyResponse, PlaylistItem } from "./models"; | ||
static getInstance(): Playlist; | ||
getPlaylists(): Promise<PlaylistItem[]>; | ||
getPlaylistNames(): Promise<string[]>; | ||
getPlaylists(qsOptions?: any): Promise<PlaylistItem[]>; | ||
getPlaylistTracks(playlist_id: string, qsOptions?: any): Promise<CodyResponse>; | ||
getPlaylistNames(qsOptions?: any): Promise<string[]>; | ||
/** | ||
@@ -10,0 +11,0 @@ * Create a new playlist |
@@ -20,3 +20,3 @@ "use strict"; | ||
} | ||
async getPlaylists() { | ||
async getPlaylists(qsOptions = {}) { | ||
let playlists = []; | ||
@@ -27,4 +27,13 @@ if (!musicStore.spotifyUserId) { | ||
if (musicStore.spotifyUserId) { | ||
const api = `/v1/users/${musicStore.spotifyUserId}/playlists?limit=50`; | ||
let codyResp = await musicClient.spotifyApiGet(api, {}); | ||
if (!qsOptions.limit) { | ||
qsOptions["limit"] = 50; | ||
} | ||
else if (qsOptions.limit < 1) { | ||
qsOptions.limit = 1; | ||
} | ||
if (!qsOptions.offset) { | ||
qsOptions["offset"] = 0; | ||
} | ||
const api = `/v1/users/${musicStore.spotifyUserId}/playlists`; | ||
let codyResp = await musicClient.spotifyApiGet(api, qsOptions); | ||
// check if the token needs to be refreshed | ||
@@ -43,5 +52,46 @@ if (codyResp.statusText === "EXPIRED") { | ||
} | ||
async getPlaylistNames() { | ||
async getPlaylistTracks(playlist_id, qsOptions = {}) { | ||
if (!qsOptions.limit) { | ||
qsOptions["limit"] = 100; | ||
} | ||
else if (qsOptions.limit < 1) { | ||
qsOptions.limit = 1; | ||
} | ||
if (!qsOptions.offset) { | ||
qsOptions["offset"] = 0; | ||
} | ||
// fields to return for the present moment | ||
// TODO: allow options to update this | ||
qsOptions["fields"] = "items(track(name,id,album(id,name),artists))"; | ||
const api = `/v1/playlists/${playlist_id}/tracks`; | ||
let codyResp = await musicClient.spotifyApiGet(api, qsOptions); | ||
// check if the token needs to be refreshed | ||
if (codyResp.statusText === "EXPIRED") { | ||
// refresh the token | ||
await musicClient.refreshSpotifyToken(); | ||
// try again | ||
codyResp = await musicClient.spotifyApiPost(api, qsOptions); | ||
} | ||
// get the artists | ||
if (codyResp.state === models_1.CodyResponseType.Success && | ||
codyResp.data.items && | ||
codyResp.data.items.length > 0) { | ||
codyResp.data.items.forEach((item) => { | ||
let artists = []; | ||
if (item.track && | ||
item.track.artists && | ||
item.track.artists.length > 0) { | ||
item.track.artists.forEach((artist) => { | ||
artists.push(artist.name); | ||
}); | ||
delete item.track.artists; | ||
item.track["artists"] = artists; | ||
} | ||
}); | ||
} | ||
return codyResp; | ||
} | ||
async getPlaylistNames(qsOptions = {}) { | ||
let names = []; | ||
let playlists = await this.getPlaylists(); | ||
let playlists = await this.getPlaylists(qsOptions); | ||
if (playlists) { | ||
@@ -48,0 +98,0 @@ names = playlists.map((playlistItem) => { |
@@ -60,2 +60,11 @@ "use strict"; | ||
}); | ||
it("return the tracks of a playlist", done => { | ||
CodyMusic.getPlaylists(models_1.PlayerName.SpotifyWeb).then(result => { | ||
let playlist_id = result[0].id; | ||
CodyMusic.getPlaylistTracks(models_1.PlayerName.SpotifyWeb, playlist_id).then(result => { | ||
expect(result.data.items[0].track).to.not.equal(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -170,6 +170,10 @@ "use strict"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export async function getTracksByPlaylistName( | ||
player: PlayerName, | ||
playListName: string | ||
playListName: string, | ||
playlist_id: string = "", | ||
qsOptions: any = {} | ||
) { | ||
@@ -199,2 +203,17 @@ const params = null; | ||
/** | ||
* Returns the tracks that are found by the given playlist name | ||
* - currently spofity-web support only | ||
* @param player {spotify-web} | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export async function getPlaylistTracks( | ||
player: PlayerName, | ||
playlist_id: string, | ||
qsOptions: any = {} | ||
) { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
} | ||
/** | ||
* Plays a specific track on the Spotify or iTunes desktop | ||
@@ -382,9 +401,11 @@ * @param player | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param (optional) {limit, offset} | ||
*/ | ||
export async function getPlaylists( | ||
player: PlayerName | ||
player: PlayerName, | ||
qsOptions: any = {} | ||
): Promise<PlaylistItem[]> { | ||
let playlists: PlaylistItem[] = []; | ||
if (player === PlayerName.SpotifyWeb) { | ||
playlists = await playlist.getPlaylists(); | ||
playlists = await playlist.getPlaylists(qsOptions); | ||
} else { | ||
@@ -408,6 +429,10 @@ let playlistNames: string[] = await getPlaylistNames(player); | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param qsOptions (optional) {limit, offset} | ||
*/ | ||
export async function getPlaylistNames(player: PlayerName): Promise<string[]> { | ||
export async function getPlaylistNames( | ||
player: PlayerName, | ||
qsOptions: any = {} | ||
): Promise<string[]> { | ||
if (player === PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistNames(); | ||
return playlist.getPlaylistNames(qsOptions); | ||
} | ||
@@ -414,0 +439,0 @@ // result will string of playlist names separated by a comma |
@@ -166,3 +166,3 @@ import axios, { AxiosInstance } from "axios"; | ||
spotifyApiGet(api: string, qsOptions: any = {}): Promise<CodyResponse> { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
@@ -189,3 +189,3 @@ spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${ | ||
): Promise<CodyResponse> { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
@@ -211,3 +211,3 @@ spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${ | ||
): Promise<CodyResponse> { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
@@ -233,3 +233,3 @@ spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${ | ||
): Promise<CodyResponse> { | ||
this.addQueryStringToApi(api, qsOptions); | ||
api = this.addQueryStringToApi(api, qsOptions); | ||
@@ -255,2 +255,3 @@ spotifyClient.defaults.headers.common["Authorization"] = `Bearer ${ | ||
} | ||
return api; | ||
} | ||
@@ -257,0 +258,0 @@ |
import { MusicClient } from "./client"; | ||
import { CodyResponse, CodyResponseType, PlaylistItem } from "./models"; | ||
import { CodyResponse, CodyResponseType, PlaylistItem, Track } from "./models"; | ||
import { MusicStore } from "./store"; | ||
@@ -22,3 +22,3 @@ import { UserProfile } from "./profile"; | ||
async getPlaylists(): Promise<PlaylistItem[]> { | ||
async getPlaylists(qsOptions: any = {}): Promise<PlaylistItem[]> { | ||
let playlists: PlaylistItem[] = []; | ||
@@ -30,8 +30,15 @@ if (!musicStore.spotifyUserId) { | ||
if (musicStore.spotifyUserId) { | ||
const api = `/v1/users/${ | ||
musicStore.spotifyUserId | ||
}/playlists?limit=50`; | ||
if (!qsOptions.limit) { | ||
qsOptions["limit"] = 50; | ||
} else if (qsOptions.limit < 1) { | ||
qsOptions.limit = 1; | ||
} | ||
if (!qsOptions.offset) { | ||
qsOptions["offset"] = 0; | ||
} | ||
const api = `/v1/users/${musicStore.spotifyUserId}/playlists`; | ||
let codyResp: CodyResponse = await musicClient.spotifyApiGet( | ||
api, | ||
{} | ||
qsOptions | ||
); | ||
@@ -53,5 +60,55 @@ // check if the token needs to be refreshed | ||
async getPlaylistNames(): Promise<string[]> { | ||
async getPlaylistTracks(playlist_id: string, qsOptions: any = {}) { | ||
if (!qsOptions.limit) { | ||
qsOptions["limit"] = 100; | ||
} else if (qsOptions.limit < 1) { | ||
qsOptions.limit = 1; | ||
} | ||
if (!qsOptions.offset) { | ||
qsOptions["offset"] = 0; | ||
} | ||
// fields to return for the present moment | ||
// TODO: allow options to update this | ||
qsOptions["fields"] = "items(track(name,id,album(id,name),artists))"; | ||
const api = `/v1/playlists/${playlist_id}/tracks`; | ||
let codyResp = await musicClient.spotifyApiGet(api, qsOptions); | ||
// check if the token needs to be refreshed | ||
if (codyResp.statusText === "EXPIRED") { | ||
// refresh the token | ||
await musicClient.refreshSpotifyToken(); | ||
// try again | ||
codyResp = await musicClient.spotifyApiPost(api, qsOptions); | ||
} | ||
// get the artists | ||
if ( | ||
codyResp.state === CodyResponseType.Success && | ||
codyResp.data.items && | ||
codyResp.data.items.length > 0 | ||
) { | ||
codyResp.data.items.forEach((item: any) => { | ||
let artists: any[] = []; | ||
if ( | ||
item.track && | ||
item.track.artists && | ||
item.track.artists.length > 0 | ||
) { | ||
item.track.artists.forEach((artist: any) => { | ||
artists.push(artist.name); | ||
}); | ||
delete item.track.artists; | ||
item.track["artists"] = artists; | ||
} | ||
}); | ||
} | ||
return codyResp; | ||
} | ||
async getPlaylistNames(qsOptions: any = {}): Promise<string[]> { | ||
let names: string[] = []; | ||
let playlists = await this.getPlaylists(); | ||
let playlists = await this.getPlaylists(qsOptions); | ||
if (playlists) { | ||
@@ -58,0 +115,0 @@ names = playlists.map((playlistItem: PlaylistItem) => { |
{ | ||
"name": "cody-music", | ||
"version": "2.1.6", | ||
"version": "2.1.7", | ||
"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", |
@@ -146,7 +146,22 @@ # cody-music | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param playListName {} | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
getTracksByPlaylistName(player: PlayerName, playListName: string) | ||
getTracksByPlaylistName(player: PlayerName, | ||
playListName: string, | ||
playlist_id: string = "", | ||
qsOptions: any = {}) | ||
/** | ||
* Returns the tracks that are found by the given playlist name | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param playlist_id | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
getPlaylistTracks(player: PlayerName, | ||
playlist_id: string, | ||
qsOptions: any = {}) | ||
/** | ||
* Plays a specific track on the Spotify or iTunes desktop | ||
@@ -275,4 +290,8 @@ * @param player | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param (optional) {limit, offset} | ||
*/ | ||
getPlaylists(player: PlayerName): Promise<PlaylistItem[]> | ||
getPlaylists( | ||
player: PlayerName, | ||
qsOptions: any = {} | ||
): Promise<PlaylistItem[]> | ||
@@ -282,4 +301,5 @@ /** | ||
* @param player {spotify|spotify-web|itunes} | ||
* @param (optional) {limit, offset} | ||
*/ | ||
getPlaylistNames(player: PlayerName):Promise<string[]> | ||
getPlaylistNames(player: PlayerName, qsOptions: any = {}):Promise<string[]> | ||
@@ -286,0 +306,0 @@ /** |
@@ -60,2 +60,15 @@ const expect = require("chai").expect; | ||
}); | ||
it("return the tracks of a playlist", done => { | ||
CodyMusic.getPlaylists(PlayerName.SpotifyWeb).then(result => { | ||
let playlist_id = result[0].id; | ||
CodyMusic.getPlaylistTracks( | ||
PlayerName.SpotifyWeb, | ||
playlist_id | ||
).then(result => { | ||
expect(result.data.items[0].track).to.not.equal(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
297929
7273
423