Repository: henriqueclaranhan/telegram-music-downloader-bot
Branch: master
Commit: 9f1daa6750e5
Files: 11
Total size: 8.3 KB
Directory structure:
gitextract_dhrpt8st/
├── .dockerignore
├── .gitignore
├── Dockerfile
├── LICENSE
├── Procfile
├── README.md
├── app.json
├── bot.py
├── heroku.yml
├── requirements.txt
└── sample.env
================================================
FILE CONTENTS
================================================
================================================
FILE: .dockerignore
================================================
README.md
.git/
__pycache__/
sample.env
================================================
FILE: .gitignore
================================================
.env
tests/
================================================
FILE: Dockerfile
================================================
FROM debian:latest
RUN apt update && apt upgrade -y
RUN apt install git ffmpeg python3-pip -y
RUN pip3 install -U pip
RUN mkdir /app/
WORKDIR /app/
COPY . /app/
RUN pip3 install -U -r requirements.txt
CMD python3 bot.py
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021 Henrique Claranhan de Oliveira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: Procfile
================================================
worker: python3 bot.py
================================================
FILE: README.md
================================================
<div align="center">
<img src="https://github.com/henriqueclaranhan/telegram-music-downloader-bot/blob/master/icon.png" width="190">
<h1>Telegram Music Downloader Bot</h1>
A Telegram bot to download music from YouTube. Click <a href="https://t.me/TLMusicDownloader_bot">@TLMusicDownloader_bot</a> to use.
</div>
## :arrow_down: Installation
To get a local copy installed and working, follow these steps:
- Clone this repository
```console
git clone https://github.com/henriqueclaranhan/telegram-music-downloader-bot.git
```
- Enter the project folder
```sh
cd telegram-music-downloader-bot
```
### 📦 Install dependencies
- Install telepotpro framework
pip3 install telepotpro
- Install youtube-dl
pip3 install youtube-dl
- Install youtube-search-python
pip3 install youtube-search-python
### 🚀 Setup the bot
1. Get the token from <a href="https://t.me/BotFather">@BotFather</a>
2. Insert your token in the `sample.env` file
```py
TOKEN = "INSERT_YOUR_TOKEN_HERE"
```
3. Rename `sample.env` to `.env`
4. Start the bot
```shell
python3 bot.py
```
## 🟪 Deploy on Heroku
[](https://heroku.com/deploy?template=https://github.com/henriqueclaranhan/telegram-music-downloader-bot)
## 📷 Screenshot
<img src="https://user-images.githubusercontent.com/58452863/134260965-005e32f3-27aa-435e-81c9-70b50cf1a8f1.png" alt="Screenshot" width="305" height="700">
================================================
FILE: app.json
================================================
{
"name": "telegram-music-downloader-bot",
"description": "YouTube Music Downloader Bot for Telegram. ",
"stack": "container",
"repository": "https://github.com/henriqueclaranhan/telegram-music-downloader-bot",
"keywords": [
"python",
"chatbot",
"telegrambot"
],
"website": "https://github.com/henriqueclaranhan/telegram-music-downloader-bot",
"success_url": "https://t.me/tlmusicdownloader_bot",
"env": {
"TOKEN": {
"description": "Make a bot at BotFather http://telegram.dog/BotFather and get the token of your bot",
"value": "",
"required": true
}
}
}
================================================
FILE: bot.py
================================================
import os
import youtube_dl
import telepotpro
from random import randint
from multiprocessing import Process
from youtubesearchpython import VideosSearch
from dotenv import load_dotenv
from os.path import join, dirname
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
TOKEN = os.environ.get("TOKEN")
bot = telepotpro.Bot(TOKEN)
class Music:
def __init__(self, user_input, msg):
self.chat = Chat
self.user_input = user_input[6:]
def search_music(self, user_input):
return VideosSearch(user_input, limit = 1).result()
def get_link(self, result):
return result['result'][0]['link']
def get_title(self, result):
return result['result'][0]['title']
def get_duration(self, result):
result = result['result'][0]['duration'].split(':')
min_duration = int(result[0])
split_count = len(result)
return min_duration, split_count
def download_music(self, file_name, link):
ydl_opts = {
'outtmpl': './'+file_name,
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '256',
}],
'prefer_ffmpeg': True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(link, download=True)
pass
class Chat:
def __init__(self, msg):
self.chat_id = msg['chat']['id']
self.user_input = msg['text']
self.user_input = self.user_input.replace('@TLMusicDownloader_bot', '')
self.user_name = msg['from']['first_name']
self.message_id = msg['message_id']
self.messages = {
'start':'🤖 Hello, '+ self.user_name +'!\n\n'
'📩 Send me:\n\n'
'"*/music* _song name_" or\n'
'"*/music* _musician name - song name_"\n\n'
'to order some music. 🎶',
'spotify_input_error':"‼️ *Oops! The bot doesn't support Spotify links!*\n"
'Try: "*/music* _song name_"\n'
'or: "*/music* _musician name - song name_"',
'invalid_command':'‼️ *Oops! Invalid command!*\n'
'Try: "*/music* _song name_"\n'
'or: "*/music* _musician name - song name_"',
'too_long':'‼️ *Oops! Video too long to convert!*\n'
'Order something 30 minutes or less.'
}
self.check_input(self.user_input, msg)
pass
def send_message(self, content):
return bot.sendMessage(self.chat_id, content, reply_to_message_id=self.message_id, parse_mode='Markdown')
def delete_message(self, message):
chat_id = message['chat']['id']
message_id = message['message_id']
bot.deleteMessage((chat_id, message_id))
pass
def send_audio(self, file_name):
bot.sendAudio(self.chat_id,audio=open(file_name,'rb'), reply_to_message_id=self.message_id)
pass
def process_request(self, user_input):
result = Music.search_music(self, user_input[6:])
min_duration, split_count = Music.get_duration(self, result)
if int(min_duration) < 30 and split_count < 3:
file_name = Music.get_title(self, result) +' - @TLMusicDownloader_bot '+str(randint(0,999999))+'.mp3'
file_name = file_name.replace('"', '')
self.send_message(f"🎵 {Music.get_title(self, result)}\n🔗 {Music.get_link(self, result)}")
downloading_message = self.send_message('⬇️ Downloading... \n_(this may take a while.)_')
Music.download_music(self, file_name, Music.get_link(self, result))
try:
self.send_audio(file_name)
self.delete_message(downloading_message)
self.send_message('✅ Sucess!')
print ("\nSucess!\n")
except:
print("\nError")
os.remove(file_name)
pass
def check_input(self, user_input, msg):
if user_input.startswith('/start'):
self.send_message(self.messages['start'])
elif user_input.startswith('/music') and user_input[6:]!='':
if 'open.spotify.com' in user_input[6:]:
self.send_message(self.messages['spotify_input_error'])
else:
#Valid command
self.process_request(user_input)
else:
#Invalid command
self.send_message(self.messages['invalid_command'])
pass
def start_new_chat(msg):
Process(target=Chat, args=(msg,)).start()
bot.message_loop(start_new_chat, run_forever=True)
================================================
FILE: heroku.yml
================================================
build:
docker:
worker: Dockerfile
run:
worker:
command:
- python3 bot.py
image: worker
================================================
FILE: requirements.txt
================================================
youtube-dl
telepotpro
youtube-search-python
python-dotenv
================================================
FILE: sample.env
================================================
TOKEN = "INSERT_YOUR_TOKEN_HERE"
gitextract_dhrpt8st/ ├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── Procfile ├── README.md ├── app.json ├── bot.py ├── heroku.yml ├── requirements.txt └── sample.env
SYMBOL INDEX (15 symbols across 1 files)
FILE: bot.py
class Music (line 16) | class Music:
method __init__ (line 17) | def __init__(self, user_input, msg):
method search_music (line 21) | def search_music(self, user_input):
method get_link (line 24) | def get_link(self, result):
method get_title (line 27) | def get_title(self, result):
method get_duration (line 30) | def get_duration(self, result):
method download_music (line 37) | def download_music(self, file_name, link):
class Chat (line 54) | class Chat:
method __init__ (line 55) | def __init__(self, msg):
method send_message (line 87) | def send_message(self, content):
method delete_message (line 90) | def delete_message(self, message):
method send_audio (line 97) | def send_audio(self, file_name):
method process_request (line 102) | def process_request(self, user_input):
method check_input (line 127) | def check_input(self, user_input, msg):
function start_new_chat (line 145) | def start_new_chat(msg):
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
{
"path": ".dockerignore",
"chars": 40,
"preview": "README.md\n.git/\n__pycache__/\nsample.env\n"
},
{
"path": ".gitignore",
"chars": 11,
"preview": ".env\ntests/"
},
{
"path": "Dockerfile",
"chars": 222,
"preview": "FROM debian:latest\n\t\nRUN apt update && apt upgrade -y\nRUN apt install git ffmpeg python3-pip -y\nRUN pip3 install -U pip\n"
},
{
"path": "LICENSE",
"chars": 1087,
"preview": "MIT License\n\nCopyright (c) 2021 Henrique Claranhan de Oliveira\n\nPermission is hereby granted, free of charge, to any per"
},
{
"path": "Procfile",
"chars": 23,
"preview": "worker: python3 bot.py\n"
},
{
"path": "README.md",
"chars": 1518,
"preview": "<div align=\"center\">\n <img src=\"https://github.com/henriqueclaranhan/telegram-music-downloader-bot/blob/master/icon.png"
},
{
"path": "app.json",
"chars": 608,
"preview": "{\n \"name\": \"telegram-music-downloader-bot\",\n \"description\": \"YouTube Music Downloader Bot for Telegram. \",\n\t\"stack\": \""
},
{
"path": "bot.py",
"chars": 4784,
"preview": "import os\nimport youtube_dl\nimport telepotpro\nfrom random import randint\nfrom multiprocessing import Process\nfrom youtub"
},
{
"path": "heroku.yml",
"chars": 109,
"preview": "build:\n docker:\n worker: Dockerfile\nrun:\n worker:\n command:\n - python3 bot.py\n image: worker\n"
},
{
"path": "requirements.txt",
"chars": 58,
"preview": "youtube-dl\ntelepotpro\nyoutube-search-python\npython-dotenv\n"
},
{
"path": "sample.env",
"chars": 33,
"preview": "TOKEN = \"INSERT_YOUR_TOKEN_HERE\"\n"
}
]
About this extraction
This page contains the full source code of the henriqueclaranhan/telegram-music-downloader-bot GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (8.3 KB), approximately 2.3k tokens, and a symbol index with 15 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.