-
Notifications
You must be signed in to change notification settings - Fork 5
/
channel_download.py
94 lines (81 loc) · 2.81 KB
/
channel_download.py
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
90
91
92
93
94
"""
Telegram Channel Media Downloader Plugin for ULTRA.
usage: .geta channel_username [will get all media from channel, tho there is limit of 3000 there to prevent API limits.]
.getc number_of_messsages channel_username
By: @Zero_cool7870
"""
from telethon import events
import asyncio
import os
import subprocess
import sys
from ULTRA.utils import admin_cmd, humanbytes, progress, time_formatter
from ULTRA import CMD_HELP
@borg.on(admin_cmd(pattern=r"getc"))
async def get_media(event):
if event.fwd_from:
return
dir= "./temp/"
try:
os.makedirs("./temp/")
except:
pass
channel_username= event.text
command = ['ls','temp','|','wc','-l' ]
limit = channel_username[6:9]
print(limit)
channel_username = channel_username[11: ]
print(channel_username)
await event.edit("Downloading Media From this Channel.")
msgs = await borg.get_messages(channel_username, limit=int(limit))
with open('log.txt','w') as f:
f.write(str(msgs))
for msg in msgs:
if msg.media is not None:
await borg.download_media(
msg,dir)
ps = subprocess.Popen(('ls', 'temp'), stdout=subprocess.PIPE)
output = subprocess.check_output(('wc', '-l'), stdin=ps.stdout)
ps.wait()
output = str(output)
output = output.replace("b'","")
output = output.replace("\n'","")
await event.edit("Downloaded "+output+" files.")
@borg.on(admin_cmd(pattern=r"geta"))
async def get_media(event):
if event.fwd_from:
return
dir= "./temp/"
try:
os.makedirs("./temp/")
except:
pass
channel_username= event.text
command = ['ls','temp','|','wc','-l' ]
channel_username = channel_username[7:]
print(channel_username)
await event.edit("Downloading All Media From this Channel.")
msgs = await borg.get_messages(channel_username,limit=3000)
with open('log.txt','w') as f:
f.write(str(msgs))
for msg in msgs:
if msg.media is not None:
await borg.download_media(
msg,dir)
ps = subprocess.Popen(('ls', 'temp'), stdout=subprocess.PIPE)
output = subprocess.check_output(('wc', '-l'), stdin=ps.stdout)
ps.wait()
output = str(output)
output = output.replace("b'","")
output = output.replace("\n'","")
await event.edit("Downloaded "+output+" files.")
CMD_HELP.update(
{
"channel_download": f"""**Plugin : **`channel_download`
**Telegram Channel Media Downloader Plugin for ULTRA.**
• **Syntax : **`.geta channel_username`
• **Function : **__will download all media from channel into your bot server but there is limit of 3000 to prevent API limits.__
• **Syntax : **`.getc number channel_username`
• **Function : **__will download latest given number of media from channel into your bot server .__"""
}
)