def process_category(self):
        torrents = QBitController.get_torrents_by_category(self.category)
        if not torrents:
            return

        logging.info('Checking {} torrents for {}'.format(
            len(torrents), self.category))

        for torrent in torrents:
            self.torrents_checked.add(torrent['hash'])

            if torrent['progress'] != 1:  # Ignore if download is not finished
                continue

            if self.should_torrent_be_deleted(torrent['hash']):
                self.torrents_to_delete[torrent['hash']] = torrent['name']

        if self.torrents_to_delete:
            logging.info(
                'Deleting following torrents from the {} category'.format(
                    self.category))
            for name in self.torrents_to_delete.values():
                logging.info(name)

            QBitController.remove_torrent_hashes(
                self.torrents_to_delete.keys(), self.delete_files)

            if self.custom_delete_files_path:
                self.delete_files_directly()
    def should_torrent_be_deleted(self, torrent_hash):
        torrent_properties = QBitController.get_torrent_properties(
            torrent_hash)

        # Torrent was not found, perhaps it was already deleted by a different ruleset
        if torrent_properties == False:
            return False

        torrent_seeding_time_in_hours = (torrent_properties['seeding_time'] /
                                         60 / 60)
        torrent_trackers = QBitController.get_torrent_trackers(torrent_hash)

        if self.tracker and Helper.does_torrent_contain_tracker(
                torrent_trackers, self.tracker) == False:
            return False

        limit_array = self.private if Helper.is_torrent_private(
            torrent_trackers) else self.public

        if limit_array['required_seeders'] > (
                torrent_properties['seeds_total'] - 1):
            return False

        if (torrent_properties['share_ratio'] >= limit_array['max_seed_ratio']
            ) or (torrent_seeding_time_in_hours >=
                  limit_array["max_seed_time"]):
            return True

        if (torrent_properties['share_ratio'] >= limit_array['min_seed_ratio']
            ) and (torrent_seeding_time_in_hours >=
                   limit_array["min_seed_time"]):
            return True

        return False
    def delete_torrents_to_be_deleted(self):
        if self.torrents_to_delete:
            logging.info(
                'Deleting following torrents from the {} category'.format(
                    self.category))
            for name in self.torrents_to_delete.values():
                logging.info(name)

            QBitController.remove_torrent_hashes(
                self.torrents_to_delete.keys(), self.delete_files)

            if self.custom_delete_files_path:
                self.delete_files_directly()
Esempio n. 4
0
    return parser.parse_args()


if __name__ == "__main__":
    args = construct_argument_parser()

    if not args.qbit_url.startswith(
            "http://") and not args.qbit_url.startswith("https://"):
        args.qbit_url = "http://" + args.qbit_url

    levels = [logging.WARNING, logging.INFO, logging.DEBUG]
    level = levels[min(2, args.verbose)]
    logging.basicConfig(level=level)

    QBitController.connect_to_qbit(args.qbit_url, args.qbit_username,
                                   args.qbit_password)

    categoryProfiles = load_category_files_into_classes(args)

    torrents = QBitController.get_torrents()

    delete_counter = 0
    torrents_checked = set()
    for torrent in torrents:
        if torrent["category"] in categoryProfiles.keys():
            for matchingCategoryProfile in categoryProfiles[
                    torrent["category"]]:
                matchingCategoryProfile.process_torrent(torrent)
            torrents_checked.add(torrent['hash'])
        elif "*" in categoryProfiles.keys():
            for matchingCategoryProfile in categoryProfiles["*"]:
Esempio n. 5
0
    return parser.parse_args()


if __name__ == "__main__":
    args = construct_argument_parser()

    if not args.qbit_url.startswith(
            "http://") and not args.qbit_url.startswith("https://"):
        args.qbit_url = "http://" + args.qbit_url

    levels = [logging.WARNING, logging.INFO, logging.DEBUG]
    level = levels[min(2, args.verbose)]
    logging.basicConfig(level=level)

    QBitController.connect_to_qbit(args.qbit_url, args.qbit_username,
                                   args.qbit_password)

    categoryProfiles = load_category_files_into_classes(args)

    delete_counter = 0
    torrents_checked = set()
    for categoryProfile in categoryProfiles:
        categoryProfile.process_category()
        delete_counter += len(categoryProfile.torrents_to_delete)
        torrents_checked = torrents_checked.union(
            categoryProfile.torrents_checked)

    print("Checked " + str(len(torrents_checked)) + " torrents!")
    print("Deleted " + str(delete_counter) + " torrents!")