@ejnshtein/nyaasi
Advanced tools
Comparing version 1.0.1 to 1.0.2
23
Nyaa.js
import deepmerge from 'deepmerge' | ||
import { Agent } from './Agent.js' | ||
import { NyaaRss } from './NyaaRss.js' | ||
import { parseComments, parseSearch } from './Scraper.js' | ||
import { parseComments, parseSearch, parseTorrent } from './Scraper.js' | ||
@@ -65,7 +65,7 @@ const DefaultOptions = { | ||
const result = await this.agent.callApi(`info/${id}`) | ||
if (options.comments) { | ||
if (options.withComments) { | ||
const comments = await this.agent.call(`view/${id}`) | ||
.then(parseComments) | ||
result.comments = comments | ||
result.data.comments = comments | ||
} | ||
@@ -77,10 +77,23 @@ return result | ||
const result = await Agent.callApi(`info/${id}`, params) | ||
if (options.comments) { | ||
if (options.withComments) { | ||
const comments = await Agent.call(`view/${id}`, params) | ||
.then(parseComments) | ||
result.comments = comments | ||
result.data.comments = comments | ||
} | ||
return result.data | ||
} | ||
async getTorrentAnonymous (id, options = { withComments: false }, params = {}) { | ||
return Nyaa.getTorrentAnonymous(id, options, params) | ||
} | ||
static async getTorrentAnonymous (id, options = { withComments: false }, params = {}) { | ||
const result = await Agent.call(`view/${id}`, params) | ||
const parsed = parseTorrent(id, params.baseUrl, result.data) | ||
if (options.withComments) { | ||
parsed.comments = parseComments(result.data) | ||
} | ||
return parsed | ||
} | ||
} | ||
@@ -87,0 +100,0 @@ |
{ | ||
"name": "@ejnshtein/nyaasi", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Nyaa.si api wrapper for Node 13.5 and newer", | ||
@@ -5,0 +5,0 @@ "main": "Nyaa.js", |
@@ -110,2 +110,51 @@ import cheerio from 'cheerio' | ||
export const parseTorrent = (id, host = 'https://nyaa.si', html) => { | ||
const select = cheerio.load(html) | ||
select('.servers-cost-money1').remove() | ||
const entryMatch = select('body > div.container > div:first-of-type') | ||
.attr('class') | ||
return { | ||
id: typeof id === 'string' ? Number.parseInt(id) : id, | ||
title: select('body > div.container > div.panel:first-of-type > div.panel-heading > h3').text().trim(), | ||
file_size: select('body > div.container > div.panel > div.panel-body > div:nth-child(4) > div:nth-child(2)').html(), | ||
file_size_bytes: bytes.parse(select('body > div.container > div.panel > div.panel-body > div:nth-child(4) > div:nth-child(2)').html()), | ||
category: select('body > div.container > div.panel > div.panel-body > div:nth-child(1) > div:nth-child(2)') | ||
.children('a') | ||
.map((i, el) => ( | ||
{ | ||
title: el.children[0].data, | ||
code: el.attribs['href'].match(/c=(\S+)/i)[1] | ||
} | ||
) | ||
).get(), | ||
entry: getEntry( | ||
entryMatch.match(/panel-(\S+)$/i)[1] | ||
), | ||
links: { | ||
torrent: host + select('body > div.container > div.panel > div:last-of-type > a:first-of-type').attr('href'), | ||
magnet: select('body > div.container > div.panel > div:last-of-type > a:last-of-type').attr('href') | ||
}, | ||
timestamp: Number.parseInt(select('body > div.container > div.panel > div.panel-body > div:nth-child(1) > div:nth-child(4)').attr('data-timestamp')) * 1000, | ||
submitter: select('body > div.container > div.panel > div.panel-body > div:nth-child(2) > div:nth-child(2) > a').html() | ||
? { | ||
name: select('body > div.container > div.panel > div.panel-body > div:nth-child(2) > div:nth-child(2) > a').html(), | ||
link: host + select('body > div.container > div.panel > div.panel-body > div:nth-child(2) > div:nth-child(2) > a').attr('href') | ||
} : { | ||
name: 'Anonymous', | ||
link: null | ||
}, | ||
description: select('#torrent-description').html(), | ||
info: select('body > div.container > div.panel > div.panel-body > div:nth-child(3) > div:nth-child(2) a').attr('href') || 'No information', | ||
info_hash: select('body > div.container > div.panel > div.panel-body > div:nth-child(5) > div.col-md-5 > kbd').html(), | ||
stats: { | ||
seeders: Number.parseInt(select('body > div.container > div.panel > div.panel-body > div:nth-child(2) > div:nth-child(4) > span').html()), | ||
leechers: Number.parseInt(select('body > div.container > div.panel > div.panel-body > div:nth-child(3) > div:nth-child(4) > span').html()), | ||
downloaded: Number.parseInt(select('body > div.container > div.panel > div.panel-body > div:nth-child(4) > div:nth-child(4)').html()) | ||
} | ||
} | ||
} | ||
function getEntry (entry) { | ||
@@ -112,0 +161,0 @@ switch (entry) { |
@@ -21,2 +21,5 @@ import * as nyaa from './nyaa.d' | ||
getTorrent (id: number, options?: GetTorrentOptions, params?: RequestOptions): Promise<nyaa.ApiTorrent> | ||
getTorrentAnonymous (id: number, options?: GetTorrentOptions, params?: RequestOptions): Promise<nyaa.ViewTorrent> | ||
} | ||
@@ -41,2 +44,4 @@ | ||
getTorrentAnonymous (id: number, options?: GetTorrentOptions, params?: RequestOptions): Promise<nyaa.ViewTorrent> | ||
} | ||
@@ -43,0 +48,0 @@ |
@@ -31,2 +31,32 @@ export interface ApiTorrent { | ||
export interface ViewTorrent { | ||
id: number | ||
title: string | ||
file_size: string | ||
file_size_bytes: string | ||
category: { | ||
title: string | ||
code: string | ||
}[] | ||
entry: '[Remake]' | '[Trusted]' | '' | ||
links: { | ||
torrent: string | ||
magnet: string | ||
} | ||
timestamp: number | ||
submitter: { | ||
name: string | ||
link: string | null | ||
} | ||
description: string | ||
info: string | ||
info_hash: string | ||
stats: { | ||
seeders: number | ||
leechers: number | ||
downloaded: number | ||
} | ||
comments?: TorrentComment[] | ||
} | ||
export interface UserProfile { | ||
@@ -33,0 +63,0 @@ id: number |
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
22923
680
4