Esempio n. 1
0
    def update_torrent_info_from_rpc_to_db(self, last_id_db=None, force_clean_check=False):
        """
        Sync torrent's id from transmission to database,
        List Start on last check id,and will return the max id as the last check id.
        """
        torrent_list = tc.get_torrents()  # Cache the torrent list
        new_torrent_list = [t for t in torrent_list if t.id > self.last_id_check]
        if new_torrent_list:
            last_id_now = max([t.id for t in new_torrent_list])
            if last_id_db is None:
                last_id_db = db.get_max_in_seed_list(column_list=db.col_seed_list[2:])
            Logger.debug("Max tid, transmission: {tr}, database: {db}".format(tr=last_id_now, db=last_id_db))

            if not force_clean_check:  # Normal Update
                Logger.info("Some new torrents were add to transmission, Sync to db~")
                for i in new_torrent_list:  # Upsert the new torrent
                    db.upsert_seed_list(self._get_torrent_info(i))
                self.last_id_check = last_id_now

            elif last_id_now != last_id_db:  # Check the torrent 's record between tr and db
                total_num_in_tr = len(set([t.name for t in torrent_list]))
                total_num_in_db = db.exec(sql="SELECT COUNT(*) FROM `seed_list`")[0]
                if int(total_num_in_tr) >= int(total_num_in_db):
                    db.cache_torrent_list()
                    Logger.info("Upsert the whole torrent id to database.")
                    for t in torrent_list:  # Upsert the whole torrent
                        db.upsert_seed_list(self._get_torrent_info(t))
                else:
                    Logger.error(
                        "The torrent list didn't match with db-records, Clean the whole \"seed_list\" for safety.")
                    db.exec(sql="DELETE FROM `seed_list` WHERE 1")  # Delete all line from seed_list
                    self.update_torrent_info_from_rpc_to_db(last_id_db=0)
        else:
            Logger.debug("No new torrent(s), Return with nothing to do.")
        return self.last_id_check
Esempio n. 2
0
    def reseeder_feed(self, dl_torrent):
        pre_reseeder_list = self.get_pre_reseeder_list()
        tname = dl_torrent.name
        cow = db.exec(
            "SELECT * FROM `seed_list` WHERE `download_id`='{did}'".format(
                did=dl_torrent.id),
            r_dict=True)

        reseed_status = False
        for pat in pattern_group:
            search = re.search(pat, tname)
            if search:
                logging.debug("The search group dict: {gr}".format(
                    gr=search.groupdict()))
                for reseeder in [
                        r for r in pre_reseeder_list
                        if int(cow[r.db_column]) == 0
                ]:  # Site feed
                    try:
                        tag = reseeder.torrent_feed(torrent=dl_torrent,
                                                    name_pattern=search)
                    except Exception as e:
                        logging.critical(
                            "{}, Will start A reseeder online check soon.".
                            format(e.args[0]))
                        Thread(target=self._online_check, daemon=True).start()
                        pass
                    else:
                        db.upsert_seed_list((tag, tname, reseeder.db_column))
                reseed_status = True
                break

        if not reseed_status:  # Update seed_id == -1 if no matched pattern
            logging.warning(
                "No match pattern,Mark \"{}\" As Un-reseed torrent,Stop watching."
                .format(tname))
            for reseeder in pre_reseeder_list:
                db.upsert_seed_list((-1, tname, reseeder.db_column))
Esempio n. 3
0
    def torrent_feed(self, torrent):
        torrent = self._get_torrent(torrent)
        reseed_tag, = db.exec(
            "SELECT `{}` FROM `seed_list` WHERE `download_id` = {}".format(self.db_column, torrent.id)
        )

        if reseed_tag in [None, 0, "0"] and reseed_tag not in [-1, "-1"]:
            # It means that the pre-reseed torrent in this site is not reseed before,
            # And this torrent not marked as an un-reseed torrent.
            self._assist_delay()
            Logger.info("Autoseed-{mo} Get A feed torrent: {na}".format(mo=self.name, na=torrent.name))

            reseed_tag = -1
            try:
                reseed_tag = self.torrent_reseed(torrent)
            except Exception as e:  # TODO 针对不同的Error情况做不同的更新(e.g. 因为网络问题则置0,其他情况置1)
                err_name = type(e).__name__
                Logger.error(
                    "Reseed not success in Site: {} for torrent: {}, "
                    "With Exception: {}, {}".format(self.name, torrent.name, err_name, e)
                )
            finally:
                db.upsert_seed_list((reseed_tag, torrent.name, self.db_column))
Esempio n. 4
0
    def torrent_feed(self, torrent):
        torrent = self._get_torrent(torrent)
        reseed_tag, = db.exec(
            "SELECT `{}` FROM `seed_list` WHERE `download_id` = {}".format(self.db_column, torrent.id)
        )

        if reseed_tag in [None, 0, "0"] and reseed_tag not in [-1, "-1"]:
            # It means that the pre-reseed torrent in this site is not reseed before,
            # And this torrent not marked as an un-reseed torrent.
            self._assist_delay()
            Logger.info("Autoseed-{mo} Get A feed torrent: {na}".format(mo=self.name, na=torrent.name))

            reseed_tag = -1
            try:
                reseed_tag = self.torrent_reseed(torrent)
            except Exception as e:  # TODO 针对不同的Error情况做不同的更新(e.g. 因为网络问题则置0,其他情况置1)
                err_name = type(e).__name__
                Logger.error(
                    "Reseed not success in Site: {} for torrent: {}, "
                    "With Exception: {}, {}".format(self.name, torrent.name, err_name, e)
                )
            finally:
                db.upsert_seed_list((reseed_tag, torrent.name, self.db_column))