UNPKG

itunes-web-api

Version:

iTunes Web API Scrapper. Get iTunes track/trackvideo/artist/album/movie/app/book/voicebook/podcast infos with their names.

118 lines (117 loc) 5.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAll = exports.getPodcast = exports.getVoiceBook = exports.getBook = exports.getMovie = exports.getApp = exports.getAlbum = exports.getArtist = exports.getSongVideo = exports.getSong = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); async function getSong(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&media=music&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getSong = getSong; async function getSongVideo(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&media=musicVideo&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getSongVideo = getSongVideo; async function getArtist(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=allArtist&attribute=allArtistTerm&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getArtist = getArtist; async function getAlbum(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=album&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getAlbum = getAlbum; async function getApp(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=software&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getApp = getApp; async function getMovie(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=movie&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getMovie = getMovie; async function getBook(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=ebook&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getBook = getBook; async function getVoiceBook(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=audiobook&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getVoiceBook = getVoiceBook; async function getPodcast(name, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=podcast&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getPodcast = getPodcast; async function getAll(name, entity, attribute, options) { try { const res = await (0, node_fetch_1.default)(`https://itunes.apple.com/search?term=${encodeURIComponent(name)}&entity=${entity}&attribute=${attribute}&limit=${options.limit ?? "1"}&lang=${options.language ?? "en"}&country=${options.country ?? "US"}`); return (await res.json()); } catch (e) { const { message, name, stack } = e; console.log({ message, name, stack }); } } exports.getAll = getAll;