Turn nyaa.si torrent pages into neat Python objects
Project description
Turn nyaa.si torrent pages into neat Python objects
Table Of Contents
About
I needed to parse the details out of nyaa torrent pages for one of my personal projects so I initially wrote a little module to do just that but then decided it'll probably be useful as an independent library so here we are.
Some features:
- Supports both sync and async.
- Supports caching.
- Provides easy access to every field except comments (comments are useless).
- Parses both the nyaa page itself and it's accompanying
.torrent
file.
Installation
pynyaa
is available on PyPI, so you can simply use pip to install it.
pip install pynyaa
Usage
pynyaa
offers two main classes:
-
Nyaa()
- Synchronous classfrom pynyaa import Nyaa nyaa = Nyaa().get("https://nyaa.si/view/1693817") # Full URL # You can also pass any httpx.Client() keyword argument to Nyaa() headers = {"user-agent": "my-app/0.0.1"} client = Nyaa(headers=headers) nyaa = client.get(1693817) # Only the ID also works print(nyaa.title) """ [LYS1TH3A] Fate/stay night Heaven's Feel I. Presage Flower (2017) (BD 1080p HEVC x265 10-bit Opus) [Dual-Audio] """ print(nyaa.submitter) """ Submitter(name='pog42', url=Url('https://nyaa.si/user/pog42'), is_trusted=False, is_banned=False) """ print(nyaa.torrent.files) """ [File('Fate.stay.night.Heavens.Feel.I.Presage.Flower.2017.1080p.BluRay.Opus5.1.H.265-LYS1TH3A.mkv', size=12263052206)] """ print(nyaa.torrent.infohash) """ 6fdc0395a7fdde6ce3fb7f144b31f3cabdcbf537 """
-
AsyncNyaa()
- Asynchronous classimport asyncio from pynyaa import AsyncNyaa nyaa = asyncio.run(AsyncNyaa().get("https://nyaa.si/view/1794334")) # Full URL # You can also pass any httpx.AsyncClient() keyword argument to AsyncNyaa() headers = {"user-agent": "my-app/0.0.1"} client = AsyncNyaa(headers=headers) nyaa = asyncio.run(client.get(1794334)) # Only the ID also works print(nyaa.title) """ [MTBB] The Dangers in My Heart S2 - 12 (WEB 1080p) | Boku no Kokoro no Yabai Yatsu S2 """ print(nyaa.submitter) """ Submitter(name='motbob', url=Url('https://nyaa.si/user/motbob'), is_trusted=True, is_banned=False) """ print(nyaa.torrent.files) """ [File('[MTBB] The Dangers in My Heart S2 - 12 (WEB 1080p) [DE972341].mkv', size=758024360)] """ print(nyaa.torrent.infohash) """ fccba66ad15e9d3918fb965654b93679a6c59936 """
Docs
Checkout the complete API Reference here
License
Distributed under the Unlicense License. See UNLICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.