def torsend2client(seriesname, issue, seriesyear, linkit, site): logger.info('matched on ' + seriesname) filename = helpers.filesafe(seriesname) filename = re.sub(' ', '_', filename) filename += "_" + str(issue) + "_" + str(seriesyear) if linkit[-7:] != "torrent": # and site != "KAT": filename += ".torrent" if mylar.TORRENT_LOCAL and mylar.LOCAL_WATCHDIR is not None: filepath = os.path.join(mylar.LOCAL_WATCHDIR, filename) logger.fdebug('filename for torrent set to : ' + filepath) elif mylar.TORRENT_SEEDBOX and mylar.SEEDBOX_WATCHDIR is not None: filepath = os.path.join(mylar.CACHE_DIR, filename) logger.fdebug('filename for torrent set to : ' + filepath) else: logger.error( 'No Local Watch Directory or Seedbox Watch Directory specified. Set it and try again.' ) return "fail" if site == '32P': url = 'https://32pag.es/torrents.php' if mylar.VERIFY_32P == 1 or mylar.VERIFY_32P == True: verify = True else: verify = False logger.fdebug('[32P] Verify SSL set to : ' + str(verify)) if mylar.MODE_32P == 0: if mylar.KEYS_32P is None or mylar.PASSKEY_32P is None: logger.warn( '[32P] Unable to retrieve keys from provided RSS Feed. Make sure you have provided a CURRENT RSS Feed from 32P' ) mylar.KEYS_32P = helpers.parse_32pfeed(mylar.FEED_32P) if mylar.KEYS_32P is None or mylar.KEYS_32P == '': return "fail" else: logger.fdebug( '[32P-AUTHENTICATION] 32P (Legacy) Authentication Successful. Re-establishing keys.' ) mylar.AUTHKEY_32P = mylar.KEYS_32P['authkey'] else: logger.fdebug( '[32P-AUTHENTICATION] 32P (Legacy) Authentication already done. Attempting to use existing keys.' ) mylar.AUTHKEY_32P = mylar.KEYS_32P['authkey'] else: if any([ mylar.USERNAME_32P is None, mylar.USERNAME_32P == '', mylar.PASSWORD_32P is None, mylar.PASSWORD_32P == '' ]): logger.error( '[RSS] Unable to sign-on to 32P to validate settings and initiate download sequence. Please enter/check your username password in the configuration.' ) return "fail" elif mylar.PASSKEY_32P is None or mylar.AUTHKEY_32P is None or mylar.KEYS_32P is None: logger.fdebug( '[32P-AUTHENTICATION] 32P (Auth Mode) Authentication enabled. Keys have not been established yet, attempting to gather.' ) feed32p = auth32p.info32p(reauthenticate=True) feedinfo = feed32p.authenticate() if feedinfo == "disable": mylar.ENABLE_32P = 0 mylar.config_write() return "fail" if mylar.PASSKEY_32P is None or mylar.AUTHKEY_32P is None or mylar.KEYS_32P is None: logger.error( '[RSS] Unable to sign-on to 32P to validate settings and initiate download sequence. Please enter/check your username password in the configuration.' ) return "fail" else: logger.fdebug( '[32P-AUTHENTICATION] 32P (Auth Mode) Authentication already done. Attempting to use existing keys.' ) payload = { 'action': 'download', 'torrent_pass': mylar.PASSKEY_32P, 'authkey': mylar.AUTHKEY_32P, 'id': linkit } headers = None #{'Accept-encoding': 'gzip', # 'User-Agent': str(mylar.USER_AGENT)} elif site == 'KAT': #stfind = linkit.find('?') #if stfind == -1: # kat_referrer = helpers.torrent_create('KAT', linkit) #else: # kat_referrer = linkit[:stfind] url = helpers.torrent_create('KAT', linkit) if url.startswith('https'): kat_referrer = 'https://torcache.net/' else: kat_referrer = 'http://torcache.net/' #logger.fdebug('KAT Referer set to :' + kat_referrer) headers = { 'Accept-encoding': 'gzip', 'User-Agent': str(mylar.USER_AGENT), 'Referer': kat_referrer } logger.fdebug('Grabbing torrent from url:' + str(url)) payload = None verify = False else: headers = { 'Accept-encoding': 'gzip', 'User-Agent': str(mylar.USER_AGENT) } #'Referer': kat_referrer} url = linkit #helpers.torrent_create('TOR', linkit) payload = None verify = False if not verify: #32P throws back an insecure warning because it can't validate against the CA. The below suppresses the message just for 32P instead of being displayed. #disable SSL warnings - too many 'warning' messages about invalid certificates try: from lib.requests.packages.urllib3 import disable_warnings disable_warnings() except ImportError: #this is probably not necessary and redudant, but leaving in for the time being. from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings() try: from urllib3.exceptions import InsecureRequestWarning urllib3.disable_warnings() except ImportError: logger.warn('[EPIC FAILURE] Cannot load the requests module') return "fail" try: r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers) except Exception, e: logger.warn('Error fetching data from %s: %s' % (site, e)) if site == '32P': if mylar.MODE_32P == 1: logger.info( 'Attempting to re-authenticate against 32P and poll new keys as required.' ) feed32p = auth32p.info32p(reauthenticate=True) feedinfo = feed32p.authenticate() if feedinfo == "disable": mylar.ENABLE_32P = 0 mylar.config_write() return "fail" try: r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers) except Exception, e: logger.warn('Error fetching data from %s: %s' % (site, e)) return "fail" else: logger.warn( '[32P] Unable to authenticate using existing RSS Feed given. Make sure that you have provided a CURRENT feed from 32P' ) return "fail"
def request(self, host, handler, request_body, verbose=0): """Replace the xmlrpc request function. Process xmlrpc request via requests library. Args: host: Target host handler: Target PRC handler. request_body: XML-RPC request body. verbose: Debugging flag. Returns: Parsed response. Raises: RequestException: Error in requests """ if verbose: self._debug() if not self._check_ssl_cert: disable_warnings() headers = {'User-Agent': self.user_agent, 'Content-Type': 'text/xml', } # Need to be done because the schema(http or https) is lost in # xmlrpc.Transport's init. if self._use_https: url = "https://{host}/{handler}".format(host=host, handler=handler) else: url = "http://{host}/{handler}".format(host=host, handler=handler) # TODO Construct kwargs query instead try: if self._authtype == "basic": response = requests.post( url, data=request_body, headers=headers, verify=self._check_ssl_cert, auth=HTTPBasicAuth( self._username, self._password), proxies=self._proxies) elif self._authtype == "digest": response = requests.post( url, data=request_body, headers=headers, verify=self._check_ssl_cert, auth=HTTPDigestAuth( self._username, self._password), proxies=self._proxies) else: response = requests.post( url, data=request_body, headers=headers, verify=self._check_ssl_cert, proxies=self._proxies) response.raise_for_status() except RequestException as error: raise xmlrpc_client.ProtocolError(url, error.message, traceback.format_exc(), response.headers) return self.parse_response(response)
def torsend2client(seriesname, issue, seriesyear, linkit, site): logger.info('matched on ' + seriesname) filename = helpers.filesafe(seriesname) filename = re.sub(' ', '_', filename) filename += "_" + str(issue) + "_" + str(seriesyear) if linkit[-7:] != "torrent": # and site != "KAT": filename += ".torrent" if mylar.TORRENT_LOCAL and mylar.LOCAL_WATCHDIR is not None: filepath = os.path.join(mylar.LOCAL_WATCHDIR, filename) logger.fdebug('filename for torrent set to : ' + filepath) elif mylar.TORRENT_SEEDBOX and mylar.SEEDBOX_WATCHDIR is not None: filepath = os.path.join(mylar.CACHE_DIR, filename) logger.fdebug('filename for torrent set to : ' + filepath) else: logger.error('No Local Watch Directory or Seedbox Watch Directory specified. Set it and try again.') return "fail" if site == '32P': url = 'https://32pag.es/torrents.php' if mylar.VERIFY_32P == 1 or mylar.VERIFY_32P == True: verify = True else: verify = False logger.fdebug('[32P] Verify SSL set to : ' + str(verify)) if mylar.MODE_32P == 0: if mylar.KEYS_32P is None or mylar.PASSKEY_32P is None: logger.warn('[32P] Unable to retrieve keys from provided RSS Feed. Make sure you have provided a CURRENT RSS Feed from 32P') mylar.KEYS_32P = helpers.parse_32pfeed(mylar.FEED_32P) if mylar.KEYS_32P is None or mylar.KEYS_32P == '': return "fail" else: logger.fdebug('[32P-AUTHENTICATION] 32P (Legacy) Authentication Successful. Re-establishing keys.') mylar.AUTHKEY_32P = mylar.KEYS_32P['authkey'] else: logger.fdebug('[32P-AUTHENTICATION] 32P (Legacy) Authentication already done. Attempting to use existing keys.') mylar.AUTHKEY_32P = mylar.KEYS_32P['authkey'] else: if any([mylar.USERNAME_32P is None, mylar.USERNAME_32P == '', mylar.PASSWORD_32P is None, mylar.PASSWORD_32P == '']): logger.error('[RSS] Unable to sign-on to 32P to validate settings and initiate download sequence. Please enter/check your username password in the configuration.') return "fail" elif mylar.PASSKEY_32P is None or mylar.AUTHKEY_32P is None or mylar.KEYS_32P is None: logger.fdebug('[32P-AUTHENTICATION] 32P (Auth Mode) Authentication enabled. Keys have not been established yet, attempting to gather.') feed32p = auth32p.info32p(reauthenticate=True) feedinfo = feed32p.authenticate() if feedinfo == "disable": mylar.ENABLE_32P = 0 mylar.config_write() return "fail" if mylar.PASSKEY_32P is None or mylar.AUTHKEY_32P is None or mylar.KEYS_32P is None: logger.error('[RSS] Unable to sign-on to 32P to validate settings and initiate download sequence. Please enter/check your username password in the configuration.') return "fail" else: logger.fdebug('[32P-AUTHENTICATION] 32P (Auth Mode) Authentication already done. Attempting to use existing keys.') payload = {'action': 'download', 'torrent_pass': mylar.PASSKEY_32P, 'authkey': mylar.AUTHKEY_32P, 'id': linkit} headers = None #{'Accept-encoding': 'gzip', # 'User-Agent': str(mylar.USER_AGENT)} elif site == 'KAT': #stfind = linkit.find('?') #if stfind == -1: # kat_referrer = helpers.torrent_create('KAT', linkit) #else: # kat_referrer = linkit[:stfind] url = helpers.torrent_create('KAT', linkit) if url.startswith('https'): kat_referrer = 'https://torcache.net/' else: kat_referrer = 'http://torcache.net/' #logger.fdebug('KAT Referer set to :' + kat_referrer) headers = {'Accept-encoding': 'gzip', 'User-Agent': str(mylar.USER_AGENT), 'Referer': kat_referrer} logger.fdebug('Grabbing torrent from url:' + str(url)) payload = None verify = False else: headers = {'Accept-encoding': 'gzip', 'User-Agent': str(mylar.USER_AGENT)} #'Referer': kat_referrer} url = linkit #helpers.torrent_create('TOR', linkit) payload = None verify = False if not verify: #32P throws back an insecure warning because it can't validate against the CA. The below suppresses the message just for 32P instead of being displayed. #disable SSL warnings - too many 'warning' messages about invalid certificates try: from lib.requests.packages.urllib3 import disable_warnings disable_warnings() except ImportError: #this is probably not necessary and redudant, but leaving in for the time being. from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings() try: from urllib3.exceptions import InsecureRequestWarning urllib3.disable_warnings() except ImportError: logger.warn('[EPIC FAILURE] Cannot load the requests module') return "fail" try: r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers) except Exception, e: logger.warn('Error fetching data from %s: %s' % (site, e)) if site == '32P': if mylar.MODE_32P == 1: logger.info('Attempting to re-authenticate against 32P and poll new keys as required.') feed32p = auth32p.info32p(reauthenticate=True) feedinfo = feed32p.authenticate() if feedinfo == "disable": mylar.ENABLE_32P = 0 mylar.config_write() return "fail" try: r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers) except Exception, e: logger.warn('Error fetching data from %s: %s' % (site, e)) return "fail" else: logger.warn('[32P] Unable to authenticate using existing RSS Feed given. Make sure that you have provided a CURRENT feed from 32P') return "fail"
"""CacheControl import Interface. Make it easy to import from cachecontrol without long namespaces. """ from .wrapper import CacheControl from .adapter import CacheControlAdapter from .controller import CacheController from lib.requests.packages import urllib3 urllib3.disable_warnings()