-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhelper.py
More file actions
89 lines (79 loc) · 2.68 KB
/
helper.py
File metadata and controls
89 lines (79 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import subprocess
import datetime
import asyncio
import os
import requests
import time
import os
import aiohttp
import tgcrypto
import concurrent.futures
from pyrogram.types import Message
from pyrogram import Client, filters
def duration(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return float(result.stdout)
def exec(cmd):
process = subprocess.run(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output = process.stdout.decode()
print(output)
return output
#err = process.stdout.decode()
def pull_run(work, cmds):
with concurrent.futures.ThreadPoolExecutor(max_workers=work) as executor:
print("Waiting for tasks to complete")
fut = executor.map(exec,cmds)
async def aio(url,name):
k = f'{name}.pdf'
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status == 200:
f = await aiofiles.open(k, mode='wb')
await f.write(await resp.read())
await f.close()
return k
async def download(url,name):
ka = f'{name}.pdf'
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status == 200:
f = await aiofiles.open(ka, mode='wb')
await f.write(await resp.read())
await f.close()
return ka
async def run(cmd):
proc = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')
if proc.returncode == 1:
return False
if stdout:
return f'[stdout]\n{stdout.decode()}'
if stderr:
return f'[stderr]\n{stderr.decode()}'
def old_download(url, file_name, chunk_size = 1024 * 10):
if os.path.exists(file_name):
os.remove(file_name)
r = requests.get(url, allow_redirects=True, stream=True)
with open(file_name, 'wb') as fd:
for chunk in r.iter_content(chunk_size=chunk_size):
if chunk:
fd.write(chunk)
return file_name
async def send_doc(bot: Client, m: Message,cc,ka,cc1,prog,count,name):
reply = await m.reply_text(f"Uploading - `{name}`")
time.sleep(1)
start_time = time.time()
await m.reply_document(ka,caption=cc1)
count+=1
await reply.delete (True)
time.sleep(1)
os.remove(ka)
time.sleep(3)