diff --git a/NyaaPy/__init__.py b/NyaaPy/__init__.py index 03f690a..5ca75df 100644 --- a/NyaaPy/__init__.py +++ b/NyaaPy/__init__.py @@ -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' diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index d9b7591..ec8cbf9 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -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') diff --git a/NyaaPy/pantsu.py b/NyaaPy/pantsu.py index e508077..b25a99e 100644 --- a/NyaaPy/pantsu.py +++ b/NyaaPy/pantsu.py @@ -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() diff --git a/NyaaPy/utils.py b/NyaaPy/utils.py index 2a18cf8..91b9bcb 100644 --- a/NyaaPy/utils.py +++ b/NyaaPy/utils.py @@ -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"] diff --git a/setup.py b/setup.py index 7475a97..ff870e4 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='nyaapy', - version='0.5.0', + version='0.6.0', url='https://github.com/juanjosalvador/nyaapy', download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz', license='MIT',