cody-music
Advanced tools
Comparing version 2.0.7 to 2.0.8
@@ -1,2 +0,2 @@ | ||
import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature } from "./models"; | ||
import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature, PlaylistItem } from "./models"; | ||
/** | ||
@@ -159,2 +159,7 @@ * Set Credentials (currently only supports Spotify) | ||
/** | ||
* Returns the playlists for a given player | ||
* @param player {spotify|spotify-web|itunes} | ||
*/ | ||
export declare function getPlaylists(player: PlayerName): Promise<PlaylistItem[]>; | ||
/** | ||
* Get the full list of the playlist names for a given player | ||
@@ -161,0 +166,0 @@ * @param player {spotify|spotify-web|itunes} |
@@ -361,2 +361,14 @@ "use strict"; | ||
/** | ||
* Returns the playlists for a given player | ||
* @param player {spotify|spotify-web|itunes} | ||
*/ | ||
async function getPlaylists(player) { | ||
let playlists = []; | ||
if (player === models_1.PlayerName.SpotifyWeb) { | ||
playlists = await playlist.getPlaylists(); | ||
} | ||
return playlists; | ||
} | ||
exports.getPlaylists = getPlaylists; | ||
/** | ||
* Get the full list of the playlist names for a given player | ||
@@ -366,2 +378,5 @@ * @param player {spotify|spotify-web|itunes} | ||
async function getPlaylistNames(player) { | ||
if (player === models_1.PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistNames(); | ||
} | ||
// result will string of playlist names separated by a comma | ||
@@ -368,0 +383,0 @@ let result = await musicCtr.run(player, "playlistNames"); |
@@ -91,1 +91,8 @@ export declare enum PlayerType { | ||
} | ||
export declare class PlaylistItem { | ||
name: string; | ||
id: string; | ||
tracks: Track[]; | ||
collaborative: boolean; | ||
public: boolean; | ||
} |
@@ -115,1 +115,11 @@ "use strict"; | ||
exports.SpotifyAudioFeature = SpotifyAudioFeature; | ||
class PlaylistItem { | ||
constructor() { | ||
this.name = ""; | ||
this.id = ""; | ||
this.tracks = []; | ||
this.collaborative = false; | ||
this.public = true; | ||
} | ||
} | ||
exports.PlaylistItem = PlaylistItem; |
@@ -1,2 +0,2 @@ | ||
import { CodyResponse } from "./models"; | ||
import { CodyResponse, PlaylistItem } from "./models"; | ||
export declare class Playlist { | ||
@@ -6,2 +6,4 @@ private static instance; | ||
static getInstance(): Playlist; | ||
getPlaylists(): Promise<PlaylistItem[]>; | ||
getPlaylistNames(): Promise<string[]>; | ||
/** | ||
@@ -8,0 +10,0 @@ * Create a new playlist |
@@ -20,2 +20,28 @@ "use strict"; | ||
} | ||
async getPlaylists() { | ||
let playlists = []; | ||
if (!musicStore.spotifyUserId) { | ||
await userProfile.getUserProfile(); | ||
} | ||
if (musicStore.spotifyUserId) { | ||
const api = `/v1/users/${musicStore.spotifyUserId}/playlists?limit=50`; | ||
let spotifyPlaylists = await musicClient.spotifyApiGet(api, {}); | ||
if (spotifyPlaylists && | ||
spotifyPlaylists.data && | ||
spotifyPlaylists.data.items) { | ||
playlists = spotifyPlaylists.data.items; | ||
} | ||
} | ||
return playlists; | ||
} | ||
async getPlaylistNames() { | ||
let names = []; | ||
let playlists = await this.getPlaylists(); | ||
if (playlists) { | ||
names = playlists.map((playlistItem) => { | ||
return playlistItem.name; | ||
}); | ||
} | ||
return names; | ||
} | ||
/** | ||
@@ -22,0 +48,0 @@ * Create a new playlist |
@@ -11,3 +11,2 @@ "use strict"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -14,0 +13,0 @@ refreshToken: data.refreshToken, |
@@ -10,10 +10,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("../../lib/util"); | ||
const expect = require("chai").expect; | ||
const CodyMusic = __importStar(require("../../index")); | ||
const controller_1 = require("../../lib/controller"); | ||
const profile_1 = require("../../lib/profile"); | ||
const musicUtil = new util_1.MusicUtil(); | ||
const userProfile = profile_1.UserProfile.getInstance(); | ||
const musicCtr = controller_1.MusicController.getInstance(); | ||
const util_1 = require("../util"); | ||
const models_1 = require("../../lib/models"); | ||
const testUtil = new util_1.TestUtil(); | ||
/** | ||
@@ -29,8 +26,9 @@ * Don't add "async" into the it condition. | ||
before(done => { | ||
const accessToken = "123abc"; | ||
let configFile = __dirname + "/../config.json"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
CodyMusic.setCredentials({ | ||
refreshToken: "AQCSjp8_taBNv46KFtHsRpU9IcppjCDyGBWN4pATLLXqBPa4Wjk38CY703-WnG4xk7zVbU7niLKQrsYi_zkGnFIy2HuZv-RyiU9fwkE-uw3HUI-vqWBxZoEbdZEIcM1zIqPs3w", | ||
clientSecret: "2b40b4975b2743189c87f4712c0cd59e", | ||
clientId: "eb67e22ba1c6474aad8ec8067480d9dc", | ||
accessToken: accessToken | ||
refreshToken: data.refreshToken, | ||
clientSecret: data.clientSecret, | ||
clientId: data.clientId, | ||
accessToken: data.accessToken | ||
}); | ||
@@ -52,2 +50,15 @@ done(); | ||
}); | ||
it("return spotify playlists", done => { | ||
CodyMusic.getPlaylists(models_1.PlayerName.SpotifyWeb).then(result => { | ||
expect(result.length).to.not.equal(0); | ||
done(); | ||
}); | ||
}); | ||
it("return spotify playlist names", done => { | ||
CodyMusic.getPlaylistNames(models_1.PlayerName.SpotifyWeb).then(result => { | ||
console.log("names: ", result); | ||
expect(result.length).to.not.equal(0); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -10,10 +10,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("../../lib/util"); | ||
const expect = require("chai").expect; | ||
const CodyMusic = __importStar(require("../../index")); | ||
const controller_1 = require("../../lib/controller"); | ||
const profile_1 = require("../../lib/profile"); | ||
const musicUtil = new util_1.MusicUtil(); | ||
const util_1 = require("../util"); | ||
const userProfile = profile_1.UserProfile.getInstance(); | ||
const musicCtr = controller_1.MusicController.getInstance(); | ||
const testUtil = new util_1.TestUtil(); | ||
/** | ||
@@ -29,8 +27,9 @@ * Don't add "async" into the it condition. | ||
before(done => { | ||
const accessToken = "123abc"; | ||
let configFile = __dirname + "/../config.json"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
CodyMusic.setCredentials({ | ||
refreshToken: "AQCSjp8_taBNv46KFtHsRpU9IcppjCDyGBWN4pATLLXqBPa4Wjk38CY703-WnG4xk7zVbU7niLKQrsYi_zkGnFIy2HuZv-RyiU9fwkE-uw3HUI-vqWBxZoEbdZEIcM1zIqPs3w", | ||
clientSecret: "2b40b4975b2743189c87f4712c0cd59e", | ||
clientId: "eb67e22ba1c6474aad8ec8067480d9dc", | ||
accessToken: accessToken | ||
refreshToken: data.refreshToken, | ||
clientSecret: data.clientSecret, | ||
clientId: data.clientId, | ||
accessToken: data.accessToken | ||
}); | ||
@@ -37,0 +36,0 @@ done(); |
@@ -15,4 +15,6 @@ "use strict"; | ||
const models_1 = require("../../lib/models"); | ||
const util_2 = require("../util"); | ||
const musicUtil = new util_1.MusicUtil(); | ||
const musicCtr = controller_1.MusicController.getInstance(); | ||
const testUtil = new util_2.TestUtil(); | ||
/** | ||
@@ -28,8 +30,9 @@ * Don't add "async" into the it condition. | ||
before(done => { | ||
const accessToken = "123abc"; | ||
let configFile = __dirname + "/../config.json"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
CodyMusic.setCredentials({ | ||
refreshToken: "AQCSjp8_taBNv46KFtHsRpU9IcppjCDyGBWN4pATLLXqBPa4Wjk38CY703-WnG4xk7zVbU7niLKQrsYi_zkGnFIy2HuZv-RyiU9fwkE-uw3HUI-vqWBxZoEbdZEIcM1zIqPs3w", | ||
clientSecret: "2b40b4975b2743189c87f4712c0cd59e", | ||
clientId: "eb67e22ba1c6474aad8ec8067480d9dc", | ||
accessToken: accessToken | ||
refreshToken: data.refreshToken, | ||
clientSecret: data.clientSecret, | ||
clientId: data.clientId, | ||
accessToken: data.accessToken | ||
}); | ||
@@ -36,0 +39,0 @@ musicCtr.quitApp(models_1.PlayerName.SpotifyDesktop).then(() => { |
@@ -15,4 +15,6 @@ "use strict"; | ||
const controller_1 = require("../../lib/controller"); | ||
const util_2 = require("../util"); | ||
const musicUtil = new util_1.MusicUtil(); | ||
const musicCtr = controller_1.MusicController.getInstance(); | ||
const testUtil = new util_2.TestUtil(); | ||
/** | ||
@@ -31,11 +33,12 @@ * Don't add "async" into the it condition. | ||
.then((result) => { | ||
const accessToken = "123abc"; | ||
let configFile = __dirname + "/../config.json"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
CodyMusic.setCredentials({ | ||
refreshToken: "AQCSjp8_taBNv46KFtHsRpU9IcppjCDyGBWN4pATLLXqBPa4Wjk38CY703-WnG4xk7zVbU7niLKQrsYi_zkGnFIy2HuZv-RyiU9fwkE-uw3HUI-vqWBxZoEbdZEIcM1zIqPs3w", | ||
clientSecret: "2b40b4975b2743189c87f4712c0cd59e", | ||
clientId: "eb67e22ba1c6474aad8ec8067480d9dc", | ||
accessToken: accessToken | ||
refreshToken: data.refreshToken, | ||
clientSecret: data.clientSecret, | ||
clientId: data.clientId, | ||
accessToken: data.accessToken | ||
}); | ||
let setAccessToken = CodyMusic.getAccessToken(); | ||
expect(setAccessToken).to.equal(accessToken); | ||
expect(setAccessToken).to.equal(data.accessToken); | ||
done(); | ||
@@ -42,0 +45,0 @@ }); |
@@ -9,3 +9,4 @@ "use strict"; | ||
SpotifyAudioFeature, | ||
PlayerType | ||
PlayerType, | ||
PlaylistItem | ||
} from "./models"; | ||
@@ -378,2 +379,17 @@ import { MusicPlayerState } from "./playerstate"; | ||
/** | ||
* Returns the playlists for a given player | ||
* @param player {spotify|spotify-web|itunes} | ||
*/ | ||
export async function getPlaylists( | ||
player: PlayerName | ||
): Promise<PlaylistItem[]> { | ||
let playlists: PlaylistItem[] = []; | ||
if (player === PlayerName.SpotifyWeb) { | ||
playlists = await playlist.getPlaylists(); | ||
} | ||
return playlists; | ||
} | ||
/** | ||
* Get the full list of the playlist names for a given player | ||
@@ -383,2 +399,5 @@ * @param player {spotify|spotify-web|itunes} | ||
export async function getPlaylistNames(player: PlayerName): Promise<string[]> { | ||
if (player === PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistNames(); | ||
} | ||
// result will string of playlist names separated by a comma | ||
@@ -385,0 +404,0 @@ let result = await musicCtr.run(player, "playlistNames"); |
@@ -102,1 +102,9 @@ export enum PlayerType { | ||
} | ||
export class PlaylistItem { | ||
name: string = ""; | ||
id: string = ""; | ||
tracks: Track[] = []; | ||
collaborative: boolean = false; | ||
public: boolean = true; | ||
} |
import { MusicClient } from "./client"; | ||
import { CodyResponse, CodyResponseType } from "./models"; | ||
import { CodyResponse, CodyResponseType, PlaylistItem } from "./models"; | ||
import { MusicStore } from "./store"; | ||
@@ -22,2 +22,36 @@ import { UserProfile } from "./profile"; | ||
async getPlaylists(): Promise<PlaylistItem[]> { | ||
let playlists: PlaylistItem[] = []; | ||
if (!musicStore.spotifyUserId) { | ||
await userProfile.getUserProfile(); | ||
} | ||
if (musicStore.spotifyUserId) { | ||
const api = `/v1/users/${ | ||
musicStore.spotifyUserId | ||
}/playlists?limit=50`; | ||
let spotifyPlaylists = await musicClient.spotifyApiGet(api, {}); | ||
if ( | ||
spotifyPlaylists && | ||
spotifyPlaylists.data && | ||
spotifyPlaylists.data.items | ||
) { | ||
playlists = spotifyPlaylists.data.items; | ||
} | ||
} | ||
return playlists; | ||
} | ||
async getPlaylistNames(): Promise<string[]> { | ||
let names: string[] = []; | ||
let playlists = await this.getPlaylists(); | ||
if (playlists) { | ||
names = playlists.map((playlistItem: PlaylistItem) => { | ||
return playlistItem.name; | ||
}); | ||
} | ||
return names; | ||
} | ||
/** | ||
@@ -24,0 +58,0 @@ * Create a new playlist |
{ | ||
"name": "cody-music", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"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", |
@@ -11,3 +11,2 @@ import { TestUtil } from "../util"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -14,0 +13,0 @@ refreshToken: data.refreshToken, |
const expect = require("chai").expect; | ||
import * as CodyMusic from "../../index"; | ||
import { TestUtil } from "../util"; | ||
import { PlayerName } from "../../lib/models"; | ||
@@ -19,3 +20,2 @@ const testUtil = new TestUtil(); | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -47,2 +47,16 @@ refreshToken: data.refreshToken, | ||
}); | ||
it("return spotify playlists", done => { | ||
CodyMusic.getPlaylists(PlayerName.SpotifyWeb).then(result => { | ||
expect(result.length).to.not.equal(0); | ||
done(); | ||
}); | ||
}); | ||
it("return spotify playlist names", done => { | ||
CodyMusic.getPlaylistNames(PlayerName.SpotifyWeb).then(result => { | ||
expect(result.length).to.not.equal(0); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -21,3 +21,2 @@ const expect = require("chai").expect; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -24,0 +23,0 @@ refreshToken: data.refreshToken, |
@@ -24,3 +24,2 @@ import { MusicUtil } from "../../lib/util"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -27,0 +26,0 @@ refreshToken: data.refreshToken, |
@@ -27,3 +27,2 @@ import { MusicUtil } from "../../lib/util"; | ||
let data = testUtil.getJsonFromFile(configFile); | ||
console.log("data: ", data); | ||
CodyMusic.setCredentials({ | ||
@@ -38,3 +37,3 @@ refreshToken: data.refreshToken, | ||
expect(setAccessToken).to.equal(accessToken); | ||
expect(setAccessToken).to.equal(data.accessToken); | ||
@@ -41,0 +40,0 @@ done(); |
287087
7028