Giter VIP home page Giter VIP logo

telegram-download-daemon's Introduction

telegram-download-daemon

A Telegram Daemon (not a bot) for file downloading automation for channels of which you have admin privileges.

ko-fi

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 (limited to 2GB by Telegram APIs).

Installation

You need Python3 (3.6 works fine, 3.5 will crash randomly).

Install dependencies by running this command:

pip install -r requirements.txt

(If you don't want to install cryptg and its dependencies, you just need to install telethon)

Warning: If you get a File size too large message, check the version of Telethon library you are using. Old versions have got a 1.5Gb file size limit.

Obtain your own api id: https://core.telegram.org/api/obtaining_api_id

Usage

You need to configure these values:

Environment Variable Command Line argument Description Default Value
TELEGRAM_DAEMON_API_ID --api-id api_id from https://core.telegram.org/api/obtaining_api_id
TELEGRAM_DAEMON_API_HASH --api-hash api_hash from https://core.telegram.org/api/obtaining_api_id
TELEGRAM_DAEMON_DEST --dest Destination path for downloaded files /telegram-downloads
TELEGRAM_DAEMON_TEMP --temp Destination path for temporary (download in progress) files use --dest
TELEGRAM_DAEMON_CHANNEL --channel Channel id to download from it (Please, check Issue 45, Issue 48 and Issue 73)
TELEGRAM_DAEMON_DUPLICATES --duplicates What to do with duplicated files: ignore, overwrite or rename them rename
TELEGRAM_DAEMON_WORKERS --workers Number of simultaneous downloads Equals to processor cores

You can define them as Environment Variables, or put them as a command line arguments, for example:

python telegram-download-daemon.py --api-id <your-id> --api-hash <your-hash> --channel <channel-number>

Finally, resend any file link to the channel to start the downloading. This daemon can manage many downloads simultaneously.

You can also 'talk' to this daemon using your Telegram client:

  • Say "list" and get a list of available files in the destination path.
  • Say "status" to the daemon to check the current status.
  • Say "clean" to remove stale (*.tdd) files from temporary directory.
  • Say "queue" to list the pending files waiting to start.

Docker

docker pull alfem/telegram-download-daemon

When we use the TelegramClient method, it requires us to interact with the Console to give it our phone number and confirm with a security code.

To do this, when using Docker, you need to interactively run the container for the first time.

When you use docker-compose, the .session file, where the login is stored is kept in Volume outside the container. Therefore, when using docker-compose you are required to:

$ docker-compose run --rm telegram-download-daemon
# Interact with the console to authenticate yourself.
# See the message "Signed in successfully as {youe name}"
# Close the container
$ docker-compose up -d

See the sessions volume in the docker-compose.yml file.

telegram-download-daemon's People

Contributors

alfem avatar anishsane avatar baruchiro avatar carlesllobet avatar davi5alexander avatar dependabot[bot] avatar gcandrade10 avatar haudankaivajasi avatar ozcho avatar pattonwebz avatar the-blank-x avatar thebigbone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telegram-download-daemon's Issues

Channel id and admin rights?

Hi,
Maybe i'm just a noob cause i don't see anyone posting this question before but i'm having problems with the usage instructions.
Where do i find the channel id? i googled about it and found this:
Go to https://web.telegram.org
Click on your channel
Look at the URL and find the part that looks like c12112121212_17878787878787878
Remove the underscore and after c12112121212
Remove the prefixed letter 12112121212
Prefix with a -100 so -10012112121212
That's your channel id.

But i dont know if that steps are correct for this daemon to work. Can you tell me?
And next... i tried to use that steps to get channel id and the script gives me an error when i try to run it saying that i need admin rights on the channel. Is that true? do i need admin rights on a channel to be able to download from it using this daemon? cause if that's true then it's not what i was expecting from it.
Here is the error:
telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by SendMessageRequest)

EDIT: just saw Error #45 and the steps provided there to get channel id are the steps that im using right now. So i dont know whats wrong... Can you provide me an example of a call you are using (just with a some random channel id)

Queue worker error: The file reference has expired and is no longer valid

Hello, if I starts a download job about 20 and more files, a few will download correctly but the most will not start downloading. There are only a many empty *.tdd files.

Installed on a Synology, using docker.

89.07 % (1858600960 / 2086666240), 90.3 % (1884291072 / 2086666240), 89.57 % (1869086720 / 2086666240), 90.82 % (1895301120 / 2086666240), 91.58 % (1911029760 / 2086666240), 92.16 % (1923088384 / 2086666240), 92.91 % (1938817024 / 2086666240), 93.39 % (1948778496 / 2086666240), 94.14 % (1964507136 / 2086666240), Queue worker error: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest), Downloading file Hyperspin AIO Windows Promo Disk.zip.085 (2086666240 bytes), Queue worker error: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest), Downloading file Hyperspin AIO Windows Promo Disk.zip.094 (2086666240 bytes), Queue worker error: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest), Downloading file Hyperspin AIO Windows Promo Disk.zip.100 (2086666240 bytes), Queue worker error: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest),

By the way, I didn't send the files with timer on the channel 馃槈

cant start after reinstall

Hi! Everything was ok until today, running smoothly and nice, but today it stopped. Something i maybe did wrong is i deleted all messages in the channel and also deleted the channel.
I tried to fix it reinstalling and did it from the very bottom, even reinstalling python.
Now i cant make it work, no way. I've made sure the channel id is correct, but there is no way i can do it.
Thanks and sorry for bothering, i've tried it the last few hours.
Here is the log:

Session loaded from /session/DownloadDaemon.session

Session saved in /session/DownloadDaemon.session

Traceback (most recent call last):

File "./telegram-download-daemon.py", line 278, in

client.loop.run_until_complete(start())

File "/usr/local/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete

return future.result()

File "./telegram-download-daemon.py", line 272, in start

await sendHelloMessage(client, peerChannel)

File "./telegram-download-daemon.py", line 112, in sendHelloMessage

entity = await client.get_entity(peerChannel)

File "/usr/local/lib/python3.6/site-packages/telethon/client/users.py", line 287, in get_entity

inputs.append(await self.get_input_entity(x))

File "/usr/local/lib/python3.6/site-packages/telethon/client/users.py", line 465, in get_input_entity

.format(peer, type(peer).__name__)

ValueError: Could not find the input entity for PeerUser(user_id=xxxxxxx) (PeerUser). Please read https://docs.telethon.dev/en/latest/concepts/entities.html to find out more details.

[ERROR/2021-11-14 21:15:24,668]asyncio:Task was destroyed but it is pending!

task: <Task pending coro=<worker() running at ./telegram-download-daemon.py:229> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0xf62670d0>()]>>

[ERROR/2021-11-14 21:15:24,669]asyncio:Task was destroyed but it is pending!

task: <Task pending coro=<worker() running at ./telegram-download-daemon.py:229> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0xf62670f0>()]>>

[ERROR/2021-11-14 21:15:24,669]asyncio:Task was destroyed but it is pending!

task: <Task pending coro=<worker() running at ./telegram-download-daemon.py:229> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0xf6267130>()]>>

[ERROR/2021-11-14 21:15:24,669]asyncio:Task was destroyed but it is pending!

task: <Task pending coro=<worker() running at ./telegram-download-daemon.py:229> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0xf6267150>()]>>

Photo's not synced

Hi,

When I add a photo (on my phone) to a group the photo is not synced. When I add the photo as attachement (added from gallery with no compression) the files is synced fine..

Any idea?

Problem downloading files with same filename

Hi,

I just realize that there maybe a bug when downloading more than one files with the same filename. Here's what I observed:

I'm running the latest code with docker-compose. Everything works as expected when there's a single task (Let's call it file1). Then if I send another file with the same filename (file2), the tdd file regenerates and grows from 0KB, while the progress of file1 in telegram channel keeps going on. The downloading of file1 finishes when the size of tdd reaches that of file1. However, the obtained file1 is broken. I did not wait for the finish of file2, but I think file2 will be broken, too.

Another problem is that if I send file2 after file1 finshed, file2 will overwrite file1 when finishes.

Could you please fix that? I think adding a suffix or timestamp for new files with the same name should be a good choice. Also, a check of file size (or sha1? I don't know whether it is possible) could be done before downloading to avoid duplication of tasks. Thanks.

Cannot download media if message contains special characters

Hi, I found a bug -- if the description of a media message contains special characters (for example, forward- or back-slash, emoji, web URL, etc.) the daemon will give an Error: [WinError 123] The filename, directory name, or volume label syntax is incorrect

I'm using Windows 10 and python 3.8.1

Thanks.

Remove unused (partial) files from the destination folder

I know, this somewhat contradicts the idea of .partial in #28, but now when we have the status, I thought maybe we can download to a Temp folder, and move to the destination folder when the download completed?

The download destination folder can be shared with other programs, since it is our program output, so the .partial solution was good, but I think it is better to use a Temp folder.


Another option, I don't want to open another issue about that because I think if we implementing the Temp folder, we don't need it, is to add a clean command to remove the unhandled .partial files.

All my issues are because my system is unstable, so my daemon is sometimes restarting and lose its download processes.

Disable notification in channel

Greetings,

How can i disable the auto messages send in Telegram.
-commands shell
-announcements
Telegram Download Daemon 1.12
Hi! Ready for your files!
Available commands: list, status, clean
Reporting of downloads

Is there an easyer way then editing/removing it in telegram-download-daemon.py??
if event.media:
if hasattr(event.media, 'document') or hasattr(event.media,'photo'):
filename=getFilename(event)
if ( path.exists("{0}/{1}.{2}".format(tempFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX)) or path.exists("{0}/{1}".format(downloadFolder,filename)) ) and duplicates == "ignore":
message=await event.reply("{0} already exists. Ignoring it.".format(filename))
else:
message=await event.reply("{0} added to queue".format(filename))
await queue.put([event, message])
else:
message=await event.reply("That is not downloadable. Try to send it as a file.")

Script don't work with Saved Messages Chat

Hi, first of all great work!

I have been testing the script and found it dont work if the chat passed is the Saved Message, I tested with another chat room owned by me and works fine, all forwarded media is downloaded properly, but if the Chat ID passed is the Saved Messages one it fails with an error:

(Channel ID edited)
ValueError: Could not find the input entity for PeerChannel(channel_id=XXXXXXXXX) (PeerChannel).

I get the channel id from telegram Web and it works in another test script I have

Is this an expected behavior?

Failed during copy to dest folder (I think)

I'm trying to download a single file. The status message kept update, until about 95.9%, and then nothing happened. The file does not exist in the dest folder (can't see it in the list`status` commands).

Log:

Session loaded from /session/DownloadDaemon.session,
Session saved in /session/DownloadDaemon.session,
Telegram Download Daemon 1.3,
NewMessage.Event(original_update=UpdateNewChannelMessage(message=Message(id=1057, peer_id=PeerChannel(channel_id=1173148616), date=datetime.datetime(2021, 3, 6, 19, 3, 51, tzinfo=datetime.timezone.utc), message='', out=True, mentioned=False, media_unread=False, silent=False, post=True, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, from_id=None, fwd_from=MessageFwdHeader(date=datetime.datetime(2021, 1, 3, 21, 43, 55, tzinfo=datetime.timezone.utc), from_id=PeerChannel(channel_id=1373916108), from_name=None, channel_post=99, post_author=None, saved_from_peer=None, saved_from_msg_id=None, psa_type=None), via_bot_id=None, reply_to=None, media=MessageMediaDocument(document=Document(id=6021780247639230837, access_hash=-5551498327692000896, file_reference=b'\x04E\xec\xd3\xc8\x00\x00\x04!`C\xd2\x16\xd5h3\t\xd4\x92\xcf8\x9bdj\xd6\xc2t\xaf\x19', date=datetime.datetime(2021, 1, 3, 21, 42, 47, tzinfo=datetime.timezone.utc), mime_type='video/mp4', size=1463402706, dc_id=4, attributes=[DocumentAttributeFilename(file_name='1080p 谞转讬 诪讚讬讛 砖讟讬住诇 注3 驻3.mp4')], thumbs=[], video_thumbs=[]), ttl_seconds=None), reply_markup=None, entities=[], views=1, forwards=0, replies=None, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[]), pts=1619, pts_count=1), pattern_match=None, message=Message(id=1057, peer_id=PeerChannel(channel_id=1173148616), date=datetime.datetime(2021, 3, 6, 19, 3, 51, tzinfo=datetime.timezone.utc), message='', out=True, mentioned=False, media_unread=False, silent=False, post=True, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, from_id=None, fwd_from=MessageFwdHeader(date=datetime.datetime(2021, 1, 3, 21, 43, 55, tzinfo=datetime.timezone.utc), from_id=PeerChannel(channel_id=1373916108), from_name=None, channel_post=99, post_author=None, saved_from_peer=None, saved_from_msg_id=None, psa_type=None), via_bot_id=None, reply_to=None, media=MessageMediaDocument(document=Document(id=6021780247639230837, access_hash=-5551498327692000896, file_reference=b'\x04E\xec\xd3\xc8\x00\x00\x04!`C\xd2\x16\xd5h3\t\xd4\x92\xcf8\x9bdj\xd6\xc2t\xaf\x19', date=datetime.datetime(2021, 1, 3, 21, 42, 47, tzinfo=datetime.timezone.utc), mime_type='video/mp4', size=1463402706, dc_id=4, attributes=[DocumentAttributeFilename(file_name='1080p 谞转讬 诪讚讬讛 砖讟讬住诇 注3 驻3.mp4')], thumbs=[], video_thumbs=[]), ttl_seconds=None), reply_markup=None, entities=[], views=1, forwards=0, replies=None, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[])),
Downloading file 1080p 谞转讬 诪讚讬讛 砖讟讬住诇 注3 驻3.mp4 (1463402706 bytes),
0.03 % (524288 / 1463402706),
0.07 % (1048576 / 1463402706),
0.1 % (1572864 / 1463402706),
0.14 % (2097152 / 1463402706),
0.17 % (2621440 / 1463402706),
0.21 % (3145728 / 1463402706),
0.25 % (3670016 / 1463402706),
0.28 % (4194304 / 1463402706),
0.32 % (4718592 / 1463402706),
0.35 % (5242880 / 1463402706),
0.39 % (5767168 / 1463402706),
0.42 % (6291456 / 1463402706),
0.46 % (6815744 / 1463402706),
0.5 % (7340032 / 1463402706),
0.53 % (7864320 / 1463402706),
0.57 % (8388608 / 1463402706),
0.6 % (8912896 / 1463402706),
0.64 % (9437184 / 1463402706),
0.68 % (9961472 / 1463402706),
0.71 % (10485760 / 1463402706),
0.75 % (11010048 / 1463402706),
0.78 % (11534336 / 1463402706),
0.82 % (12058624 / 1463402706),
0.85 % (12582912 / 1463402706),
0.89 % (13107200 / 1463402706),
0.93 % (13631488 / 1463402706),
0.96 % (14155776 / 1463402706),
5.01 % (73400320 / 1463402706),
5.05 % (73924608 / 1463402706),
5.08 % (74448896 / 1463402706),
5.12 % (74973184 / 1463402706),
5.15 % (75497472 / 1463402706),
5.19 % (76021760 / 1463402706),
5.23 % (76546048 / 1463402706),
5.26 % (77070336 / 1463402706),
5.3 % (77594624 / 1463402706),
5.33 % (78118912 / 1463402706),
5.37 % (78643200 / 1463402706),
5.4 % (79167488 / 1463402706),
5.44 % (79691776 / 1463402706),
5.48 % (80216064 / 1463402706),
5.51 % (80740352 / 1463402706),
5.55 % (81264640 / 1463402706),
5.58 % (81788928 / 1463402706),
5.62 % (82313216 / 1463402706),
5.66 % (82837504 / 1463402706),
5.69 % (83361792 / 1463402706),
5.73 % (83886080 / 1463402706),
5.76 % (84410368 / 1463402706),
5.8 % (84934656 / 1463402706),
5.83 % (85458944 / 1463402706),
5.87 % (85983232 / 1463402706),
5.91 % (86507520 / 1463402706),
5.94 % (87031808 / 1463402706),
5.98 % (87556096 / 1463402706),
10.03 % (146800640 / 1463402706),
10.06 % (147324928 / 1463402706),
10.1 % (147849216 / 1463402706),
10.13 % (148373504 / 1463402706),
10.17 % (148897792 / 1463402706),
10.21 % (149422080 / 1463402706),
10.24 % (149946368 / 1463402706),
10.28 % (150470656 / 1463402706),
10.31 % (150994944 / 1463402706),
10.35 % (151519232 / 1463402706),
10.38 % (152043520 / 1463402706),
10.42 % (152567808 / 1463402706),
10.46 % (153092096 / 1463402706),
10.49 % (153616384 / 1463402706),
10.53 % (154140672 / 1463402706),
10.56 % (154664960 / 1463402706),
10.6 % (155189248 / 1463402706),
10.64 % (155713536 / 1463402706),
10.67 % (156237824 / 1463402706),
10.71 % (156762112 / 1463402706),
10.74 % (157286400 / 1463402706),
10.78 % (157810688 / 1463402706),
10.81 % (158334976 / 1463402706),
10.85 % (158859264 / 1463402706),
10.89 % (159383552 / 1463402706),
10.92 % (159907840 / 1463402706),
10.96 % (160432128 / 1463402706),
10.99 % (160956416 / 1463402706),
15.01 % (219676672 / 1463402706),
15.04 % (220200960 / 1463402706),
15.08 % (220725248 / 1463402706),
15.11 % (221249536 / 1463402706),
15.15 % (221773824 / 1463402706),
15.19 % (222298112 / 1463402706),
15.22 % (222822400 / 1463402706),
15.26 % (223346688 / 1463402706),
15.29 % (223870976 / 1463402706),
15.33 % (224395264 / 1463402706),
15.36 % (224919552 / 1463402706),
15.4 % (225443840 / 1463402706),
15.44 % (225968128 / 1463402706),
15.47 % (226492416 / 1463402706),
15.51 % (227016704 / 1463402706),
15.54 % (227540992 / 1463402706),
15.58 % (228065280 / 1463402706),
15.62 % (228589568 / 1463402706),
15.65 % (229113856 / 1463402706),
15.69 % (229638144 / 1463402706),
15.72 % (230162432 / 1463402706),
15.76 % (230686720 / 1463402706),
15.79 % (231211008 / 1463402706),
15.83 % (231735296 / 1463402706),
15.87 % (232259584 / 1463402706),
15.9 % (232783872 / 1463402706),
15.94 % (233308160 / 1463402706),
15.97 % (233832448 / 1463402706),
20.02 % (293076992 / 1463402706),
20.06 % (293601280 / 1463402706),
20.09 % (294125568 / 1463402706),
20.13 % (294649856 / 1463402706),
20.17 % (295174144 / 1463402706),
20.2 % (295698432 / 1463402706),
20.24 % (296222720 / 1463402706),
20.27 % (296747008 / 1463402706),
20.31 % (297271296 / 1463402706),
20.34 % (297795584 / 1463402706),
20.38 % (298319872 / 1463402706),
20.42 % (298844160 / 1463402706),
20.45 % (299368448 / 1463402706),
20.49 % (299892736 / 1463402706),
20.52 % (300417024 / 1463402706),
20.56 % (300941312 / 1463402706),
20.6 % (301465600 / 1463402706),
20.63 % (301989888 / 1463402706),
20.67 % (302514176 / 1463402706),
20.7 % (303038464 / 1463402706),
20.74 % (303562752 / 1463402706),
20.77 % (304087040 / 1463402706),
20.81 % (304611328 / 1463402706),
20.85 % (305135616 / 1463402706),
20.88 % (305659904 / 1463402706),
20.92 % (306184192 / 1463402706),
20.95 % (306708480 / 1463402706),
20.99 % (307232768 / 1463402706),
25.0 % (365953024 / 1463402706),
25.04 % (366477312 / 1463402706),
25.07 % (367001600 / 1463402706),
25.11 % (367525888 / 1463402706),
25.15 % (368050176 / 1463402706),
25.18 % (368574464 / 1463402706),
25.22 % (369098752 / 1463402706),
25.25 % (369623040 / 1463402706),
25.29 % (370147328 / 1463402706),
25.32 % (370671616 / 1463402706),
25.36 % (371195904 / 1463402706),
25.4 % (371720192 / 1463402706),
25.43 % (372244480 / 1463402706),
25.47 % (372768768 / 1463402706),
25.5 % (373293056 / 1463402706),
25.54 % (373817344 / 1463402706),
25.58 % (374341632 / 1463402706),
25.61 % (374865920 / 1463402706),
25.65 % (375390208 / 1463402706),
25.68 % (375914496 / 1463402706),
25.72 % (376438784 / 1463402706),
25.75 % (376963072 / 1463402706),
25.79 % (377487360 / 1463402706),
25.83 % (378011648 / 1463402706),
25.86 % (378535936 / 1463402706),
25.9 % (379060224 / 1463402706),
25.93 % (379584512 / 1463402706),
25.97 % (380108800 / 1463402706),
30.02 % (439353344 / 1463402706),
30.05 % (439877632 / 1463402706),
30.09 % (440401920 / 1463402706),
30.13 % (440926208 / 1463402706),
30.16 % (441450496 / 1463402706),
30.2 % (441974784 / 1463402706),
30.23 % (442499072 / 1463402706),
30.27 % (443023360 / 1463402706),
30.3 % (443547648 / 1463402706),
30.34 % (444071936 / 1463402706),
30.38 % (444596224 / 1463402706),
30.41 % (445120512 / 1463402706),
30.45 % (445644800 / 1463402706),
30.48 % (446169088 / 1463402706),
30.52 % (446693376 / 1463402706),
30.56 % (447217664 / 1463402706),
30.59 % (447741952 / 1463402706),
30.63 % (448266240 / 1463402706),
30.66 % (448790528 / 1463402706),
30.7 % (449314816 / 1463402706),
30.73 % (449839104 / 1463402706),
30.77 % (450363392 / 1463402706),
30.81 % (450887680 / 1463402706),
30.84 % (451411968 / 1463402706),
30.88 % (451936256 / 1463402706),
30.91 % (452460544 / 1463402706),
30.95 % (452984832 / 1463402706),
30.99 % (453509120 / 1463402706),
35.0 % (512229376 / 1463402706),
35.03 % (512753664 / 1463402706),
35.07 % (513277952 / 1463402706),
35.11 % (513802240 / 1463402706),
35.14 % (514326528 / 1463402706),
35.18 % (514850816 / 1463402706),
35.21 % (515375104 / 1463402706),
35.25 % (515899392 / 1463402706),
35.28 % (516423680 / 1463402706),
35.32 % (516947968 / 1463402706),
35.36 % (517472256 / 1463402706),
35.39 % (517996544 / 1463402706),
35.43 % (518520832 / 1463402706),
35.46 % (519045120 / 1463402706),
35.5 % (519569408 / 1463402706),
35.54 % (520093696 / 1463402706),
35.57 % (520617984 / 1463402706),
35.61 % (521142272 / 1463402706),
35.64 % (521666560 / 1463402706),
35.68 % (522190848 / 1463402706),
35.71 % (522715136 / 1463402706),
35.75 % (523239424 / 1463402706),
35.79 % (523763712 / 1463402706),
35.82 % (524288000 / 1463402706),
35.86 % (524812288 / 1463402706),
35.89 % (525336576 / 1463402706),
35.93 % (525860864 / 1463402706),
35.96 % (526385152 / 1463402706),
40.01 % (585629696 / 1463402706),
40.05 % (586153984 / 1463402706),
40.09 % (586678272 / 1463402706),
40.12 % (587202560 / 1463402706),
40.16 % (587726848 / 1463402706),
40.19 % (588251136 / 1463402706),
40.23 % (588775424 / 1463402706),
40.26 % (589299712 / 1463402706),
40.3 % (589824000 / 1463402706),
40.34 % (590348288 / 1463402706),
40.37 % (590872576 / 1463402706),
40.41 % (591396864 / 1463402706),
40.44 % (591921152 / 1463402706),
40.48 % (592445440 / 1463402706),
40.51 % (592969728 / 1463402706),
40.55 % (593494016 / 1463402706),
40.59 % (594018304 / 1463402706),
40.62 % (594542592 / 1463402706),
40.66 % (595066880 / 1463402706),
40.69 % (595591168 / 1463402706),
40.73 % (596115456 / 1463402706),
40.77 % (596639744 / 1463402706),
40.8 % (597164032 / 1463402706),
40.84 % (597688320 / 1463402706),
40.87 % (598212608 / 1463402706),
40.91 % (598736896 / 1463402706),
40.94 % (599261184 / 1463402706),
40.98 % (599785472 / 1463402706),
45.03 % (659030016 / 1463402706),
45.06 % (659554304 / 1463402706),
45.1 % (660078592 / 1463402706),
45.14 % (660602880 / 1463402706),
45.17 % (661127168 / 1463402706),
45.21 % (661651456 / 1463402706),
45.24 % (662175744 / 1463402706),
45.28 % (662700032 / 1463402706),
45.32 % (663224320 / 1463402706),
45.35 % (663748608 / 1463402706),
45.39 % (664272896 / 1463402706),
45.42 % (664797184 / 1463402706),
45.46 % (665321472 / 1463402706),
45.49 % (665845760 / 1463402706),
45.53 % (666370048 / 1463402706),
45.57 % (666894336 / 1463402706),
45.6 % (667418624 / 1463402706),
45.64 % (667942912 / 1463402706),
45.67 % (668467200 / 1463402706),
45.71 % (668991488 / 1463402706),
45.75 % (669515776 / 1463402706),
45.78 % (670040064 / 1463402706),
45.82 % (670564352 / 1463402706),
45.85 % (671088640 / 1463402706),
45.89 % (671612928 / 1463402706),
45.92 % (672137216 / 1463402706),
45.96 % (672661504 / 1463402706),
50.01 % (731906048 / 1463402706),
50.04 % (732430336 / 1463402706),
50.08 % (732954624 / 1463402706),
50.12 % (733478912 / 1463402706),
50.15 % (734003200 / 1463402706),
50.19 % (734527488 / 1463402706),
50.22 % (735051776 / 1463402706),
50.26 % (735576064 / 1463402706),
50.3 % (736100352 / 1463402706),
50.33 % (736624640 / 1463402706),
50.37 % (737148928 / 1463402706),
50.4 % (737673216 / 1463402706),
50.44 % (738197504 / 1463402706),
50.47 % (738721792 / 1463402706),
50.51 % (739246080 / 1463402706),
50.55 % (739770368 / 1463402706),
50.58 % (740294656 / 1463402706),
50.62 % (740818944 / 1463402706),
50.65 % (741343232 / 1463402706),
50.69 % (741867520 / 1463402706),
50.73 % (742391808 / 1463402706),
50.76 % (742916096 / 1463402706),
50.8 % (743440384 / 1463402706),
50.83 % (743964672 / 1463402706),
50.87 % (744488960 / 1463402706),
50.9 % (745013248 / 1463402706),
50.94 % (745537536 / 1463402706),
50.98 % (746061824 / 1463402706),
55.02 % (805306368 / 1463402706),
55.06 % (805830656 / 1463402706),
55.1 % (806354944 / 1463402706),
55.13 % (806879232 / 1463402706),
55.17 % (807403520 / 1463402706),
55.2 % (807927808 / 1463402706),
55.24 % (808452096 / 1463402706),
55.28 % (808976384 / 1463402706),
55.31 % (809500672 / 1463402706),
55.35 % (810024960 / 1463402706),
55.38 % (810549248 / 1463402706),
55.42 % (811073536 / 1463402706),
55.45 % (811597824 / 1463402706),
55.49 % (812122112 / 1463402706),
55.53 % (812646400 / 1463402706),
55.56 % (813170688 / 1463402706),
55.6 % (813694976 / 1463402706),
55.63 % (814219264 / 1463402706),
55.67 % (814743552 / 1463402706),
55.71 % (815267840 / 1463402706),
55.74 % (815792128 / 1463402706),
55.78 % (816316416 / 1463402706),
55.81 % (816840704 / 1463402706),
55.85 % (817364992 / 1463402706),
55.88 % (817889280 / 1463402706),
55.92 % (818413568 / 1463402706),
55.96 % (818937856 / 1463402706),
55.99 % (819462144 / 1463402706),
60.0 % (878182400 / 1463402706),
60.04 % (878706688 / 1463402706),
60.08 % (879230976 / 1463402706),
60.11 % (879755264 / 1463402706),
60.15 % (880279552 / 1463402706),
60.18 % (880803840 / 1463402706),
60.22 % (881328128 / 1463402706),
60.26 % (881852416 / 1463402706),
60.29 % (882376704 / 1463402706),
60.33 % (882900992 / 1463402706),
60.36 % (883425280 / 1463402706),
60.4 % (883949568 / 1463402706),
60.43 % (884473856 / 1463402706),
60.47 % (884998144 / 1463402706),
60.51 % (885522432 / 1463402706),
60.54 % (886046720 / 1463402706),
60.58 % (886571008 / 1463402706),
60.61 % (887095296 / 1463402706),
60.65 % (887619584 / 1463402706),
60.69 % (888143872 / 1463402706),
60.72 % (888668160 / 1463402706),
60.76 % (889192448 / 1463402706),
60.79 % (889716736 / 1463402706),
60.83 % (890241024 / 1463402706),
60.86 % (890765312 / 1463402706),
60.9 % (891289600 / 1463402706),
60.94 % (891813888 / 1463402706),
60.97 % (892338176 / 1463402706),
65.02 % (951582720 / 1463402706),
65.06 % (952107008 / 1463402706),
65.09 % (952631296 / 1463402706),
65.13 % (953155584 / 1463402706),
65.16 % (953679872 / 1463402706),
65.2 % (954204160 / 1463402706),
65.24 % (954728448 / 1463402706),
65.27 % (955252736 / 1463402706),
65.31 % (955777024 / 1463402706),
65.34 % (956301312 / 1463402706),
65.38 % (956825600 / 1463402706),
65.41 % (957349888 / 1463402706),
65.45 % (957874176 / 1463402706),
65.49 % (958398464 / 1463402706),
65.52 % (958922752 / 1463402706),
65.56 % (959447040 / 1463402706),
65.59 % (959971328 / 1463402706),
65.63 % (960495616 / 1463402706),
65.67 % (961019904 / 1463402706),
65.7 % (961544192 / 1463402706),
65.74 % (962068480 / 1463402706),
65.77 % (962592768 / 1463402706),
65.81 % (963117056 / 1463402706),
65.84 % (963641344 / 1463402706),
65.88 % (964165632 / 1463402706),
65.92 % (964689920 / 1463402706),
65.95 % (965214208 / 1463402706),
65.99 % (965738496 / 1463402706),
70.0 % (1024458752 / 1463402706),
70.04 % (1024983040 / 1463402706),
70.07 % (1025507328 / 1463402706),
70.11 % (1026031616 / 1463402706),
70.14 % (1026555904 / 1463402706),
70.18 % (1027080192 / 1463402706),
70.22 % (1027604480 / 1463402706),
70.25 % (1028128768 / 1463402706),
70.29 % (1028653056 / 1463402706),
70.32 % (1029177344 / 1463402706),
70.36 % (1029701632 / 1463402706),
70.39 % (1030225920 / 1463402706),
70.43 % (1030750208 / 1463402706),
70.47 % (1031274496 / 1463402706),
70.5 % (1031798784 / 1463402706),
70.54 % (1032323072 / 1463402706),
70.57 % (1032847360 / 1463402706),
70.61 % (1033371648 / 1463402706),
70.65 % (1033895936 / 1463402706),
70.68 % (1034420224 / 1463402706),
70.72 % (1034944512 / 1463402706),
70.75 % (1035468800 / 1463402706),
70.79 % (1035993088 / 1463402706),
70.82 % (1036517376 / 1463402706),
70.86 % (1037041664 / 1463402706),
70.9 % (1037565952 / 1463402706),
70.93 % (1038090240 / 1463402706),
//./telegram-download-daemon.py:193: RuntimeWarning: coroutine 'set_progress' was never awaited,
  set_progress(filename, message, 100, 100),
RuntimeWarning: Enable tracemalloc to get the object allocation traceback,

Sorry for the Hebrew filename :-)

Wrong file extension

Sometimes I see (double) files with a temporary extension

I can view the file with a photoviewer, so it's only the naming part.

image

Limit the parallelism degree

I think the amount of parallel downloads should be in the amount of CPU cores, or something similar.

Because there is a limit of how we can download in any moment, and if this moment shared with a lot of downloads, it will take a long time for the first download to finish.

So we need a queue, maybe python can handle this out of the box, and if not, we want to decide on the parallelism degree.

Docker

We need to put this deamon in Docker Image and publish it with Github Actions

Issue with file size limit

Hi, I鈥檓 trying to downloads files of 1990MB but the script doesn鈥檛 work for me.
FFDB0194-3272-4574-B9AC-97158D299DCA

Through ssh the terminal returns the following message:

Downloading file Attract_Mode_Pack_Sony_PlayStation_Full_Collection_1531_Games_part001.rar (2086666240 bytes) Queue worker error: File size too large

Thanks

Error

i go the following error (Win10,Python 3.9.2):

Telegram Download Daemon 1.4
Traceback (most recent call last):
  File "M:\telepy\telegram-download-daemon.py", line 224, in <module>
    client.loop.run_until_complete(start())
  File "C:\Users\Maik\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "M:\telepy\telegram-download-daemon.py", line 218, in start
    await sendHelloMessage(client, peerChannel)
  File "M:\telepy\telegram-download-daemon.py", line 100, in sendHelloMessage
    await client.send_message(entity, "Telegram Download Daemon "+TDD_VERSION)
  File "C:\Users\Maik\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\messages.py", line 826, in send_message
    result = await self(request)
  File "C:\Users\Maik\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\Maik\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by SendMessageRequest)
[ERROR/2021-03-22 11:34:47,712]asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-10' coro=<worker() running at M:\telepy\telegram-download-daemon.py:189> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000001FB4FA01520>()]>>

Queue worker error

the file never is completed
0.03 % (262144 / 690880595) 5.8 % (40108032 / 690880595) 11.99 % (82837504 / 690880595) Queue worker error: A timeout occurred while fetching data from the worker (caused by GetFileRequest)

Feature Request : Option to organise forwarded files

Great work by the way. I find this script very usefull. What do you think of an option to organise files based on sender? By sender I mean the original sender of files that are forwarded with quotes. All files quoted from the same source can go to a dedicated folder.

Enhancement request: suffix in-progress downloads as .part

I often download the files in bulk. E.g. entire season of a TV series.
For this, I just forward the messages to the channel using my phone and this script running on a home system downloads them nicely.
After the downloads are complete, I move the files from my download directory to the actual location where I want those files (external HDD) using ssh.

However, when you have enqueued 20+ files, it is difficult to keep a track of completed downloads by going through the "file XXXXXXXXX.mp4 is ready" messages.
It will be useful if we can suffix the in-progress downloads as .part or .tdd (short for telegram-downloader-daemon). After the download completes, rename the file to remove the suffix.
So, just by the file extension, we can easily find which files are completed.

Alternately, if having a suffix is difficult, we can have a folder named "partials" in the downloads directory and the files will be downloaded there. After the download is completed, move them to the download folder.

[Suggestion] Filename

If a video is sent to the chat as photo/video (instead of sending as a file), the daemon will name it as something like -da5gts3m (that is 8 characters of lowercase letters and/or numbers, starting with a dash, and no .mp4 suffix).
But if I download the same video using telegram web or windows app, the filename is something like 2877589252854127294.mp4 (that is 19 digits of numbers).

The problem is, if a video is sent to the chat twice, the daemon will name 2 videos differently, while the telegram app will give them the same name.

So, would you add the suffix to those .mp4 files when downloading, and is it possible to change the naming format to the telegram app style?

Thank you!

Use messages as DB

Currently we have some problems in the area of persistency.

The main problem is that if the daemon stopped without finishing its tasks, it will not continue them next time it loaded.

I think we can solve that somehow by reading the history of the messages when the daemon loading, then for each file, the daemon need to search all the replies of that message to get the latest status.

To reduce the amount of the message, we can update the status by editing the message, instead of replying new one.

What do you think?

Two factor authentication

The first time I ran the script, it requests me to give him my phone number to validate.

But it was one time, and after that, it doesn't ask me anymore.

Is it will ask me again sometimes?

Can we automate that (I saw something about bot_id?)?

Limit of files size?

In the README you writte the limit is 1'5GB, is it correct? Or the new limit of Telegram is 2GB?

requirements.txt

There is a convention to declare pip dependencies in requirements,txt file, and then install them all by one pip command.

Get values from Environment Variables

I think we need to get the three custom values from environment variables, and from command line argument (if no command line argument- read from environment variable)

Reply and maybe edit messages

Currently we responding to the channel, so assume I sent 10 files, I will see another 10 messages about start downloading, then 10 messages about finish downloading, and I need to search which file is downloaded.

If we will use the reply method instead of respond, we will see which file we talking about.

Consider to edit the original or reply message, we can keep all the data in one message: reply to the incoming message with the message Starting to download, then adding to this message the message download complete.

problems

Hi, I have everything configured correctly .. the program works for 80% ...

It often happens that it does not download the file, even if it says that it is in download but it does not go in download, then if I put another it remains in the queue .. this often happens.
I hope for a resolution of the problem.
Excuse my English, but I'm Italian

edite and delete messages

Hi
It would be useful if there was only one answer for each file and it was edited. I have tried modifying with client.edit_message and it works if you only download 1 in 1
the problem comes when there are multiple files in the queue. I do not know how to do it. I mention it in case you want to add this function
in the code I see% download but when I use it it only appears in queue, downloading and finish

Docker arm compatible

I don't really know where can I ask for this, but I was using Docker on an old laptop with ubuntu and it was working perfect, but I decided to move all my containers to a Raspberry pi and I'm having issues as it's arm and the container is only for x86/x64.
Is there any chance to be able to have an arm version of the docker container?
Thank you

the messages reappear

running the script only shows that you have deleted 100 messages. When looking at the telegram group, all the messages disappear but after a while all the messages appear again except 100 messages

Not working with AVI or MKV files

In the 1.3 versi贸n, the service does not work with AVI or MKV files. It shows that it is downloading the file but the status indicates that there are no active downloads. It does not show the percentage of progress.

Error message

There is a situation (I need to open a specific bug on it) that you sending a media file (maybe it is a streaming file or something? this is related to a different bug), but the daemon failed to download it.

We need to send a message to the channel failed to download.

Error with DocumentAttributeVideo

Hi, first thank you for sharing, great job with this project!
I faced an error when message contains a DocumentAttributeVideo instead of a DocumentAttributeFilename

This is the stacktrace:

NewMessage.Event(original_update=UpdateNewChannelMessage(message=Message(id=34, to_id=PeerChannel(channel_id=1424057180), date=datetime.datetime(2020, 9, 13, 3, 17, 31, tzinfo=datetime.timezone.utc), message='2020 (subtitulada)', out=True, mentioned=False, media_unread=False, silent=False, post=True, from_scheduled=False, legacy=False, edit_hide=False, from_id=None, fwd_from=MessageFwdHeader(date=datetime.datetime(2020, 9, 4, 20, 32, 14, tzinfo=datetime.timezone.utc), from_id=None, from_name=None, channel_id=1286109059, channel_post=363, post_author='Girohens', saved_from_peer=None, saved_from_msg_id=None, psa_type=None), via_bot_id=None, reply_to_msg_id=None, media=MessageMediaDocument(document=Document(id=5085077086159241436, access_hash=-3834822399060811738, file_reference=b'\x04T\xe1c\\x00\x00\x00"]\x8fK\x86\xe3\x8at\xc4W\xc8\xca\x15\xc8*\x9c\xa8\xcf\x95\xd8', date=datetime.datetime(2020, 9, 4, 20, 31, 40, tzinfo=datetime.timezone.utc), mime_type='video/mp4', size=1059123240, dc_id=1, attributes=[DocumentAttributeVideo(duration=6908, w=1280, h=536, round_message=False, supports_streaming=True)], thumbs=[PhotoStrippedSize(type='i', bytes=b'\x01\x11(\xc5\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x03'), PhotoSize(type='m', location=FileLocationToBeDeprecated(volume_id=107831094, local_id=19068), w=320, h=134, size=1108)], video_thumbs=[]), ttl_seconds=None), reply_markup=None, entities=[], views=1, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[]), pts=35, pts_count=1), pattern_match=None, message=Message(id=34, to_id=PeerChannel(channel_id=1424057180), date=datetime.datetime(2020, 9, 13, 3, 17, 31, tzinfo=datetime.timezone.utc), message='2020 (subtitulada)', out=True, mentioned=False, media_unread=False, silent=False, post=True, from_scheduled=False, legacy=False, edit_hide=False, from_id=None, fwd_from=MessageFwdHeader(date=datetime.datetime(2020, 9, 4, 20, 32, 14, tzinfo=datetime.timezone.utc), from_id=None, from_name=None, channel_id=1286109059, channel_post=363, post_author='Girohens', saved_from_peer=None, saved_from_msg_id=None, psa_type=None), via_bot_id=None, reply_to_msg_id=None, media=MessageMediaDocument(document=Document(id=5085077086159241436, access_hash=-3834822399060811738, file_reference=b'\x04T\xe1c\\x00\x00\x00"]\x8fK\x86\xe3\x8at\xc4W\xc8\xca\x15\xc8*\x9c\xa8\xcf\x95\xd8', date=datetime.datetime(2020, 9, 4, 20, 31, 40, tzinfo=datetime.timezone.utc), mime_type='video/mp4', size=1059123240, dc_id=1, attributes=[DocumentAttributeVideo(duration=6908, w=1280, h=536, round_message=False, supports_streaming=True)], thumbs=[PhotoStrippedSize(type='i', bytes=b'\x01\x11(\xc5\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x03'), PhotoSize(type='m', location=FileLocationToBeDeprecated(volume_id=107831094, local_id=19068), w=320, h=134, size=1108)], video_thumbs=[]), ttl_seconds=None), reply_markup=None, entities=[], views=1, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[]))
[ERROR/2020-09-12 22:17:31,552]telethon.client.updates:Unhandled exception on handler
Traceback (most recent call last):
File "telegram-download-daemon.py", line 103, in handler
filename=getFilename(event)
File "telegram-download-daemon.py", line 83, in getFilename
return next(x for x in event.media.document.attributes if isinstance(x, DocumentAttributeFilename)).file_name
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/telethon/client/updates.py", line 443, in _dispatch_update
await callback(event)
RuntimeError: coroutine raised StopIteration

I will try to solve it but I'm very unfamiliar with python!

not download anything

Hi
I have followed all the steps the session is created correctly but when I send files to the channel it does not download anything
20200604133750.tar added to queue
Downloading file 20200604133750.tar (29747200 bytes)

Would you save message content nearby downloaded file?

Hello, @alfem !

I did some changes to save messages with downloading files and some debug info send back to telegram message. I did it because messages could contains some sensitive info like password for archive :) See diff bellow. Also i did somewhere safe concatenation dir and filename with os module.

diff --git a/telegram-download-daemon.py b/telegram-download-daemon.py
index 36ece73..2da9ffc 100644
--- a/telegram-download-daemon.py
+++ b/telegram-download-daemon.py
@@ -3,8 +3,8 @@
 # Author: Alfonso E.M. <[email protected]>
 # You need to install telethon (and cryptg to speed up downloads)
 
-from os import getenv
-from shutil import move
+import os
+import shutil
 import subprocess
 import math
 import time
@@ -25,14 +25,14 @@ import asyncio
 
 TDD_VERSION="1.4"
 
-TELEGRAM_DAEMON_API_ID = getenv("TELEGRAM_DAEMON_API_ID")
-TELEGRAM_DAEMON_API_HASH = getenv("TELEGRAM_DAEMON_API_HASH")
-TELEGRAM_DAEMON_CHANNEL = getenv("TELEGRAM_DAEMON_CHANNEL")
+TELEGRAM_DAEMON_API_ID = os.getenv("TELEGRAM_DAEMON_API_ID")
+TELEGRAM_DAEMON_API_HASH = os.getenv("TELEGRAM_DAEMON_API_HASH")
+TELEGRAM_DAEMON_CHANNEL = os.getenv("TELEGRAM_DAEMON_CHANNEL")
 
-TELEGRAM_DAEMON_SESSION_PATH = getenv("TELEGRAM_DAEMON_SESSION_PATH")
+TELEGRAM_DAEMON_SESSION_PATH = os.getenv("TELEGRAM_DAEMON_SESSION_PATH")
 
-TELEGRAM_DAEMON_DEST=getenv("TELEGRAM_DAEMON_DEST", "/telegram-downloads")
-TELEGRAM_DAEMON_TEMP=getenv("TELEGRAM_DAEMON_TEMP", "")
+TELEGRAM_DAEMON_DEST=os.getenv("TELEGRAM_DAEMON_DEST", "/telegram-downloads")
+TELEGRAM_DAEMON_TEMP=os.getenv("TELEGRAM_DAEMON_TEMP", "")
 
 TELEGRAM_DAEMON_TEMP_SUFFIX="tdd"
 
@@ -184,6 +184,7 @@ with TelegramClient(getSession(), api_id, api_hash,
                 print('Events handler error: ', e)
 
     async def worker():
+        global downloadFolder
         while True:
             try:
                 element = await queue.get()
@@ -201,12 +202,34 @@ with TelegramClient(getSession(), api_id, api_hash,
 
                 await client.download_media(event.message, "{0}/{1}.{2}".format(tempFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX), progress_callback = download_callback)
                 set_progress(filename, message, 100, 100)
-                move("{0}/{1}.{2}".format(tempFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX), "{0}/{1}".format(downloadFolder,filename))
+                if event.message.message:
+                    try:
+                        _dir = os.path.splitext(filename)[0]
+                    except:
+                        _dir = filename
+                    downloadFolder = os.path.join(downloadFolder, _dir)
+                    if not os.path.exists(downloadFolder):
+                        os.makedirs(downloadFolder)
+                    with open(os.path.join(downloadFolder, "message.txt"), "w") as f:
+                        f.write(f'{event.message.message}\n')
+                try:
+                    move_from = os.path.join(tempFolder, "{}.{}".format(filename,TELEGRAM_DAEMON_TEMP_SUFFIX))
+                    move_to = os.path.join(downloadFolder, filename)
+                    if os.path.exists(move_from):
+                        shutil.move(move_from, move_to)
+                    else:
+                        set_progress(filename, f"error: tmpfile for '{filename}' doesn't exist!", 0, 0)
+                except Exception as exc:
+                    set_progress(filename, f"shutil error: {str(exc)}", 0, 0)
+                    print('shutil error: ', e)
+
                 await log_reply(message, "{0} ready".format(filename))
 
                 queue.task_done()
             except Exception as e:
+                set_progress(filename, f"Queue worker error: {str(e)}", 0, 0)
                 print('Queue worker error: ', e)
+
  
     async def start():

request

is possible view realtime speed and % for finish
image

Synology Docker installation

Hi, I saw you have a Synology.
Is it possible to make a tutorial for the demon installation (docker) on the Synology please?

RPCError 406: UPDATE_APP_TO_LOGIN (caused by SendCodeRequest)

Greetings,

I am receiving the following error:
Traceback (most recent call last):
File "./telegram-download-daemon.py", line 170, in
proxy=proxy).start() as client:
File "/usr/local/lib/python3.6/site-packages/telethon/client/auth.py", line 133, in start
else self.loop.run_until_complete(coro)
File "/usr/local/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/site-packages/telethon/client/auth.py", line 189, in _start
await self.send_code_request(phone, force_sms=force_sms)
File "/usr/local/lib/python3.6/site-packages/telethon/client/auth.py", line 515, in send_code_request
phone, self.api_id, self.api_hash, types.CodeSettings()))
File "/usr/local/lib/python3.6/site-packages/telethon/client/users.py", line 30, in call
return await self._call(self._sender, request, ordered=ordered)
File "/usr/local/lib/python3.6/site-packages/telethon/client/users.py", line 79, in _call
result = await future
telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SendCodeRequest)

This is received after putting in the number.
Script seems to be in need of an update since the last twitter update.

Anyone els also receiving this?

error when try to download a file from a channel with no english name

[ERROR/2021-09-30 14:18:09,013]telethon.client.updates:Unhandled exception on handler Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/telethon/client/updates.py", line 454, in _dispatch_update await callback(event) File "telegram-download-daemon.py", line 183, in handler print(event) UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f3c6' in position 212: ordinal not in range(128)

Downloading multiple DocumentAttributeVideo not possible

def getFilename(event: events.NewMessage.Event): for attribute in event.media.document.attributes: if isinstance(attribute, DocumentAttributeFilename): return attribute.file_name if isinstance(attribute, DocumentAttributeVideo): return "DocumentAttributeVideo"
Because DocumentAttributVideos have no Filenames you overide the last download of DocumentAttributeVideo

It would be bether if the Daemon asks if you want to rename the file before.

Chat admin privileges are required

Got this error message

Traceback (most recent call last):
  File "C:\Users\gilsh\Downloads\telegram-download-daemon-master\telegram-download-daemon-master\telegram-download-daemon.py", line 277, in <module>
    client.loop.run_until_complete(start())
  File "C:\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\gilsh\Downloads\telegram-download-daemon-master\telegram-download-daemon-master\telegram-download-daemon.py", line 271, in start
    await sendHelloMessage(client, peerChannel)
  File "C:\Users\gilsh\Downloads\telegram-download-daemon-master\telegram-download-daemon-master\telegram-download-daemon.py", line 114, in sendHelloMessage
    await client.send_message(entity, "Telegram Download Daemon "+TDD_VERSION)
  File "C:\Python39\lib\site-packages\telethon\client\messages.py", line 853, in send_message
    result = await self(request)
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by SendMessageRequest)
[ERROR/2021-11-20 08:52:22,712]asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-16' coro=<worker() running at C:\Users\gilsh\Downloads\telegram-download-daemon-master\telegram-download-daemon-master\telegram-download-daemon.py:228> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002099058C070>()]>>
[ERROR/2021-11-20 08:52:22,712]asyncio:Task was destroyed but it is pending!
task: <Task pending name='Task-17' coro=<worker() running at C:\Users\gilsh\Downloads\telegram-download-daemon-master\telegram-download-daemon-master\telegram-download-daemon.py:228> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002099058C0A0>()]>>

m煤ltiple links

Hello
I think something was updated because now when sending multiple links at 1 time, only the first one is downloaded. I have to send one by one

Python 3.5 is not supported

Thanks for this repo, but Python 3.5 is not supported with f string :

  File "telegram-download-daemon.py", line 73
    async def sendHelloMessage(client, peerChannel):
            ^
SyntaxError: invalid syntax

Telegram is having internal issues ServerError: RPCError -500: No workers running (caused by GetChannelDifferenceRequest)

Hello @alfem!

First of all thanks for the code here, it's awasome and saved me a lot of manual tasks.

It's been few days that it stopped working with the following error:

[WARNING/2021-10-04 20:43:17,029]telethon.client.users:Telegram is having internal issues ServerError: RPCError -500: No workers running (caused by GetChannelDifferenceRequest)

Do you have any idea what is the root cause?

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.