Tdesktop: Bulk download images

Created on 12 Dec 2015  Â·  48Comments  Â·  Source: telegramdesktop/tdesktop

For example my friend upload and send me 10 pictures to me. Please provide an option to download all of them together, not one by one.

enhancement

Most helpful comment

Since nobody mentioned it yet, you can export the content of a chat and decide to export images only. You can also select a timeframe so you don't have to download the whole pictures history

image

All 48 comments

@auchri is it possible to add this feature? Takes so much time to download one by one.

809 ?

@Aokromes it's related to #809, but it's not the same.

My sister sent me 100 photos from the trip we went and I wasn't able to download the images one by one! So she emailed me. Here is a real situation when telegram lacks this feature.

@amiremami I know this is a dumb workaround, but:
1) Set "Default download path" to the folder you want your photos to be downloaded.
2) Open the most recent photo in a batch.
3) Hover mouse over "Download" icon.
4) Now repedeately press "Left" (or "Right", I don't remember) on keyboard and click left mouse button.

This is the fastest (IMO) method (~2 photos per second) to bulk download images.
Or setup an IFTTT integration...

Hey @MasterGroosha thanks a lot for this trick. Yeah it works, or we can use gmail for sending images, much more easier!

Hope Telegram adds this feature 😞

Upvote from me. Android has an option to auto save all images to gallery, but that feature is missing on Windows (PC) version. Would like to be able to auto save all images on PC so that I can avoid filling up my sd card, as I have a 36 terabyte NAS server which I can save images to instead.

I thought it already was possible, was surprised it was not.
Ideally, what I would like to do is to select a few pictures/messages and right click > save image as...
Saving to the default download folder is limited to the current image being viewed, and for a Telegram Desktop folder with a lot of files it is really inconvenient to have to look and find the ones I want right now.

Just an up to this enhancement. It's necessary to get this option to download or resend images.

Quick tip. It is possible to download media with small python script.

  1. Goto https://my.telegram.org and generate api id and api hash
  2. Install Telethon library with pip3 install telethon
  3. Run following code (replace api_id, api_hash and username with your values):
from telethon.sync import TelegramClient
api_id=123456
api_hash='secretHashYO'
client = TelegramClient('test_session', api_id, api_hash)
client.start()
for message in client.iter_messages('username', limit=25):
    client.download_media(message)

This code downloads media from the last 25 messages from the dialog with username user in current directory.

UPD: Made the script work with the new version of the library (as of 2019-08-08).
UPD 2019-11-14: Replaced get_message_history → iter_messages as the former doesn't work anymore.

This would be extremely useful not for images only but also for files

@Zebradil , nice trick to download, but can it download all videos of the specific group?

@ganeshdeshmukh1612, At the moment I used this approach there was no way to request only media files. If Telegram API is not changed, you have to iterate over all messages in a channel and process each of them one by one.

@ganeshdeshmukh1612 I used this script to download all media from specific group:

requirements.txt

beautifulsoup4==4.6.0
certifi==2017.11.5
chardet==3.0.4
click==6.7
Django==1.11.9
dparse==0.4.1
idna==2.6
mercurial==4.4.2
packaging==17.1
protobuf==3.5.1
pycairo==1.17.0
pygobject==3.28.2
pyparsing==2.2.0
pytz==2017.3
PyYAML==3.13
requests==2.18.4
safety==1.8.4
six==1.11.0
sshuttle==0.78.3
urllib3==1.22
virtualenv==15.1.0
pip install -r requirements.txt
from telethon import TelegramClient
import telethon.sync

import asyncio
import socks

api_id = PLACE_YOUR_APP_ID_HERE
api_hash = PLACE_YOUR_API_HASH_HERE

# to use with TOR proxy
client = TelegramClient('my_session', api_id, api_hash, proxy=(socks.SOCKS5, 'localhost', 9150))
# to use without proxy
# client = TelegramClient('my_session', api_id, api_hash)

client.start()

def load_messages():
    dialogs = client.get_dialogs()
    chat = None

    for dialog in dialogs:
        if dialog.name == YOUR_GROUP_NAME_HERE:
            chat = dialog
            break

    for message in client.iter_messages(chat):
        if message.media:
            print('Downloading...')
            client.download_media(message)

load_messages()

Would you please implement that feature.

My use-case here is that I want to download some (not all) images from a channel. And as I see it the user-friendliest method to implement it would just be a simple SAVE TO PC button to the bar of buttons on top when you selected some messages. Like this eg.
DeepinScreenshot_select-area_20190512165549

Are there any news about this?

Quick tip. It is possible to download media with small python script.

  1. Goto https://my.telegram.org and generate api id and api hash
  2. Install Telethon library with pip3 install telethon
  3. Run following code (replace api_id, api_hash and username with your values):
from telethon import TelegramClient
api_id=123456
api_hash='secretHashYO'
client = TelegramClient('test_session', api_id, api_hash)
client.start()
for message in client.get_message_history('username', limit=25):
    client.download_media(message)

This code downloads media from the last 25 messages from the dialog with username user in current directory.

From which channel/group will it download?

@vijaychandra800 "This code downloads media from the last 25 messages from the dialog with username user in current directory"

This is pathetic.
The need for this feature should have been obvious the very moment saving an image was conceived (which I guess was when Telegram Desktop was created, given that sending photos in the mobile app probably already existed when the Desktop app was created).
It has been explicitly asked for by users for three f**ng years and we are still waiting??

@teo1978 is there a pull request for this already? If not, you can go and implement this feature, it’s open source project and authors aren’t obligated to implement everything people ask them.

Would be also interested about the feature. Also currently up to 100 images can be selected and not more. Download should be possible for all or selected images. Would be good to have ability to select images also by month.

Since nobody mentioned it yet, you can export the content of a chat and decide to export images only. You can also select a timeframe so you don't have to download the whole pictures history

image

Since nobody mentioned it yet, you can export the content of a chat and decide to export images only. You can also select a timeframe so you don't have to download the whole pictures history

image

Nice trick, thanks ;)

Thank you, nice workaround.

Of course, the fact that a few workarounds exist is no excuse for not being able to just select a few images and download them in the exact same way you would a single image (I.e. right-click download).

By the way, I also tried selecting the images, copying with Ctrl+c, and pasting then into a folder in Nautilus. I would expect that to work too, as long as the only thing you've selected is images, videos, and files.

Thank you!

what worked for me here (a year after this script was published) - adding 'import asyncio' as a second line.

Quick tip. It is possible to download media with small python script.

  1. Goto https://my.telegram.org and generate api id and api hash
  2. Install Telethon library with pip3 install telethon
  3. Run following code (replace api_id, api_hash and username with your values):
from telethon import TelegramClient
api_id=123456
api_hash='secretHashYO'
client = TelegramClient('test_session', api_id, api_hash)
client.start()
for message in client.get_message_history('username', limit=25):
    client.download_media(message)

This code downloads media from the last 25 messages from the dialog with username user in current directory.

Thank you!

what worked for me here (a year after this script was published) - adding 'import asyncio' as a second line.

Not working for me :( showing error.

AttributeError: 'TelegramClient' object has no attribute 'get_message_history'

How to overcome this?

Thank you!
what worked for me here (a year after this script was published) - adding 'import asyncio' as a second line.

Not working for me :( showing error.

AttributeError: 'TelegramClient' object has no attribute 'get_message_history'

How to overcome this?
Oh, yes, this part is aoutdated too. I
I used the following code:

from telethon import TelegramClient
import telethon.sync

import asyncio

api_id=123456
api_hash=124343
client = TelegramClient('test_session', api_id, api_hash)
client.start()
#for dialog in client.iter_dialogs():
 #   print(dialog.name, 'has ID', dialog.id)
for message in client.get_messages(ID, limit=50):
    client.download_media(message)

I used the commented lines to see all the IDs and find the one I need
(I was looking to download images from a group chat, so it took time to understand that group ID starts with "-")

from telethon import TelegramClient
import telethon.sync

import asyncio

api_id=123456
api_hash=124343
client = TelegramClient('test_session', api_id, api_hash)
client.start()
#for dialog in client.iter_dialogs():
 #   print(dialog.name, 'has ID', dialog.id)
for message in client.get_messages(ID, limit=50):
    client.download_media(message)

I used the commented lines to see all the IDs and find the one I need
(I was looking to download images from a group chat, so it took time to understand that group ID starts with "-")

Thanks for the quick reply :)
For some reasons I was not able to use your mentioned script due to telethon update(maybe). So after some research I was able to build a new version of this script. Thanks again.

from telethon import TelegramClient
import telethon.sync
import asyncio
from tqdm import tqdm
api_id = 12345
api_hash = 'HASH'
with TelegramClient('SESSION', api_id, api_hash) as client:
    messages = client.get_messages(ID, limit=15)
    print(len(messages))
    for msg in tqdm(messages):
        client.download_media(msg)

https://github.com/telegramdesktop/tdesktop/issues/1382#issuecomment-502555459

Exporting and then choosing your options worked for me... awesome!!! Thanks!

Since nobody mentioned it yet, you can export the content of a chat and decide to export images only. You can also select a timeframe so you don't have to download the whole pictures history

image

How is this done? I can't find an export option.

How is this done? I can't find an export option.

Three dot menu top right or when you open the chat info again on the top right of that one

Strangely not available?

Screenshot 2019-11-04 at 09 45 31

Strangely not available?

Screenshot 2019-11-04 at 09 45 31

I'm not surprised that you're not seeing it given that this thread is for the desktop client and you're looking at your phone.......

That screenshot is from the desktop client on MacOS.

Version: 5.8 (185085) AppStore

Screenshot 2019-11-04 at 10 24 17

There are two desktop clients for mac. This one and one from the app store. The one you are looking at must be from the app store and has no relation to this one. In other words, this is not the place you're looking for.

Strange, the original screenshot looks identical to my phone. Apologies for my tone earlier.

Edit: Nice find @Nachtalb !

Thank you @Nachtalb !
Don't worry about it @Speeddymon .

@Zebradil I just saw realized that you don't use a takeout session in your code-snippet (https://github.com/telegramdesktop/tdesktop/issues/1382#issuecomment-362860530). I would use it / update your code-snippet:

Some of the calls made through the takeout session will have lower flood limits. This is useful if you want to export the data from conversations or mass-download media, since the rate limits will be lower.
https://docs.telethon.dev/en/latest/modules/client.html#telethon.client.account.AccountMethods.takeout

Hey @Nachtalb, thanks for pointing that out. I've checked the approach with takeout object and decided to stay with usual client object instead. The reason is that the "takeout" approach requires handling export request, so just replacing client by takeout will break the example, which is meant to be as simple as possible — it is needed just to give an idea of how to approach the solution.

For some reason, the built-in exportation option is not downloading all the images from a group I'm in. I ended up creating a script based on the ones on this thread (thank you guys for the snippets), allowing me to search for a chat by name and them downloading all its media. In case it might be helpful for anyone here's the link to the repository: https://github.com/zignd/telegram-media-downloader The usage is quite simple:

$ python main.py --api-id 12345 --api-hash 1ab1ab1ab1ab1ab --chat-title 'Bunker Reborn'

+1 for this feature, plz allow download of albums (bulk of 10 pictures for example) at once. thank you

Seriously? So much time passed and this issue is still not implemented?? Telegram, when? It's the most obvious thing that had to be available from day 0.

@RememberTheAir, thanks, that definitely simplifies the saving

However it's still a trick and not what the author asked for. If a person sent me several bunches of photos I may not want to export all of them. Or if it was say several days ago I shouldn't need to remember the date and reproduce it in the dialog window. It should be point and click feature - I look at what I need to save, click it and save it.

I guess this issue kind of conflicts with the more recent #6984. Bulk downloading can be done using the export tool, while selectively saving selected images is still something missing. It's related to what one want "bulk downloading" to mean. Since #6984 has not been closed as a duplicate, I guess we can split the two topics (bulk downloading/exporting and saving a selection of images)

Hey there!

This issue will be automatically closed in 7 days if there would be no activity. We therefore assume that the user has lost interest or resolved the problem on their own.

Don't worry though; if this is an error, let us know with a comment and we'll be happy to reopen the issue.

Thanks!

Please do not close this.

I was about to create a new issue, but remembered I could search first. This feature would make even more sense right now, as the latest update features grouping files into a single message. It shouldn't be available only for images, but for any type of file.

Is your feature request related to a problem?

Not really a problem, but something a bit inconvenient. Since the latest update (https://telegram.org/blog/pinned-messages-locations-playlists at the date of writing), Telegram for Android enables the user to select multiple files, be it all of them grouped in a single message, or each in a separate message, and then tap on a single button at the top to download all the selected files at once. On desktop, we still have to click on the download button for all files, one by one.

Describe the solution you'd like

For messages that consist of grouped files, offer a button inside the context menu to download everything contained within that single message. If multiple files are selected, show a _Download_ button at the top, next to the _Forward_ and _Delete_ buttons, that allows for downloading the selected files. If possible, and even better, ask the user where to save the files when the button is pressed (as it happens when right clicking a file -> save file as).

Describe alternatives you've considered

The "alternative" would be to only offer the Download button when selecting multiple files, and discard the option inside the context menu.

Additional context

Since we can now send multiple files grouped in a single message, it's similar to sending zipped files. The advantage here is that you can download individual files if you want, and are not forced to download the whole zip for a single file (which you would have to do if, let's say, you deleted one single file from inside the zip by accident).
Before, we could send both the individual files + a zip file to accomplish this very same system, but now sending an extra zip file shouldn't be required anymore, saving both user's upload bandwitdh and time, and Telegram's server available storage. And this would only be possible by allowing the download of multiple files at once.

Was this page helpful?
0 / 5 - 0 ratings