'Function to select which torrent in the torrent list will be downloaded in the
next iteration. It depends on the source and applied policy'

def _select_torrent(self):

    torrents = {}
    for infohash in list(self.torrents):
        torrent = self.torrents.get(infohash)
        if torrent.get('preload', False):
            if ('download' not in torrent):
                self.start_download(torrent)
            elif (torrent['download'].get_status() == DLSTATUS_SEEDING):
                self.stop_download(torrent)
        elif (not torrent.get('is_duplicate', False)):
            if torrent.get('enabled', True):
                torrents[infohash] = torrent
    if ((self.settings.policy is not None) and torrents):
        (torrents_start, torrents_stop) = self.settings.policy.apply(torrents, self.settings.max_torrents_active)
        for torrent in torrents_stop:
            self.stop_download(torrent)
        for torrent in torrents_start:
            self.start_download(torrent)
        self._logger.info('Selecting    from    %s    torrents    %s    start    download', len(torrents), len(torrents_start))
