'Returns channel id, name, nrfavorites of most popular channel if any'

def getMostPopularChannelFromTorrent(self, infohash):

    sql = 'SELECT    Channels.id,    Channels.dispersy_cid,    Channels.name,    Channels.description,\n                                                        Channels.nr_torrents,    Channels.nr_favorite,    Channels.nr_spam,    Channels.modified,\n                                                        ChannelTorrents.id\n                                                        FROM    Channels,    ChannelTorrents,    Torrent\n                                                        WHERE    Channels.id    =    ChannelTorrents.channel_id\n                                                        AND    ChannelTorrents.torrent_id    =    Torrent.torrent_id    AND    infohash    =    ?'
    channels = self._db.fetchall(sql, (bin2str(infohash),))
    if (len(channels) > 0):
        channel_ids = set()
        for result in channels:
            channel_ids.add(result[0])
        myVotes = self.votecast_db.getMyVotes()
        best_channel = None
        for (id, dispersy_cid, name, description, nr_torrents, nr_favorites, nr_spam, modified, channeltorrent_id) in channels:
            channel = (id, dispersy_cid, name, description, nr_torrents, nr_favorites, nr_spam, myVotes.get(id, 0), modified, (id == self._channel_id), channeltorrent_id)
            if channel[(-1)]:
                return channel
            if ((not best_channel) or (channel[5] > best_channel[5])):
                best_channel = channel
            elif ((channel[5] == best_channel[5]) and (channel[4] > best_channel[4])):
                best_channel = channel
        return best_channel
