From 0d6003f7a8cf20a80d515458ca41716a129a73a1 Mon Sep 17 00:00:00 2001 From: John Victor Date: Wed, 13 May 2020 20:42:28 -0300 Subject: [PATCH 1/2] Add argument to specify number of entries for selection (Closes #11) --- CHANGELOG.md | 6 +++ nyaacli/cli/__init__.py | 9 ++-- nyaacli/nyaa_search.py | 6 +-- poetry.lock | 115 +++++++++++++++++++++++++++------------- pyproject.toml | 7 +-- 5 files changed, 96 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e7f38..d1fabf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ --- +## 0.1.8 + +- Add argument `-n` (`--number`, default = 10) to specify the number of entries to select from + +--- + ## 0.1.7 - Fix issue when searching for specific episode numbers [`(f1ac2e9)`](https://github.com/johnvictorfs/nyaa-cli/commit/f1ac2e983fdb72c7a608d6c20d149ac1cb94dfa0) diff --git a/nyaacli/cli/__init__.py b/nyaacli/cli/__init__.py index baf61de..7e8feb3 100644 --- a/nyaacli/cli/__init__.py +++ b/nyaacli/cli/__init__.py @@ -16,11 +16,12 @@ @click.command() @click.argument('anime') @click.argument('episode', type=int, default=None, required=False) -@click.option('--debug/--no-debug', default=False, help=green('Debug Mode')) @click.option('--output', '-o', default='~/Videos/Anime', help=green('Output Folder'), type=click.Path(), show_default=True) -def main(anime: str, episode: int, output: str, debug: bool = False): +@click.option('--debug/--no-debug', default=False, help=green('Debug Mode')) +@click.option('--number', '-n', default=10, help=green('Number of entries'), show_default=True) +def main(anime: str, episode: int, output: str, debug: bool = False, number: int = 10): """ - Search for an Anime on https://nyaa.si and downloads it + Search for Anime on https://nyaa.si and downloads it \b Usage: @@ -45,7 +46,7 @@ def main(anime: str, episode: int, output: str, debug: bool = False): logger.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG) - torrent_search = search_torrent(anime, episode) + torrent_search = search_torrent(anime, episode, number=number) if torrent_search: torrent_path, result_name = torrent_search diff --git a/nyaacli/nyaa_search.py b/nyaacli/nyaa_search.py index 7369232..0871498 100644 --- a/nyaacli/nyaa_search.py +++ b/nyaacli/nyaa_search.py @@ -58,7 +58,7 @@ def __str__(self): return f'Entry(title={repr(self.title)}, episode={repr(self.episode)})' -def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False) -> Optional[Tuple[str, str]]: +def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False, number: int = 10) -> Optional[Tuple[str, str]]: """ Results a tuple with (Path to .torrent file, Result name of video file) Nyaa.si rss search flags @@ -124,7 +124,7 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False print(red(f'No results found for search: \'{search_query.replace("%20", " ")}\'')) return None - for entry in entries[:5]: + for entry in entries[:number]: entry_title = entry.title entry.full_title = entry.title @@ -162,7 +162,7 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False entry.display_title = entry_title - choices = [{'name': entry.display_title, 'value': index} for index, entry in enumerate(entries[:5])] + choices = [{'name': entry.display_title, 'value': index} for index, entry in enumerate(entries[:number])] questions = [ { diff --git a/poetry.lock b/poetry.lock index e3c9823..7af4f39 100644 --- a/poetry.lock +++ b/poetry.lock @@ -4,7 +4,7 @@ description = "A tool that automatically formats Python code to conform to the P name = "autopep8" optional = false python-versions = "*" -version = "1.5" +version = "1.5.2" [package.dependencies] pycodestyle = ">=2.5.0" @@ -34,12 +34,13 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "0.4.3" [[package]] -category = "dev" -description = "Discover and load entry points from installed packages." -name = "entrypoints" +category = "main" +description = "A backport of the dataclasses module for Python 3.6" +marker = "python_version >= \"3.6\" and python_version < \"3.7\"" +name = "dataclasses" optional = false -python-versions = ">=2.7" -version = "0.3" +python-versions = ">=3.6, <3.7" +version = "0.7" [[package]] category = "main" @@ -51,17 +52,20 @@ version = "5.2.1" [[package]] category = "dev" -description = "the modular source code checker: pep8, pyflakes and co" +description = "the modular source code checker: pep8 pyflakes and co" name = "flake8" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "3.7.9" +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +version = "3.8.1" [package.dependencies] -entrypoints = ">=0.3.0,<0.4.0" mccabe = ">=0.6.0,<0.7.0" -pycodestyle = ">=2.5.0,<2.6.0" -pyflakes = ">=2.1.0,<2.2.0" +pycodestyle = ">=2.6.0a1,<2.7.0" +pyflakes = ">=2.2.0,<2.3.0" + +[package.dependencies.importlib-metadata] +python = "<3.8" +version = "*" [[package]] category = "main" @@ -80,6 +84,22 @@ rebulk = "<2" dev = ["zest.releaser", "pylint", "tox", "sphinx", "sphinx-autobuild"] test = ["pytest (>=3.3)", "pytest-benchmark", "pyyaml"] +[[package]] +category = "dev" +description = "Read metadata from Python packages" +marker = "python_version < \"3.8\"" +name = "importlib-metadata" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +version = "1.6.0" + +[package.dependencies] +zipp = ">=0.5" + +[package.extras] +docs = ["sphinx", "rst.linker"] +testing = ["packaging", "importlib-resources"] + [[package]] category = "dev" description = "McCabe checker, plugin for flake8" @@ -129,7 +149,7 @@ description = "Python style guide checker" name = "pycodestyle" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "2.5.0" +version = "2.6.0" [[package]] category = "dev" @@ -137,7 +157,7 @@ description = "passive checker of Python programs" name = "pyflakes" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "2.1.1" +version = "2.2.0" [[package]] category = "main" @@ -156,13 +176,13 @@ description = "Python library to build pretty command line user prompts ⭐️" name = "questionary" optional = false python-versions = "*" -version = "1.5.1" +version = "1.5.2" [package.dependencies] prompt-toolkit = ">=2.0,<4.0" [package.extras] -test = ["pytest (>=4.0,<5.0)", "pytest-pycodestyle (>=1.3,<2.0)", "pytest-cov (>=2.6,<3.0)", "coveralls (>=1.3,<2.0)"] +test = ["pytest", "pytest-pycodestyle", "pytest-cov", "coveralls"] [[package]] category = "main" @@ -202,7 +222,7 @@ description = "Backported and Experimental Type Hints for Python 3.5+" name = "typing-extensions" optional = false python-versions = "*" -version = "3.7.4.1" +version = "3.7.4.2" [[package]] category = "main" @@ -210,15 +230,28 @@ description = "Measures number of Terminal column cells of wide-character codes" name = "wcwidth" optional = false python-versions = "*" -version = "0.1.8" +version = "0.1.9" + +[[package]] +category = "dev" +description = "Backport of pathlib-compatible object wrapper for zip files" +marker = "python_version < \"3.8\"" +name = "zipp" +optional = false +python-versions = ">=3.6" +version = "3.1.0" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] +testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "430826df2dc11749dc299658decd4389c359a1fe0752a13249bd4ab1bd92e159" -python-versions = "^3.7" +content-hash = "52a7001c66bd0b4dca95d579df72bc153eab4b84a7981cb73bf46fd3935ef93f" +python-versions = "^3.6" [metadata.files] autopep8 = [ - {file = "autopep8-1.5.tar.gz", hash = "sha256:0f592a0447acea0c2b0a9602be1e4e3d86db52badd2e3c84f0193bfd89fd3a43"}, + {file = "autopep8-1.5.2.tar.gz", hash = "sha256:152fd8fe47d02082be86e05001ec23d6f420086db56b17fc883f3f965fb34954"}, ] babelfish = [ {file = "babelfish-0.5.5.tar.gz", hash = "sha256:8380879fa51164ac54a3e393f83c4551a275f03617f54a99d70151358e444104"}, @@ -231,9 +264,9 @@ colorama = [ {file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"}, {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, ] -entrypoints = [ - {file = "entrypoints-0.3-py2.py3-none-any.whl", hash = "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19"}, - {file = "entrypoints-0.3.tar.gz", hash = "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451"}, +dataclasses = [ + {file = "dataclasses-0.7-py3-none-any.whl", hash = "sha256:3459118f7ede7c8bea0fe795bff7c6c2ce287d01dd226202f7c9ebc0610a7836"}, + {file = "dataclasses-0.7.tar.gz", hash = "sha256:494a6dcae3b8bcf80848eea2ef64c0cc5cd307ffc263e17cdf42f3e5420808e6"}, ] feedparser = [ {file = "feedparser-5.2.1.tar.bz2", hash = "sha256:ce875495c90ebd74b179855449040003a1beb40cd13d5f037a0654251e260b02"}, @@ -241,12 +274,16 @@ feedparser = [ {file = "feedparser-5.2.1.zip", hash = "sha256:cd2485472e41471632ed3029d44033ee420ad0b57111db95c240c9160a85831c"}, ] flake8 = [ - {file = "flake8-3.7.9-py2.py3-none-any.whl", hash = "sha256:49356e766643ad15072a789a20915d3c91dc89fd313ccd71802303fd67e4deca"}, - {file = "flake8-3.7.9.tar.gz", hash = "sha256:45681a117ecc81e870cbf1262835ae4af5e7a8b08e40b944a8a6e6b895914cfb"}, + {file = "flake8-3.8.1-py2.py3-none-any.whl", hash = "sha256:6c1193b0c3f853ef763969238f6c81e9e63ace9d024518edc020d5f1d6d93195"}, + {file = "flake8-3.8.1.tar.gz", hash = "sha256:ea6623797bf9a52f4c9577d780da0bb17d65f870213f7b5bcc9fca82540c31d5"}, ] guessit = [ {file = "guessit-3.0.5.tar.gz", hash = "sha256:3559c2f37575b048c3d8723cc7a8eedb83b6c411d1be0d64e8b54f4b90138ca2"}, ] +importlib-metadata = [ + {file = "importlib_metadata-1.6.0-py2.py3-none-any.whl", hash = "sha256:2a688cbaa90e0cc587f1df48bdc97a6eadccdcd9c35fb3f976a09e3b5016d90f"}, + {file = "importlib_metadata-1.6.0.tar.gz", hash = "sha256:34513a8a0c4962bc66d35b359558fd8a5e10cd472d37aec5f66858addef32c1e"}, +] mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, @@ -276,20 +313,20 @@ prompt-toolkit = [ {file = "prompt_toolkit-3.0.3.tar.gz", hash = "sha256:a402e9bf468b63314e37460b68ba68243d55b2f8c4d0192f85a019af3945050e"}, ] pycodestyle = [ - {file = "pycodestyle-2.5.0-py2.py3-none-any.whl", hash = "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56"}, - {file = "pycodestyle-2.5.0.tar.gz", hash = "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c"}, + {file = "pycodestyle-2.6.0-py2.py3-none-any.whl", hash = "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367"}, + {file = "pycodestyle-2.6.0.tar.gz", hash = "sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e"}, ] pyflakes = [ - {file = "pyflakes-2.1.1-py2.py3-none-any.whl", hash = "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0"}, - {file = "pyflakes-2.1.1.tar.gz", hash = "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2"}, + {file = "pyflakes-2.2.0-py2.py3-none-any.whl", hash = "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92"}, + {file = "pyflakes-2.2.0.tar.gz", hash = "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8"}, ] python-dateutil = [ {file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"}, {file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"}, ] questionary = [ - {file = "questionary-1.5.1-py3-none-any.whl", hash = "sha256:5314bfb746321997a9dc457e5e0a533e577a661347f3a89c63277c6746e9a8b9"}, - {file = "questionary-1.5.1.tar.gz", hash = "sha256:f199d4a780183679725f10a209b68be27f07cfd2852d6d7ea9e4a31fb45fb0c0"}, + {file = "questionary-1.5.2-py3-none-any.whl", hash = "sha256:6998a1fe0639daec0da44e0a973f387e7c778bdc418d76ecfa45a7b3a0997049"}, + {file = "questionary-1.5.2.tar.gz", hash = "sha256:f6e41e36b6c86fe0c3ff12a30c6c6a4e80129efba5ad0a115d71fd5df119c726"}, ] rebulk = [ {file = "rebulk-1.0.1.tar.gz", hash = "sha256:81142667c5626913392d81c199bfb2ca60a16d85c402c3e371f0f29dbc262684"}, @@ -322,11 +359,15 @@ typed-ast = [ {file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"}, ] typing-extensions = [ - {file = "typing_extensions-3.7.4.1-py2-none-any.whl", hash = "sha256:910f4656f54de5993ad9304959ce9bb903f90aadc7c67a0bef07e678014e892d"}, - {file = "typing_extensions-3.7.4.1-py3-none-any.whl", hash = "sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575"}, - {file = "typing_extensions-3.7.4.1.tar.gz", hash = "sha256:091ecc894d5e908ac75209f10d5b4f118fbdb2eb1ede6a63544054bb1edb41f2"}, + {file = "typing_extensions-3.7.4.2-py2-none-any.whl", hash = "sha256:f8d2bd89d25bc39dabe7d23df520442fa1d8969b82544370e03d88b5a591c392"}, + {file = "typing_extensions-3.7.4.2-py3-none-any.whl", hash = "sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0cb89af24e761c5"}, + {file = "typing_extensions-3.7.4.2.tar.gz", hash = "sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962a1e6a1815969ae"}, ] wcwidth = [ - {file = "wcwidth-0.1.8-py2.py3-none-any.whl", hash = "sha256:8fd29383f539be45b20bd4df0dc29c20ba48654a41e661925e612311e9f3c603"}, - {file = "wcwidth-0.1.8.tar.gz", hash = "sha256:f28b3e8a6483e5d49e7f8949ac1a78314e740333ae305b4ba5defd3e74fb37a8"}, + {file = "wcwidth-0.1.9-py2.py3-none-any.whl", hash = "sha256:cafe2186b3c009a04067022ce1dcd79cb38d8d65ee4f4791b8888d6599d1bbe1"}, + {file = "wcwidth-0.1.9.tar.gz", hash = "sha256:ee73862862a156bf77ff92b09034fc4825dd3af9cf81bc5b360668d425f3c5f1"}, +] +zipp = [ + {file = "zipp-3.1.0-py3-none-any.whl", hash = "sha256:aa36550ff0c0b7ef7fa639055d797116ee891440eac1a56f378e2d3179e0320b"}, + {file = "zipp-3.1.0.tar.gz", hash = "sha256:c599e4d75c98f6798c509911d08a22e6c021d074469042177c8c86fb92eefd96"}, ] diff --git a/pyproject.toml b/pyproject.toml index 349b083..ca40c70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nyaacli" -version = "0.1.7" +version = "0.1.8" description = "A CLI for downloading Anime from https://nyaa.si" authors = ["John Victor "] license = "MIT" @@ -12,11 +12,12 @@ keywords = ["CLI", "anime"] classifiers = [ "Environment :: Console", "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7" + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8" ] [tool.poetry.dependencies] -python = "^3.7" +python = "^3.6" feedparser = "~5.2" guessit = "~3.0" click = "~7.0" From 49c4ce88c7ae7d86942e4f7d309f600849b7d33e Mon Sep 17 00:00:00 2001 From: John Victor Date: Wed, 13 May 2020 21:34:59 -0300 Subject: [PATCH 2/2] Update libtorrent package recommendation for arch-based distros --- README.md | 2 +- nyaacli/cli/__init__.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 93ad448..af16464 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ A CLI for downloading Anime from https://nyaa.si making use of their RSS Feed an - `python3 -m pip install nyaacli --user` - *Note:* python-libtorrent will still need to be downloaded separately as shown below -- This Program depends on python3-libtorrent, which can be installed using Apt with `sudo apt install python3-libtorrent` or can be built from source here: [python-libtorrent](https://github.com/arvidn/libtorrent/blob/RC_1_2/docs/python_binding.rst) +- This Program depends on libtorrent together with its Python API, which can be installed using apt on debian-based linux distros with `sudo apt install python3-libtorrent` (`libtorrent-rasterbar` with pacman for Arch-based distros) or can be built from source here: [python-libtorrent](https://github.com/arvidn/libtorrent/blob/RC_1_2/docs/python_binding.rst) --- diff --git a/nyaacli/cli/__init__.py b/nyaacli/cli/__init__.py index 7e8feb3..48b0a91 100644 --- a/nyaacli/cli/__init__.py +++ b/nyaacli/cli/__init__.py @@ -2,6 +2,7 @@ import logging import sys +from typing import List from nyaacli.nyaa_search import search_torrent from nyaacli.colors import red, green @@ -13,12 +14,29 @@ init() +def entries_autocomplete(ctx, args: List[str], incomplete: str): + """ + Auto-complete choices for --number / -n argument + """ + + text = 'Selection Entries' + + entries = [ + ('5', f'5 {text}'), + ('10', f'10 {text}'), + ('15', f'15 {text}'), + ('20', f'20 {text}') + ] + + return [c for c in entries if incomplete in c[0]] + + @click.command() @click.argument('anime') @click.argument('episode', type=int, default=None, required=False) @click.option('--output', '-o', default='~/Videos/Anime', help=green('Output Folder'), type=click.Path(), show_default=True) @click.option('--debug/--no-debug', default=False, help=green('Debug Mode')) -@click.option('--number', '-n', default=10, help=green('Number of entries'), show_default=True) +@click.option('--number', '-n', default=10, help=green('Number of entries'), show_default=True, autocompletion=entries_autocomplete) def main(anime: str, episode: int, output: str, debug: bool = False, number: int = 10): """ Search for Anime on https://nyaa.si and downloads it @@ -57,16 +75,14 @@ def main(anime: str, episode: int, output: str, debug: bool = False, number: int try: from nyaacli.torrenting import download_torrent except ModuleNotFoundError: - print(red("You need to have the 'python3-libtorrent' library installed to user nyaa-cli.\n")) - - aur_url = 'https://aur.archlinux.org/packages/libtorrent-rasterbar-git' + print(red("You need to have the 'libtorrent' library (with the Python API) installed to user nyaa-cli.\n")) - print('- Install with Apt:', green('sudo apt install python3-libtorrent')) - print('- Install from the AUR:', green(aur_url)) + print('- Install with apt:', green('sudo apt install python3-libtorrent')) + print('- Install with pacman:', green('sudo pacman -S libtorrent-rasterbar')) - libtorrent_url = "https://github.com/arvidn/libtorrent/blob/RC_1_2/docs/python_binding.rst" + libtorrent_url = green("https://github.com/arvidn/libtorrent/blob/RC_1_2/docs/python_binding.rst") - print(f"\nOtherwise, look into how you can build it here: {libtorrent_url}") + print(f"\nOtherwise, look into how you can build it from source here: {libtorrent_url}") sys.exit(1) main()