'Update libtorrent stats and check if the download should be stopped.'

def update_lt_stats(self):

    status = self.handle.status()
    self.dlstate = (self.dlstates[status.state] if (not status.paused) else DLSTATUS_STOPPED)
    self.dlstate = (DLSTATUS_STOPPED_ON_ERROR if ((self.dlstate == DLSTATUS_STOPPED) and status.error) else self.dlstate)
    if (self.get_mode() == DLMODE_VOD):
        self.progress = self.get_byte_progress([(self.get_vod_fileindex(), 0, (-1))])
        self.dlstate = ((DLSTATUS_SEEDING if (self.progress == 1.0) else self.dlstate) if (not status.paused) else DLSTATUS_STOPPED)
    else:
        self.progress = status.progress
    self.error = (status.error.decode('utf-8') if status.error else None)
    self.length = float(status.total_wanted)
    self.curspeeds[DOWNLOAD] = (float(status.download_payload_rate) if (self.dlstate not in [DLSTATUS_STOPPED, DLSTATUS_STOPPED]) else 0.0)
    self.curspeeds[UPLOAD] = (float(status.upload_payload_rate) if (self.dlstate not in [DLSTATUS_STOPPED, DLSTATUS_STOPPED]) else 0.0)
    self.all_time_upload = status.all_time_upload
    self.all_time_download = status.all_time_download
    if status.all_time_download:
        self.all_time_ratio = (status.all_time_upload / float(status.all_time_download))
    self.finished_time = status.finished_time
    self._stop_if_finished()
