npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kitsuneislife/nyaa

v1.1.0

Published

Robust unofficial API/scraper for nyaa.si with retry, cache, and advanced features

Readme

Nyaa.si Scraper/API Wrapper

CI npm version License: MIT TypeScript codecov

Um wrapper/scraper robusto e não-oficial para o site nyaa.si, desenvolvido em TypeScript.

� Documentação

�🚀 Funcionalidades

Core Features

  • ✅ Busca de torrents com filtros avançados
  • ✅ Obtenção de detalhes completos de torrents
  • ✅ Busca por usuário
  • ✅ Listagem de torrents mais recentes
  • ✅ Suporte a paginação
  • ✅ Parsing robusto de HTML com Cheerio
  • ✅ Tratamento de erros completo
  • ✅ TypeScript com tipagem completa
  • ✅ Suporte a categorias do Nyaa
  • ✅ Identificação de uploads confiáveis (trusted)
  • ✅ Links de torrent e magnet

🆕 Advanced Features

  • Retry automático com exponential backoff
  • Cache em memória para reduzir requisições
  • Download de arquivos .torrent
  • Paginação automática (buscar todas as páginas)
  • Validação de parâmetros de entrada
  • Estatísticas de requisições (total, cache hit rate, retries, etc.)
  • Configuração flexível (timeout, retry, cache TTL)

� Getting Started

Para começar rapidamente, consulte o Guia de Início.

�📦 Instalação

npm install

🔧 Uso

Inicialização Básica

import { NyaaScraper, NyaaCategory } from '@kitsuneislife/nyaa';

// Uso básico
const scraper = new NyaaScraper();

// Com configuração avançada
const scraper = new NyaaScraper({
  timeout: 30000,
  retry: {
    maxRetries: 5,
    initialDelay: 1000,
    maxDelay: 10000,
    backoffMultiplier: 2
  },
  enableCache: true,
  cacheTTL: 300000  // 5 minutos
});

Busca Básica

// Buscar torrents
const results = await scraper.search({
  query: 'one piece',
  category: NyaaCategory.ANIME_ENGLISH,
  filter: 'trusted-only',
  page: 1,
});

console.log(results.torrents);
console.log(results.hasNextPage);

Busca Avançada

// Busca com todos os filtros
const results = await scraper.search({
  query: 'anime',
  category: NyaaCategory.ANIME_ENGLISH,
  filter: 'trusted-only', // 'no-filter' | 'no-remakes' | 'trusted-only'
  page: 1,
  sortBy: 'seeders', // 'id' | 'size' | 'seeders' | 'leechers' | 'downloads'
  order: 'desc', // 'asc' | 'desc'
});

🆕 Buscar Todas as Páginas

// Buscar automaticamente múltiplas páginas
const allTorrents = await scraper.searchAllPages({
  query: 'one piece',
  filter: 'trusted-only'
}, 5); // Máximo de 5 páginas

console.log(`Encontrados ${allTorrents.length} torrents`);

🆕 Download de Arquivo .torrent

import fs from 'fs/promises';

// Baixar arquivo .torrent
const torrentData = await scraper.downloadTorrent('1234567');
await fs.writeFile('myfile.torrent', torrentData);
console.log('Arquivo .torrent salvo!');

🆕 Estatísticas de Uso

// Fazer algumas requisições
await scraper.search({ query: 'test' });
await scraper.search({ query: 'test' }); // Virá do cache

// Obter estatísticas
const stats = scraper.getStats();
console.log(`Total de requisições: ${stats.totalRequests}`);
console.log(`Respostas cacheadas: ${stats.cachedResponses}`);
console.log(`Taxa de cache: ${(stats.cachedResponses / (stats.totalRequests + stats.cachedResponses) * 100).toFixed(2)}%`);

// Limpar cache e estatísticas
scraper.clearCache();
scraper.resetStats();

Obter Detalhes de um Torrent

const details = await scraper.getTorrent('1234567');

console.log(details.title);
console.log(details.description);
console.log(details.files); // Lista de arquivos
console.log(details.infoHash);
console.log(details.magnetLink);

Buscar por Usuário

const userTorrents = await scraper.searchByUser('subsplease', {
  page: 1,
  sortBy: 'id',
  order: 'desc',
});

Obter Torrents Mais Recentes

const latest = await scraper.getLatest(1);

📋 API

NyaaScraper

Métodos

  • search(options: SearchOptions): Promise<SearchResult>

    • Busca torrents com filtros opcionais
  • getTorrent(id: string): Promise<NyaaTorrentDetails>

    • Obtém informações detalhadas de um torrent específico
  • getLatest(page?: number): Promise<SearchResult>

    • Obtém os torrents mais recentes
  • searchByUser(username: string, options?: SearchOptions): Promise<SearchResult>

    • Busca torrents de um usuário específico

Tipos

SearchOptions

interface SearchOptions {
  query?: string;
  category?: string;
  filter?: 'no-filter' | 'no-remakes' | 'trusted-only';
  page?: number;
  sortBy?: 'id' | 'size' | 'comments' | 'seeders' | 'leechers' | 'downloads';
  order?: 'asc' | 'desc';
  user?: string;
}

NyaaTorrent

interface NyaaTorrent {
  id: string;
  title: string;
  category: string;
  torrentLink: string;
  magnetLink: string;
  size: string;
  date: string;
  seeders: number;
  leechers: number;
  downloads: number;
  link: string;
  uploader?: string;
  isTrusted?: boolean;
  isRemake?: boolean;
}

NyaaCategory

enum NyaaCategory {
  ALL = '0_0',
  ANIME = '1_0',
  ANIME_AMV = '1_1',
  ANIME_ENGLISH = '1_2',
  ANIME_NON_ENGLISH = '1_3',
  ANIME_RAW = '1_4',
  AUDIO = '2_0',
  AUDIO_LOSSLESS = '2_1',
  AUDIO_LOSSY = '2_2',
  LITERATURE = '3_0',
  // ... e mais
}

🧪 Testes

Executar Testes

# Executar todos os testes
npm test

# Executar testes com coverage
npm run test:coverage

# Executar testes em watch mode
npm run test:watch

# Executar testes de integração (cuidado com rate limiting!)
INTEGRATION_TESTS=true npm test

Cobertura de Testes

Este projeto mantém alta cobertura de testes:

  • ✅ Testes unitários para todas as funções principais
  • ✅ Testes de integração (opcionais)
  • ✅ Testes de parsing HTML
  • ✅ Testes de tratamento de erros

🧪 Executar Exemplos

npm run example

🏗️ Build

npm run build

🤝 Contribuindo

Contribuições são bem-vindas! Por favor, leia CONTRIBUTING.md para detalhes sobre nosso código de conduta e processo de submissão de pull requests.

Desenvolvimento

# Instalar dependências
npm install

# Rodar em modo dev
npm run dev

# Lint
npm run lint

# Format
npm run format

⚠️ Aviso Legal

Este é um projeto não-oficial e não tem afiliação com nyaa.si. Use de forma responsável e respeite os termos de serviço do site.

📄 Licença

MIT

🛠️ Tecnologias

  • TypeScript
  • Axios (HTTP client)
  • Cheerio (HTML parsing)
  • Node.js