|
| 1 | +# This file is part of the Compressor distribution. |
| 2 | +# Copyright (c) 2021 Danish_00 |
| 3 | +# |
| 4 | +# This program is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, version 3. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, but |
| 9 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | +# General Public License for more details. |
| 12 | +# |
| 13 | +# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> . |
| 14 | + |
| 15 | +from .config import * |
| 16 | + |
| 17 | +COUNT = [] |
| 18 | + |
| 19 | +uptime = dt.now() |
| 20 | +os.system("wget https://telegra.ph/file/75ee20ec8d8c8bba84f02.jpg") |
| 21 | + |
| 22 | +if not os.path.isdir("downloads/"): |
| 23 | + os.mkdir("downloads/") |
| 24 | +if not os.path.isdir("encode/"): |
| 25 | + os.mkdir("encode/") |
| 26 | +if not os.path.isdir("thumb/"): |
| 27 | + os.mkdir("thumb/") |
| 28 | + |
| 29 | + |
| 30 | +def stdr(seconds: int) -> str: |
| 31 | + minutes, seconds = divmod(seconds, 60) |
| 32 | + hours, minutes = divmod(minutes, 60) |
| 33 | + if len(str(minutes)) == 1: |
| 34 | + minutes = "0" + str(minutes) |
| 35 | + if len(str(hours)) == 1: |
| 36 | + hours = "0" + str(hours) |
| 37 | + if len(str(seconds)) == 1: |
| 38 | + seconds = "0" + str(seconds) |
| 39 | + dur = ( |
| 40 | + ((str(hours) + ":") if hours else "00:") |
| 41 | + + ((str(minutes) + ":") if minutes else "00:") |
| 42 | + + ((str(seconds)) if seconds else "") |
| 43 | + ) |
| 44 | + return dur |
| 45 | + |
| 46 | + |
| 47 | +def ts(milliseconds: int) -> str: |
| 48 | + seconds, milliseconds = divmod(int(milliseconds), 1000) |
| 49 | + minutes, seconds = divmod(seconds, 60) |
| 50 | + hours, minutes = divmod(minutes, 60) |
| 51 | + days, hours = divmod(hours, 24) |
| 52 | + tmp = ( |
| 53 | + ((str(days) + "d, ") if days else "") |
| 54 | + + ((str(hours) + "h, ") if hours else "") |
| 55 | + + ((str(minutes) + "m, ") if minutes else "") |
| 56 | + + ((str(seconds) + "s, ") if seconds else "") |
| 57 | + + ((str(milliseconds) + "ms, ") if milliseconds else "") |
| 58 | + ) |
| 59 | + return tmp[:-2] |
| 60 | + |
| 61 | + |
| 62 | +def hbs(size): |
| 63 | + if not size: |
| 64 | + return "" |
| 65 | + power = 2 ** 10 |
| 66 | + raised_to_pow = 0 |
| 67 | + dict_power_n = {0: "B", 1: "K", 2: "M", 3: "G", 4: "T", 5: "P"} |
| 68 | + while size > power: |
| 69 | + size /= power |
| 70 | + raised_to_pow += 1 |
| 71 | + return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B" |
| 72 | + |
| 73 | + |
| 74 | +async def progress(current, total, event, start, type_of_ps, file=None): |
| 75 | + now = time.time() |
| 76 | + diff = now - start |
| 77 | + if round(diff % 10.00) == 0 or current == total: |
| 78 | + percentage = current * 100 / total |
| 79 | + speed = current / diff |
| 80 | + time_to_completion = round((total - current) / speed) * 1000 |
| 81 | + progress_str = "`[{0}{1}] {2}%`\n\n".format( |
| 82 | + "".join(["𒊹︎︎︎" for i in range(math.floor(percentage / 5))]), |
| 83 | + "".join(["●" for i in range(20 - math.floor(percentage / 5))]), |
| 84 | + round(percentage, 2), |
| 85 | + ) |
| 86 | + tmp = ( |
| 87 | + progress_str |
| 88 | + + "`{0} of {1}`\n\n`✦ Speed: {2}/s`\n\n`✦ ETA: {3}`\n\n".format( |
| 89 | + hbs(current), |
| 90 | + hbs(total), |
| 91 | + hbs(speed), |
| 92 | + ts(time_to_completion), |
| 93 | + ) |
| 94 | + ) |
| 95 | + if file: |
| 96 | + await event.edit( |
| 97 | + "`✦ {}`\n\n`File Name: {}`\n\n{}".format(type_of_ps, file, tmp) |
| 98 | + ) |
| 99 | + else: |
| 100 | + await event.edit("`✦ {}`\n\n{}".format(type_of_ps, tmp)) |
| 101 | + |
| 102 | + |
| 103 | +async def genss(file): |
| 104 | + process = subprocess.Popen( |
| 105 | + ["mediainfo", file, "--Output=JSON"], |
| 106 | + stdout=subprocess.PIPE, |
| 107 | + stderr=subprocess.STDOUT, |
| 108 | + ) |
| 109 | + stdout, stderr = process.communicate() |
| 110 | + out = stdout.decode().strip() |
| 111 | + z = json.loads(out) |
| 112 | + p = z["media"]["track"][0]["Duration"] |
| 113 | + return int(p.split(".")[-2]) |
| 114 | + |
| 115 | + |
| 116 | +async def duration_s(file): |
| 117 | + tsec = await genss(file) |
| 118 | + x = round(tsec / 5) |
| 119 | + y = round(tsec / 5 + 60) |
| 120 | + pin = stdr(x) |
| 121 | + if y < tsec: |
| 122 | + pon = stdr(y) |
| 123 | + else: |
| 124 | + pon = stdr(tsec) |
| 125 | + return pin, pon |
| 126 | + |
| 127 | + |
| 128 | +def code(data): |
| 129 | + key = ( |
| 130 | + requests.post("https://nekobin.com/api/documents", json={"content": data}) |
| 131 | + .json() |
| 132 | + .get("result") |
| 133 | + .get("key") |
| 134 | + ) |
| 135 | + return key |
| 136 | + |
| 137 | + |
| 138 | +def decode(key): |
| 139 | + a = requests.get(f"https://nekobin.com/raw/{key}") |
| 140 | + return a.text |
| 141 | + |
| 142 | + |
| 143 | +async def skip(e): |
| 144 | + wah = e.pattern_match.group(1).decode("UTF-8") |
| 145 | + wh = decode(wah) |
| 146 | + out, dl, thum, dtime = wh.split(";") |
| 147 | + try: |
| 148 | + os.remove(dl) |
| 149 | + os.remove(out) |
| 150 | + COUNT.remove(e.sender_id) |
| 151 | + except: |
| 152 | + pass |
| 153 | + return await e.delete() |
0 commit comments