Make --list more powerful

master
Vishnunarayan K I 2018-06-03 18:13:19 +05:30
parent 73ab5d691f
commit 88d56a93db
4 changed files with 62 additions and 4 deletions

View File

@ -17,6 +17,7 @@ Yeah. Me too! That's why this tool exists.
- Specify the quality you want to stream or download.
- Search and download. (Only 9anime)
- Save yourselves from those malicious ads.
- Add any anime to your watch list using `anime watch` and let anime downloader take care of everything for you.
## Supported Sites
@ -47,7 +48,7 @@ pip install -U git+https://github.com/vn-ki/anime-downloader.git#egg=anime-downl
## Usage
Anime downloader has two sub commands, `dl` and `watch`.
Anime downloader has two sub commands, `dl` and `watch`. You can find the documentation in [wiki](https://github.com/vn-ki/anime-downloader/wiki)
- [dl](https://github.com/vn-ki/anime-downloader/wiki/dl-command)
- [watch](https://github.com/vn-ki/anime-downloader/wiki/watch-command)

View File

@ -140,7 +140,7 @@ def watch(anime_name, new, _list, quality, log_level, remove):
sys.exit(0)
if _list:
watcher.list()
list_animes(watcher)
sys.exit(0)
if anime_name:
@ -170,3 +170,48 @@ def watch(anime_name, new, _list, quality, log_level, remove):
anime.episodes_done += 1
watcher.update(anime)
break
def list_animes(watcher):
watcher.list()
inp = click.prompt('Select an anime', default=1)
try:
anime = watcher.get(int(inp)-1)
except IndexError:
sys.exit(0)
while True:
click.clear()
click.secho('Title: ' + click.style(anime.title, fg='green', bold=True))
click.echo('episodes_done: {}'.format(click.style(
str(anime.episodes_done), bold=True, fg='yellow')))
click.echo('Length: {}'.format(len(anime)))
meta = ''
for k, v in anime.meta.items():
meta += '{}: {}\n'.format(k, click.style(v, bold=True))
click.echo(meta)
click.echo('You can set title and episodes_done. '
'Ex: set episodes_done=3\n'
'You can remove by remove\n')
inp = click.prompt('Press q to exit', default='q').strip()
if inp == 'q':
break
elif inp == 'remove':
watcher.remove(anime.title)
break
elif 'set' in inp:
inp = inp.split('set ')[-1]
key, val = [v.strip() for v in inp.split('=')]
key = key.lower()
if key == 'title':
watcher.remove(anime)
setattr(anime, key, val)
watcher.add(anime)
elif key == 'episodes_done':
setattr(anime, key, int(val))
watcher.update(anime)

View File

@ -6,7 +6,12 @@ import sys
import pickle
import logging
import click
from fuzzywuzzy import process
import warnings
# Don't warn if not using fuzzywuzzy[speedup]
with warnings.catch_warnings():
warnings.simplefilter('ignore')
from fuzzywuzzy import process
class Watcher:
@ -39,10 +44,17 @@ class Watcher:
def get(self, anime_name):
animes = self._read_from_watch_file()
if isinstance(anime_name, int):
return animes[anime_name]
match = process.extractOne(anime_name, animes, score_cutoff=40)
if match:
return match[0]
def add(self, anime):
self._append_to_watch_file(anime)
def remove(self, anime_name):
animes = self._read_from_watch_file()
animes = [anime for anime in animes if anime.title != anime_name]

View File

@ -20,7 +20,7 @@ setup(
'beautifulsoup4>=4.6.0',
'requests>=2.18.4',
'Click>=6.7',
'fuzzywuzzy[speedup]>=0.16.0',
'fuzzywuzzy>=0.16.0',
],
extras_require={
'cloudflare': ['cfscrape>=1.9.5']