Exemple #1
0
            def sl_button_clicked(ctrl):
                saved_log = torrent_scraper.logger.log
                null_func = lambda _, __, ___: None

                torrent_scraper.logger.log = null_func

                saved_stdout = sys.stdout
                sys.stdout = io.StringIO()

                uri_extractor = r'urn\:btih\:([^&]+)'
                magnet_uri = re.findall(uri_extractor, hash)
                if not magnet_uri:
                    return
                magnet_uri = magnet_uri[0]
                try:
                    _, s, l, __ = torrent_scraper.scrape(
                        magnet_uri, 'tracker.coppersurfer.tk', 6969)
                except ValueError:
                    torrent_scraper.logger.log = saved_log
                    return

                self.ui.torrentBox.removeCellWidget(
                    row, self.ui.torrentBox.column_sl)
                self.ui.torrentBox.setItem(row, self.ui.torrentBox.column_sl,
                                           QTableWidgetItem(f'{s} / {l}'))
                torrent_scraper.logger.log = saved_log
                sys.stdout = saved_stdout
    def test_scraper_infohash_error(self):
        f = open('bad_infohashes.txt', 'rb')

        content = f.readlines()

        for infohash in content:
            infohash = infohash.decode('utf-8')
            infohash = infohash.strip()
            error = scraper.scrape(infohash, "tracker.coppersurfer.tk", 6969)
            self.assertEqual(error, "Invalid infohash {0}".format(infohash))

        f.close()
    def test_bad_tracker(self):
        f = open('good_infohashes.txt', 'rb')

        content = f.readlines()

        for infohash in content:
            infohash = infohash.decode('utf-8')
            infohash = infohash.strip()
            error = scraper.scrape(infohash, "invalidhostname.tk", 6969)
            self.assertEqual(tuple, type(error))

        f.close()
    def test_scraper(self):
        f = open('good_infohashes.txt', 'rb')

        content = f.readlines()

        for infohash in content:
            infohash = infohash.decode('utf-8')
            infohash = infohash.strip()
            torrent_infohash, seeders, leechers, complete = scraper.scrape(
                infohash, "tracker.coppersurfer.tk", 6969)
            self.assertEqual(torrent_infohash, infohash)

        f.close()