cody-music
Advanced tools
Comparing version 2.2.4 to 2.2.5
@@ -55,6 +55,4 @@ import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature, PlaylistItem, CodyResponse } from "./models"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export declare function getTracksByPlaylistName(player: PlayerName, playListName: string, playlist_id?: string, qsOptions?: any): Promise<any>; | ||
export declare function getTracksByPlaylistName(player: PlayerName, playListName: string): Promise<PlaylistItem[]>; | ||
/** | ||
@@ -61,0 +59,0 @@ * Returns the tracks that are found by the given playlist name |
@@ -157,6 +157,5 @@ "use strict"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
async function getTracksByPlaylistName(player, playListName, playlist_id = "", qsOptions = {}) { | ||
async function getTracksByPlaylistName(player, playListName) { | ||
let playlistItems = []; | ||
const params = null; | ||
@@ -171,12 +170,28 @@ const argv = [playListName]; | ||
let jsonStr = jsonList[i].trim(); | ||
try { | ||
jsonResult[i] = JSON.parse(jsonStr); | ||
if (jsonStr.toLowerCase() !== "ok") { | ||
try { | ||
jsonResult[i] = JSON.parse(jsonStr); | ||
} | ||
catch (err) { | ||
// it might be the success response "ok" | ||
} | ||
} | ||
catch (err) { | ||
// it might be the success response "ok" | ||
} | ||
} | ||
} | ||
} | ||
return jsonResult; | ||
if (jsonResult) { | ||
// go through the keys and create an array | ||
// of PlaylistItem | ||
playlistItems = Object.keys(jsonResult).map((key) => { | ||
let trackItem = jsonResult[key]; | ||
let playlistItem = new models_1.PlaylistItem(); | ||
playlistItem.name = trackItem.name; | ||
playlistItem.type = "track"; | ||
playlistItem.public = true; | ||
playlistItem.collaborative = false; | ||
playlistItem.id = trackItem.id; | ||
return playlistItem; | ||
}); | ||
} | ||
return playlistItems; | ||
} | ||
@@ -192,3 +207,10 @@ exports.getTracksByPlaylistName = getTracksByPlaylistName; | ||
async function getPlaylistTracks(player, playlist_id, qsOptions = {}) { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
if (player === models_1.PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
} | ||
// itunes or spotify desktop | ||
const playlistItems = await getTracksByPlaylistName(player, playlist_id); | ||
let codyResp = new models_1.CodyResponse(); | ||
codyResp.data = playlistItems; | ||
return codyResp; | ||
} | ||
@@ -394,8 +416,8 @@ exports.getPlaylistTracks = getPlaylistTracks; | ||
if (result) { | ||
result = result.split("},"); | ||
result = result.split("[TRACK_END]"); | ||
if (result && result.length > 0) { | ||
playlists = result.map((resultItem) => { | ||
if (!resultItem.includes("}")) { | ||
resultItem = `${resultItem}}`; | ||
} | ||
// if (!resultItem.includes("}")) { | ||
// resultItem = `${resultItem}}`; | ||
// } | ||
try { | ||
@@ -402,0 +424,0 @@ // {name, count} |
@@ -73,2 +73,12 @@ "use strict"; | ||
}); | ||
it("Get itunes playlists tracks", done => { | ||
CodyMusic.getPlaylists(models_1.PlayerName.ItunesDesktop).then((result) => { | ||
expect(result.length).to.not.equal(0); | ||
const playlistItem = result[0]; | ||
CodyMusic.getPlaylistTracks(models_1.PlayerName.ItunesDesktop, playlistItem.id).then((result) => { | ||
expect(result.data.length).to.not.equal(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -172,11 +172,8 @@ "use strict"; | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
export async function getTracksByPlaylistName( | ||
player: PlayerName, | ||
playListName: string, | ||
playlist_id: string = "", | ||
qsOptions: any = {} | ||
) { | ||
playListName: string | ||
): Promise<PlaylistItem[]> { | ||
let playlistItems: PlaylistItem[] = []; | ||
const params = null; | ||
@@ -197,6 +194,8 @@ const argv = [playListName]; | ||
let jsonStr = jsonList[i].trim(); | ||
try { | ||
jsonResult[i] = JSON.parse(jsonStr); | ||
} catch (err) { | ||
// it might be the success response "ok" | ||
if (jsonStr.toLowerCase() !== "ok") { | ||
try { | ||
jsonResult[i] = JSON.parse(jsonStr); | ||
} catch (err) { | ||
// it might be the success response "ok" | ||
} | ||
} | ||
@@ -206,3 +205,17 @@ } | ||
} | ||
return jsonResult; | ||
if (jsonResult) { | ||
// go through the keys and create an array | ||
// of PlaylistItem | ||
playlistItems = Object.keys(jsonResult).map((key: string) => { | ||
let trackItem = jsonResult[key]; | ||
let playlistItem: PlaylistItem = new PlaylistItem(); | ||
playlistItem.name = trackItem.name; | ||
playlistItem.type = "track"; | ||
playlistItem.public = true; | ||
playlistItem.collaborative = false; | ||
playlistItem.id = trackItem.id; | ||
return playlistItem; | ||
}); | ||
} | ||
return playlistItems; | ||
} | ||
@@ -222,3 +235,14 @@ | ||
): Promise<CodyResponse> { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
if (player === PlayerName.SpotifyWeb) { | ||
return playlist.getPlaylistTracks(playlist_id, qsOptions); | ||
} | ||
// itunes or spotify desktop | ||
const playlistItems: PlaylistItem[] = await getTracksByPlaylistName( | ||
player, | ||
playlist_id | ||
); | ||
let codyResp: CodyResponse = new CodyResponse(); | ||
codyResp.data = playlistItems; | ||
return codyResp; | ||
} | ||
@@ -421,8 +445,8 @@ | ||
if (result) { | ||
result = result.split("},"); | ||
result = result.split("[TRACK_END]"); | ||
if (result && result.length > 0) { | ||
playlists = result.map((resultItem: string) => { | ||
if (!resultItem.includes("}")) { | ||
resultItem = `${resultItem}}`; | ||
} | ||
// if (!resultItem.includes("}")) { | ||
// resultItem = `${resultItem}}`; | ||
// } | ||
try { | ||
@@ -429,0 +453,0 @@ // {name, count} |
{ | ||
"name": "cody-music", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"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", |
@@ -182,9 +182,5 @@ # cody-music | ||
* @param playListName | ||
* @param playlist_id (optional) | ||
* @param qsOptions (optional) {offset, limit} | ||
*/ | ||
getTracksByPlaylistName(player: PlayerName, | ||
playListName: string, | ||
playlist_id: string = "", | ||
qsOptions: any = {}) | ||
playListName: string): Promise<PlaylistItem[]> | ||
@@ -202,3 +198,3 @@ /** | ||
playlist_id: string, | ||
qsOptions: any = {}) | ||
qsOptions: any = {}): Promise<CodyResponse> | ||
@@ -205,0 +201,0 @@ /** |
import { MusicUtil } from "../../lib/util"; | ||
const expect = require("chai").expect; | ||
import * as CodyMusic from "../../index"; | ||
import { Track, PlayerName, PlaylistItem } from "../../lib/models"; | ||
import { | ||
Track, | ||
PlayerName, | ||
PlaylistItem, | ||
CodyResponse | ||
} from "../../lib/models"; | ||
import { MusicController } from "../../lib/controller"; | ||
@@ -74,2 +79,18 @@ | ||
}); | ||
it("Get itunes playlists tracks", done => { | ||
CodyMusic.getPlaylists(PlayerName.ItunesDesktop).then( | ||
(result: PlaylistItem[]) => { | ||
expect(result.length).to.not.equal(0); | ||
const playlistItem: PlaylistItem = result[0]; | ||
CodyMusic.getPlaylistTracks( | ||
PlayerName.ItunesDesktop, | ||
playlistItem.id | ||
).then((result: CodyResponse) => { | ||
expect(result.data.length).to.not.equal(0); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
312225
7585
457