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

Commit

Permalink
Release V2.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
subinps committed Jun 8, 2021
0 parents commit 65a6bfd
Show file tree
Hide file tree
Showing 16 changed files with 1,560 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM debian:latest

RUN apt update && apt upgrade -y
RUN apt install git curl python3-pip ffmpeg -y
RUN pip3 install -U pip
RUN cd /
RUN git clone https://github.com/subinps/MusicPlayer.git
RUN cd MusicPlayer
WORKDIR /MusicPlayer
RUN pip3 install -U -r requirements.txt
CMD python3 main.py
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 SUBIN

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.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python3 main.py
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Telegram Voice Chat Bot with Channel Support.

A Telegram Bot to Play Audio in Voice Chats With Youtube and Deezer support.
Supports Live streaming from youtube

```
Please fork this repository don't import code
Made with Python3
(C) @subinps
Copyright permission under MIT License
License -> https://github.com/subinps/MusicPlayer/blob/master/LICENSE
```

## Deploy to Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/subinps/MusicPlayer)


### Deploy to VPS

```sh
git clone https://github.com/subinps/MusicPlayer
cd MusicPlayer
pip3 install -r requirements.txt
# <Create Variables appropriately>
python3 main.py
```

# Vars:
1. `API_ID` : Get From my.telegram.org
2. `API_HASH` : Get from my.telegram.org
3. `BOT_TOKEN` : @Botfather
4. `SESSION_STRING` : Generate From here [![GenerateStringName](https://img.shields.io/badge/repl.it-generateStringName-yellowgreen)](https://repl.it/@subinps/getStringName)
5. `CHAT` : ID of Channel/Group where the bot plays Music.
6. `LOG_GROUP` : Group to send Playlist, if CHAT is a Group
7. `ADMINS` : ID of users who can use admin commands.
8. `ARQ_API` : Get it for free from [@ARQRobot](https://telegram.dog/ARQRobot), This is required for /dplay to work.
8. `STREAM_URL` : Stream URL of radio station or a youtube live video to stream when the bot starts or with /radio command.

- Enable the worker after deploy the project to Heroku
- 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.)
- To play a song use /play as a reply to audio file or a youtube link.
- Use /play <song name> to play song from youtube and /dplay <song name> to play from Deezer.
- Use /help to know about other commands.

**Features**

- Playlist, queue
- Supports Live streaming from youtube
- Supports both deezer and youtube to search songs.
- Play from telegram file supported.
- Starts Radio after if no songs in playlist.
- Automatically downloads audio for the first two tracks in the playlist to ensure smooth playing
- Automatic restart even if heroku restarts.

### Note

```
Contributions are welcomed, But Kanging and editing a few lines wont make you a Developer.
Fork the repo, Do not Import code.
```
#### Support

Connect Me On [Telegram](https://telegram.dog/subinps_bot)

## Credits
- [Dash Eclipse's](https://github.com/dashezup) for his[tgvc-userbot](https://github.com/callsmusic/tgvc-userbot).

69 changes: 69 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "Telegram Voice Chat Music Player Bot ",
"description": "Telegram Bot to Play Audio in Telegram Voice Chats",
"repository": "https://github.com/subinps/MusicPlayer",
"keywords": [
"telegram",
"bot",
"voicechat",
"music",
"python",
"pyrogram",
"pytgcalls",
"tgcalls",
"voip"
],
"env": {
"API_ID": {
"description": "api_id part of your Telegram API Key from my.telegram.org/apps",
"required": true
},
"API_HASH": {
"description": "api_hash part of your Telegram API Key from my.telegram.org/apps",
"required": true
},
"BOT_TOKEN": {
"description": "Bot token of Bot, get from @Botfather",
"required": true
},
"ARQ_API": {
"description": "get it for free from @ARQRobot",
"required": false
},
"SESSION_STRING": {
"description": "Session string, read the README to learn how to export it with Pyrogram",
"required": true
},
"CHAT": {
"description": "ID of Channel or Group where the Bot plays Music",
"required": true
},
"LOG_GROUP": {
"description": "ID of the group to send playlist If CHAT is a Group, if channel thenleave blank",
"required": false
},
"ADMINS": {
"description": "ID of Users who can use Admin commands(for multiple users seperated by space)",
"required": true
},
"STREAM_URL": {
"description": "URL of Radio station or Youtube live video url to stream with /radio command",
"value": "https://youtu.be/zcrUCvBD16k",
"required": false
}
},
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
},
"buildpacks": [
{
"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest"
},
{
"url": "heroku/python"
}
]
}
62 changes: 62 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#MIT License

#Copyright (c) 2021 SUBIN

#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.
import os
import re
from youtube_dl import YoutubeDL
ydl_opts = {
"geo-bypass": True,
"nocheckcertificate": True
}
ydl = YoutubeDL(ydl_opts)
links=[]
finalurl=""
STREAM=os.environ.get("STREAM_URL", "https://youtu.be/zcrUCvBD16k")
regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
match = re.match(regex,STREAM)
if match:
meta = ydl.extract_info(STREAM, download=False)
formats = meta.get('formats', [meta])
for f in formats:
links.append(f['url'])
finalurl=links[0]
else:
finalurl=STREAM

class Config:
ADMIN = os.environ.get("ADMINS", '')
ADMINS = [int(admin) if re.search('^\d+$', admin) else admin for admin in (ADMIN).split()]
API_ID = int(os.environ.get("API_ID", ''))
CHAT = int(os.environ.get("CHAT", ""))
LOG_GROUP=os.environ.get("LOG_GROUP", "")
if LOG_GROUP:
LOG_GROUP=int(LOG_GROUP)
else:
LOG_GROUP=None
STREAM_URL=finalurl
ARQ_API=os.environ.get("ARQ_API", "")
DURATION_LIMIT=int(os.environ.get("DUR", 15))
API_HASH = os.environ.get("API_HASH", "")
BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
SESSION = os.environ.get("SESSION_STRING", "")
playlist=[]
msg = {}

148 changes: 148 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#MIT License

#Copyright (c) 2021 SUBIN

#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.
from pyrogram import Client, idle, filters
import os
from threading import Thread
import sys
from config import Config
from utils import mp
import asyncio
from pyrogram.raw import functions, types


CHAT=Config.CHAT
bot = Client(
"Musicplayer",
Config.API_ID,
Config.API_HASH,
bot_token=Config.BOT_TOKEN,
plugins=dict(root="plugins")
)
async def main():
async with bot:
await mp.startupradio()
await asyncio.sleep(2)
await mp.startupradio()

def stop_and_restart():
bot.stop()
os.execl(sys.executable, sys.executable, *sys.argv)

bot.run(main())
bot.start()
bot.send(
functions.bots.SetBotCommands(
commands=[
types.BotCommand(
command="start",
description="Check if bot alive"
),
types.BotCommand(
command="help",
description="Shows help message"
),
types.BotCommand(
command="play",
description="Play song from youtube/audiofile"
),
types.BotCommand(
command="dplay",
description="Play song from Deezer"
),
types.BotCommand(
command="player",
description="Shows current playing song with controls"
),
types.BotCommand(
command="playlist",
description="Shows the playlist"
),
types.BotCommand(
command="skip",
description="Skip the current song"
),
types.BotCommand(
command="join",
description="Join VC"
),
types.BotCommand(
command="leave",
description="Leave from VC"
),
types.BotCommand(
command="vc",
description="Ckeck if VC is joined"
),
types.BotCommand(
command="stop",
description="Stops Playing"
),
types.BotCommand(
command="radio",
description="Start radio / Live stream"
),
types.BotCommand(
command="stopradio",
description="Stops radio/Livestream"
),
types.BotCommand(
command="replay",
description="Replay from beggining"
),
types.BotCommand(
command="clean",
description="Cleans RAW files"
),
types.BotCommand(
command="pause",
description="Pause the song"
),
types.BotCommand(
command="resume",
description="Resume the paused song"
),
types.BotCommand(
command="mute",
description="Mute in VC"
),
types.BotCommand(
command="unmute",
description="Unmute in VC"
),
types.BotCommand(
command="restart",
description="Restart the bot"
)
]
)
)


@bot.on_message(filters.command("restart") & filters.user(Config.ADMINS))
def restart(client, message):
message.reply_text("Restarting...")
Thread(
target=stop_and_restart
).start()

idle()
bot.stop()
Loading

0 comments on commit 65a6bfd

Please sign in to comment.