def __file_created(self, filename, file_id): """ Callback for when the physical torrent file has been downloaded. Used when Transmission client is not running """ log.msg('Saved file for torrent. ID: {}'.format(file_id)) log.msg('Torrent saved at: {}'.format(filename)) TorrentQueue.update_status( new_status=u'FOUND', id=file_id, async=False )
def __error_finding_torrents(self, file_name, file_id): """ Error callback for when the physical torrent file has failed to downlaod. Used when Transmission client is not running """ log.msg( 'Problem with downloading torrent {}, going to set ' 'to NOT_FOUND and try again later'.format(file_name) ) TorrentQueue.update_status( new_status=u'FOUND', id=file_id, async=False )
def on_torrents_found(self, torrents, db_id): """ Callback for reponse from pirate bay sites :param: list of torrents :param: the id refrencing the queue database table """ if len(torrents) > 0: log.msg('Torrent found for queue with id of {}'.format(db_id)) self.download_manager.download(torrents[0], db_id) else: log.msg('No Torrents found for queue with id of {}'.format(db_id)) TorrentQueue.update_status( new_status='NOT_FOUND', id=db_id, async=False ) self.error_finding_torrents()
def update_status(self, request, **kwargs): check = self._check_args(kwargs, ('torrent_queue_id', 'status', )) if check is not None: defer.returnValue(Ok(check)) queue_id = kwargs.get('torrent_queue_id') status = kwargs.get('status', '').upper() statuses = ( 'PENDING', 'FOUND', 'NOT_FOUND', 'FINISHED', 'DOWNLOADING', 'WATCHED', 'DELETED' ) if status not in statuses: defer.returnValue( Ok(self._generate_response(200, 'Invalid status')) ) yield TorrentQueue.update_status(new_status=status, id=int(queue_id)) defer.returnValue(Ok(self._generate_response( code=0, message='Updated status for ID {} to {}'.format(queue_id, status))) )
def retry_download(self): log.msg('Going to reset the statuses of NOT_FOUND items in queue') TorrentQueue.update_status( new_status='PENDING', status='NOT_FOUND', async=False )