2018-02-04 15:21:15 -08:00
|
|
|
import click
|
2018-02-05 07:01:37 -08:00
|
|
|
import subprocess
|
2018-05-27 06:36:08 -07:00
|
|
|
from anime_downloader.sites.nineanime import NineAnime
|
|
|
|
from anime_downloader.sites.anime import NotFoundError
|
2018-02-04 15:21:15 -08:00
|
|
|
|
|
|
|
echo = click.echo
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.argument('anime_url')
|
2018-02-05 08:54:30 -08:00
|
|
|
@click.option('--range', 'range_', metavar='<int>:<int>',
|
|
|
|
help="Range of anime you want to download in the form <start>:<end>")
|
|
|
|
@click.option('--playlist', default=False, type=bool, is_flag=True,
|
|
|
|
help="If flag is set, saves the stream urls in an m3u file")
|
|
|
|
@click.option('--url', default=False, type=bool, is_flag=True,
|
|
|
|
help="If flag is set, prints the stream url and not download")
|
2018-02-05 07:01:37 -08:00
|
|
|
@click.option('--play', 'player', metavar='PLAYER',
|
|
|
|
help="Streams in the specified player")
|
2018-02-05 08:54:30 -08:00
|
|
|
@click.option('--no-download', default=False, is_flag=True,
|
|
|
|
help="Retrieve without downloading")
|
2018-02-05 07:01:37 -08:00
|
|
|
@click.option('--quality', type=click.Choice(['360p', '480p', '720p']),
|
2018-02-05 08:54:30 -08:00
|
|
|
default='720p',
|
|
|
|
help='Specify the quality of episode. Default-720p')
|
2018-02-08 15:07:11 -08:00
|
|
|
@click.option('--force', is_flag=True, default=False,
|
|
|
|
help='Force downloads even if file exists')
|
|
|
|
def cli(anime_url, range_, playlist, url, player, no_download, quality, force):
|
2018-02-04 15:21:15 -08:00
|
|
|
""" Anime Downloader
|
|
|
|
|
|
|
|
Download your favourite anime.
|
|
|
|
"""
|
2018-02-04 15:57:10 -08:00
|
|
|
try:
|
2018-05-27 06:36:08 -07:00
|
|
|
anime = NineAnime(anime_url, quality=quality,
|
|
|
|
callback=lambda message: print('[INFO] '+message))
|
2018-02-04 15:57:10 -08:00
|
|
|
except NotFoundError as e:
|
|
|
|
echo(e.args[0])
|
|
|
|
return
|
2018-02-04 15:21:15 -08:00
|
|
|
|
2018-02-05 07:01:37 -08:00
|
|
|
if url or player:
|
|
|
|
no_download = True
|
|
|
|
|
2018-02-04 15:21:15 -08:00
|
|
|
if range is None:
|
2018-02-05 07:01:37 -08:00
|
|
|
range_ = '1:'+str(len(anime)+1)
|
2018-02-04 15:21:15 -08:00
|
|
|
|
|
|
|
try:
|
2018-02-05 07:01:37 -08:00
|
|
|
start, end = [int(x) for x in range_.split(':')]
|
2018-02-04 15:21:15 -08:00
|
|
|
anime._episodeIds = anime._episodeIds[start-1:end-1]
|
|
|
|
except ValueError:
|
|
|
|
# Only one episode specified
|
2018-02-05 07:01:37 -08:00
|
|
|
anime = [anime[int(range_)-1]]
|
2018-02-04 15:21:15 -08:00
|
|
|
|
|
|
|
for episode in anime:
|
|
|
|
if url:
|
|
|
|
print(episode.stream_url)
|
|
|
|
continue
|
|
|
|
|
2018-02-05 07:01:37 -08:00
|
|
|
if player:
|
|
|
|
p = subprocess.Popen([player, episode.stream_url])
|
|
|
|
p.wait()
|
|
|
|
|
|
|
|
if not no_download:
|
2018-02-08 15:07:11 -08:00
|
|
|
episode.download(force)
|
2018-02-05 07:01:37 -08:00
|
|
|
print()
|