@@ -1,5 +1,5 @@
|
||||
# Info about the module
|
||||
__version__ = '0.5.0'
|
||||
__version__ = '0.6.0'
|
||||
__author__ = 'Juanjo Salvador'
|
||||
__email__ = 'juanjosalvador@netc.eu'
|
||||
__url__ = 'http://juanjosalvador.me'
|
||||
|
||||
@@ -3,11 +3,7 @@ from bs4 import BeautifulSoup
|
||||
from NyaaPy.utils import Utils as utils
|
||||
|
||||
class Nyaa:
|
||||
'''
|
||||
Return a list of dicts with the results of the query.
|
||||
'''
|
||||
def search(keyword, **kwargs):
|
||||
|
||||
category = kwargs.get('category', 0)
|
||||
subcategory = kwargs.get('subcategory', 0)
|
||||
filters = kwargs.get('filters', 0)
|
||||
@@ -21,16 +17,21 @@ class Nyaa:
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
rows = soup.select('table tr')
|
||||
|
||||
results = {}
|
||||
return utils.parse_nyaa(rows, limit=None)
|
||||
|
||||
if rows:
|
||||
results = utils.parse_nyaa(rows, limit=None)
|
||||
def get(id):
|
||||
r = requests.get("http://nyaa.si/view/{}".format(id))
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
content = soup.findAll("div", { "class": "panel", "id": None})
|
||||
|
||||
return utils.parse_single(content)
|
||||
|
||||
def get_user(username):
|
||||
r = requests.get("http://nyaa.si/user/{}".format(username))
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
return utils.parse_nyaa(soup.select('table tr'), limit=None)
|
||||
|
||||
return results
|
||||
|
||||
'''
|
||||
Returns an array of dicts with the n last updates of Nyaa.si
|
||||
'''
|
||||
def news(number_of_results):
|
||||
r = requests.get("http://nyaa.si/")
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
@@ -5,7 +5,6 @@ class Pantsu:
|
||||
|
||||
# Torrents - GET
|
||||
def search(keyword, **kwargs):
|
||||
print(utils.query_builder(keyword, kwargs))
|
||||
request = requests.get("{}/search{}".format("https://nyaa.pantsu.cat/api", utils.query_builder(keyword, kwargs)))
|
||||
|
||||
return request.json()
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
Module utils
|
||||
'''
|
||||
|
||||
class Utils():
|
||||
import re
|
||||
|
||||
class Utils:
|
||||
|
||||
def nyaa_categories(b):
|
||||
c = b.replace('/?c=', '')
|
||||
@@ -69,6 +71,8 @@ class Utils():
|
||||
return category_name
|
||||
|
||||
def parse_nyaa(table_rows, limit):
|
||||
if limit == 0:
|
||||
limit = len(table_rows)
|
||||
|
||||
torrents = []
|
||||
|
||||
@@ -88,6 +92,7 @@ class Utils():
|
||||
|
||||
try:
|
||||
torrent = {
|
||||
'id': block[1].replace("/view/", ""),
|
||||
'category': Utils.nyaa_categories(block[0]),
|
||||
'url': "http://nyaa.si{}".format(block[1]),
|
||||
'name': block[2],
|
||||
@@ -106,6 +111,37 @@ class Utils():
|
||||
|
||||
return torrents
|
||||
|
||||
def parse_single(content):
|
||||
torrent = {}
|
||||
data = []
|
||||
torrent_files = []
|
||||
|
||||
for row in content[0].find_all('div', {'class': 'row'}):
|
||||
for div in row.find_all('div', {'class': 'col-md-5'}):
|
||||
data.append(div.text.replace("\n", ""))
|
||||
|
||||
files = content[2].find('div', {'class', 'torrent-file-list'}).find_all('li')
|
||||
|
||||
for file in files:
|
||||
torrent_files.append(file.text)
|
||||
|
||||
|
||||
torrent['title'] = re.sub('\n|\r|\t', '', content[0].find('h3', {"class": "panel-title"}).text.replace("\n", ""))
|
||||
torrent['category'] = data[0]
|
||||
torrent['uploader'] = data[2]
|
||||
torrent['uploader_profile'] = "https://nyaa.si/user/{}".format(data[2])
|
||||
torrent['website'] = re.sub('\t', '', data[4])
|
||||
torrent['size'] = data[6]
|
||||
torrent['date'] = data[1]
|
||||
torrent['seeders'] = data[3]
|
||||
torrent['leechers'] = data[5]
|
||||
torrent['completed'] = data[7]
|
||||
torrent['hash'] = data[8]
|
||||
torrent['description'] = re.sub('\t', '', content[1].find('div', {'id': 'torrent-description'}).text)
|
||||
torrent['files'] = torrent_files
|
||||
|
||||
return torrent
|
||||
|
||||
def query_builder(q, params):
|
||||
available_params = ["category", "page", "limit", "userID", "fromID", "status", "maxage", "toDate", "fromDate",\
|
||||
"dateType", "minSize", "maxSize", "sizeType", "sort", "order", "lang"]
|
||||
|
||||
Reference in New Issue
Block a user