New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cody-music

Package Overview
Dependencies
Maintainers
5
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.9.35 to 2.9.36

config.json

4

dist/lib/apis.js

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

const profile_1 = require("./profile");
// initi the props
require('dotenv').config();
// get the instances

@@ -316,3 +318,3 @@ const musicCtr = controller_1.MusicController.getInstance();

*/
async function getSpotifyTracks(ids, includeFullArtistData = false, includeAudioFeaturesData = false, includeGenre = false) {
async function getSpotifyTracks(ids, includeFullArtistData = false, includeAudioFeaturesData = false, includeGenre = true) {
return musicPlayerCtr.getSpotifyTracks(ids, includeFullArtistData, includeAudioFeaturesData, includeGenre);

@@ -319,0 +321,0 @@ }

@@ -179,7 +179,17 @@ "use strict";

}
// get the features if the flag is set to true
let spotifyAudioFeaturesP = null;
if (includeAudioFeaturesData) {
// async - call the spotify api to fetch the audio features
spotifyAudioFeaturesP = audioStat
.getSpotifyAudioFeatures(ids)
.catch((e) => {
return null;
});
}
if (response && response.status === 200 && response.data) {
// get the tracks
let artistIdMap = {};
const tracks = response.data.tracks || [];
for (let x = 0; x < tracks.length; x++) {
const trackData = tracks[x];
tracks.forEach((trackData) => {
const track = musicUtil.copySpotifyTrackToCodyTrack(trackData);

@@ -189,14 +199,12 @@ track.progress_ms = response.data.progress_ms

: 0;
if (includeArtistData) {
for (let i = 0; i < track.artists.length; i++) {
const artist = track.artists[i];
if (track.artists) {
track.artists.forEach((artist) => {
artistIdMap[artist.id] = artist.id;
}
});
}
tracksToReturn.push(track);
}
});
// fetch the artists from spotify if this flag is set to true
if (includeArtistData) {
let artistIds = Object.keys(artistIdMap).map((key) => {
return key;
});
let artistIds = Object.keys(artistIdMap).map(key => key);
// fetch the artists all at once or in batches

@@ -207,5 +215,4 @@ let artists = [];

if (artistIds.length > 50) {
let hasData = artistIds.length ? true : false;
while (hasData) {
// keep removing from the artistIds
while (artistIds.length) {
// keep removing from the artistIds 50 at a time
let splicedArtistIds = artistIds.splice(0, 50);

@@ -216,6 +223,2 @@ const batchedArtists = await this.getSpotifyArtistsByIds(splicedArtistIds);

}
hasData = artistIds.length ? true : false;
if (!hasData) {
break;
}
}

@@ -227,11 +230,12 @@ }

}
if (artists && artists.length > 0) {
// go through the tracks and update the artist with the fully populated one
for (let t of tracksToReturn) {
const trackArtistIds = t.artists.map((artist) => {
return artist.id;
});
// populate the artists into the existing tracks
if (artists && artists.length) {
tracksToReturn.forEach((t) => {
// get the artist IDs from the tracks to return shallow artists array
const trackArtistIds = t.artists.map((artist) => artist.id);
// filter out the full artists found in the artists response
// based on the artist IDs that were in the tracksToReturn
const artistsForTrack = artists.filter((n) => trackArtistIds.includes(n.id));
if (artistsForTrack && artistsForTrack.length) {
// replace the artists
// replace the shallow artists with the full artists
t.artists = artistsForTrack;

@@ -260,23 +264,20 @@ }

}
}
});
}
}
// get the features
// get the features if the flag is set to true
if (includeAudioFeaturesData) {
const spotifyAudioFeatures = await audioStat
.getSpotifyAudioFeatures(ids)
.catch((e) => {
return null;
});
if (spotifyAudioFeatures && spotifyAudioFeatures.length > 0) {
// await for the call we made earlier
const spotifyAudioFeatures = await spotifyAudioFeaturesP;
if (spotifyAudioFeatures && spotifyAudioFeatures.length) {
// "id": "4JpKVNYnVcJ8tuMKjAj50A",
// "uri": "spotify:track:4JpKVNYnVcJ8tuMKjAj50A",
// track.features = spotifyAudioFeatures[0];
for (let i = 0; i < spotifyAudioFeatures.length; i++) {
const uri = spotifyAudioFeatures[i].uri;
spotifyAudioFeatures.forEach((feature) => {
const uri = feature.uri;
const foundTrack = tracksToReturn.find((t) => t.uri === uri);
if (foundTrack) {
foundTrack.features = spotifyAudioFeatures[i];
foundTrack.features = feature;
}
}
});
}

@@ -283,0 +284,0 @@ }

@@ -25,2 +25,5 @@ "use strict";

// initi the props
require('dotenv').config();
// get the instances

@@ -399,3 +402,3 @@ const musicCtr = MusicController.getInstance();

includeAudioFeaturesData: boolean = false,
includeGenre: boolean = false
includeGenre: boolean = true
): Promise<Track[]> {

@@ -439,3 +442,3 @@ return musicPlayerCtr.getSpotifyTracks(

}
} catch (e) {}
} catch (e) { }
}

@@ -442,0 +445,0 @@ }

@@ -212,7 +212,18 @@ import { MusicUtil } from "./util";

// get the features if the flag is set to true
let spotifyAudioFeaturesP = null;
if (includeAudioFeaturesData) {
// async - call the spotify api to fetch the audio features
spotifyAudioFeaturesP = audioStat
.getSpotifyAudioFeatures(ids)
.catch((e) => {
return null;
});
}
if (response && response.status === 200 && response.data) {
// get the tracks
let artistIdMap: any = {};
const tracks: any[] = response.data.tracks || [];
for (let x = 0; x < tracks.length; x++) {
const trackData = tracks[x];
tracks.forEach((trackData: Track) => {
const track: Track = musicUtil.copySpotifyTrackToCodyTrack(

@@ -225,16 +236,14 @@ trackData

if (includeArtistData) {
for (let i = 0; i < track.artists.length; i++) {
const artist: any = track.artists[i];
if (track.artists) {
track.artists.forEach((artist: any) => {
artistIdMap[artist.id] = artist.id;
}
});
}
tracksToReturn.push(track);
}
});
// fetch the artists from spotify if this flag is set to true
if (includeArtistData) {
let artistIds = Object.keys(artistIdMap).map((key) => {
return key;
});
let artistIds = Object.keys(artistIdMap).map(key => key);

@@ -246,5 +255,4 @@ // fetch the artists all at once or in batches

if (artistIds.length > 50) {
let hasData = artistIds.length ? true : false;
while (hasData) {
// keep removing from the artistIds
while (artistIds.length) {
// keep removing from the artistIds 50 at a time
let splicedArtistIds = artistIds.splice(0, 50);

@@ -258,6 +266,2 @@

}
hasData = artistIds.length ? true : false;
if (!hasData) {
break;
}
}

@@ -269,15 +273,16 @@ } else {

if (artists && artists.length > 0) {
// go through the tracks and update the artist with the fully populated one
for (let t of tracksToReturn) {
const trackArtistIds: string[] = t.artists.map(
(artist: any) => {
return artist.id;
}
);
// populate the artists into the existing tracks
if (artists && artists.length) {
tracksToReturn.forEach((t: Track) => {
// get the artist IDs from the tracks to return shallow artists array
const trackArtistIds: string[] = t.artists.map((artist: any) => artist.id);
// filter out the full artists found in the artists response
// based on the artist IDs that were in the tracksToReturn
const artistsForTrack: any[] = artists.filter(
(n: any) => trackArtistIds.includes(n.id)
);
if (artistsForTrack && artistsForTrack.length) {
// replace the artists
// replace the shallow artists with the full artists
t.artists = artistsForTrack;

@@ -310,19 +315,16 @@ }

}
}
});
}
}
// get the features
// get the features if the flag is set to true
if (includeAudioFeaturesData) {
const spotifyAudioFeatures = await audioStat
.getSpotifyAudioFeatures(ids)
.catch((e) => {
return null;
});
if (spotifyAudioFeatures && spotifyAudioFeatures.length > 0) {
// await for the call we made earlier
const spotifyAudioFeatures = await spotifyAudioFeaturesP;
if (spotifyAudioFeatures && spotifyAudioFeatures.length) {
// "id": "4JpKVNYnVcJ8tuMKjAj50A",
// "uri": "spotify:track:4JpKVNYnVcJ8tuMKjAj50A",
// track.features = spotifyAudioFeatures[0];
for (let i = 0; i < spotifyAudioFeatures.length; i++) {
const uri: string = spotifyAudioFeatures[i].uri;
spotifyAudioFeatures.forEach((feature: any) => {
const uri: string = feature.uri;
const foundTrack = tracksToReturn.find(

@@ -332,5 +334,5 @@ (t: Track) => t.uri === uri

if (foundTrack) {
foundTrack.features = spotifyAudioFeatures[i];
foundTrack.features = feature;
}
}
});
}

@@ -337,0 +339,0 @@ }

{
"name": "cody-music",
"version": "2.9.35",
"version": "2.9.36",
"description": "mac osx spotify and itunes music player controller, spotify audio features, itunes and spotify genre, and playlist control",

@@ -9,3 +9,4 @@ "main": "dist/index.js",

"build": "babel --presets es2015 -d dist/ lib && tsc && node packaging",
"test": "yarn build && mocha -r ts-node/register test/**/test.ts --reporter spec --timeout 20000 --exit"
"test": "yarn build && mocha -r ts-node/register test/**/test.ts --reporter spec --timeout 20000 --exit",
"tracks-test": "yarn build && mocha -r ts-node/register test/tracks/*.ts --timeout 20000 --exit"
},

@@ -49,2 +50,3 @@ "repository": {

"axios": "^0.19.0",
"dotenv": "^8.2.0",
"kind-of": "^6.0.3",

@@ -51,0 +53,0 @@ "moment-timezone": "^0.5.28",

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