Beispiel #1
0
 def testFormatSpeed(self):
     table = {
         512                : (512, 'B/s'),
         1024               : (1.0, 'KiB/s'),
         1048575            : (1023.999, 'KiB/s'),
         1048576            : (1.0, 'MiB/s'),
         1073741824         : (1.0, 'GiB/s'),
         1099511627776      : (1.0, 'TiB/s'),
         1125899906842624   : (1.0, 'PiB/s'),
         1152921504606846976: (1.0, 'EiB/s'),
     }
     for size, expected in table.items():
         result = tu.format_speed(size)
         self.assertAlmostEqual(result[0], expected[0], 4)
         self.assertEqual(result[1], expected[1])
def torrent_menu(torrent_id: int) -> Tuple[str, telegram.InlineKeyboardMarkup]:
    torrent = transClient.get_torrent(torrent_id)
    text = f"*{escape_markdown(torrent.name, 2)}*\n"
    if torrent.status != "checking":
        text += escape_markdown(
            f"{utils.progress_bar(torrent.progress)}  {(round(torrent.progress, 1))}% ",
            2,
        )
    else:
        text += escape_markdown(
            f"{utils.progress_bar(torrent.recheckProgress * 100)}  "
            f"{(round(torrent.recheckProgress * 100, 1))}% ",
            2,
        )
    text += f"{STATUS_LIST[torrent.status]}\n"
    if download := torrent.rateDownload:
        speed = trans_utils.format_speed(download)
        raw_text = (f"Time remaining: {utils.formated_eta(torrent)}\n"
                    f"Download rate: {round(speed[0], 1)} {speed[1]}\n")
        text += escape_markdown(raw_text, 2)
Beispiel #3
0
def test_format_speed(size, expected):
    result = utils.format_speed(size)
    assert_almost_eq(result[0], expected[0])
    assert result[1] == expected[1]
         f"{(round(torrent.recheckProgress * 100, 1))}% ",
         2,
     )
 text += f"{STATUS_LIST[torrent.status]}\n"
 if download := torrent.rateDownload:
     speed = trans_utils.format_speed(download)
     raw_text = (f"Time remaining: {utils.formated_eta(torrent)}\n"
                 f"Download rate: {round(speed[0], 1)} {speed[1]}\n")
     text += escape_markdown(raw_text, 2)
 if torrent.status != "seeding":
     downloaded_bytes: int = torrent.sizeWhenDone - torrent.leftUntilDone
     downloaded = trans_utils.format_size(downloaded_bytes)
     raw_text = f"Downloaded: {round(downloaded[0],2)} {downloaded[1]}\n"
     text += escape_markdown(raw_text, 2)
 if upload := torrent.rateUpload:
     speed = trans_utils.format_speed(upload)
     raw_text = f"Upload rate: {round(speed[0], 1)} {speed[1]}\n"
     text += escape_markdown(raw_text, 2)
 size_when_done = trans_utils.format_size(torrent.sizeWhenDone)
 total_size = trans_utils.format_size(torrent.totalSize)
 total_uploaded = trans_utils.format_size(torrent.uploadedEver)
 raw_text = (
     f"Size to download: {round(size_when_done[0], 2)} {size_when_done[1]}"
     f" / {round(total_size[0], 2)} {total_size[1]}\n")
 raw_text += (
     f"Total ever uploaded: {round(total_uploaded[0], 2)} {total_uploaded[1]}\n"
 )
 text += escape_markdown(raw_text, 2)
 if torrent.status == "stopped":
     start_stop = telegram.InlineKeyboardButton(
         "▶️Start",