Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cody-music

Package Overview
Dependencies
Maintainers
1
Versions
234
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cody-music - npm Package Compare versions

Comparing version 2.7.9 to 2.8.0

1

dist/lib/playerstate.d.ts

@@ -45,2 +45,3 @@ import { PlayerDevice, Track, PlayerContext, Artist, PlayerName, CodyResponse } from "./models";

getSpotifyTrackById(id: string, includeArtistData?: boolean, includeAudioFeaturesData?: boolean, includeGenre?: boolean): Promise<Track>;
getSpotifyArtistsByIds(ids: string[]): Promise<Artist[]>;
getSpotifyArtistById(id: string): Promise<Artist>;

@@ -47,0 +48,0 @@ getSpotifyWebCurrentTrack(): Promise<Track>;

84

dist/lib/playerstate.js

@@ -160,2 +160,3 @@ "use strict";

if (response && response.status === 200 && response.data) {
let artistIdMap = {};
const tracks = response.data.tracks || [];

@@ -168,23 +169,29 @@ for (let x = 0; x < tracks.length; x++) {

: 0;
// get the arist data
if (includeArtistData && track.artists) {
let artists = [];
if (includeArtistData) {
for (let i = 0; i < track.artists.length; i++) {
const artist = track.artists[i];
try {
const artistData = await this.getSpotifyArtistById(artist.id);
artists.push(artistData);
}
catch (e) {
// just use the current artists info
artists.push(artist);
}
artistIdMap[artist.id] = artist.id;
}
if (artists.length > 0) {
track.artists = artists;
}
else {
track.artists = [];
}
}
// // get the arist data
// if (includeArtistData && track.artists) {
// let artists: Artist[] = [];
// for (let i = 0; i < track.artists.length; i++) {
// const artist = track.artists[i];
// try {
// const artistData: Artist = await this.getSpotifyArtistById(
// artist.id
// );
// artists.push(artistData);
// } catch (e) {
// // just use the current artists info
// artists.push(artist);
// }
// }
// if (artists.length > 0) {
// track.artists = artists;
// } else {
// track.artists = [];
// }
// }
if (!track.genre && includeGenre) {

@@ -210,2 +217,26 @@ // first check if we have an artist in artists

}
let artists = [];
if (includeArtistData) {
let artistIds = Object.keys(artistIdMap).map(key => {
return key;
});
if (artistIds.length > 50) {
// we can't go over 50
artistIds = artistIds.splice(0, 50);
}
artists = await this.getSpotifyArtistsByIds(artistIds);
if (artists && artists.length > 0) {
// go through the tracks and update the artist with the fully populated one
tracksToReturn.forEach((t) => {
const trackArtistIds = t.artists.map((artist) => {
return artist.id;
});
const artistsForTrack = artists.filter((n) => trackArtistIds.includes(n.id));
if (artistsForTrack && artistsForTrack.length) {
// replace the artists
t.artists = artistsForTrack;
}
});
}
}
// get the features

@@ -293,2 +324,21 @@ if (includeAudioFeaturesData) {

}
async getSpotifyArtistsByIds(ids) {
let artists = [];
ids = musicUtil.createSpotifyIdsFromUris(ids);
// check the cache first
let api = `/v1/artists`;
const qParam = { ids };
let response = await musicClient.spotifyApiGet(api, qParam);
// check if the token needs to be refreshed
if (response.statusText === "EXPIRED") {
// refresh the token
await musicClient.refreshSpotifyToken();
// try again
response = await musicClient.spotifyApiGet(api);
}
if (response && response.status === 200 && response.data) {
artists = response.data.artists || [];
}
return artists;
}
async getSpotifyArtistById(id) {

@@ -295,0 +345,0 @@ let artist = new models_1.Artist();

@@ -26,2 +26,3 @@ import { PlayerName, Track, CodyResponse } from "./models";

createSpotifyIdFromUri(uri: string): string;
createSpotifyIdsFromUris(uris: string[]): string[];
extractAristFromSpotifyTrack(track: any): void;

@@ -28,0 +29,0 @@ launchWebUrl(url: string): Promise<any>;

@@ -174,2 +174,11 @@ "use strict";

}
createSpotifyIdsFromUris(uris) {
const ids = [];
if (uris && uris.length) {
uris.forEach(uri => {
ids.push(this.createSpotifyIdFromUri(uri));
});
}
return ids;
}
extractAristFromSpotifyTrack(track) {

@@ -176,0 +185,0 @@ if (!track) {

@@ -190,2 +190,3 @@ import { MusicUtil } from "./util";

if (response && response.status === 200 && response.data) {
let artistIdMap: any = {};
const tracks: any[] = response.data.tracks || [];

@@ -201,25 +202,32 @@ for (let x = 0; x < tracks.length; x++) {

// get the arist data
if (includeArtistData && track.artists) {
let artists: Artist[] = [];
if (includeArtistData) {
for (let i = 0; i < track.artists.length; i++) {
const artist = track.artists[i];
try {
const artistData: Artist = await this.getSpotifyArtistById(
artist.id
);
artists.push(artistData);
} catch (e) {
// just use the current artists info
artists.push(artist);
}
const artist: any = track.artists[i];
artistIdMap[artist.id] = artist.id;
}
if (artists.length > 0) {
track.artists = artists;
} else {
track.artists = [];
}
}
// // get the arist data
// if (includeArtistData && track.artists) {
// let artists: Artist[] = [];
// for (let i = 0; i < track.artists.length; i++) {
// const artist = track.artists[i];
// try {
// const artistData: Artist = await this.getSpotifyArtistById(
// artist.id
// );
// artists.push(artistData);
// } catch (e) {
// // just use the current artists info
// artists.push(artist);
// }
// }
// if (artists.length > 0) {
// track.artists = artists;
// } else {
// track.artists = [];
// }
// }
if (!track.genre && includeGenre) {

@@ -255,2 +263,31 @@ // first check if we have an artist in artists

let artists: any[] = [];
if (includeArtistData) {
let artistIds = Object.keys(artistIdMap).map(key => {
return key;
});
if (artistIds.length > 50) {
// we can't go over 50
artistIds = artistIds.splice(0, 50);
}
artists = await this.getSpotifyArtistsByIds(artistIds);
if (artists && artists.length > 0) {
// go through the tracks and update the artist with the fully populated one
tracksToReturn.forEach((t: Track) => {
const trackArtistIds: string[] = t.artists.map(
(artist: any) => {
return artist.id;
}
);
const artistsForTrack: any[] = artists.filter(
(n: any) => trackArtistIds.includes(n.id)
);
if (artistsForTrack && artistsForTrack.length) {
// replace the artists
t.artists = artistsForTrack;
}
});
}
}
// get the features

@@ -368,2 +405,29 @@ if (includeAudioFeaturesData) {

async getSpotifyArtistsByIds(ids: string[]): Promise<Artist[]> {
let artists: Artist[] = [];
ids = musicUtil.createSpotifyIdsFromUris(ids);
// check the cache first
let api = `/v1/artists`;
const qParam = { ids };
let response = await musicClient.spotifyApiGet(api, qParam);
// check if the token needs to be refreshed
if (response.statusText === "EXPIRED") {
// refresh the token
await musicClient.refreshSpotifyToken();
// try again
response = await musicClient.spotifyApiGet(api);
}
if (response && response.status === 200 && response.data) {
artists = response.data.artists || [];
}
return artists;
}
async getSpotifyArtistById(id: string): Promise<Artist> {

@@ -370,0 +434,0 @@ let artist: Artist = new Artist();

@@ -213,2 +213,12 @@ import {

createSpotifyIdsFromUris(uris: string[]) {
const ids: string[] = [];
if (uris && uris.length) {
uris.forEach(uri => {
ids.push(this.createSpotifyIdFromUri(uri));
});
}
return ids;
}
extractAristFromSpotifyTrack(track: any) {

@@ -215,0 +225,0 @@ if (!track) {

{
"name": "cody-music",
"version": "2.7.9",
"version": "2.8.0",
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc