From 1a03d9fd12e601a072aeb3d30e3e3693373d841d Mon Sep 17 00:00:00 2001 From: Anthony Arnaud Date: Thu, 6 Jan 2022 07:56:24 -0500 Subject: [PATCH] Added cookies option for addic7ed to avoid anti-captcha provider requirement --- bazarr/config.py | 2 ++ bazarr/get_providers.py | 2 ++ frontend/src/Settings/Providers/list.ts | 8 +++++- libs/subliminal/providers/addic7ed.py | 4 ++- libs/subliminal_patch/providers/addic7ed.py | 32 ++++++++++++++++++--- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/bazarr/config.py b/bazarr/config.py index 619981d42..a577da32a 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -136,6 +136,8 @@ defaults = { 'addic7ed': { 'username': '', 'password': '', + 'cookies': '', + 'user_agent': '', 'vip': 'False' }, 'podnapisi': { diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py index 363ee93e9..bbe445927 100644 --- a/bazarr/get_providers.py +++ b/bazarr/get_providers.py @@ -128,6 +128,8 @@ def get_providers_auth(): 'addic7ed': { 'username': settings.addic7ed.username, 'password': settings.addic7ed.password, + 'cookies': settings.addic7ed.cookies, + 'user_agent': settings.addic7ed.user_agent, 'is_vip': settings.addic7ed.getboolean('vip'), }, 'opensubtitles': { diff --git a/frontend/src/Settings/Providers/list.ts b/frontend/src/Settings/Providers/list.ts index d6a2ff2c1..aac5ce6bb 100644 --- a/frontend/src/Settings/Providers/list.ts +++ b/frontend/src/Settings/Providers/list.ts @@ -17,14 +17,20 @@ export interface ProviderInfo { export const ProviderList: Readonly = [ { key: "addic7ed", - description: "Requires Anti-Captcha Provider", + description: "Requires Anti-Captcha Provider or cookies", defaultKey: { username: "", password: "", + cookies: "", + user_agent: "", vip: false, }, keyNameOverride: { vip: "VIP", + cookies: + "Cookies, e.g., PHPSESSID=abc; wikisubtitlesuser=xyz; wikisubtitlespass=efg", + user_agent: + "User-Agent, e.g., Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0", }, }, { key: "argenteam", description: "LATAM Spanish Subtitles Provider" }, diff --git a/libs/subliminal/providers/addic7ed.py b/libs/subliminal/providers/addic7ed.py index 7c9ab1501..52c7ec03a 100644 --- a/libs/subliminal/providers/addic7ed.py +++ b/libs/subliminal/providers/addic7ed.py @@ -98,12 +98,14 @@ class Addic7edProvider(Provider): server_url = 'http://www.addic7ed.com/' subtitle_class = Addic7edSubtitle - def __init__(self, username=None, password=None): + def __init__(self, username=None, password=None, cookies=None, user_agent=None): if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username self.password = password + self.cookies = cookies + self.user_agent = user_agent self.logged_in = False self.session = None diff --git a/libs/subliminal_patch/providers/addic7ed.py b/libs/subliminal_patch/providers/addic7ed.py index e7ff5e2c4..b4f18d6c3 100644 --- a/libs/subliminal_patch/providers/addic7ed.py +++ b/libs/subliminal_patch/providers/addic7ed.py @@ -83,13 +83,15 @@ class Addic7edProvider(_Addic7edProvider): sanitize_characters = {'-', ':', '(', ')', '.', '/'} last_show_ids_fetch_key = "addic7ed_last_id_fetch" - def __init__(self, username=None, password=None, use_random_agents=False, is_vip=False): - super(Addic7edProvider, self).__init__(username=username, password=password) + def __init__(self, username=None, password=None, cookies=None, user_agent=None, use_random_agents=False, + is_vip=False): + super(Addic7edProvider, self).__init__(username=username, password=password, cookies=cookies, + user_agent=user_agent) self.USE_ADDICTED_RANDOM_AGENTS = use_random_agents self.vip = is_vip - if not all((username, password)): - raise ConfigurationError('Username and password must be specified') + if not all((username, password)) and not cookies: + raise ConfigurationError('Username and password or cookies must be specified') def initialize(self): self.session = Session() @@ -100,6 +102,28 @@ class Addic7edProvider(_Addic7edProvider): self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)] self.session.headers['Referer'] = self.server_url + if self.user_agent: + self.session.headers['User-Agent'] = self.user_agent + if self.cookies: + cookies_string = self.cookies.split(";") + from requests.cookies import RequestsCookieJar + self.session.cookies = RequestsCookieJar() + for c in cookies_string: + k, v = c.split("=") + self.session.cookies.set(k,v) + + rr = self.session.get(self.server_url + 'panel.php', allow_redirects=False, timeout=10, + headers={"Referer": self.server_url}) + if rr.status_code == 302: + logger.info('Addic7ed: Login expired') + raise AuthenticationError("cookies not valid anymore") + + store_verification("addic7ed", self.session) + logger.debug('Addic7ed: Logged in') + self.logged_in = True + time.sleep(2) + return True + # login if self.username and self.password: def check_verification(cache_region):