Download media files from a telegram conversation/chat/channel up to 2GiB per file
Find a file
2020-12-12 21:41:32 +01:00
.github upd: make target names 2020-12-12 21:41:32 +01:00
tests add: test cases for utils 2020-07-21 21:38:55 +02:00
utils upd: docstrings 2020-12-12 17:05:44 +01:00
.gitignore upd: ignore list 2020-08-22 12:29:50 +02:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2020-12-10 00:14:50 +01:00
codecov.yml Add: codecov yaml config 2020-07-15 13:04:08 +02:00
config.yaml enh: download specific file formats 2020-06-11 16:05:41 +02:00
CONTRIBUTING.md add: contribution guide 2020-12-12 21:11:49 +01:00
dev-requirements.txt build(deps-dev): bump mypy from 0.780 to 0.781 (#20) 2020-06-22 16:52:39 +02:00
LICENSE Batman! (this commit has no parents) 2019-07-24 17:41:01 +02:00
Makefile upd: make target names 2020-12-12 21:41:32 +01:00
media_downloader.py upd: docstrings 2020-12-12 17:05:44 +01:00
pylintrc add: pylint & mypy code check 2019-11-06 17:38:48 +01:00
README.md Add proxy usage in 'README.md' 2020-12-10 19:01:18 +08:00
requirements.txt bump-up pyrogram to V1 2020-11-02 17:04:02 +01:00

Telegram Media Downloader

Unittest Coverage Status License: MIT Code style: black

Overview:

Download all media files from a conversation or a channel that you are a part of from telegram. A meta of last read/downloaded message is stored in the config file so that in such a way it won't download the same media file again.

Support:

Category Support
Language Python 3.6 and above
Download media types audio, document, photo, video, voice

ToDo:

  • Add support for multiple channels/chats.

Installation

For *nix os distributions with make availability

$ git clone https://github.com/Dineshkarthik/telegram_media_downloader.git
$ cd telegram_media_downloader
$ make install

For Windows which doesn't have make inbuilt

$ git clone https://github.com/Dineshkarthik/telegram_media_downloader.git
$ cd telegram_media_downloader
$ pip3 install -r requirements.txt

Configuration

Getting your API Keys: The very first step requires you to obtain a valid Telegram API key (API id/hash pair):

  1. Visit https://my.telegram.org/apps and log in with your Telegram Account.
  2. Fill out the form to register a new Telegram application.
  3. Done! The API key consists of two parts: api_id and api_hash.

Getting chat id:

  1. Open https://web.telegram.org
  2. Now go to the chat/channel and you will see the URL as something like
    • https://web.telegram.org/#/im?p=u853521067_2449618633394 here 853521067 is the chat id.
    • https://web.telegram.org/#/im?p=@somename here somename is the chat id.
    • https://web.telegram.org/#/im?p=s1301254321_6925449697188775560 here take 1301254321 and add -100 to the start of the id => -1001301254321.
api_hash: your_api_hash
api_id: your_api_id
chat_id: telegram_chat_id
last_read_message_id: 0
media_types:
- audio
- document
- photo
- video
- voice
file_formats:
  audio:
  - all
  document:
  - pdf
  - epub
  video:
  - mp4
  • api_hash - The api_hash you got from telegram apps
  • api_id - The api_id you got from telegram apps
  • chat_id - The id of the chat/channel you want to download media. Which you get from the above-mentioned steps.
  • last_read_message_id - If it is the first time you are going to read the channel let it be 0 or if you have already used this script to download media it will have some numbers which are auto-updated after the scripts successful execution. Don't change it.
  • media_types - Type of media to download, you can update which type of media you want to download it can be one or any of the available types.
  • file_formats - File types to download for supported media types which are audio, document and video. Default format is all, downloads all files.

Execution

$ python3 media_downloader.py

All the downloaded media will be stored inside respective direcotry named in the same path as the python script.

Media type Download directory
audio path/to/project/audio
document path/to/project/document
photo path/to/project/photo
video path/to/project/video
voice path/to/project/voice

Proxy

Socks5 proxy is supported in this project currently. To use it, simply create a config.ini file in the path of this project, and edit it with your proxy server info as follow:

[proxy]
enabled = True
hostname = 127.0.0.1
port = 1080
username =
password =

Then the proxy will automatically be enabled.