Esempio n. 1
0
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"
Esempio n. 2
0
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":
        filename += ".torrent"
    if any([mylar.USE_UTORRENT, mylar.USE_RTORRENT, mylar.USE_TRANSMISSION,mylar.USE_DELUGE]):
        filepath = os.path.join(mylar.CACHE_DIR, filename)
        logger.fdebug('filename for torrent set to : ' + filepath)
        
    elif mylar.USE_WATCHDIR:
        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"

    cf_cookievalue = None
    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 == 'TPSE':
        url = helpers.torrent_create('TPSE', linkit)

        if url.startswith('https'):
            tpse_referrer = 'https://torrentproject.se/'
        else:
            tpse_referrer = 'http://torrentproject.se/'

        try:
            scraper = cfscrape.create_scraper()
            cf_cookievalue, cf_user_agent = scraper.get_tokens(url)
            headers = {'Accept-encoding': 'gzip',
                       'User-Agent':       cf_user_agent}

        except Exception, e:
            return "fail"

        logger.fdebug('Grabbing torrent from url:' + str(url))

        payload = None
        verify = False
Esempio n. 3
0
    def run(self, forcerss=None):
        with rss_lock:

            #logger.info('[RSS-FEEDS] RSS Feed Check was last run at : ' + str(mylar.SCHED_RSS_LAST))
            firstrun = "no"
            #check the last run of rss to make sure it's not hammering.
            if mylar.SCHED_RSS_LAST is None or mylar.SCHED_RSS_LAST == '' or mylar.SCHED_RSS_LAST == '0' or forcerss == True:
                logger.info('[RSS-FEEDS] RSS Feed Check Initalizing....')
                firstrun = "yes"
                duration_diff = 0
            else:
                tstamp = float(mylar.SCHED_RSS_LAST)
                duration_diff = abs(helpers.utctimestamp() - tstamp) / 60
            #logger.fdebug('[RSS-FEEDS] Duration diff: %s' % duration_diff)
            if firstrun == "no" and duration_diff < int(
                    mylar.CONFIG.RSS_CHECKINTERVAL):
                logger.fdebug(
                    '[RSS-FEEDS] RSS Check has taken place less than the threshold - not initiating at this time.'
                )
                return

            helpers.job_management(write=True,
                                   job='RSS Feeds',
                                   current_run=helpers.utctimestamp(),
                                   status='Running')
            mylar.RSS_STATUS = 'Running'
            #logger.fdebug('[RSS-FEEDS] Updated RSS Run time to : ' + str(mylar.SCHED_RSS_LAST))

            #function for looping through nzbs/torrent feeds
            if mylar.CONFIG.ENABLE_TORRENT_SEARCH:
                logger.info('[RSS-FEEDS] Initiating Torrent RSS Check.')
                if mylar.CONFIG.ENABLE_PUBLIC:
                    logger.info(
                        '[RSS-FEEDS] Initiating Torrent RSS Feed Check on Demonoid / WorldWideTorrents.'
                    )
                    #rsscheck.torrents(pickfeed='3')   #TP.SE RSS Check (has to be page-parsed)
                    rsscheck.torrents(pickfeed='Public'
                                      )  #TPSE = DEM RSS Check + WWT RSS Check
                if mylar.CONFIG.ENABLE_32P:
                    logger.info(
                        '[RSS-FEEDS] Initiating Torrent RSS Feed Check on 32P.'
                    )
                    if mylar.CONFIG.MODE_32P == 0:
                        logger.fdebug(
                            '[RSS-FEEDS] 32P mode set to Legacy mode. Monitoring New Releases feed only.'
                        )
                        if any([
                                mylar.CONFIG.PASSKEY_32P is None,
                                mylar.CONFIG.PASSKEY_32P == '',
                                mylar.CONFIG.RSSFEED_32P is None,
                                mylar.CONFIG.RSSFEED_32P == ''
                        ]):
                            logger.error(
                                '[RSS-FEEDS] Unable to validate information from provided RSS Feed. Verify that the feed provided is a current one.'
                            )
                        else:
                            rsscheck.torrents(pickfeed='1',
                                              feedinfo=mylar.KEYS_32P)
                    else:
                        logger.fdebug(
                            '[RSS-FEEDS] 32P mode set to Auth mode. Monitoring all personal notification feeds & New Releases feed'
                        )
                        if any([
                                mylar.CONFIG.USERNAME_32P is None,
                                mylar.CONFIG.USERNAME_32P == '',
                                mylar.CONFIG.PASSWORD_32P is None
                        ]):
                            logger.error(
                                '[RSS-FEEDS] Unable to sign-on to 32P to validate settings. Please enter/check your username password in the configuration.'
                            )
                        else:
                            if mylar.KEYS_32P is None:
                                feed32p = auth32p.info32p()
                                feedinfo = feed32p.authenticate()
                                if feedinfo != "disable":
                                    pass
                                else:
                                    mylar.CONFIG.ENABLE_32P = 0
                                    #mylar.config_write()
                            else:
                                feedinfo = mylar.FEEDINFO_32P

                            if feedinfo is None or len(
                                    feedinfo) == 0 or feedinfo == "disable":
                                logger.error(
                                    '[RSS-FEEDS] Unable to retrieve any information from 32P for RSS Feeds. Skipping for now.'
                                )
                            else:
                                rsscheck.torrents(pickfeed='1',
                                                  feedinfo=feedinfo[0])
                                x = 0
                                #assign personal feeds for 32p > +8
                                for fi in feedinfo:
                                    x += 1
                                    pfeed_32p = str(7 + x)
                                    rsscheck.torrents(pickfeed=pfeed_32p,
                                                      feedinfo=fi)

            logger.info(
                '[RSS-FEEDS] Initiating RSS Feed Check for NZB Providers.')
            rsscheck.nzbs(forcerss=forcerss)
            logger.info('[RSS-FEEDS] RSS Feed Check/Update Complete')
            logger.info('[RSS-FEEDS] Watchlist Check for new Releases')
            mylar.search.searchforissue(rsscheck='yes')
            logger.info('[RSS-FEEDS] Watchlist Check complete.')
            if forcerss:
                logger.info('[RSS-FEEDS] Successfully ran a forced RSS Check.')
            helpers.job_management(write=True,
                                   job='RSS Feeds',
                                   last_run_completed=helpers.utctimestamp(),
                                   status='Waiting')
            mylar.RSS_STATUS = 'Waiting'
            return True
Esempio n. 4
0
    def run(self, forcerss=None):
        with rss_lock:

            #logger.info('[RSS-FEEDS] RSS Feed Check was last run at : ' + str(mylar.SCHED_RSS_LAST))
            firstrun = "no"
            #check the last run of rss to make sure it's not hammering.
            if mylar.SCHED_RSS_LAST is None or mylar.SCHED_RSS_LAST == '' or mylar.SCHED_RSS_LAST == '0' or forcerss == True:
                logger.info('[RSS-FEEDS] RSS Feed Check Initalizing....')
                firstrun = "yes"
                duration_diff = 0
            else:
                tstamp = float(mylar.SCHED_RSS_LAST)
                duration_diff = abs(helpers.utctimestamp() - tstamp)/60
            #logger.fdebug('[RSS-FEEDS] Duration diff: %s' % duration_diff)
            if firstrun == "no" and duration_diff < int(mylar.CONFIG.RSS_CHECKINTERVAL):
                logger.fdebug('[RSS-FEEDS] RSS Check has taken place less than the threshold - not initiating at this time.')
                return

            helpers.job_management(write=True, job='RSS Feeds', current_run=helpers.utctimestamp(), status='Running')
            mylar.RSS_STATUS = 'Running'
            #logger.fdebug('[RSS-FEEDS] Updated RSS Run time to : ' + str(mylar.SCHED_RSS_LAST))

            #function for looping through nzbs/torrent feeds
            if mylar.CONFIG.ENABLE_TORRENT_SEARCH:
                logger.info('[RSS-FEEDS] Initiating Torrent RSS Check.')
                if mylar.CONFIG.ENABLE_PUBLIC:
                    logger.info('[RSS-FEEDS] Initiating Torrent RSS Feed Check on Demonoid / WorldWideTorrents.')
                    rsscheck.torrents(pickfeed='Public')    #TPSE = DEM RSS Check + WWT RSS Check
                if mylar.CONFIG.ENABLE_32P is True:
                    logger.info('[RSS-FEEDS] Initiating Torrent RSS Feed Check on 32P.')
                    if mylar.CONFIG.MODE_32P == 0:
                        logger.fdebug('[RSS-FEEDS] 32P mode set to Legacy mode. Monitoring New Releases feed only.')
                        if any([mylar.CONFIG.PASSKEY_32P is None, mylar.CONFIG.PASSKEY_32P == '', mylar.CONFIG.RSSFEED_32P is None, mylar.CONFIG.RSSFEED_32P == '']):
                            logger.error('[RSS-FEEDS] Unable to validate information from provided RSS Feed. Verify that the feed provided is a current one.')
                        else:
                            rsscheck.torrents(pickfeed='1', feedinfo=mylar.KEYS_32P)
                    else:
                        logger.fdebug('[RSS-FEEDS] 32P mode set to Auth mode. Monitoring all personal notification feeds & New Releases feed')
                        if any([mylar.CONFIG.USERNAME_32P is None, mylar.CONFIG.USERNAME_32P == '', mylar.CONFIG.PASSWORD_32P is None]):
                            logger.error('[RSS-FEEDS] Unable to sign-on to 32P to validate settings. Please enter/check your username password in the configuration.')
                        else:
                            if mylar.KEYS_32P is None:
                                feed32p = auth32p.info32p()
                                feedinfo = feed32p.authenticate()
                                if feedinfo != "disable":
                                    pass
                                else:
                                    helpers.disable_provider('32P')
                            else:
                                feedinfo = mylar.FEEDINFO_32P

                            if feedinfo is None or len(feedinfo) == 0 or feedinfo == "disable":
                                logger.error('[RSS-FEEDS] Unable to retrieve any information from 32P for RSS Feeds. Skipping for now.')
                            else:
                                rsscheck.torrents(pickfeed='1', feedinfo=feedinfo[0])
                                x = 0
                                #assign personal feeds for 32p > +8
                                for fi in feedinfo:
                                    x+=1
                                    pfeed_32p = str(7 + x)
                                    rsscheck.torrents(pickfeed=pfeed_32p, feedinfo=fi)

            logger.info('[RSS-FEEDS] Initiating RSS Feed Check for NZB Providers.')
            rsscheck.nzbs(forcerss=forcerss)
            logger.info('[RSS-FEEDS] RSS Feed Check/Update Complete')
            logger.info('[RSS-FEEDS] Watchlist Check for new Releases')
            mylar.search.searchforissue(rsscheck='yes')
            logger.info('[RSS-FEEDS] Watchlist Check complete.')
            if forcerss:
                logger.info('[RSS-FEEDS] Successfully ran a forced RSS Check.')
            helpers.job_management(write=True, job='RSS Feeds', last_run_completed=helpers.utctimestamp(), status='Waiting')
            mylar.RSS_STATUS = 'Waiting'
            return True
Esempio n. 5
0
    try:
        scraper = cfscrape.create_scraper()
        if cf_cookievalue:
            r = scraper.get(url, params=payload, cookies=cf_cookievalue, verify=verify, stream=True, headers=headers)
        else:
            r = scraper.get(url, params=payload, verify=verify, stream=True, headers=headers)
        #r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers)

    except Exception, e:
        logger.warn('Error fetching data from %s (%s): %s' % (site, url, e))
        if site == '32P':
            logger.info('[TOR2CLIENT-32P] Retrying with 32P')
            if mylar.MODE_32P == 1:
                
                logger.info('[TOR2CLIENT-32P] 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"
                
                logger.debug('[TOR2CLIENT-32P] Creating CF Scraper')
                scraper = cfscrape.create_scraper()

                logger.debug('[TOR2CLIENT-32P] payload: %s \n verify %s \n headers %s \n', payload, verify, headers)
                
                try:
                    r = scraper.get(url, params=payload, verify=verify, allow_redirects=True)
                except Exception, e:
Esempio n. 6
0
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"
Esempio n. 7
0
    def run(self):

        with rss_lock:

            logger.info('RSS Feed Check was last run at : ' +
                        str(mylar.RSS_LASTRUN))
            firstrun = "no"
            #check the last run of rss to make sure it's not hammering.
            if mylar.RSS_LASTRUN is None or mylar.RSS_LASTRUN == '' or mylar.RSS_LASTRUN == '0' or self.forcerss == True:
                logger.info('RSS Feed Check First Ever Run.')
                firstrun = "yes"
                mins = 0
            else:
                c_obj_date = datetime.datetime.strptime(
                    mylar.RSS_LASTRUN, "%Y-%m-%d %H:%M:%S")
                n_date = datetime.datetime.now()
                absdiff = abs(n_date - c_obj_date)
                mins = (absdiff.days * 24 * 60 * 60 +
                        absdiff.seconds) / 60.0  #3600 is for hours.

            if firstrun == "no" and mins < int(mylar.RSS_CHECKINTERVAL):
                logger.fdebug(
                    'RSS Check has taken place less than the threshold - not initiating at this time.'
                )
                return

            mylar.RSS_LASTRUN = helpers.now()
            logger.fdebug('Updating RSS Run time to : ' +
                          str(mylar.RSS_LASTRUN))
            mylar.config_write()

            #function for looping through nzbs/torrent feeds
            if mylar.ENABLE_TORRENT_SEARCH:
                logger.info('[RSS] Initiating Torrent RSS Check.')
                if mylar.ENABLE_KAT:
                    logger.info(
                        '[RSS] Initiating Torrent RSS Feed Check on KAT.')
                    rsscheck.torrents(pickfeed='3')
                    rsscheck.torrents(pickfeed='6')
                if mylar.ENABLE_32P:
                    logger.info(
                        '[RSS] Initiating Torrent RSS Feed Check on 32P.')
                    if mylar.MODE_32P == 0:
                        logger.fdebug(
                            '[RSS] 32P mode set to Legacy mode. Monitoring New Releases feed only.'
                        )
                        if any([
                                mylar.PASSKEY_32P is None,
                                mylar.PASSKEY_32P == '',
                                mylar.RSSFEED_32P is None,
                                mylar.RSSFEED_32P == ''
                        ]):
                            logger.error(
                                '[RSS] Unable to validate information from provided RSS Feed. Verify that the feed provided is a current one.'
                            )
                        else:
                            rsscheck.torrents(pickfeed='1',
                                              feedinfo=mylar.KEYS_32P)
                    else:
                        logger.fdebug(
                            '[RSS] 32P mode set to Auth mode. Monitoring all personal notification feeds & New Releases feed'
                        )
                        if any([
                                mylar.USERNAME_32P is None,
                                mylar.USERNAME_32P == '',
                                mylar.PASSWORD_32P is None
                        ]):
                            logger.error(
                                '[RSS] Unable to sign-on to 32P to validate settings. Please enter/check your username password in the configuration.'
                            )
                        else:
                            if mylar.KEYS_32P is None:
                                feed32p = auth32p.info32p()
                                feedinfo = feed32p.authenticate()
                            else:
                                feedinfo = mylar.FEEDINFO_32P

                            if feedinfo is None or len(feedinfo) == 0:
                                logger.error(
                                    '[RSS] Unable to retrieve any information from 32P for RSS Feeds. Skipping for now.'
                                )
                            else:
                                rsscheck.torrents(pickfeed='1',
                                                  feedinfo=feedinfo[0])
                                x = 0
                                #assign personal feeds for 32p > +8
                                for fi in feedinfo:
                                    x += 1
                                    pfeed_32p = str(7 + x)
                                    rsscheck.torrents(pickfeed=pfeed_32p,
                                                      feedinfo=fi)

            logger.info('[RSS] Initiating RSS Feed Check for NZB Providers.')
            rsscheck.nzbs(forcerss=self.forcerss)
            logger.info('[RSS] RSS Feed Check/Update Complete')
            logger.info('[RSS] Watchlist Check for new Releases')
            mylar.search.searchforissue(rsscheck='yes')
            logger.info('[RSS] Watchlist Check complete.')
            if self.forcerss:
                logger.info('[RSS] Successfully ran a forced RSS Check.')
            return
Esempio n. 8
0
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":
        filename += ".torrent"
    if any([mylar.USE_UTORRENT, mylar.USE_RTORRENT, mylar.USE_TRANSMISSION, mylar.USE_DELUGE, mylar.USE_QBITTORRENT]):
        filepath = os.path.join(mylar.CACHE_DIR, filename)
        logger.fdebug('filename for torrent set to : ' + filepath)
        
    elif mylar.USE_WATCHDIR:
        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"

    cf_cookievalue = None
    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 == 'TPSE':
        url = helpers.torrent_create('TPSE', linkit)

        if url.startswith('https'):
            tpse_referrer = 'https://torrentproject.se/'
        else:
            tpse_referrer = 'http://torrentproject.se/'

        try:
            scraper = cfscrape.create_scraper()
            cf_cookievalue, cf_user_agent = scraper.get_tokens(url)
            headers = {'Accept-encoding': 'gzip',
                       'User-Agent':       cf_user_agent}

        except Exception, e:
            return "fail"

        logger.fdebug('Grabbing torrent from url:' + str(url))

        payload = None
        verify = False
Esempio n. 9
0
    try:
        scraper = cfscrape.create_scraper()
        if cf_cookievalue:
            r = scraper.get(url, params=payload, cookies=cf_cookievalue, verify=verify, stream=True, headers=headers)
        else:
            r = scraper.get(url, params=payload, verify=verify, stream=True, headers=headers)
        #r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers)

    except Exception, e:
        logger.warn('Error fetching data from %s (%s): %s' % (site, url, e))
        if site == '32P':
            logger.info('[TOR2CLIENT-32P] Retrying with 32P')
            if mylar.MODE_32P == 1:
                
                logger.info('[TOR2CLIENT-32P] 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"
                
                logger.debug('[TOR2CLIENT-32P] Creating CF Scraper')
                scraper = cfscrape.create_scraper()

                logger.debug('[TOR2CLIENT-32P] payload: %s \n verify %s \n headers %s \n', payload, verify, headers)
                
                try:
                    r = scraper.get(url, params=payload, verify=verify, allow_redirects=True)
                except Exception, e:
Esempio n. 10
0
    def run(self):

        with rss_lock:

            logger.info('RSS Feed Check was last run at : ' + str(mylar.RSS_LASTRUN))
            firstrun = "no"
            #check the last run of rss to make sure it's not hammering.
            if mylar.RSS_LASTRUN is None or mylar.RSS_LASTRUN == '' or mylar.RSS_LASTRUN == '0' or self.forcerss == True:
                logger.info('RSS Feed Check First Ever Run.')
                firstrun = "yes"
                mins = 0
            else:
                c_obj_date = datetime.datetime.strptime(mylar.RSS_LASTRUN, "%Y-%m-%d %H:%M:%S")
                n_date = datetime.datetime.now()
                absdiff = abs(n_date - c_obj_date)
                mins = (absdiff.days * 24 * 60 * 60 + absdiff.seconds) / 60.0  #3600 is for hours.

            if firstrun == "no" and mins < int(mylar.RSS_CHECKINTERVAL):
                logger.fdebug('RSS Check has taken place less than the threshold - not initiating at this time.')
                return

            mylar.RSS_LASTRUN = helpers.now()
            logger.fdebug('Updating RSS Run time to : ' + str(mylar.RSS_LASTRUN))
            mylar.config_write()

            #function for looping through nzbs/torrent feeds
            if mylar.ENABLE_TORRENT_SEARCH:
                logger.info('[RSS] Initiating Torrent RSS Check.')
                if mylar.ENABLE_KAT:
                    logger.info('[RSS] Initiating Torrent RSS Feed Check on KAT.')
                    rsscheck.torrents(pickfeed='3')
                    rsscheck.torrents(pickfeed='6')
                if mylar.ENABLE_32P:
                    logger.info('[RSS] Initiating Torrent RSS Feed Check on 32P.')
                    if mylar.MODE_32P == 0:
                        logger.fdebug('[RSS] 32P mode set to Legacy mode. Monitoring New Releases feed only.')
                        if any([mylar.PASSKEY_32P is None, mylar.PASSKEY_32P == '', mylar.RSSFEED_32P is None, mylar.RSSFEED_32P == '']):
                            logger.error('[RSS] Unable to validate information from provided RSS Feed. Verify that the feed provided is a current one.')
                        else:
                            rsscheck.torrents(pickfeed='1', feedinfo=mylar.KEYS_32P)
                    else:
                        logger.fdebug('[RSS] 32P mode set to Auth mode. Monitoring all personal notification feeds & New Releases feed')
                        if any([mylar.USERNAME_32P is None, mylar.USERNAME_32P == '', mylar.PASSWORD_32P is None]):
                            logger.error('[RSS] Unable to sign-on to 32P to validate settings. Please enter/check your username password in the configuration.')
                        else:
                            if mylar.KEYS_32P is None:
                                feed32p = auth32p.info32p()
                                feedinfo = feed32p.authenticate()
                                if feedinfo == "disable":
                                    mylar.ENABLE_32P = 0
                                    mylar.config_write()
                            else:
                                feedinfo = mylar.FEEDINFO_32P

                            if feedinfo is None or len(feedinfo) == 0 or feedinfo == "disable":
                                logger.error('[RSS] Unable to retrieve any information from 32P for RSS Feeds. Skipping for now.')
                            else:
                                rsscheck.torrents(pickfeed='1', feedinfo=feedinfo[0])
                                x = 0
                                #assign personal feeds for 32p > +8
                                for fi in feedinfo:
                                    x+=1
                                    pfeed_32p = str(7 + x)
                                    rsscheck.torrents(pickfeed=pfeed_32p, feedinfo=fi)

            logger.info('[RSS] Initiating RSS Feed Check for NZB Providers.')
            rsscheck.nzbs(forcerss=self.forcerss)
            logger.info('[RSS] RSS Feed Check/Update Complete')
            logger.info('[RSS] Watchlist Check for new Releases')
            mylar.search.searchforissue(rsscheck='yes')
            logger.info('[RSS] Watchlist Check complete.')
            if self.forcerss:
                logger.info('[RSS] Successfully ran a forced RSS Check.')
            return