Exemplo n.º 1
0
    def _update_progress(self):
        torrents = [
            t for t in self._api.torrents()
            if t.status.state not in (STATUS_FINISHED, STATUS_SEEDING,
                                      STATUS_PAUSED)
        ]
        torrents_count = len(torrents)

        if torrents_count > 0:
            if self._index >= torrents_count:
                download_rate = sum(t.status.download_rate for t in torrents)
                upload_rate = sum(t.status.upload_rate for t in torrents)
                progress = sum(t.status.progress
                               for t in torrents) / torrents_count
                name = kodi.translate(30106)
                self._index = 0
            else:
                download_rate = torrents[self._index].status.download_rate
                upload_rate = torrents[self._index].status.upload_rate
                progress = torrents[self._index].status.progress
                name = torrents[self._index].name
                if len(name) > 30:
                    name = name[:30] + "..."
                self._index += 1

            message = "{} - D:{}/s U:{}/s".format(name,
                                                  sizeof_fmt(download_rate),
                                                  sizeof_fmt(upload_rate))
            self._get_dialog().update(int(progress), kodi.ADDON_NAME, message)
        else:
            self._close_dialog()
Exemplo n.º 2
0
def get_status_labels(info_hash):
    status = api.torrent_status(info_hash)
    return ("{:s} ({:.2f}%)".format(get_state_string(status.state),
                                    status.progress),
            "D:{:s}/s U:{:s}/s S:{:d}/{:d} P:{:d}/{:d}".format(
                sizeof_fmt(status.download_rate),
                sizeof_fmt(status.upload_rate), status.seeders,
                status.seeders_total, status.peers, status.peers_total))
Exemplo n.º 3
0
 def print_search_results(self, results):
     for result in results:
         if 'error' in result:
             print 'ERROR {}'.format(result['error'])
         else:
             print '{:35s}: ({:5s}) {:15s} - {:50s}'.format(
                 result['nzbid'], sizeof_fmt(float(result['size'])), result['category'], result['name']
             )
Exemplo n.º 4
0
 def print_search_results(self, results):
     for result in results:
         if 'error' in result:
             print 'ERROR {}'.format(result['error'])
         else:
             print '{:35s}: ({:5s}) {:15s} - {:50s}'.format(
                 result['nzbid'], sizeof_fmt(float(result['size'])),
                 result['category'], result['name'])
Exemplo n.º 5
0
def wait_for_buffering_completion(info_hash, file_id):
    close_busy_dialog()
    info = api.file_info(info_hash, file_id)
    of = translate(30244)
    timeout = get_buffering_timeout()
    last_time = last_done = 0
    start_time = time.time()

    monitor = Monitor()
    progress = DialogProgress()
    progress.create(ADDON_NAME)

    try:
        while True:
            current_time = time.time()
            status = api.file_status(info_hash, file_id)
            if status.buffering_progress >= 100:
                break

            total_done = status.buffering_total * status.buffering_progress / 100
            speed = float(total_done - last_done) / (current_time - last_time)
            last_time = current_time
            last_done = total_done
            progress.update(
                int(status.buffering_progress),
                "{} - {:.2f}%\n{} {} {} - {}/s\n{}\n".format(
                    get_state_string(status.state), status.buffering_progress,
                    sizeof_fmt(total_done), of,
                    sizeof_fmt(status.buffering_total), sizeof_fmt(speed),
                    info.name))

            if progress.iscanceled():
                raise CanceledError("User canceled buffering", info_hash)
            if 0 < timeout < current_time - start_time:
                notification(translate(30236))
                raise PlayError("Buffering timeout reached")
            if monitor.waitForAbort(1):
                raise PlayError("Abort requested")
    finally:
        progress.close()