Skip to content

Commit

Permalink
Merge pull request #24 from johnvictorfs/add-numbers-argument
Browse files Browse the repository at this point in the history
Add numbers argument to specify number of entries to select from
  • Loading branch information
johnvictorfs committed May 14, 2020
2 parents 77736eb + 49c4ce8 commit 5377168
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down
39 changes: 28 additions & 11 deletions nyaacli/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,14 +14,32 @@
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('--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, autocompletion=entries_autocomplete)
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:
Expand All @@ -45,7 +64,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
Expand All @@ -56,16 +75,14 @@ def main(anime: str, episode: int, output: str, debug: bool = False):
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()
6 changes: 3 additions & 3 deletions nyaacli/nyaa_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 = [
{
Expand Down
115 changes: 78 additions & 37 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <johnvictorfs@gmail.com>"]
license = "MIT"
Expand All @@ -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"
Expand Down

0 comments on commit 5377168

Please sign in to comment.