JuanjoSalvador / NyaaPy

Unofficial Python wrapper for Nyaa anime torrent sites
MIT License
47 stars 23 forks source link

Confusion #60

Closed topspinz closed 1 year ago

topspinz commented 2 years ago

The search function seems to return a torrent object list?

JuanjoSalvador commented 2 years ago

Yes, it is. There is a TO-DO about this, to write docs about Torrent object. At this moment it looks like this.

{
  'id': '1280334',
  'category': 'Anime - English-translated', 
  'url': 'https://nyaa.si/view/1280334', 
  'name': '[neoHEVC] Altair: A Record of Battles [BD 1080p x265 HEVC AAC] Shoukoku no Altair', 
  'download_url': 'https://nyaa.si/download/1280334.torrent', 
  'magnet': 'magnet:?xt=urn:btih:4134e838b795614b14742f1c2beec2a735d86ae8&dn=%5BneoHEVC%5D%20Altair%3A%20A%20Record%20of%20Battles%20%5BBD%201080p%20x265%20HEVC%20AAC%5D%20Shoukoku%20no%20Altair&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce', 
  'size': '7.5 GiB', 
  'date': '2020-09-14 10:32', 
  'seeders': '7', 
  'leechers': '2', 
  'completed_downloads': '739', 
  'type': 'remake'
}
topspinz commented 2 years ago

Sorry, I am a novice. When I write Nyaa.search(keyword="Shoukoku no Altair", category=1) how do I output that dictionary? I just get -

[NyaaPy.torrent.Torrent object at 0x000002872E556820>, <NyaaPy.torrent.Torrent object at 0x000002872E556730]

JuanjoSalvador commented 2 years ago

In order to print the dictionary, I'm using the following code

from NyaaPy.nyaa import Nyaa
nyaa = Nyaa()

results = nyaa.search(keyword="Shoukoku no Altair", category=1)[0]
print(results.__dict__)

So you can access any key from the Torrent object just by

Torrent.name

for example. If for any reason you need to return this as dictionary, we can consider adding a to_dict() function for the next release (0.7.0)

topspinz commented 2 years ago

ok, awesome I see now. Thanks.