def __init__(self, username=None, password=None, use_hash=True, api_key=None): if not all((username, password)): raise ConfigurationError('Username and password must be specified') if not api_key: raise ConfigurationError('Api_key must be specified') if not all((username, password)): raise ConfigurationError('Username and password must be specified') self.session = Session() self.session.headers = { 'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2"), 'Api-Key': api_key, 'Content-Type': 'application/json' } self.token = None self.username = username self.password = password self.video = None self.use_hash = use_hash self._started = None
def __init__(self, username=None, password=None, skip_wrong_fps=None, approved_only=None, multithreading=None): if not all([username, password]): raise ConfigurationError( "Username and password must be specified!") if type(skip_wrong_fps) is not bool: raise ConfigurationError( f"Skip_wrong_fps {skip_wrong_fps} must be a boolean!") if type(approved_only) is not bool: raise ConfigurationError( f"Approved_only {approved_only} must be a boolean!") if type(multithreading) is not bool: raise ConfigurationError( f"Multithreading {multithreading} must be a boolean!") self.username = username self.password = password self.skip_wrong_fps = skip_wrong_fps self.approved_only = approved_only self.multithreading = multithreading self.session = None
def __init__(self, username=None, password=None): # Provider needs UNRAR installed. If not available raise ConfigurationError try: rarfile.custom_check([rarfile.UNRAR_TOOL], True) except rarfile.RarExecError: raise ConfigurationError('UNRAR tool not available') if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username self.password = password self.logged_in = False self.session = None
def __init__(self, username=None, password=None, use_tag_search=False, only_foreign=False, skip_wrong_fps=True, is_vip=False): if username is not None and password is None or username is None and password is not None: raise ConfigurationError('Username and password must be specified') self.username = username or '' self.password = password or '' self.use_tag_search = use_tag_search self.only_foreign = only_foreign self.skip_wrong_fps = skip_wrong_fps self.token = None self.is_vip = is_vip if is_vip: self.server = self.get_server_proxy(self.vip_url) logger.info("Using VIP server") else: self.server = self.get_server_proxy(self.default_url) if use_tag_search: logger.info("Using tag/exact filename search") if only_foreign: logger.info("Only searching for foreign/forced subtitles")
def __init__(self, username=None, password=None, featured_only=False): # Provider needs UNRAR installed. If not available raise ConfigurationError try: rarfile.tool_setup() except rarfile.RarExecError: raise ConfigurationError('UNRAR tool not available') if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username self.password = password self.logged_in = False self.session = None self.featured_only = featured_only
def __init__(self, username, password, skip_wrong_fps=True): # make sure login credentials are configured. if any((username, password)) and not all((username, password)): raise ConfigurationError('Legendasdivx.pt :: Username and password must be specified') self.username = username self.password = password self.skip_wrong_fps = skip_wrong_fps
def __init__(self, username=None, password=None, use_random_agents=False): super(Addic7edProvider, self).__init__(username=username, password=password) self.USE_ADDICTED_RANDOM_AGENTS = use_random_agents if not all((username, password)): raise ConfigurationError('Username and password must be specified')
def _get_season_subtitles(self, show_id, season, sub_format): params = { 'apikey': self.apikey, 'show_id': show_id, 'q': 'Stagione %%%d' % season, 'version': sub_format } r = self.session.get(self.server_url + 'subtitles/search', params=params, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) if int(root.find('data/count').text) == 0: logger.warning('Subtitles for season not found, try with rip suffix') params['version'] = sub_format + 'rip' r = self.session.get(self.server_url + 'subtitles/search', params=params, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) if int(root.find('data/count').text) == 0: logger.warning('Subtitles for season not found') return [] subs = [] # Looking for subtitles in first page season_re = re.compile('.*?stagione 0*?%d.*' % season) for subtitle in root.findall('data/subtitles/subtitle'): if season_re.match(subtitle.find('name').text.lower()): logger.debug('Found season zip id %d - %r - %r', int(subtitle.find('id').text), subtitle.find('name').text, subtitle.find('version').text) content = self._download_zip(int(subtitle.find('id').text)) if not is_zipfile(io.BytesIO(content)): # pragma: no cover if 'limite di download' in content: raise DownloadLimitExceeded('You reached the download limit') else: raise ConfigurationError('Not a zip file: %r' % content) with ZipFile(io.BytesIO(content)) as zf: episode_re = re.compile('s(\d{1,2})e(\d{1,2})') for name in zf.namelist(): match = episode_re.search(name) if not match: # pragma: no cover logger.debug('Cannot decode subtitle %r', name) else: sub = ItaSASubtitle( int(subtitle.find('id').text), subtitle.find('show_name').text, int(match.group(1)), int(match.group(2)), None, None, None, name, ) sub.content = fix_line_ending(zf.read(name)) subs.append(sub) return subs
def __init__(self, only_foreign=False, username=None, password=None): if not all((username, password)): raise ConfigurationError('Username and password must be specified') self.only_foreign = only_foreign self.username = username self.password = password
def convert(self, alpha3, country=None, script=None): if (alpha3, country, script) in self.to_zimuku: return self.to_zimuku[(alpha3, country, script)] raise ConfigurationError( 'Unsupported language for zimuku: %s, %s, %s' % (alpha3, country, script))
def __init__(self, username=None, password=None, use_tag_search=False, only_foreign=False, also_foreign=False, skip_wrong_fps=True, is_vip=False, use_ssl=True, timeout=15): if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username or '' self.password = password or '' self.use_tag_search = use_tag_search self.only_foreign = only_foreign self.also_foreign = also_foreign self.skip_wrong_fps = skip_wrong_fps self.token = None self.is_vip = is_vip self.use_ssl = use_ssl self.timeout = timeout logger.debug("Using timeout: %d", timeout) if use_ssl: logger.debug("Using HTTPS connection") self.default_url = ("https:" if use_ssl else "http:") + self.default_url self.vip_url = ("https:" if use_ssl else "http:") + self.vip_url if use_tag_search: logger.info("Using tag/exact filename search") if only_foreign: logger.info("Only searching for foreign/forced subtitles")
def reverse(self, titlovi): if titlovi in self.from_titlovi: return self.from_titlovi[titlovi] logger.error( ConfigurationError('Unsupported language code for titlovi: %s' % titlovi))
def convert(self, alpha3, country=None, script=None): if alpha3 in exact_languages_alpha3: return Language(alpha3).name if alpha3 in to_subscene: return to_subscene[alpha3] raise ConfigurationError('Unsupported language for subscene: %s, %s, %s' % (alpha3, country, script))
def __init__(self, username=None, password=None): if username is not None and password is None or username is None and password is not None: raise ConfigurationError('Username and password must be specified') self.username = username or '' self.password = password or '' super(PatchedOpenSubtitlesProvider, self).__init__()
def __init__(self, username=None, password=None): if username is not None and password is None or username is None and password is not None: raise ConfigurationError('Username and password must be specified') self.session = None self.username = username self.password = password self.logged_in = False
def __init__(self, username=None, password=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.logged_in = False self.session = None
def convert(self, alpha3, country=None, script=None): if (alpha3, country, script) in self.to_titlovi: return self.to_titlovi[(alpha3, country, script)] if (alpha3, ) in self.to_titlovi: return self.to_titlovi[(alpha3, )] raise ConfigurationError( 'Unsupported language code for titlovi: %s, %s, %s' % (alpha3, country, script))
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)) and not cookies: raise ConfigurationError('Username and password or cookies must be specified')
def convert(self, alpha3, country=None, script=None): if (alpha3, country) in self.to_thesubdb: return self.to_thesubdb[(alpha3, country)] if (alpha3, ) in self.to_thesubdb: return self.to_thesubdb[(alpha3, )] raise ConfigurationError( 'Unsupported language for thesubdb: %s, %s, %s' % (alpha3, country, script))
def __init__(self, username=None, password=None): if not all((username, password)): raise ConfigurationError('Username and password must be specified') self.session = None self.username = username self.password = password self.encrypted_password = None self.salt = None
def __init__(self, email=None, hashed_password=None): if any((email, hashed_password)) and not all((email, hashed_password)): raise ConfigurationError( "Email and Hashed Password must be specified") self.email = email self.hashed_password = hashed_password self.logged_in = False self.session = None self.login_cookie = None
def reverse(self, titlovi): if titlovi in self.from_titlovi: return self.from_titlovi[titlovi] # temporary fix, should be removed as soon as API is used if titlovi in self.lang_from_countrycode: return self.lang_from_countrycode[titlovi] raise ConfigurationError( 'Unsupported language number for titlovi: %s' % titlovi)
def __init__(self, username=None, password=None): if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username self.password = hashlib.md5(password.encode('utf-8')).hexdigest() self.logged_in = False self.cookies = { 'wikisubtitlesuser': self.username, 'wikisubtitlespass': self.password }
def reverse(self, code): if code in from_subscene: return (from_subscene[code],) if code in alpha3_of_code: return (alpha3_of_code[code],) if code in unspecified_languages: raise NotImplementedError("currently this language is unspecified: %s" % code) raise ConfigurationError('Unsupported language code for subscene: %s' % code)
def __init__(self, username=None, password=None): if not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username self.password = password self.session = None self.user_id = None self.login_token = None self.token_exp = None
def __init__(self, username=None, password=None, use_tag_search=False, only_foreign=False): if username is not None and password is None or username is None and password is not None: raise ConfigurationError('Username and password must be specified') self.username = username or '' self.password = password or '' self.use_tag_search = use_tag_search self.only_foreign = only_foreign if use_tag_search: logger.info("Using tag/exact filename search") if only_foreign: logger.info("Only searching for foreign/forced subtitles") super(PatchedOpenSubtitlesProvider, self).__init__() self.server = ServerProxy('http://api.opensubtitles.org/xml-rpc', TimeoutTransport(10))
def __init__(self, username=None, password=None, use_tag_search=False, only_foreign=False, skip_wrong_fps=True, is_vip=False): if any((username, password)) and not all((username, password)): raise ConfigurationError('Username and password must be specified') self.username = username or '' self.password = password or '' self.use_tag_search = use_tag_search self.only_foreign = only_foreign self.skip_wrong_fps = skip_wrong_fps self.token = None self.is_vip = is_vip if use_tag_search: logger.info("Using tag/exact filename search") if only_foreign: logger.info("Only searching for foreign/forced subtitles")
def query(self, series, season, episode, video_format, resolution, country=None): # To make queries you need to be logged in if not self.logged_in: # pragma: no cover raise ConfigurationError('Cannot query if not logged in') # get the show id show_id = self.get_show_id(series, country) if show_id is None: logger.error('No show id found for %r ', series) return [] # get the page of the season of the show logger.info( 'Getting the subtitle of show id %d, season %d episode %d, format %r', show_id, season, episode, video_format) subtitles = [] # Default format is SDTV if not video_format or video_format.lower() == 'hdtv': if resolution in ('1080i', '1080p', '720p'): sub_format = resolution else: sub_format = 'normale' else: sub_format = video_format.lower() # Look for year params = {'apikey': self.apikey} r = self.session.get(self.server_url + 'shows/' + str(show_id), params=params, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) year = root.find('data/show/started').text if year: year = int(year.split('-', 1)[0]) tvdb_id = root.find('data/show/id_tvdb').text if tvdb_id: tvdb_id = int(tvdb_id) params = { 'apikey': self.apikey, 'show_id': show_id, 'q': '{0}x{1:02}'.format(season, episode), 'version': sub_format } r = self.session.get(self.server_url + 'subtitles/search', params=params, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) if int(root.find('data/count').text) == 0: logger.warning('Subtitles not found, try with rip suffix') params['version'] = sub_format + 'rip' r = self.session.get(self.server_url + 'subtitles/search', params=params, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) if int(root.find('data/count').text) == 0: logger.warning('Subtitles not found, go season mode') # If no subtitle are found for single episode try to download all season zip subs = self._get_season_subtitles(show_id, season, sub_format) if subs: for subtitle in subs: subtitle.format = video_format subtitle.year = year subtitle.tvdb_id = tvdb_id return subs else: return [] # Looking for subtitles in first page for subtitle in root.findall('data/subtitles/subtitle'): if '{0}x{1:02}'.format( season, episode) in subtitle.find('name').text.lower(): logger.debug('Found subtitle id %d - %r - %r', int(subtitle.find('id').text), subtitle.find('name').text, subtitle.find('version').text) sub = ItaSASubtitle(int(subtitle.find('id').text), subtitle.find('show_name').text, season, episode, video_format, year, tvdb_id, subtitle.find('name').text) subtitles.append(sub) # Not in the first page of result try next (if any) next_page = root.find('data/next') while next_page.text is not None: # pragma: no cover r = self.session.get(next_page.text, timeout=30) r.raise_for_status() root = etree.fromstring(r.content) logger.info('Loading subtitles page %r', root.data.page.text) # Looking for show in following pages for subtitle in root.findall('data/subtitles/subtitle'): if '{0}x{1:02}'.format( season, episode) in subtitle.find('name').text.lower(): logger.debug('Found subtitle id %d - %r - %r', int(subtitle.find('id').text), subtitle.find('name').text, subtitle.find('version').text) sub = ItaSASubtitle(int(subtitle.find('id').text), subtitle.find('show_name').text, season, episode, video_format, year, tvdb_id, subtitle.find('name').text) subtitles.append(sub) next_page = root.find('data/next') # Download the subs found, can be more than one in zip additional_subs = [] for sub in subtitles: # open the zip content = self._download_zip(sub.sub_id) if not is_zipfile(io.BytesIO(content)): # pragma: no cover if 'limite di download' in content: raise TooManyRequests() else: raise ConfigurationError( 'Not a zip file: {!r}'.format(content)) with ZipFile(io.BytesIO(content)) as zf: if len(zf.namelist()) > 1: # pragma: no cover for index, name in enumerate(zf.namelist()): if index == 0: # First element sub.content = fix_line_ending(zf.read(name)) sub.full_data = name else: add_sub = copy.deepcopy(sub) add_sub.content = fix_line_ending(zf.read(name)) add_sub.full_data = name additional_subs.append(add_sub) else: sub.content = fix_line_ending(zf.read(zf.namelist()[0])) sub.full_data = zf.namelist()[0] return subtitles + additional_subs
def __init__(self, token=None): if not token: raise ConfigurationError('Token must be specified') self.token = token
def reverse(self, assrt): if assrt in self.from_assrt: return self.from_assrt[assrt] raise ConfigurationError('Unsupported language code for assrt: %s' % assrt)