@spacepumpkin/modified-nyaapi
Version:
Non-official api for getting torrent links from Nyaa.si and Nyaa.pantsu.cat
31 lines (25 loc) • 742 B
JavaScript
const request = require('request-promise')
const { extractPageFromHTML } = require('./scrap.js')
const URI = require('./url.json').url
/**
* Request torrent information according to its ID.
*
* @param {number} id The ID of the torrent you want information of.
*
* @returns {promise}
*/
const infoRequest = (id) => {
return new Promise((resolve, reject) => {
if (!id) {
reject(new Error('[Nyaapi]: No ID given on request demand.'))
return
}
request.get(`${URI}view/${id}`)
.then((data) => resolve(extractPageFromHTML(data)))
.then((info) => ({ id, ...info }))
.catch(/* istanbul ignore next */ (err) => reject(err))
})
}
module.exports = {
infoRequest
}