cody-music
Advanced tools
Comparing version 2.7.5 to 2.7.6
@@ -120,2 +120,10 @@ import { PlayerName, Track, PlayerDevice, SpotifyAudioFeature, PlaylistItem, CodyResponse, CodyConfig, PlayerContext, SpotifyAuthState } from "./models"; | ||
/** | ||
* Returns tracks by the given spotify track ids | ||
* @param ids | ||
* @param includeFullArtistData (optional - if true it will return full artist info) | ||
* @package includeAudioFeaturesData (optional) | ||
* @param includeGenre (optional) | ||
*/ | ||
export declare function getSpotifyTracks(ids: string[], includeFullArtistData?: boolean, includeAudioFeaturesData?: boolean, includeGenre?: boolean): Promise<Track[]>; | ||
/** | ||
* Returns the track of a given player {spotify|spotify-web|itunes} | ||
@@ -122,0 +130,0 @@ * - Spotify does not return a "genre" |
@@ -294,2 +294,13 @@ "use strict"; | ||
/** | ||
* Returns tracks by the given spotify track ids | ||
* @param ids | ||
* @param includeFullArtistData (optional - if true it will return full artist info) | ||
* @package includeAudioFeaturesData (optional) | ||
* @param includeGenre (optional) | ||
*/ | ||
async function getSpotifyTracks(ids, includeFullArtistData = false, includeAudioFeaturesData = false, includeGenre = false) { | ||
return musicPlayerCtr.getSpotifyTracks(ids, includeFullArtistData, includeAudioFeaturesData, includeGenre); | ||
} | ||
exports.getSpotifyTracks = getSpotifyTracks; | ||
/** | ||
* Returns the track of a given player {spotify|spotify-web|itunes} | ||
@@ -296,0 +307,0 @@ * - Spotify does not return a "genre" |
@@ -43,2 +43,3 @@ import { PlayerDevice, Track, PlayerContext, Artist, PlayerName, CodyResponse } from "./models"; | ||
getWindowsSpotifyTrackInfo(): Promise<any>; | ||
getSpotifyTracks(ids: string[], includeArtistData?: boolean, includeAudioFeaturesData?: boolean, includeGenre?: boolean): Promise<Track[]>; | ||
getSpotifyTrackById(id: string, includeArtistData?: boolean, includeAudioFeaturesData?: boolean, includeGenre?: boolean): Promise<Track>; | ||
@@ -45,0 +46,0 @@ getSpotifyArtistById(id: string): Promise<Artist>; |
@@ -143,2 +143,78 @@ "use strict"; | ||
} | ||
async getSpotifyTracks(ids, includeArtistData = false, includeAudioFeaturesData = false, includeGenre = false) { | ||
const finalIds = []; | ||
ids.forEach(id => { | ||
finalIds.push(musicUtil.createSpotifyIdFromUri(id)); | ||
}); | ||
const tracks = []; | ||
const api = `/v1/tracks`; | ||
const qsOptions = { ids: finalIds.join(",") }; | ||
let response = await musicClient.spotifyApiGet(api, qsOptions); | ||
// 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) { | ||
for (const trackData in response.data.tracks) { | ||
const track = musicUtil.copySpotifyTrackToCodyTrack(trackData); | ||
track.progress_ms = response.data.progress_ms | ||
? response.data.progress_ms | ||
: 0; | ||
// get the arist data | ||
if (includeArtistData && track.artists) { | ||
let artists = []; | ||
for (let i = 0; i < track.artists.length; i++) { | ||
const artist = track.artists[i]; | ||
const artistData = await this.getSpotifyArtistById(artist.id); | ||
artists.push(artistData); | ||
} | ||
if (artists.length > 0) { | ||
track.artists = artists; | ||
} | ||
else { | ||
track.artists = []; | ||
} | ||
} | ||
if (!track.genre && includeGenre) { | ||
// first check if we have an artist in artists | ||
// artists[0].genres[0] | ||
let genre = ""; | ||
if (track.artists && | ||
track.artists.length > 0 && | ||
track.artists[0].genres) { | ||
// make sure we use the highest frequency genre | ||
genre = musicClient.getHighestFrequencySpotifyGenre(track.artists[0].genres); | ||
} | ||
if (!genre) { | ||
// get the genre | ||
genre = await musicController.getGenre(track.artist, track.name); | ||
} | ||
if (genre) { | ||
track.genre = genre; | ||
} | ||
} | ||
tracks.push(track); | ||
} | ||
// get the features | ||
if (includeAudioFeaturesData) { | ||
const spotifyAudioFeatures = await audioStat.getSpotifyAudioFeatures(ids); | ||
if (spotifyAudioFeatures && spotifyAudioFeatures.length > 0) { | ||
// "id": "4JpKVNYnVcJ8tuMKjAj50A", | ||
// "uri": "spotify:track:4JpKVNYnVcJ8tuMKjAj50A", | ||
// track.features = spotifyAudioFeatures[0]; | ||
for (let i = 0; i < spotifyAudioFeatures.length; i++) { | ||
const uri = spotifyAudioFeatures[i].uri; | ||
const foundTrack = tracks.find((t) => t.uri === uri); | ||
if (foundTrack) { | ||
foundTrack.features = spotifyAudioFeatures[i]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return tracks; | ||
} | ||
async getSpotifyTrackById(id, includeArtistData = false, includeAudioFeaturesData = false, includeGenre = false) { | ||
@@ -145,0 +221,0 @@ id = musicUtil.createSpotifyIdFromUri(id); |
@@ -369,2 +369,23 @@ "use strict"; | ||
/** | ||
* Returns tracks by the given spotify track ids | ||
* @param ids | ||
* @param includeFullArtistData (optional - if true it will return full artist info) | ||
* @package includeAudioFeaturesData (optional) | ||
* @param includeGenre (optional) | ||
*/ | ||
export async function getSpotifyTracks( | ||
ids: string[], | ||
includeFullArtistData: boolean = false, | ||
includeAudioFeaturesData: boolean = false, | ||
includeGenre: boolean = false | ||
): Promise<Track[]> { | ||
return musicPlayerCtr.getSpotifyTracks( | ||
ids, | ||
includeFullArtistData, | ||
includeAudioFeaturesData, | ||
includeGenre | ||
); | ||
} | ||
/** | ||
* Returns the track of a given player {spotify|spotify-web|itunes} | ||
@@ -371,0 +392,0 @@ * - Spotify does not return a "genre" |
@@ -165,2 +165,108 @@ import { MusicUtil } from "./util"; | ||
async getSpotifyTracks( | ||
ids: string[], | ||
includeArtistData: boolean = false, | ||
includeAudioFeaturesData: boolean = false, | ||
includeGenre: boolean = false | ||
): Promise<Track[]> { | ||
const finalIds: string[] = []; | ||
ids.forEach(id => { | ||
finalIds.push(musicUtil.createSpotifyIdFromUri(id)); | ||
}); | ||
const tracks: Track[] = []; | ||
const api = `/v1/tracks`; | ||
const qsOptions = { ids: finalIds.join(",") }; | ||
let response = await musicClient.spotifyApiGet(api, qsOptions); | ||
// 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) { | ||
for (const trackData in response.data.tracks) { | ||
const track: Track = musicUtil.copySpotifyTrackToCodyTrack( | ||
trackData | ||
); | ||
track.progress_ms = response.data.progress_ms | ||
? response.data.progress_ms | ||
: 0; | ||
// 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]; | ||
const artistData: Artist = await this.getSpotifyArtistById( | ||
artist.id | ||
); | ||
artists.push(artistData); | ||
} | ||
if (artists.length > 0) { | ||
track.artists = artists; | ||
} else { | ||
track.artists = []; | ||
} | ||
} | ||
if (!track.genre && includeGenre) { | ||
// first check if we have an artist in artists | ||
// artists[0].genres[0] | ||
let genre = ""; | ||
if ( | ||
track.artists && | ||
track.artists.length > 0 && | ||
track.artists[0].genres | ||
) { | ||
// make sure we use the highest frequency genre | ||
genre = musicClient.getHighestFrequencySpotifyGenre( | ||
track.artists[0].genres | ||
); | ||
} | ||
if (!genre) { | ||
// get the genre | ||
genre = await musicController.getGenre( | ||
track.artist, | ||
track.name | ||
); | ||
} | ||
if (genre) { | ||
track.genre = genre; | ||
} | ||
} | ||
tracks.push(track); | ||
} | ||
// get the features | ||
if (includeAudioFeaturesData) { | ||
const spotifyAudioFeatures = await audioStat.getSpotifyAudioFeatures( | ||
ids | ||
); | ||
if (spotifyAudioFeatures && spotifyAudioFeatures.length > 0) { | ||
// "id": "4JpKVNYnVcJ8tuMKjAj50A", | ||
// "uri": "spotify:track:4JpKVNYnVcJ8tuMKjAj50A", | ||
// track.features = spotifyAudioFeatures[0]; | ||
for (let i = 0; i < spotifyAudioFeatures.length; i++) { | ||
const uri: string = spotifyAudioFeatures[i].uri; | ||
const foundTrack = tracks.find( | ||
(t: Track) => t.uri === uri | ||
); | ||
if (foundTrack) { | ||
foundTrack.features = spotifyAudioFeatures[i]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return tracks; | ||
} | ||
async getSpotifyTrackById( | ||
@@ -167,0 +273,0 @@ id: string, |
{ | ||
"name": "cody-music", | ||
"version": "2.7.5", | ||
"version": "2.7.6", | ||
"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", |
@@ -291,2 +291,16 @@ # cody-music | ||
/** | ||
* Returns tracks by the given spotify track ids | ||
* @param ids | ||
* @param includeFullArtistData (optional - if true it will return full artist info) | ||
* @package includeAudioFeaturesData (optional) | ||
* @param includeGenre (optional) | ||
*/ | ||
export async function getSpotifyTracks( | ||
ids: string[], | ||
includeFullArtistData: boolean = false, | ||
includeAudioFeaturesData: boolean = false, | ||
includeGenre: boolean = false | ||
): Promise<Track[]> | ||
/** | ||
* Returns the track of a given player {spotify|spotify-web|itunes} | ||
@@ -293,0 +307,0 @@ * - Spotify does not return a "genre" |
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
545440
13260
784