diff --git a/NyaaPy/__init__.py b/NyaaPy/__init__.py index a6c4040..03f690a 100644 --- a/NyaaPy/__init__.py +++ b/NyaaPy/__init__.py @@ -1,9 +1,10 @@ # Info about the module -__version__ = '0.4.1' +__version__ = '0.5.0' __author__ = 'Juanjo Salvador' __email__ = 'juanjosalvador@netc.eu' __url__ = 'http://juanjosalvador.me' __copyright__ = '2017 Juanjo Salvador' __license__ = 'MIT license' -from NyaaPy.nyaa import Nyaa \ No newline at end of file +from NyaaPy.nyaa import Nyaa +from NyaaPy.pantsu import Pantsu \ No newline at end of file diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index daebb61..d9b7591 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -2,7 +2,7 @@ import requests from bs4 import BeautifulSoup from NyaaPy.utils import Utils as utils -class Nyaa(): +class Nyaa: ''' Return a list of dicts with the results of the query. ''' @@ -14,9 +14,9 @@ class Nyaa(): page = kwargs.get('page', 0) if page > 0: - r = requests.get("http://nyaa.si/?f={}&c={}_{}&q={}&p={}".format(filters, category, subcategory, keyword, page)) + r = requests.get("{}/?f={}&c={}_{}&q={}&p={}".format("http://nyaa.si", filters, category, subcategory, keyword, page)) else: - r = requests.get("http://nyaa.si/?f={}&c={}_{}&q={}".format(filters, category, subcategory, keyword)) + r = requests.get("{}/?f={}&c={}_{}&q={}".format("http://nyaa.si", filters, category, subcategory, keyword)) soup = BeautifulSoup(r.text, 'html.parser') rows = soup.select('table tr') diff --git a/NyaaPy/pantsu.py b/NyaaPy/pantsu.py new file mode 100644 index 0000000..e508077 --- /dev/null +++ b/NyaaPy/pantsu.py @@ -0,0 +1,30 @@ +import requests +from NyaaPy.utils import Utils as utils + +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() + + def view(item_id): + request = requests.get("/view/{}".format("https://nyaa.pantsu.cat/api", item_id)) + + return request.json() + + # Torrents - POST + + # Users + + def login(username, password): + login = requests.post("{}/login/".format(BASE_URL), data={'username': username, 'password': password}) + + return login.json() + + def profile(user_id): + profile = requests.post("{}/profile/".format(BASE_URL), data={'id': user_id}) + + return profile.json() \ No newline at end of file diff --git a/NyaaPy/utils.py b/NyaaPy/utils.py index 36d5fee..2a18cf8 100644 --- a/NyaaPy/utils.py +++ b/NyaaPy/utils.py @@ -104,4 +104,26 @@ class Utils(): except IndexError as ie: pass - return torrents \ No newline at end of file + return torrents + + def query_builder(q, params): + available_params = ["category", "page", "limit", "userID", "fromID", "status", "maxage", "toDate", "fromDate",\ + "dateType", "minSize", "maxSize", "sizeType", "sort", "order", "lang"] + query = "?q={}".format(q.replace(" ", "+")) + + for param, value in params.items(): + if param in available_params: + if param != "category" and param != "status" and param != "lang": + query += "&{}={}".format(param, value) + else: + if param == "category": + query += "&c={}_{}".format(value[0], value[1]) + + if param == "status": + query += "&s={}".format(value) + + if param == "lang": + for lang in value: + query += "&lang={}".format(lang) + + return query \ No newline at end of file diff --git a/README.md b/README.md index f826e5f..b21e568 100644 --- a/README.md +++ b/README.md @@ -4,27 +4,23 @@ # NyaaPy -Unofficial Python module to search into Nyaa.si +Unofficial Python module for Nyaa.si (WebScraping) and Nyaa.pantsu.cat (API wrapper) Supports Python 3+ +Full docs available on [repo Wiki](https://github.com/JuanjoSalvador/NyaaPy/wiki) + * [Installation](#installation) * [Example](#example) -* [Methods](#methods) - * [search()](#search) - * [news()](#news) -* [Categories and subcategories](#categories-and-subcategories) -* [Contributions and development](#contributons-and-development) * [License](#license) - ## Installation Install it using pip. pip install nyaapy -## Example +## Nyaa.si Example ```python from NyaaPy import Nyaa @@ -156,8 +152,6 @@ At this moment there isn't an official Nyaa.si API, so we only can make requests 3. If you are ussing a clonned repo, please create a new branch named `patch--`. Example: `patch-juanjosalvador-0.2` -4. Always use the code into `src` folder, never the package. - ## License MIT license. diff --git a/setup.py b/setup.py index 6028d87..7475a97 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='nyaapy', - version='0.4.3', + version='0.5.0', url='https://github.com/juanjosalvador/nyaapy', download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz', license='MIT', diff --git a/tests/test.py b/tests/test.py index efca379..c37dbb9 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,12 +1,3 @@ -from NyaaPy import Nyaa +from NyaaPy import Pantsu -# Nyaa.si results -nyaa_query = Nyaa.search() - -nyaa_news = Nyaa.news(5) - -if len(nyaa_query) > 0: - for result in nyaa_query: - print(result['name']) -else: - print('Nothing here!') \ No newline at end of file +print(Pantsu.search('koe no katachi', lang=["es", "ja"], category=[1, 3])) \ No newline at end of file