def addTorrent(self, videoObj): """ Add a torrent to transmission and return torrent hash as id""" torrents_hash = [torrent.hashString for torrent in self.tc.list().values()] if compute_hash(videoObj) in torrents_hash: raise AlreadyDownloading("Torrent already in download") else: if self.download_dir is not None: self.tc.add_uri(videoObj.download_url, download_dir=self.download_dir) else: self.tc.add_uri(videoObj.download_url)
def _add_torrent(self, videoObj): if len(self.torrent_downloaders): try: self.torrent_downloaders[0].addTorrent(videoObj) except AlreadyDownloading: LOGGER.error("Download %s already downloading" % videoObj) videoObj.extra['downloader_id'] = compute_hash(videoObj) try: self.queue.append(videoObj, self.queue.STARTED) except AlreadyExist: LOGGER.error("Download %s already in download queue" % videoObj) else: LOGGER.warning('No available downloader, put in queue') try: self.queue.append(videoObj) except AlreadyExist: LOGGER.error("Download %s already in download queue" % videoObj)