Пример #1
0
    def test_download_file(self, remove_file_mock, df_mock):
        """
        Test download_result
        """
        domain = "domain"
        filename = "TestFilename.nzb"
        urls = [
            "http://{0}/{1}.torrentNO_DOWNLOAD_NAME".format(domain, filename),
            "http://{0}/{1}.torrent".format(domain, filename),
        ]

        # Test the login() check
        gp1 = GenericProvider("Test Provider 1")
        login_mock = MagicMock()
        login_mock.return_value = False
        with patch.object(gp1, "login", login_mock):
            self.assertFalse(gp1.download_result("result 1"))
            self.assertTrue(login_mock.called)

        # Test the _make_url call
        gp2 = GenericProvider("Test Provider 2")
        make_url_mock = MagicMock()
        make_url_mock.return_value = (urls, filename)
        df_mock.return_value = True
        with patch.object(gp2, "_make_url", make_url_mock):
            resp = gp2.download_result("result 2")
            self.assertTrue(resp)
            self.assertTrue("Referer" in gp2.headers)
            self.assertTrue(domain in gp2.headers["Referer"])
            self.assertTrue(df_mock.called)

        # Test the remove_file_failed path
        gp3 = GenericProvider("Test Provider 3")
        make_url_mock = MagicMock()
        make_url_mock.return_value = (urls, filename)
        verify_download_mock = MagicMock()
        verify_download_mock.return_value = False
        df_mock.return_value = True
        with patch.object(gp3, "_make_url", make_url_mock):
            with patch.object(gp3, "_verify_download", verify_download_mock):
                resp = gp3.download_result("result 3")
                self.assertFalse(resp)
                self.assertTrue(remove_file_mock.called)
Пример #2
0
    def test_download_file(self, remove_file_mock, df_mock):
        """
        Test download_result
        """
        domain = 'domain'
        filename = 'TestFilename.nzb'
        urls = [
            'http://{0}/{1}.torrentNO_DOWNLOAD_NAME'.format(domain, filename),
            'http://{0}/{1}.torrent'.format(domain, filename),
        ]

        # Test the login() check
        gp1 = GenericProvider('Test Provider 1')
        login_mock = MagicMock()
        login_mock.return_value = False
        with patch.object(gp1, 'login', login_mock):
            self.assertFalse(gp1.download_result('result 1'))
            self.assertTrue(login_mock.called)

        # Test the _make_url call
        gp2 = GenericProvider('Test Provider 2')
        make_url_mock = MagicMock()
        make_url_mock.return_value = (urls, filename)
        df_mock.return_value = True
        with patch.object(gp2, '_make_url', make_url_mock):
            resp = gp2.download_result('result 2')
            self.assertTrue(resp)
            self.assertTrue('Referer' in gp2.headers)
            self.assertTrue(domain in gp2.headers['Referer'])
            self.assertTrue(df_mock.called)

        # Test the remove_file_failed path
        gp3 = GenericProvider('Test Provider 3')
        make_url_mock = MagicMock()
        make_url_mock.return_value = (urls, filename)
        verify_download_mock = MagicMock()
        verify_download_mock.return_value = False
        df_mock.return_value = True
        with patch.object(gp3, '_make_url', make_url_mock):
            with patch.object(gp3, '_verify_download', verify_download_mock):
                resp = gp3.download_result('result 3')
                self.assertFalse(resp)
                self.assertTrue(remove_file_mock.called)
Пример #3
0
def sendNZB(nzb, proper=False):
    """
    Sends NZB to NZBGet client

    :param nzb: nzb object
    :param proper: True if this is a Proper download, False if not. Defaults to False
    """
    addToTop = False
    nzbgetprio = 0
    category = sickbeard.NZBGET_CATEGORY
    if nzb.show.is_anime:
        category = sickbeard.NZBGET_CATEGORY_ANIME

    if sickbeard.NZBGET_USE_HTTPS:
        nzbgetXMLrpc = "https://%(username)s:%(password)[email protected]%(host)s/xmlrpc"
    else:
        nzbgetXMLrpc = "http://%(username)s:%(password)[email protected]%(host)s/xmlrpc"

    if sickbeard.NZBGET_HOST is None:
        logger.log(u"No NZBget host found in configuration. Please configure it.", logger.WARNING)
        return False

    url = nzbgetXMLrpc % {"host": sickbeard.NZBGET_HOST, "username": sickbeard.NZBGET_USERNAME,
                          "password": sickbeard.NZBGET_PASSWORD}

    nzbGetRPC = xmlrpclib.ServerProxy(url)
    try:
        if nzbGetRPC.writelog("INFO", "SickRage connected to drop of %s any moment now." % (nzb.name + ".nzb")):
            logger.log(u"Successful connected to NZBget", logger.DEBUG)
        else:
            logger.log(u"Successful connected to NZBget, but unable to send a message", logger.WARNING)

    except httplib.socket.error:
        logger.log(
            u"Please check your NZBget host and port (if it is running). NZBget is not responding to this combination",
            logger.WARNING)
        return False

    except xmlrpclib.ProtocolError as e:
        if e.errmsg == "Unauthorized":
            logger.log(u"NZBget username or password is incorrect.", logger.WARNING)
        else:
            logger.log(u"Protocol Error: " + e.errmsg, logger.ERROR)
        return False

    dupekey = ""
    dupescore = 0
    # if it aired recently make it high priority and generate DupeKey/Score
    for curEp in nzb.episodes:
        if dupekey == "":
            if curEp.show.indexer == 1:
                dupekey = "SickRage-" + str(curEp.show.indexerid)
            elif curEp.show.indexer == 2:
                dupekey = "SickRage-tvr" + str(curEp.show.indexerid)
        dupekey += "-" + str(curEp.season) + "." + str(curEp.episode)
        if datetime.date.today() - curEp.airdate <= datetime.timedelta(days=7):
            addToTop = True
            nzbgetprio = sickbeard.NZBGET_PRIORITY
        else:
            category = sickbeard.NZBGET_CATEGORY_BACKLOG
            if nzb.show.is_anime:
                category = sickbeard.NZBGET_CATEGORY_ANIME_BACKLOG

    if nzb.quality != Quality.UNKNOWN:
        dupescore = nzb.quality * 100
    if proper:
        dupescore += 10

    nzbcontent64 = None
    if nzb.resultType == "nzbdata":
        data = nzb.extraInfo[0]
        nzbcontent64 = standard_b64encode(data)

    logger.log(u"Sending NZB to NZBget")
    logger.log(u"URL: " + url, logger.DEBUG)

    try:
        # Find out if nzbget supports priority (Version 9.0+), old versions beginning with a 0.x will use the old command
        nzbget_version_str = nzbGetRPC.version()
        nzbget_version = try_int(nzbget_version_str[:nzbget_version_str.find(".")])
        if nzbget_version == 0:
            if nzbcontent64 is not None:
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, addToTop, nzbcontent64)
            else:
                if nzb.resultType == "nzb":
                    genProvider = GenericProvider("")
                    data = genProvider.get_url(nzb.url)
                    if data is None:
                        return False
                    nzbcontent64 = standard_b64encode(data)
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, addToTop, nzbcontent64)
        elif nzbget_version == 12:
            if nzbcontent64 is not None:
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, nzbgetprio, False,
                                                 nzbcontent64, False, dupekey, dupescore, "score")
            else:
                nzbget_result = nzbGetRPC.appendurl(nzb.name + ".nzb", category, nzbgetprio, False,
                                                    nzb.url, False, dupekey, dupescore, "score")
        # v13+ has a new combined append method that accepts both (url and content)
        # also the return value has changed from boolean to integer
        # (Positive number representing NZBID of the queue item. 0 and negative numbers represent error codes.)
        elif nzbget_version >= 13:
            nzbget_result = True if nzbGetRPC.append(nzb.name + ".nzb", nzbcontent64 if nzbcontent64 is not None else nzb.url,
                                                     category, nzbgetprio, False, False, dupekey, dupescore,
                                                     "score") > 0 else False
        else:
            if nzbcontent64 is not None:
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, nzbgetprio, False,
                                                 nzbcontent64)
            else:
                nzbget_result = nzbGetRPC.appendurl(nzb.name + ".nzb", category, nzbgetprio, False,
                                                    nzb.url)

        if nzbget_result:
            logger.log(u"NZB sent to NZBget successfully", logger.DEBUG)
            return True
        else:
            logger.log(u"NZBget could not add %s to the queue" % (nzb.name + ".nzb"), logger.WARNING)
            return False
    except Exception:
        logger.log(u"Connect Error to NZBget: could not add %s to the queue" % (nzb.name + ".nzb"), logger.WARNING)
        return False
Пример #4
0
    def test_make_id(self):
        """
        Test make_id
        """
        test_cases = {
            None: "",
            123: "123",
            12.3: "12_3",
            0: "",
            -123: "_123",
            -12.3: "_12_3",
            "": "",
            " ": "",
            "123": "123",
            " 123 ": "123",
            "12.3": "12_3",
            " 12.3 ": "12_3",
            "0": "0",
            " 0 ": "0",
            "-123": "_123",
            " -123 ": "_123",
            "-12.3": "_12_3",
            " -12.3 ": "_12_3",
            "abc": "abc",
            " abc ": "abc",
            "ABC": "abc",
            " ABC ": "abc",
            ".def": "_def",
            "g,hi": "g_hi",
            "jk!l": "jk_l",
            "mno?": "mno_",
            "_pqr$": "_pqr_",
        }

        unicode_test_cases = {
            u"": "",
            u" ": "",
            u"123": "123",
            u" 123 ": "123",
            u"12.3": "12_3",
            u" 12.3 ": "12_3",
            u"0": "0",
            u" 0 ": "0",
            u"-123": "_123",
            u" -123 ": "_123",
            u"-12.3": "_12_3",
            u" -12.3 ": "_12_3",
            u"abc": "abc",
            u" abc ": "abc",
            u"ABC": "abc",
            u" ABC ": "abc",
            u".def": "_def",
            u"g,hi": "g_hi",
            u"jk!l": "jk_l",
            u"mno?": "mno_",
            u"_pqr$": "_pqr_",
        }

        for test in test_cases, unicode_test_cases:
            for (name, result) in test.iteritems():
                self.assertEqual(GenericProvider.make_id(name), result)
Пример #5
0
    def __init__(self, name):
        GenericProvider.__init__(self, name)

        self.provider_type = GenericProvider.TORRENT
Пример #6
0
    def test_make_id(self):
        """
        Test make_id
        """
        test_cases = {
            None: '',
            123: '123',
            12.3: '12_3',
            0: '',
            -123: '_123',
            -12.3: '_12_3',
            '': '',
            ' ': '',
            '123': '123',
            ' 123 ': '123',
            '12.3': '12_3',
            ' 12.3 ': '12_3',
            '0': '0',
            ' 0 ': '0',
            '-123': '_123',
            ' -123 ': '_123',
            '-12.3': '_12_3',
            ' -12.3 ': '_12_3',
            'abc': 'abc',
            ' abc ': 'abc',
            'ABC': 'abc',
            ' ABC ': 'abc',
            '.def': '_def',
            'g,hi': 'g_hi',
            'jk!l': 'jk_l',
            'mno?': 'mno_',
            '_pqr$': '_pqr_',
        }

        unicode_test_cases = {
            u'': '',
            u' ': '',
            u'123': '123',
            u' 123 ': '123',
            u'12.3': '12_3',
            u' 12.3 ': '12_3',
            u'0': '0',
            u' 0 ': '0',
            u'-123': '_123',
            u' -123 ': '_123',
            u'-12.3': '_12_3',
            u' -12.3 ': '_12_3',
            u'abc': 'abc',
            u' abc ': 'abc',
            u'ABC': 'abc',
            u' ABC ': 'abc',
            u'.def': '_def',
            u'g,hi': 'g_hi',
            u'jk!l': 'jk_l',
            u'mno?': 'mno_',
            u'_pqr$': '_pqr_',
        }

        for test in test_cases, unicode_test_cases:
            for (name, result) in test.iteritems():
                self.assertEqual(GenericProvider.make_id(name), result)
Пример #7
0
        data = nzb.extraInfo[0]
        nzbcontent64 = standard_b64encode(data)

    logger.log(u"Sending NZB to NZBget")
    logger.log(u"URL: " + url, logger.DEBUG)

    try:
        # Find out if nzbget supports priority (Version 9.0+), old versions beginning with a 0.x will use the old command
        nzbget_version_str = nzbGetRPC.version()
        nzbget_version = try_int(nzbget_version_str[:nzbget_version_str.find(".")])
        if nzbget_version == 0:
            if nzbcontent64 is not None:
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, addToTop, nzbcontent64)
            else:
                if nzb.resultType == "nzb":
                    genProvider = GenericProvider("")
                    data = genProvider.get_url(nzb.url)
                    if data is None:
                        return False
                    nzbcontent64 = standard_b64encode(data)
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, addToTop, nzbcontent64)
        elif nzbget_version == 12:
            if nzbcontent64 is not None:
                nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, nzbgetprio, False,
                                                 nzbcontent64, False, dupekey, dupescore, "score")
            else:
                nzbget_result = nzbGetRPC.appendurl(nzb.name + ".nzb", category, nzbgetprio, False,
                                                    nzb.url, False, dupekey, dupescore, "score")
        # v13+ has a new combined append method that accepts both (url and content)
        # also the return value has changed from boolean to integer
        # (Positive number representing NZBID of the queue item. 0 and negative numbers represent error codes.)
Пример #8
0
    def __init__(self, name):
        GenericProvider.__init__(self, name)

        self.provider_type = GenericProvider.NZB
        self.torznab = False
Пример #9
0
 def __init__(self, name):
     GenericProvider.__init__(self, name)
     self.ratio = None
     self.provider_type = GenericProvider.DDL