cody-music
Advanced tools
Comparing version 2.6.66 to 2.6.67
@@ -18,2 +18,3 @@ import { CodyResponse } from "./models"; | ||
getGenreFromItunes(artist: string, songName?: string): Promise<string>; | ||
findNameFromItunesResponse(resp: any): any; | ||
/** | ||
@@ -20,0 +21,0 @@ * Refresh the spotify access token |
@@ -76,2 +76,3 @@ "use strict"; | ||
async getGenreFromItunes(artist, songName = "") { | ||
let genre = ""; | ||
// try from itunes | ||
@@ -81,25 +82,36 @@ // search?term=${terms}&limit=3 | ||
terms = terms.trim(); | ||
const api = `search?term=${encodeURIComponent(terms)}`; | ||
return itunesSearchClient | ||
.get(api) | ||
.then(resp => { | ||
let secondaryGenreName = ""; | ||
if (resp.data && resp.data.resultCount > 0) { | ||
for (let i = 0; i < resp.data.resultCount; i++) { | ||
let result = resp.data.results[i]; | ||
if (result.kind === "song" && result.primaryGenreName) { | ||
return result.primaryGenreName; | ||
} | ||
else if (result.primaryGenreName) { | ||
secondaryGenreName = result.primaryGenreName; | ||
} | ||
} | ||
} | ||
return secondaryGenreName; | ||
}) | ||
.catch(err => { | ||
console.error("Unable to retrieve genre from itunes search: ", err.message); | ||
let api = `search?term=${encodeURIComponent(terms)}`; | ||
let resp = await itunesSearchClient.get(api).catch(err => { | ||
return ""; | ||
}); | ||
if (resp) { | ||
genre = await this.findNameFromItunesResponse(resp); | ||
} | ||
else { | ||
// try without the artist, just the song name | ||
api = `search?term=${encodeURIComponent(songName)}`; | ||
resp = await itunesSearchClient.get(api).catch(err => { | ||
return ""; | ||
}); | ||
if (resp) { | ||
genre = await this.findNameFromItunesResponse(resp); | ||
} | ||
} | ||
return genre; | ||
} | ||
findNameFromItunesResponse(resp) { | ||
let genre = ""; | ||
if (resp.data && resp.data.resultCount > 0) { | ||
for (let i = 0; i < resp.data.resultCount; i++) { | ||
let result = resp.data.results[i]; | ||
if (result.kind === "song" && result.primaryGenreName) { | ||
return result.primaryGenreName; | ||
} | ||
else if (result.primaryGenreName) { | ||
genre = result.primaryGenreName; | ||
} | ||
} | ||
} | ||
return genre; | ||
} | ||
/** | ||
@@ -106,0 +118,0 @@ * Refresh the spotify access token |
@@ -84,2 +84,4 @@ import axios, { AxiosInstance } from "axios"; | ||
): Promise<string> { | ||
let genre = ""; | ||
// try from itunes | ||
@@ -89,28 +91,36 @@ // search?term=${terms}&limit=3 | ||
terms = terms.trim(); | ||
const api = `search?term=${encodeURIComponent(terms)}`; | ||
return itunesSearchClient | ||
.get(api) | ||
.then(resp => { | ||
let secondaryGenreName = ""; | ||
if (resp.data && resp.data.resultCount > 0) { | ||
for (let i = 0; i < resp.data.resultCount; i++) { | ||
let result = resp.data.results[i]; | ||
if (result.kind === "song" && result.primaryGenreName) { | ||
return result.primaryGenreName; | ||
} else if (result.primaryGenreName) { | ||
secondaryGenreName = result.primaryGenreName; | ||
} | ||
} | ||
} | ||
return secondaryGenreName; | ||
}) | ||
.catch(err => { | ||
console.error( | ||
"Unable to retrieve genre from itunes search: ", | ||
err.message | ||
); | ||
let api = `search?term=${encodeURIComponent(terms)}`; | ||
let resp = await itunesSearchClient.get(api).catch(err => { | ||
return ""; | ||
}); | ||
if (resp) { | ||
genre = await this.findNameFromItunesResponse(resp); | ||
} else { | ||
// try without the artist, just the song name | ||
api = `search?term=${encodeURIComponent(songName)}`; | ||
resp = await itunesSearchClient.get(api).catch(err => { | ||
return ""; | ||
}); | ||
if (resp) { | ||
genre = await this.findNameFromItunesResponse(resp); | ||
} | ||
} | ||
return genre; | ||
} | ||
findNameFromItunesResponse(resp: any) { | ||
let genre = ""; | ||
if (resp.data && resp.data.resultCount > 0) { | ||
for (let i = 0; i < resp.data.resultCount; i++) { | ||
let result = resp.data.results[i]; | ||
if (result.kind === "song" && result.primaryGenreName) { | ||
return result.primaryGenreName; | ||
} else if (result.primaryGenreName) { | ||
genre = result.primaryGenreName; | ||
} | ||
} | ||
} | ||
return genre; | ||
} | ||
/** | ||
@@ -117,0 +127,0 @@ * Refresh the spotify access token |
{ | ||
"name": "cody-music", | ||
"version": "2.6.66", | ||
"version": "2.6.67", | ||
"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", |
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
505946
12363