From 781258ad0fd11e7e88da3ea7dda972a50d901831 Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Fri, 20 Mar 2020 22:38:01 +0530 Subject: [PATCH] feat: add new command test --- anime_downloader/commands/dl.py | 1 - anime_downloader/commands/test.py | 64 ++++++++++++++++++++++++++++++ anime_downloader/commands/watch.py | 3 ++ docs/index.rst | 1 + docs/usage/test.rst | 12 ++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 anime_downloader/commands/test.py create mode 100644 docs/usage/test.rst diff --git a/anime_downloader/commands/dl.py b/anime_downloader/commands/dl.py index 9b7aa5d..7e2b945 100644 --- a/anime_downloader/commands/dl.py +++ b/anime_downloader/commands/dl.py @@ -77,7 +77,6 @@ def command(ctx, anime_url, episode_range, url, player, skip_download, quality, 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) diff --git a/anime_downloader/commands/test.py b/anime_downloader/commands/test.py new file mode 100644 index 0000000..df0178f --- /dev/null +++ b/anime_downloader/commands/test.py @@ -0,0 +1,64 @@ +import logging +import sys +import threading + +import click + +from anime_downloader.sites import get_anime_class, ALL_ANIME_SITES +from anime_downloader import util +from anime_downloader.__version__ import __version__ + +logger = logging.getLogger(__name__) + +echo = click.echo +sitenames = [v[1] for v in ALL_ANIME_SITES] + + +class SiteThread(threading.Thread): + def __init__(self, site, *args, **kwargs): + self.site = site + self.exception = None + super().__init__(*args, **kwargs) + + def run(self): + try: + ani = get_anime_class(self.site) + + # this should be more dynamic + sr = ani.search('naruto')[0] + + anime = ani(sr.url) + + stream_url = anime[0].source().stream_url + except Exception as e: + self.exception = e + + +@click.command() +@click.argument('test_query', default='naruto') +def command(test_query): + """Test all sites to see which ones are working and which ones aren't. Test naruto as a default.""" + util.print_info(__version__) + logger = logging.getLogger("anime_downloader") + logger.setLevel(logging.WARNING) + + threads = [] + + for site in sitenames: + t = SiteThread(site, daemon=True) + t.start() + threads.append(t) + + for thread in threads: + thread.join(timeout=10) + if not thread.is_alive(): + if not thread.exception: + # echo(click.style('Works ', fg='green') + site) + echo(click.style('✅ ', fg='green') + thread.site) + else: + logging.debug('Error occured during testing') + logging.debug(thread.exception) + echo(click.style("❌ ", fg='red') + thread.site) + else: + logging.debug('timeout during testing') + echo(click.style("❌ ", fg='red') + thread.site) diff --git a/anime_downloader/commands/watch.py b/anime_downloader/commands/watch.py index 884750e..26fe9fc 100644 --- a/anime_downloader/commands/watch.py +++ b/anime_downloader/commands/watch.py @@ -52,6 +52,9 @@ def command(anime_name, new, update_all, _list, quality, remove, download : Download episodes of selected anime """ util.print_info(__version__) + echo('Watch is deprecated in favour of adl: https://github.com/RaitaroH/adl .') + echo('You can use dl command to stream anime if you do not want anime tracking.') + echo('watch command may come back in the future.') watcher = _watch.Watcher() diff --git a/docs/index.rst b/docs/index.rst index d0f9297..e95e931 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -39,6 +39,7 @@ NOTE: To download from sites marked `[cloudflare]`, anime-downloader has to be i usage/installation usage/dl + usage/test usage/watch usage/config usage/sites diff --git a/docs/usage/test.rst b/docs/usage/test.rst new file mode 100644 index 0000000..9c688e2 --- /dev/null +++ b/docs/usage/test.rst @@ -0,0 +1,12 @@ +``anime test`` +============== + +You can check which provider has your favorite anime and check which provider is currrently working. + +Usage +^^^^^ + +- To check the providers with code geass + +.. code:: bash + anime test 'code geass'