Skip to content

Commit

Permalink
Merge pull request #246 from pjzzz/cli-option
Browse files Browse the repository at this point in the history
feat: choice option
  • Loading branch information
vn-ki committed Oct 18, 2019
2 parents e12ec08 + b9a0ced commit a1742d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions anime_downloader/commands/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from anime_downloader.__version__ import __version__
from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES

logger = logging.Logger(__name__)
logger = logging.getLogger(__name__)

echo = click.echo
sitenames = [v[1] for v in ALL_ANIME_SITES]
Expand Down Expand Up @@ -67,22 +67,26 @@
is_flag=True,
help='Disable verifying the SSL certificate, if flag is set'
)
@click.option(
'--choice', '-c',type=int,
help='Choice to start downloading given anime number '
)
@click.pass_context
def command(ctx, anime_url, episode_range, url, player, skip_download, quality,
force_download, download_dir, file_format, provider,
external_downloader, chunk_size, disable_ssl, fallback_qualities):
external_downloader, chunk_size, disable_ssl, fallback_qualities, choice):
""" Download the anime using the url or search for it.
"""

util.print_info(__version__)

# TODO: Replace by factory
cls = get_anime_class(anime_url)

disable_ssl = cls and cls.__name__ == 'Masterani' or disable_ssl
session.get_session().verify = not disable_ssl

if not cls:
anime_url = util.search(anime_url, provider)
anime_url = util.search(anime_url, provider, choice)
cls = get_anime_class(anime_url)

anime = cls(anime_url, quality=quality,
Expand Down
9 changes: 6 additions & 3 deletions anime_downloader/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def format_search_results(search_results):
return table


def search(query, provider):
def search(query, provider, choice=None):
# Since this function outputs to stdout this should ideally be in
# cli. But it is used in watch too. :(
cls = get_anime_class(provider)
Expand All @@ -82,8 +82,11 @@ def search(query, provider):
if not search_results:
logger.error('No such Anime found. Please ensure correct spelling.')
sys.exit(1)

val = click.prompt('Enter the anime no: ', type=int, default=1)

if choice:
val = choice
else:
val = click.prompt('Enter the anime no: ', type=int, default=1)

try:
url = search_results[val-1].url
Expand Down

0 comments on commit a1742d4

Please sign in to comment.