itunes-web-api
Advanced tools
Comparing version 2.0.3 to 2.0.4
{ | ||
"name": "itunes-web-api", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "iTunes Web API Scrapper. Get iTunes track/trackvideo/artist/album/movie/app/book/voicebook/podcast infos with their names.", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
@@ -9,20 +9,21 @@ "use strict"; | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&media=music&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&media=music&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Song not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -33,20 +34,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&media=musicVideo&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&media=musicVideo&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Song not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -57,20 +59,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=allArtist&attribute=allArtistTerm&limit=${ | ||
options.limit ?? "1" | ||
}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=allArtist&attribute=allArtistTerm&limit=${ | ||
options.limit ?? "1" | ||
}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Artist not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -81,20 +84,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=album&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=album&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Album not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -105,20 +109,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=software&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=software&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("App not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -129,20 +134,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=movie&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=movie&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Movie not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -153,20 +159,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=ebook&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=ebook&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Book not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -177,20 +184,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=audiobook&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=audiobook&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Voice Book not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -201,20 +209,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=podcast&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=podcast&limit=${options.limit ?? "1"}&lang=${ | ||
options.language ?? "en" | ||
}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Podcast not found."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} | ||
@@ -227,20 +236,21 @@ | ||
options?: options | ||
): Promise<ReturnTypes> { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=${entity}&attribute=${attribute}&limit=${ | ||
options.limit ?? "1" | ||
}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}` | ||
) | ||
.then((x) => x.json()) | ||
.catch((e) => console.log(e)); | ||
): Promise<ReturnTypes | void> { | ||
try { | ||
const res = await fetch( | ||
`https://itunes.apple.com/search?term=${encodeURI( | ||
name | ||
)}&entity=${entity}&attribute=${attribute}&limit=${ | ||
options.limit ?? "1" | ||
}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}` | ||
); | ||
if (!res.resultCount) throw new Error("Resulsts are doesn't exist."); | ||
if (res.errorMessage) | ||
throw new TypeError( | ||
`Unspecified language or country. ${res.errorMessage}\nPlease Check https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2` | ||
); | ||
if (res) return res; | ||
throw new Error("Resulsts are doesn't exist."); | ||
const json: ReturnTypes = await res.json(); | ||
return json; | ||
} catch (e: any) { | ||
const errorTouse: Error = e; | ||
const { message, name, stack } = errorTouse; | ||
console.log({ message, name, stack }); | ||
} | ||
} |
12270
275