test cli
parent
6a8b500dd8
commit
b17c07c1a7
|
@ -8,7 +8,7 @@ import os
|
|||
import click
|
||||
import logging
|
||||
|
||||
from anime_downloader.sites.exceptions import AnimeDLError
|
||||
from anime_downloader.sites.exceptions import AnimeDLError, NotFoundError
|
||||
from anime_downloader import util
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ class BaseAnime():
|
|||
|
||||
def __getitem__(self, index):
|
||||
ep_id = self._episodeIds[index]
|
||||
return self._episodeClass(ep_id, self.quality)
|
||||
return self._episodeClass(ep_id, self.quality, parent=self)
|
||||
|
||||
def __repr__(self):
|
||||
return '''
|
||||
|
@ -78,7 +78,7 @@ class BaseEpisode:
|
|||
title = ''
|
||||
stream_url = ''
|
||||
|
||||
def __init__(self, episode_id, quality='720p'):
|
||||
def __init__(self, episode_id, quality='720p', parent=None):
|
||||
|
||||
if quality not in self.QUALITIES:
|
||||
raise AnimeDLError('Incorrect quality: "{}"'.format(quality))
|
||||
|
@ -86,7 +86,20 @@ class BaseEpisode:
|
|||
self.episode_id = episode_id
|
||||
self.quality = quality
|
||||
logging.info("Extracting stream info of id: {}".format(self.episode_id))
|
||||
self.getData()
|
||||
|
||||
try:
|
||||
self.getData()
|
||||
except NotFoundError:
|
||||
for quality in parent.QUALITIES:
|
||||
parent.QUALITIES.remove(self.quality)
|
||||
logging.warning('Quality {} not found. Trying {}.'.format(self.quality, quality))
|
||||
self.quality = quality
|
||||
try:
|
||||
self.getData()
|
||||
parent.quality = self.quality
|
||||
break
|
||||
except NotFoundError:
|
||||
pass
|
||||
|
||||
def getData(self):
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -45,10 +45,14 @@ class NineAnimeEpisode(BaseEpisode):
|
|||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
try:
|
||||
self.stream_url = soup.find_all('source')[0].get('src')
|
||||
self.title = title_re.findall(r.text)[0]
|
||||
self.image = image_re.findall(r.text)[0]
|
||||
except IndexError:
|
||||
raise NotFoundError("Episode not found")
|
||||
try:
|
||||
self.title = title_re.findall(r.text)[0]
|
||||
self.image = image_re.findall(r.text)[0]
|
||||
except Exception as e:
|
||||
logging.debug(e)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
from anime_downloader import cli
|
||||
|
||||
import pytest
|
||||
|
||||
pytest_plugins = ["pytester"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run(testdir):
|
||||
def do_run(*args):
|
||||
args = ["anime-dl"] + list(args)
|
||||
return testdir._run(*args)
|
||||
return do_run
|
||||
|
||||
|
||||
def test_streamurl(run):
|
||||
result = run(
|
||||
'https://www4.9anime.is/watch/the-seven-deadly-sins-signs-of-holy-war.lxqm/39px7y',
|
||||
'--url'
|
||||
)
|
||||
|
||||
assert result.ret == 0
|
||||
|
||||
for line in result.stdout.lines:
|
||||
assert line.endswith('.mp4')
|
||||
|
||||
|
||||
def test_range(run):
|
||||
result = run(
|
||||
'https://www4.9anime.is/watch/naruto.xx8z/r9k04y',
|
||||
'--url',
|
||||
'-e',
|
||||
'50:55'
|
||||
)
|
||||
|
||||
assert result.ret == 0
|
||||
|
||||
for line in result.stdout.lines:
|
||||
assert line.endswith('.mp4')
|
||||
|
||||
assert len(result.stdout.lines) == 5
|
Loading…
Reference in New Issue