• Stars
    star
    2,025
  • Rank 22,862 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Download media files from a telegram conversation/chat/channel up to 2GiB per file

Telegram Media Downloader

Unittest Coverage Status License: MIT Code style: black

Feature request · Report a bug · Support: Discussions & Telegram Community

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.7 and above
Download media types audio, document, photo, video, video_note, 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

All the configurations are passed to the Telegram Media Downloader via config.yaml file.

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. Using web telegram:

  1. Open https://web.telegram.org/?legacy=1#/im
  2. Now go to the chat/channel and you will see the URL as something like
    • https://web.telegram.org/?legacy=1#/im?p=u853521067_2449618633394 here 853521067 is the chat id.
    • https://web.telegram.org/?legacy=1#/im?p=@somename here somename is the chat id.
    • https://web.telegram.org/?legacy=1#/im?p=s1301254321_6925449697188775560 here take 1301254321 and add -100 to the start of the id => -1001301254321.
    • https://web.telegram.org/?legacy=1#/im?p=c1301254321_6925449697188775560 here take 1301254321 and add -100 to the start of the id => -1001301254321.

2. Using bot:

  1. Use @username_to_id_bot to get the chat_id of
    • almost any telegram user: send username to the bot or just forward their message to the bot
    • any chat: send chat username or copy and send its joinchat link to the bot
    • public or private channel: same as chats, just copy and send to the bot
    • id of any telegram bot

config.yaml

api_hash: your_api_hash
api_id: your_api_id
chat_id: telegram_chat_id
last_read_message_id: 0
ids_to_retry: []
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.
  • ids_to_retry - Leave it as it is. This is used by the downloader script to keep track of all skipped downloads so that it can be downloaded during the next execution of the script.
  • 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
voice_note path/to/project/voice_note

Proxy

socks4, socks5, http proxies are supported in this project currently. To use it, add the following to the bottom of your config.yaml file

proxy:
  scheme: socks5
  hostname: 11.22.33.44
  port: 1234
  username: your_username
  password: your_password

If your proxy doesn’t require authorization you can omit username and password. Then the proxy will automatically be enabled.

Contributing

Contributing Guidelines

Read through our contributing guidelines to learn about our submission process, coding rules and more.

Want to Help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing.

Code of Conduct

Help us keep Telegram Media Downloader open and inclusive. Please read and follow our Code of Conduct.

More Repositories

1

codility-training

Solutions for Codility training assignments in Python
Python
148
star
2

Whatsapp-analyzer

Visualize your WhatsApp conversations and have fun..!
Python
31
star
3

pinterest-telegram-bot

Downloads Pinterest image from the given Pinterest shared URL and sends it back in telegram
Python
27
star
4

OSM-Translate-TelegramBot

TelegramBot Handcrafted for Translation of places in OpenStreetMap
Python
12
star
5

real-time-IoT-data-streaming

Realtime IoT data streaming from Smartphone sensors
Python
11
star
6

browsing_history_viz

Visualise your browsing history
Python
5
star
7

Send2Kindle

A Python mailer specifically crafted for FreeTamilEbooks users to add ebooks directly to their kindle device.
HTML
5
star
8

n-gram_processor

Using n-gram get set of words and their frequency of occurrence in given directory / sub-directory/ text file, which are present in a specific order at specific distance from a word.
Python
4
star
9

awesome-data-science-and-engineering

A curated list of Data Science and Engineering frameworks, tools, libraries and related list of tutorials.
4
star
10

wiki-user-contributions

Generates user's Wikipedia Contribution
Python
3
star
11

json-generator-api

A json data generator - API mocking tool
Python
3
star
12

tweetalyzer

Stream and Visualise Tweets on specific topics
Python
3
star
13

leetcode-python

Solutions for Leetcode Algorithm problem in Python
Python
2
star
14

animefox

A simple application to follow on going episodes/seasons of anime
HTML
2
star
15

Dineshkarthik

Python
2
star
16

HackerRank

HackerRank solutions in Python
Jupyter Notebook
2
star
17

Dineshkarthik.github.io

Hello World! It's DK
JavaScript
1
star
18

APIficator

Expose existing database via a REST API
Python
1
star
19

design-patterns

Java
1
star