Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit 65a6bfd

Browse files
committed
Release V2.0
added ytdl added deezer play added youtube live streaming fixed LOG_GROUP added requester name in playlist added LICENCE added Dockerfile fixed stopradio error added inline search added commands
0 parents  commit 65a6bfd

File tree

16 files changed

+1560
-0
lines changed

16 files changed

+1560
-0
lines changed

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM debian:latest
2+
3+
RUN apt update && apt upgrade -y
4+
RUN apt install git curl python3-pip ffmpeg -y
5+
RUN pip3 install -U pip
6+
RUN cd /
7+
RUN git clone https://github.com/subinps/MusicPlayer.git
8+
RUN cd MusicPlayer
9+
WORKDIR /MusicPlayer
10+
RUN pip3 install -U -r requirements.txt
11+
CMD python3 main.py

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 SUBIN
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: python3 main.py

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Telegram Voice Chat Bot with Channel Support.
2+
3+
A Telegram Bot to Play Audio in Voice Chats With Youtube and Deezer support.
4+
Supports Live streaming from youtube
5+
6+
```
7+
Please fork this repository don't import code
8+
Made with Python3
9+
(C) @subinps
10+
Copyright permission under MIT License
11+
License -> https://github.com/subinps/MusicPlayer/blob/master/LICENSE
12+
13+
```
14+
15+
## Deploy to Heroku
16+
17+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/subinps/MusicPlayer)
18+
19+
20+
### Deploy to VPS
21+
22+
```sh
23+
git clone https://github.com/subinps/MusicPlayer
24+
cd MusicPlayer
25+
pip3 install -r requirements.txt
26+
# <Create Variables appropriately>
27+
python3 main.py
28+
```
29+
30+
# Vars:
31+
1. `API_ID` : Get From my.telegram.org
32+
2. `API_HASH` : Get from my.telegram.org
33+
3. `BOT_TOKEN` : @Botfather
34+
4. `SESSION_STRING` : Generate From here [![GenerateStringName](https://img.shields.io/badge/repl.it-generateStringName-yellowgreen)](https://repl.it/@subinps/getStringName)
35+
5. `CHAT` : ID of Channel/Group where the bot plays Music.
36+
6. `LOG_GROUP` : Group to send Playlist, if CHAT is a Group
37+
7. `ADMINS` : ID of users who can use admin commands.
38+
8. `ARQ_API` : Get it for free from [@ARQRobot](https://telegram.dog/ARQRobot), This is required for /dplay to work.
39+
8. `STREAM_URL` : Stream URL of radio station or a youtube live video to stream when the bot starts or with /radio command.
40+
41+
- Enable the worker after deploy the project to Heroku
42+
- Bot will starts radio automatically in given `CHAT` with given `STREAM_URL` after deploy.(24*7 Music even if heroku restarts, radio stream restarts automatically.)
43+
- To play a song use /play as a reply to audio file or a youtube link.
44+
- Use /play <song name> to play song from youtube and /dplay <song name> to play from Deezer.
45+
- Use /help to know about other commands.
46+
47+
**Features**
48+
49+
- Playlist, queue
50+
- Supports Live streaming from youtube
51+
- Supports both deezer and youtube to search songs.
52+
- Play from telegram file supported.
53+
- Starts Radio after if no songs in playlist.
54+
- Automatically downloads audio for the first two tracks in the playlist to ensure smooth playing
55+
- Automatic restart even if heroku restarts.
56+
57+
### Note
58+
59+
```
60+
Contributions are welcomed, But Kanging and editing a few lines wont make you a Developer.
61+
Fork the repo, Do not Import code.
62+
63+
```
64+
#### Support
65+
66+
Connect Me On [Telegram](https://telegram.dog/subinps_bot)
67+
68+
## Credits
69+
- [Dash Eclipse's](https://github.com/dashezup) for his[tgvc-userbot](https://github.com/callsmusic/tgvc-userbot).
70+

app.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "Telegram Voice Chat Music Player Bot ",
3+
"description": "Telegram Bot to Play Audio in Telegram Voice Chats",
4+
"repository": "https://github.com/subinps/MusicPlayer",
5+
"keywords": [
6+
"telegram",
7+
"bot",
8+
"voicechat",
9+
"music",
10+
"python",
11+
"pyrogram",
12+
"pytgcalls",
13+
"tgcalls",
14+
"voip"
15+
],
16+
"env": {
17+
"API_ID": {
18+
"description": "api_id part of your Telegram API Key from my.telegram.org/apps",
19+
"required": true
20+
},
21+
"API_HASH": {
22+
"description": "api_hash part of your Telegram API Key from my.telegram.org/apps",
23+
"required": true
24+
},
25+
"BOT_TOKEN": {
26+
"description": "Bot token of Bot, get from @Botfather",
27+
"required": true
28+
},
29+
"ARQ_API": {
30+
"description": "get it for free from @ARQRobot",
31+
"required": false
32+
},
33+
"SESSION_STRING": {
34+
"description": "Session string, read the README to learn how to export it with Pyrogram",
35+
"required": true
36+
},
37+
"CHAT": {
38+
"description": "ID of Channel or Group where the Bot plays Music",
39+
"required": true
40+
},
41+
"LOG_GROUP": {
42+
"description": "ID of the group to send playlist If CHAT is a Group, if channel thenleave blank",
43+
"required": false
44+
},
45+
"ADMINS": {
46+
"description": "ID of Users who can use Admin commands(for multiple users seperated by space)",
47+
"required": true
48+
},
49+
"STREAM_URL": {
50+
"description": "URL of Radio station or Youtube live video url to stream with /radio command",
51+
"value": "https://youtu.be/zcrUCvBD16k",
52+
"required": false
53+
}
54+
},
55+
"formation": {
56+
"worker": {
57+
"quantity": 1,
58+
"size": "free"
59+
}
60+
},
61+
"buildpacks": [
62+
{
63+
"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest"
64+
},
65+
{
66+
"url": "heroku/python"
67+
}
68+
]
69+
}

config.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#MIT License
2+
3+
#Copyright (c) 2021 SUBIN
4+
5+
#Permission is hereby granted, free of charge, to any person obtaining a copy
6+
#of this software and associated documentation files (the "Software"), to deal
7+
#in the Software without restriction, including without limitation the rights
8+
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
#copies of the Software, and to permit persons to whom the Software is
10+
#furnished to do so, subject to the following conditions:
11+
12+
#The above copyright notice and this permission notice shall be included in all
13+
#copies or substantial portions of the Software.
14+
15+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
#SOFTWARE.
22+
import os
23+
import re
24+
from youtube_dl import YoutubeDL
25+
ydl_opts = {
26+
"geo-bypass": True,
27+
"nocheckcertificate": True
28+
}
29+
ydl = YoutubeDL(ydl_opts)
30+
links=[]
31+
finalurl=""
32+
STREAM=os.environ.get("STREAM_URL", "https://youtu.be/zcrUCvBD16k")
33+
regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
34+
match = re.match(regex,STREAM)
35+
if match:
36+
meta = ydl.extract_info(STREAM, download=False)
37+
formats = meta.get('formats', [meta])
38+
for f in formats:
39+
links.append(f['url'])
40+
finalurl=links[0]
41+
else:
42+
finalurl=STREAM
43+
44+
class Config:
45+
ADMIN = os.environ.get("ADMINS", '')
46+
ADMINS = [int(admin) if re.search('^\d+$', admin) else admin for admin in (ADMIN).split()]
47+
API_ID = int(os.environ.get("API_ID", ''))
48+
CHAT = int(os.environ.get("CHAT", ""))
49+
LOG_GROUP=os.environ.get("LOG_GROUP", "")
50+
if LOG_GROUP:
51+
LOG_GROUP=int(LOG_GROUP)
52+
else:
53+
LOG_GROUP=None
54+
STREAM_URL=finalurl
55+
ARQ_API=os.environ.get("ARQ_API", "")
56+
DURATION_LIMIT=int(os.environ.get("DUR", 15))
57+
API_HASH = os.environ.get("API_HASH", "")
58+
BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
59+
SESSION = os.environ.get("SESSION_STRING", "")
60+
playlist=[]
61+
msg = {}
62+

main.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#MIT License
2+
3+
#Copyright (c) 2021 SUBIN
4+
5+
#Permission is hereby granted, free of charge, to any person obtaining a copy
6+
#of this software and associated documentation files (the "Software"), to deal
7+
#in the Software without restriction, including without limitation the rights
8+
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
#copies of the Software, and to permit persons to whom the Software is
10+
#furnished to do so, subject to the following conditions:
11+
12+
#The above copyright notice and this permission notice shall be included in all
13+
#copies or substantial portions of the Software.
14+
15+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
#SOFTWARE.
22+
from pyrogram import Client, idle, filters
23+
import os
24+
from threading import Thread
25+
import sys
26+
from config import Config
27+
from utils import mp
28+
import asyncio
29+
from pyrogram.raw import functions, types
30+
31+
32+
CHAT=Config.CHAT
33+
bot = Client(
34+
"Musicplayer",
35+
Config.API_ID,
36+
Config.API_HASH,
37+
bot_token=Config.BOT_TOKEN,
38+
plugins=dict(root="plugins")
39+
)
40+
async def main():
41+
async with bot:
42+
await mp.startupradio()
43+
await asyncio.sleep(2)
44+
await mp.startupradio()
45+
46+
def stop_and_restart():
47+
bot.stop()
48+
os.execl(sys.executable, sys.executable, *sys.argv)
49+
50+
bot.run(main())
51+
bot.start()
52+
bot.send(
53+
functions.bots.SetBotCommands(
54+
commands=[
55+
types.BotCommand(
56+
command="start",
57+
description="Check if bot alive"
58+
),
59+
types.BotCommand(
60+
command="help",
61+
description="Shows help message"
62+
),
63+
types.BotCommand(
64+
command="play",
65+
description="Play song from youtube/audiofile"
66+
),
67+
types.BotCommand(
68+
command="dplay",
69+
description="Play song from Deezer"
70+
),
71+
types.BotCommand(
72+
command="player",
73+
description="Shows current playing song with controls"
74+
),
75+
types.BotCommand(
76+
command="playlist",
77+
description="Shows the playlist"
78+
),
79+
types.BotCommand(
80+
command="skip",
81+
description="Skip the current song"
82+
),
83+
types.BotCommand(
84+
command="join",
85+
description="Join VC"
86+
),
87+
types.BotCommand(
88+
command="leave",
89+
description="Leave from VC"
90+
),
91+
types.BotCommand(
92+
command="vc",
93+
description="Ckeck if VC is joined"
94+
),
95+
types.BotCommand(
96+
command="stop",
97+
description="Stops Playing"
98+
),
99+
types.BotCommand(
100+
command="radio",
101+
description="Start radio / Live stream"
102+
),
103+
types.BotCommand(
104+
command="stopradio",
105+
description="Stops radio/Livestream"
106+
),
107+
types.BotCommand(
108+
command="replay",
109+
description="Replay from beggining"
110+
),
111+
types.BotCommand(
112+
command="clean",
113+
description="Cleans RAW files"
114+
),
115+
types.BotCommand(
116+
command="pause",
117+
description="Pause the song"
118+
),
119+
types.BotCommand(
120+
command="resume",
121+
description="Resume the paused song"
122+
),
123+
types.BotCommand(
124+
command="mute",
125+
description="Mute in VC"
126+
),
127+
types.BotCommand(
128+
command="unmute",
129+
description="Unmute in VC"
130+
),
131+
types.BotCommand(
132+
command="restart",
133+
description="Restart the bot"
134+
)
135+
]
136+
)
137+
)
138+
139+
140+
@bot.on_message(filters.command("restart") & filters.user(Config.ADMINS))
141+
def restart(client, message):
142+
message.reply_text("Restarting...")
143+
Thread(
144+
target=stop_and_restart
145+
).start()
146+
147+
idle()
148+
bot.stop()

0 commit comments

Comments
 (0)