Issue #30 Improve the torrent objects
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
import requests
|
||||
from NyaaPy import utils
|
||||
from NyaaPy import torrent
|
||||
|
||||
|
||||
class Nyaa:
|
||||
|
||||
def __init__(self):
|
||||
self.SITE = utils.TorrentSite.NYAASI
|
||||
self.URI = "https://nyaa.si"
|
||||
self.URL = "https://nyaa.si"
|
||||
|
||||
def last_uploads(self, number_of_results):
|
||||
r = requests.get(self.SITE.value)
|
||||
r = requests.get(self.URL)
|
||||
|
||||
# If anything up with nyaa servers let the user know.
|
||||
r.raise_for_status()
|
||||
|
||||
return utils.parse_nyaa(
|
||||
json_data = utils.parse_nyaa(
|
||||
request_text=r.text,
|
||||
limit=number_of_results + 1,
|
||||
site=self.SITE
|
||||
)
|
||||
return torrent.json_to_class(json_data)
|
||||
|
||||
def search(self, keyword, **kwargs):
|
||||
url = self.SITE.value
|
||||
url = self.URL
|
||||
|
||||
user = kwargs.get('user', None)
|
||||
category = kwargs.get('category', 0)
|
||||
@@ -30,7 +32,7 @@ class Nyaa:
|
||||
page = kwargs.get('page', 0)
|
||||
|
||||
if user:
|
||||
user_uri = "user/{}".format(user)
|
||||
user_uri = f"user/{user}"
|
||||
else:
|
||||
user_uri = ""
|
||||
|
||||
@@ -44,24 +46,29 @@ class Nyaa:
|
||||
|
||||
r.raise_for_status()
|
||||
|
||||
return utils.parse_nyaa(
|
||||
json_data = utils.parse_nyaa(
|
||||
request_text=r.text,
|
||||
limit=None,
|
||||
site=self.SITE
|
||||
)
|
||||
|
||||
def get(self, id):
|
||||
r = requests.get("{}/view/{}".format(self.SITE.value, id))
|
||||
return torrent.json_to_class(json_data)
|
||||
|
||||
def get(self, view_id):
|
||||
r = requests.get(f'{self.URL}/view/{view_id}')
|
||||
r.raise_for_status()
|
||||
|
||||
return utils.parse_single(request_text=r.text, site=self.SITE)
|
||||
json_data = utils.parse_single(request_text=r.text, site=self.SITE)
|
||||
|
||||
return torrent.json_to_class(json_data)
|
||||
|
||||
def get_user(self, username):
|
||||
r = requests.get("{}/user/{}".format(self.SITE.value, username))
|
||||
r = requests.get(f'{self.URL}/user/{username}')
|
||||
r.raise_for_status()
|
||||
|
||||
return utils.parse_nyaa(
|
||||
json_data = utils.parse_nyaa(
|
||||
request_text=r.text,
|
||||
limit=None,
|
||||
site=self.SITE
|
||||
)
|
||||
return torrent.json_to_class(json_data)
|
||||
|
||||
Reference in New Issue
Block a user