First working version

This commit is contained in:
Alfonso E.M 2020-04-22 20:35:13 +02:00
parent a15c32ed6a
commit 2540e13f90
3 changed files with 1141 additions and 0 deletions

1058
LICENSE.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -1 +1,40 @@
# telegram-download-daemon
A Telegram Daemon (not a bot) for file downloading automation
If you have got an Internet connected computer or NAS and you want to automate file downloading from Telegram channels, this
daemon is for you.
Telegram bots are limited to 20Mb file size downloads. So I wrote this agent
or daemon to allow bigger downloads.
# Installation
You need Python3 (tested in 3.5).
Install Telethon module (using pip or your OS package system):
pip install --user telethon
Install cryptg to use a C library to speed up downloads (optional)
pip install --user cryptg
Obtain your own api id: https://core.telegram.org/api/obtaining_api_id
Edit telegram-download-daemon.py and put your own api_id and api_hash values
into the proper variables.
Change the destination folder if desired.
Use your favorite Telegram app to create a new (private)channel.
Change the channel_id in telegram-download-daemon.py.
Run the script!

View file

@ -0,0 +1,44 @@
#!/usr/bin/env python3
# Telegram Download Daemon
# Author: Alfonso E.M. <alfonso@el-magnifico.org>
# You need to install telethon (and cryptg to speed up downloads)
from telethon import TelegramClient, events
from telethon.tl.types import PeerChannel
import logging
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s]%(name)s:%(message)s',level=logging.WARNING)
# Edit these lines:
api_id = NNNNNN
api_hash = "XXXXXXXXXXXXXXXXXXXXXXXXXX"
downloadFolder="/tmp"
channel_id= NNNNNNNNN
proxy = None
# End of interesting parameters
session = "DownloadDaemon"
client = TelegramClient(session, api_id, api_hash, proxy=proxy).start()
@client.on(events.NewMessage())
async def handler(event):
if event.to_id != PeerChannel(channel_id):
return
print(event)
if event.media:
filename=event.media.document.attributes[0].file_name
answer="Downloading file %s (%i bytes)" % (filename,event.media.document.size)
print(answer)
await event.respond(answer)
await client.download_media(event.message,downloadFolder)
await event.respond(filename+" ready")
with client:
client.run_until_disconnected()