def check_auth_from_data(self, data): if data is None: return self._check_auth() if 'error' in data.feed: code = data.feed['error']['code'] if '100' == code: raise AuthException( 'Your API key for %s is incorrect, check your config.' % self.name) elif '101' == code: raise AuthException( 'Your account on %s has been suspended, contact the admin.' % self.name) elif '102' == code: raise AuthException( 'Your account isn\'t allowed to use the API on %s, contact the admin.' % self.name) elif '910' == code: logger.log( u'%s currently has their API disabled, please check with provider.' % self.name, logger.WARNING) else: logger.log( u'Unknown error given from %s: %s' % (self.name, data.feed['error']['description']), logger.ERROR) return False return True
def _check_auth_from_data(self, data, url): if data is None or not hasattr(data, 'tag'): return False if 'error' == data.tag: code = data.get('code', '') description = data.get('description', '') if '100' == code: raise AuthException('Your API key for %s is incorrect, check your config.' % self.name) elif '101' == code: raise AuthException('Your account on %s has been suspended, contact the admin.' % self.name) elif '102' == code: raise AuthException('Your account isn\'t allowed to use the API on %s, contact the admin.' % self.name) elif '500' == code: try: retry_time, unit = re.findall(r'Retry in (\d+)\W+([a-z]+)', description, flags=re.I)[0] except IndexError: retry_time, unit = None, None self.tmr_limit_update(retry_time, unit, description) self.log_failure_url(url) elif '910' == code: logger.log( '%s %s, please check with provider.' % (self.name, ('currently has their API disabled', description)[description not in (None, '')]), logger.WARNING) else: logger.log('Unknown error given from %s: %s' % (self.name, data.get('description', '')), logger.WARNING) return False self.tmr_limit_count = 0 return True
def check_auth_from_data(self, data): if data is None or not hasattr(data, 'tag'): return False if 'error' == data.tag: code = data.get('code', '') description = data.get('description', '') if '100' == code: raise AuthException( 'Your API key for %s is incorrect, check your config.' % self.name) elif '101' == code: raise AuthException( 'Your account on %s has been suspended, contact the admin.' % self.name) elif '102' == code: raise AuthException( 'Your account isn\'t allowed to use the API on %s, contact the admin.' % self.name) elif '910' == code: logger.log( '%s %s, please check with provider.' % (self.name, ('currently has their API disabled', description)[description not in (None, '')]), logger.WARNING) else: logger.log( 'Unknown error given from %s: %s' % (self.name, data.get('description', '')), logger.ERROR) return False return True
def _checkAuthFromData(self, data): try: data['feed'] data['entries'] except: return self._checkAuth() try: err_code = int(data['feed']['error']['code']) err_desc = data['feed']['error']['description'] if not err_code or err_desc: raise except: return True if err_code == 100: raise AuthException("Your API key for " + self.name + " is incorrect, check your config.") elif err_code == 101: raise AuthException( "Your account on " + self.name + " has been suspended, contact the administrator.") elif err_code == 102: raise AuthException( "Your account isn't allowed to use the API on " + self.name + ", contact the administrator") else: logger.log( u"Unknown error given from " + self.name + ": " + err_desc, logger.ERROR)
def _checkAuthFromData(self, parsedXML): if parsedXML is None: return self._checkAuth() if parsedXML.tag == 'error': code = parsedXML.attrib['code'] if code == '100': raise AuthException("Your API key for " + self.name + " is incorrect, check your config.") elif code == '101': raise AuthException( "Your account on " + self.name + " has been suspended, contact the administrator.") elif code == '102': raise AuthException( "Your account isn't allowed to use the API on " + self.name + ", contact the administrator") else: logger.log( u"Unknown error given from " + self.name + ": " + parsedXML.attrib['description'], logger.ERROR) return False return True
def _authorised_html(self): if self.username and self.password: return super(BTNProvider, self)._authorised( post_params={'login': '******'}, logged_in=(lambda y='': 'casThe' in y[0:512] and '<title>Index' in y[0:512])) raise AuthException('Password or Username for %s is empty in config provider options' % self.name)
def updateCache(self): # delete anything older then 7 days logger.log(u"Clearing " + self.provider.name + " cache") self._clearCache() if not self.shouldUpdate(): return if self._checkAuth(None): data = self._getRSSData() # as long as the http request worked we count this as an update if data: self.setLastUpdate() else: return [] if self._checkAuth(data): items = data.entries ql = [] for item in items: ci = self._parseItem(item) if ci is not None: ql.append(ci) myDB = self._getDB() myDB.mass_action(ql) else: raise AuthException(u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config") return []
def _check_auth(self, **kwargs): if not self.api_key and not (self.username and self.password): raise AuthException( 'Must set Api key or Username/Password for %s in config provider options' % self.name) return True
def _checkAuth(self): if not sickbeard.TVTORRENTS_DIGEST or not sickbeard.TVTORRENTS_HASH: raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True
def _checkAuth(self): if not self.digest or not self.hash: raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True
def updateCache(self): if self.shouldUpdate() and self._checkAuth(None): data = self._getRSSData() # as long as the http request worked we count this as an update if not data: return [] self.setLastUpdate() # clear cache self._clearCache() if self._checkAuth(data): items = data.entries cl = [] for item in items: ci = self._parseItem(item) if ci is not None: cl.append(ci) if len(cl) > 0: myDB = self._getDB() myDB.mass_action(cl) else: raise AuthException(u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config") return []
def _checkAuthFromData(self, parsed_data, is_XML=True): if parsed_data is None: return self._checkAuth() if is_XML: # provider doesn't return xml on error return True else: parsedJSON = parsed_data if 'notice' in parsedJSON: description_text = parsedJSON.get('notice') if 'information is incorrect' in parsedJSON.get('notice'): logger.log( u"Incorrect authentication credentials for " + self.name + " : " + str(description_text), logger.DEBUG) raise AuthException( "Your authentication credentials for " + self.name + " are incorrect, check your config.") elif '0 results matched your terms' in parsedJSON.get( 'notice'): return True else: logger.log( u"Unknown error given from " + self.name + " : " + str(description_text), logger.DEBUG) return False return True
def updateCache(self): if not self.shouldUpdate(): return if self._checkAuth(None): data = self._getRSSData() # As long as we got something from the provider we count it as an update if data: self.setLastUpdate() else: return [] logger.log(u"Clearing " + self.provider.name + " cache and updating with new information") self._clearCache() if self._checkAuth(data): # By now we know we've got data and no auth errors, all we need to do is put it in the database for item in data: self._parseItem(item) else: raise AuthException("Your authentication info for " + self.provider.name + " is incorrect, check your config") else: return []
def updateCache(self): if self.shouldUpdate() and self._checkAuth(None): # as long as the http request worked we count this as an update data = self._getDailyData() if not data: return [] # clear cache self._clearCache() # set updated self.setLastUpdate() # parse data if self._checkAuth(data): cl = [] for item in data: title, url = self.provider._get_title_and_url(item) ci = self._parseItem(title, url) if ci is not None: cl.append(ci) if len(cl) > 0: myDB = self._getDB() myDB.mass_action(cl) else: raise AuthException(u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config") return []
def _check_auth_from_data(self, data_json): if 'error' not in data_json: return True logger.log(u'Incorrect authentication credentials for %s : %s' % (self.name, data_json['error']), logger.DEBUG) raise AuthException('Authentication credentials for %s are incorrect, check your config' % self.name)
def _check_auth_from_data(self, parsed_data, is_xml=True): if parsed_data is None: return self._check_auth() if is_xml: # provider doesn't return xml on error return True else: data_json = parsed_data if 'notice' in data_json: description_text = data_json.get('notice') if 'information is incorrect' in data_json.get('notice'): logger.log( u'Incorrect authentication credentials for ' + self.name + ' : ' + str(description_text), logger.DEBUG) raise AuthException( 'Your authentication credentials for ' + self.name + ' are incorrect, check your config.') elif '0 results matched your terms' in data_json.get('notice'): return True else: logger.log( u'Unknown error given from ' + self.name + ' : ' + str(description_text), logger.DEBUG) return False return True
def _checkAuth(self): if not sickbeard.HDBITS_USERNAME or not sickbeard.HDBITS_PASSKEY: raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True
def _checkAuth(self): if self.needs_auth and not self.key: logger.log(u"Incorrect authentication credentials for " + self.name + " : " + "API key is missing", logger.DEBUG) raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True
def updateCache(self): if not self.shouldUpdate(): return if self._checkAuth(None): data = self._getRSSData() # as long as the http request worked we count this as an update if data: self.setLastUpdate() else: return [] # now that we've loaded the current RSS feed lets delete the old cache logger.log(u"Clearing " + self.provider.name + " cache and updating with new information") self._clearCache() if self._checkAuth(data): items = data.entries cl = [] for item in items: ci = self._parseItem(item) if ci is not None: cl.append(ci) if len(cl) > 0: myDB = self._getDB() myDB.mass_action(cl) else: raise AuthException( u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config") return []
def _check_auth(self, is_required=False): if hasattr(self, 'username') and hasattr(self, 'password'): if self.username and self.password: return True setting = 'Password or Username' elif hasattr(self, 'username') and hasattr(self, 'api_key'): if self.username and self.api_key: return True setting = 'Apikey or Username' elif hasattr(self, 'username') and hasattr(self, 'passkey'): if self.username and self.passkey: return True setting = 'Passkey or Username' elif hasattr(self, 'uid') and hasattr(self, 'passkey'): if self.uid and self.passkey: return True setting = 'Passkey or uid' elif hasattr(self, 'api_key'): if self.api_key: return True setting = 'Apikey' elif hasattr(self, 'passkey'): if self.passkey: return True setting = 'Passkey' else: return not is_required and GenericProvider._check_auth(self) raise AuthException('%s for %s is empty in config provider options' % (setting, self.name))
def _checkAuth(self): if not self.username or not self.api_key: raise AuthException("Your authentication credentials for " + self.name + " are missing, check your config.") return True
def _checkAuthFromData(self, data): if not self.passkey: self._checkAuth() elif not (data['entries'] and data['feed']): logger.log(u"Incorrect authentication credentials for " + self.name, logger.DEBUG) raise AuthException( u"Your authentication credentials for " + self.name + " are incorrect, check your config") return True
def updateCache(self): if not self.shouldUpdate(): return if self._checkAuth(None): data = self._getRSSData() # as long as the http request worked we count this as an update if data: self.setLastUpdate() else: return [] # now that we've loaded the current RSS feed lets delete the old cache logger.log(u"Clearing " + self.provider.name + " cache and updating with new information") self._clearCache() try: parsedXML, n_spaces = self.parse_and_get_ns(data) items = parsedXML.findall('.//item') except Exception, e: logger.log( u"Error trying to load " + self.provider.name + " RSS feed: " + ex(e), logger.ERROR) logger.log(u"Feed contents: " + repr(data), logger.DEBUG) return [] if parsedXML is None: logger.log( u"Error trying to load " + self.provider.name + " RSS feed", logger.ERROR) return [] if self._checkAuth(parsedXML): if parsedXML.tag != 'rss': logger.log( u"Resulting XML from " + self.provider.name + " isn't RSS, not parsing it", logger.ERROR) return [] ql = [] for item in items: ci = self._parseItem(item, n_spaces) if ci is not None: ql.append(ci) myDB = self._getDB() myDB.mass_action(ql) else: raise AuthException(u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config")
def _checkAuthFromData(self, data): if data is None: return self._checkAuth() if 'error' in data.feed: logger.log(u"Newznab ERROR:[%s] CODE:[%s]" % (data.feed['error']['description'], data.feed['error']['code']), logger.DEBUG) raise AuthException("%s" % data.feed['error']['description']) return True
def _check_auth(self, is_required=None): has_key = self.maybe_apikey() if has_key: return has_key if None is has_key: raise AuthException('%s for %s is empty in config provider options' % ('API key' + ('', ' and/or Username')[hasattr(self, 'username')], self.name)) return GenericProvider._check_auth(self)
def _checkAuthFromData(self, parsedJSON): if 'status' in parsedJSON and 'message' in parsedJSON: if parsedJSON.get('status') == 5: logger.log(u"Incorrect authentication credentials for " + self.name + " : " + parsedJSON['message'], logger.DEBUG) raise AuthException( "Your authentication credentials for " + self.name + " are incorrect, check your config.") return True
def _checkAuthFromData(self, parsedJSON): if parsedJSON is None: return self._checkAuth() if 'api-error' in parsedJSON: logger.log(u"Incorrect authentication credentials for " + self.name + " : " + parsedJSON['api-error'], logger.DEBUG) raise AuthException("Your authentication credentials for " + self.name + " are incorrect, check your config.") return True
def _checkAuthFromData(self, data): if data is None: return self._checkAuth() if 'status' in data: if data.status in [200, 301]: return True if data.status == 100: raise AuthException("Your API key for " + self.name + " is incorrect, check your config.") elif data.status == 101: raise AuthException("Your account on " + self.name + " has been suspended, contact the administrator.") elif data.status == 102: raise AuthException( "Your account isn't allowed to use the API on " + self.name + ", contact the administrator") else: logger.log(u"Unknown error given from " + self.name + ": " + data.feed.title, logger.ERROR) return False return True
def _checkAuthFromData(self, data): if 'error' in data: logger.log( u'Incorrect authentication credentials for ' + self.name + ' : ' + data['error'], logger.DEBUG) raise AuthException('Your authentication credentials for ' + self.name + ' are incorrect, check your config.') return True
def _checkAuthFromData(self, parsedXML): if parsedXML is None: return self._checkAuth() description_text = helpers.get_xml_text(parsedXML.find('.//channel/item/description')) if "Your RSS key is invalid" in description_text: logger.log(u"Incorrect authentication credentials for " + self.name + " : " + str(description_text), logger.DEBUG) raise AuthException(u"Your authentication credentials for " + self.name + " are incorrect, check your config") return True