aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVitiko <[email protected]>2021-12-23 21:10:35 -0400
committerVitiko <[email protected]>2021-12-23 21:10:35 -0400
commita88f0a7f198faf1fe2de139a7fb49da41c0ee658 (patch)
tree70ccf2d10071d9a60a2b35477672e85f0007d0b2
parent048307e4299106ea2340bed72fce8207859d5fa9 (diff)
downloadbazarr-a88f0a7f198faf1fe2de139a7fb49da41c0ee658.tar.gz
bazarr-a88f0a7f198faf1fe2de139a7fb49da41c0ee658.zip
Fix Addic7ed provider TypeError
-rw-r--r--libs/subliminal_patch/providers/addic7ed.py6
-rw-r--r--tests/subliminal_patch/test_addic7ed.py70
2 files changed, 73 insertions, 3 deletions
diff --git a/libs/subliminal_patch/providers/addic7ed.py b/libs/subliminal_patch/providers/addic7ed.py
index 66e29070c..592ee5124 100644
--- a/libs/subliminal_patch/providers/addic7ed.py
+++ b/libs/subliminal_patch/providers/addic7ed.py
@@ -300,9 +300,9 @@ class Addic7edProvider(_Addic7edProvider):
# LXML parser seems to fail when parsing Addic7ed.com HTML markup.
# Last known version to work properly is 3.6.4 (next version, 3.7.0, fails)
# Assuming the site's markup is bad, and stripping it down to only contain what's needed.
- show_cells = re.findall(show_cells_re, r.content)
+ show_cells = [cell.decode("utf-8", "ignore") for cell in re.findall(show_cells_re, r.content)]
if show_cells:
- soup = ParserBeautifulSoup(''.join(show_cells).decode('utf-8', 'ignore'), ['lxml', 'html.parser'])
+ soup = ParserBeautifulSoup(''.join(show_cells), ['lxml', 'html.parser'])
else:
# If RegEx fails, fall back to original r.content and use 'html.parser'
soup = ParserBeautifulSoup(r.content, ['html.parser'])
@@ -461,7 +461,7 @@ class Addic7edProvider(_Addic7edProvider):
def query_movie(self, movie_id, title, year=None):
# get the page of the movie
- logger.info('Getting the page of movie id %d', movie_id)
+ logger.info('Getting the page of movie id %s', movie_id)
r = self.session.get(self.server_url + 'movie/' + movie_id,
timeout=10,
headers={
diff --git a/tests/subliminal_patch/test_addic7ed.py b/tests/subliminal_patch/test_addic7ed.py
new file mode 100644
index 000000000..f0f47e447
--- /dev/null
+++ b/tests/subliminal_patch/test_addic7ed.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+
+import os
+import pytest
+import datetime
+import tempfile
+
+import subliminal
+from subliminal_patch.providers.addic7ed import Addic7edProvider
+from subliminal_patch.providers.addic7ed import Addic7edSubtitle
+from dogpile.cache.region import register_backend as register_cache_backend
+from subzero.language import Language
+
+
+_ENV_VARS = (
+ "ANTICAPTCHA_CLASS",
+ "ANTICAPTCHA_ACCOUNT_KEY",
+ "ADDIC7ED_USERNAME",
+ "ADDIC7ED_PASSWORD",
+)
+
+
+def _can_run():
+ for env_var in _ENV_VARS:
+ if not os.environ.get(env_var):
+ return True
+
+ return False
+
+
+pytestmark = pytest.mark.skipif(
+ _can_run(), reason=f"Some environment variables not set: {_ENV_VARS}"
+)
+
+
[email protected](scope="session")
+def region():
+ register_cache_backend(
+ "subzero.cache.file", "subzero.cache_backends.file", "SZFileBackend"
+ )
+ subliminal.region.configure(
+ "subzero.cache.file",
+ expiration_time=datetime.timedelta(days=30),
+ arguments={"appname": "sz_cache", "app_cache_dir": tempfile.gettempdir()},
+ )
+ subliminal.region.backend.sync()
+
+
+def test_list_subtitles_episode(region, episodes):
+ item = episodes["breaking_bad_s01e01"]
+ language = Language("eng")
+ with Addic7edProvider(
+ os.environ["ADDIC7ED_USERNAME"], os.environ["ADDIC7ED_PASSWORD"]
+ ) as provider:
+ subtitles = provider.list_subtitles(item, {language})
+ assert len(subtitles) == 6
+
+ subliminal.region.backend.sync()
+
+
+def test_list_subtitles_movie(region, movies):
+ item = movies["dune"]
+ language = Language("eng")
+ with Addic7edProvider(
+ os.environ["ADDIC7ED_USERNAME"], os.environ["ADDIC7ED_PASSWORD"]
+ ) as provider:
+ subtitles = provider.list_subtitles(item, {language})
+ assert len(subtitles) == 2
+
+ subliminal.region.backend.sync()