mirror of https://github.com/morpheus65535/bazarr
Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
8753e8c545
|
@ -193,11 +193,22 @@ class SZProviderPool(ProviderPool):
|
|||
|
||||
# Check if any new provider has been added
|
||||
updated = providers != self.providers or ban_list != self.ban_list
|
||||
removed_providers = list(sorted(self.providers - providers))
|
||||
new_providers = list(sorted(providers - self.providers))
|
||||
removed_providers = set(sorted(self.providers - providers))
|
||||
|
||||
logger.debug("Discarded providers: %s | New providers: %s", self.discarded_providers, providers)
|
||||
self.discarded_providers.difference_update(providers)
|
||||
logger.debug("Updated discarded providers: %s", self.discarded_providers)
|
||||
|
||||
removed_providers.update(self.discarded_providers)
|
||||
|
||||
logger.debug("Removed providers: %s", removed_providers)
|
||||
|
||||
self.providers.difference_update(removed_providers)
|
||||
self.providers.update(list(providers))
|
||||
|
||||
# Terminate and delete removed providers from instance
|
||||
for removed in removed_providers:
|
||||
logger.debug("Removing provider: %s", removed)
|
||||
try:
|
||||
del self[removed]
|
||||
# If the user has updated the providers but hasn't made any
|
||||
|
@ -206,14 +217,6 @@ class SZProviderPool(ProviderPool):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
if updated:
|
||||
logger.debug("Removed providers: %s", removed_providers)
|
||||
logger.debug("New providers: %s", new_providers)
|
||||
|
||||
self.discarded_providers.difference_update(new_providers)
|
||||
self.providers.difference_update(removed_providers)
|
||||
self.providers.update(list(providers))
|
||||
|
||||
# self.provider_configs = provider_configs
|
||||
self.provider_configs.update(provider_configs)
|
||||
|
||||
|
|
|
@ -104,9 +104,24 @@ class GestdownProvider(Provider):
|
|||
logger.debug("Found subtitle: %s", sub)
|
||||
yield sub
|
||||
|
||||
def _show_exists(self, video):
|
||||
try:
|
||||
response = self._session.get(f"{_BASE_URL}/shows/search/{video.series}")
|
||||
response.raise_for_status()
|
||||
return True
|
||||
except HTTPError as error:
|
||||
if error.response.status_code == 404:
|
||||
return False
|
||||
raise
|
||||
|
||||
|
||||
@_retry_on_423
|
||||
def list_subtitles(self, video, languages):
|
||||
subtitles = []
|
||||
if not self._show_exists(video):
|
||||
logger.debug("Couldn't find the show")
|
||||
return subtitles
|
||||
|
||||
for language in languages:
|
||||
try:
|
||||
subtitles += self._subtitles_search(video, language)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from subliminal_patch import core
|
||||
|
||||
|
||||
|
@ -17,3 +19,54 @@ def test_scan_video_episode(tmpdir):
|
|||
|
||||
result = core.scan_video(str(video_path))
|
||||
assert isinstance(result, core.Episode)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pool_instance():
|
||||
yield core.SZProviderPool({"argenteam"}, {})
|
||||
|
||||
|
||||
def test_pool_update_w_nothing(pool_instance):
|
||||
pool_instance.update({}, {}, [], {})
|
||||
assert pool_instance.providers == set()
|
||||
assert pool_instance.discarded_providers == set()
|
||||
|
||||
|
||||
def test_pool_update_w_multiple_providers(pool_instance):
|
||||
assert pool_instance.providers == {"argenteam"}
|
||||
pool_instance.update({"argenteam", "subdivx", "subf2m"}, {}, [], {})
|
||||
assert pool_instance.providers == {"argenteam", "subdivx", "subf2m"}
|
||||
|
||||
|
||||
def test_pool_update_discarded_providers(pool_instance):
|
||||
assert pool_instance.providers == {"argenteam"}
|
||||
|
||||
# Provider was discarded internally
|
||||
pool_instance.discarded_providers = {"argenteam"}
|
||||
|
||||
assert pool_instance.discarded_providers == {"argenteam"}
|
||||
|
||||
# Provider is set to be used again
|
||||
pool_instance.update({"subdivx", "argenteam"}, {}, [], {})
|
||||
|
||||
assert pool_instance.providers == {"argenteam", "subdivx"}
|
||||
|
||||
# Provider should disappear from discarded providers
|
||||
assert pool_instance.discarded_providers == set()
|
||||
|
||||
|
||||
def test_pool_update_discarded_providers_2(pool_instance):
|
||||
assert pool_instance.providers == {"argenteam"}
|
||||
|
||||
# Provider was discarded internally
|
||||
pool_instance.discarded_providers = {"argenteam"}
|
||||
|
||||
assert pool_instance.discarded_providers == {"argenteam"}
|
||||
|
||||
# Provider is not set to be used again
|
||||
pool_instance.update({"subdivx"}, {}, [], {})
|
||||
|
||||
assert pool_instance.providers == {"subdivx"}
|
||||
|
||||
# Provider should not disappear from discarded providers
|
||||
assert pool_instance.discarded_providers == {"argenteam"}
|
||||
|
|
|
@ -78,6 +78,7 @@ def test_subtitle_download(subtitle):
|
|||
|
||||
def test_list_subtitles_423(episodes, requests_mock, mocker):
|
||||
mocker.patch("time.sleep")
|
||||
requests_mock.get("https://api.gestdown.info/shows/search/Breaking%20Bad", status_code=200)
|
||||
requests_mock.get(
|
||||
f"{_BASE_URL}/subtitles/find/English/Breaking%20Bad/1/1", status_code=423
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue