@@ -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)
|
||||
@@ -23,17 +19,19 @@ class Nyaa:
|
||||
|
||||
return utils.parse_nyaa(rows, limit=None)
|
||||
|
||||
|
||||
def get(url):
|
||||
r = requests.get("https://nyaa.si/view/975533")
|
||||
def get(id):
|
||||
r = requests.get("http://nyaa.si/view/{}".format(id))
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
content = soup.findAll("div", { "class": "panel panel-default", "id": None})
|
||||
content = soup.findAll("div", { "class": "panel", "id": None})
|
||||
|
||||
return utils.parse_single(content)
|
||||
|
||||
'''
|
||||
Returns an array of dicts with the n last updates of Nyaa.si
|
||||
'''
|
||||
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)
|
||||
|
||||
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,6 +2,8 @@
|
||||
Module utils
|
||||
'''
|
||||
|
||||
import re
|
||||
|
||||
class Utils:
|
||||
|
||||
def nyaa_categories(b):
|
||||
@@ -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],
|
||||
@@ -121,18 +126,18 @@ class Utils:
|
||||
torrent_files.append(file.text)
|
||||
|
||||
|
||||
torrent['title'] = content[0].find('h3', {"class": "panel-title"}).text.replace("\n", "")
|
||||
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'] = data[4]
|
||||
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'] = content[1].find('div', {'id': 'torrent-description'}).text
|
||||
torrent['description'] = re.sub('\t', '', content[1].find('div', {'id': 'torrent-description'}).text)
|
||||
torrent['files'] = torrent_files
|
||||
|
||||
return torrent
|
||||
|
||||
Reference in New Issue
Block a user