feat(nyaasi): add static classes instead of object-based ones

This commit is contained in:
Juanjo Salvador
2024-07-18 09:45:02 +00:00
parent bbd129cc2b
commit 2c3d3ea58e
13 changed files with 346 additions and 527 deletions

22
nyaapy/magnet.py Normal file
View File

@@ -0,0 +1,22 @@
import urllib
from urllib.parse import urlencode
def magnet_builder(info_hash, title):
"""
Generates a magnet link using the info_hash and title of a given file.
"""
known_trackers = [
"http://nyaa.tracker.wf:7777/announce",
"udp://open.stealth.si:80/announce",
"udp://tracker.opentrackr.org:1337/announce",
"udp://exodus.desync.com:6969/announce",
"udp://tracker.torrent.eu.org:451/announce",
]
magnet_link = f"magnet:?xt=urn:btih:{info_hash}&" + urlencode(
{"dn": title}, quote_via=urllib.parse.quote
)
for tracker in known_trackers:
magnet_link += f"&{urlencode({'tr': tracker})}"
return magnet_link