Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps committed Oct 10, 2021
1 parent 97b42e1 commit 6bbc2e4
Show file tree
Hide file tree
Showing 22 changed files with 976 additions and 465 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Telegram bot to stream videos in telegram voicechat for both groups and channels
1. `DATABASE_URI`: MongoDB database Url, get from [mongodb](https://cloud.mongodb.com). This is an optional var, but it is recomonded to use this to experiance the full features.
2. `HEROKU_API_KEY`: Your heroku api key. Get one from [here](https://dashboard.heroku.com/account/applications/authorizations/new)
3. `HEROKU_APP_NAME`: Your heroku apps name.
4. `FILTERS`: Filter the search for channel play. Channel play means you can play all the files in a purticular channel using /cplay command. Current filters are `video document` . For searching audio files use `video document audio` . for video only search , use `video` and so on.

### Optional Vars
1. `LOG_GROUP` : Group to send Playlist, if CHAT is a Group()
Expand Down Expand Up @@ -72,6 +73,7 @@ python3 main.py
## Features

- Playlist, queue.
- Zero downtime in playing.
- Supports Video Recording.
- Supports Scheduling voicechats.
- Cool UI for controling the player.
Expand Down
178 changes: 102 additions & 76 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from logger import LOGGER
from utils import LOGGER
try:
import os
import heroku3
from dotenv import load_dotenv
from ast import literal_eval as is_enabled
from pytgcalls.types.input_stream.quality import (
HighQualityVideo,
HighQualityAudio,
MediumQualityAudio,
MediumQualityVideo,
LowQualityAudio,
LowQualityVideo
)

except ModuleNotFoundError:
import os
Expand Down Expand Up @@ -79,13 +71,15 @@ class Config:
PORTRAIT=is_enabled(os.environ.get("PORTRAIT", 'False'))
IS_VIDEO_RECORD=is_enabled(os.environ.get("IS_VIDEO_RECORD", 'True'))
DEBUG=is_enabled(os.environ.get("DEBUG", 'False'))
PTN=is_enabled(os.environ.get("PTN", "False"))

#Quality vars
BITRATE=os.environ.get("BITRATE", False)
FPS=os.environ.get("FPS", False)
CUSTOM_QUALITY=os.environ.get("QUALITY", "HIGH")

E_BITRATE=os.environ.get("BITRATE", False)
E_FPS=os.environ.get("FPS", False)
CUSTOM_QUALITY=os.environ.get("QUALITY", "100")

#Search filters for cplay
FILTERS = [filter.lower() for filter in (os.environ.get("FILTERS", "video document")).split(" ")]


#Dont touch these, these are not for configuring player
Expand All @@ -105,6 +99,7 @@ class Config:
CALL_STATUS=False
YPLAY=False
YSTREAM=False
CPLAY=False
STREAM_SETUP=False
LISTEN=False
STREAM_LINK=False
Expand Down Expand Up @@ -141,65 +136,92 @@ class Config:
REPLY_MESSAGE=None
REPLY_PM=False

if BITRATE:
if E_BITRATE:
try:
BITRATE=int(BITRATE)
BITRATE=int(E_BITRATE)
except:
LOGGER.error("Invalid bitrate specified.")
BITRATE=False
E_BITRATE=False
BITRATE=48000
if not BITRATE >= 48000:
BITRATE=48000
else:
BITRATE=False
BITRATE=48000

if FPS:
if E_FPS:
try:
FPS=int(FPS)
FPS=int(E_FPS)
except:
LOGGER.error("Invalid FPS specified")
if BITRATE:
FPS=False
if not FPS <= 30:
FPS=False
else:
FPS=False

if CUSTOM_QUALITY.lower() == 'high':
VIDEO_Q=HighQualityVideo()
AUDIO_Q=HighQualityAudio()
elif CUSTOM_QUALITY.lower() == 'medium':
VIDEO_Q=MediumQualityVideo()
AUDIO_Q=MediumQualityAudio()
elif CUSTOM_QUALITY.lower() == 'low':
VIDEO_Q=LowQualityVideo()
AUDIO_Q=LowQualityAudio()
E_FPS=False
if not FPS >= 30:
FPS=30
else:
LOGGER.warning("Invalid QUALITY specified.Defaulting to High.")
VIDEO_Q=HighQualityVideo()
AUDIO_Q=HighQualityVideo()

FPS=30
try:
CUSTOM_QUALITY=int(CUSTOM_QUALITY)
if CUSTOM_QUALITY > 100:
CUSTOM_QUALITY = 100
LOGGER.warning("maximum quality allowed is 100, invalid quality specified. Quality set to 100")
elif CUSTOM_QUALITY < 10:
LOGGER.warning("Minimum Quality allowed is 10., Qulaity set to 10")
CUSTOM_QUALITY = 10
if 66.9 < CUSTOM_QUALITY < 100:
if not E_BITRATE:
BITRATE=48000
elif 50 < CUSTOM_QUALITY < 66.9:
if not E_BITRATE:
BITRATE=36000
else:
if not E_BITRATE:
BITRATE=24000
except:
if CUSTOM_QUALITY.lower() == 'high':
CUSTOM_QUALITY=100
elif CUSTOM_QUALITY.lower() == 'medium':
CUSTOM_QUALITY=66.9
elif CUSTOM_QUALITY.lower() == 'low':
CUSTOM_QUALITY=50
else:
LOGGER.warning("Invalid QUALITY specified.Defaulting to High.")
CUSTOM_QUALITY=100



#help strings
PLAY_HELP="""
__You can play using any of these options__
1. Play a video from a YouTube link.
Command: **/play**
__You can use this as a reply to a YouTube link or pass link along command. or as a reply to message to search that in YouTube.__
Command: **/play**
__You can use this as a reply to a YouTube link or pass link along command. or as a reply to message to search that in YouTube.__
2. Play from a telegram file.
Command: **/play**
__Reply to a supported media(video and documents or audio file ).__
Note: __For both the cases /fplay also can be used by admins to play the song immediately without waiting for queue to end.__
Command: **/play**
__Reply to a supported media(video and documents or audio file ).__
Note: __For both the cases /fplay also can be used by admins to play the song immediately without waiting for queue to end.__
3. Play from a YouTube playlist
Command: **/yplay**
__First get a playlist file from @GetPlaylistBot or @DumpPlaylist and reply to playlist file.__
Command: **/yplay**
__First get a playlist file from @GetPlaylistBot or @DumpPlaylist and reply to playlist file.__
4. Live Stream
Command: **/stream**
__Pass a live stream URL or any direct URL to play it as stream.__
Command: **/stream**
__Pass a live stream URL or any direct URL to play it as stream.__
5. Import an old playlist.
Command: **/import**
__Reply to a previously exported playlist file. __
Command: **/import**
__Reply to a previously exported playlist file. __
6. Channel Play
Command: **/cplay**
__Use `/cplay channel username or channel id` to play all the files from the given channel.
By default both video files and documents will be played . You can add or remove the file type using `FILTERS` var.
For example , to stream audio, video and document from the channel use `/env FILTERS video document audio` . If you need only audio , you can use `/env FILTERS video audio` and so on.
To set up the files from a channel as STARTUP_STREAM, so that the files will be automatically added to playlist on startup of bot. use `/env STARTUP_STREAM channel username or channel id`
Note that for public channels you should use username of channels along with '@' and for private channels you should use channel id.
For private channels , make sure both the bot and USER account is a member of channel.__
"""
SETTINGS_HELP="""
**You can easily customize you player as per you needs. The following configurations are available:**
Expand Down Expand Up @@ -270,41 +292,41 @@ class Config:
CONTROL_HELP="""
__VCPlayer allows you to control your streams easily__
1. Skip a song.
Command: **/skip**
__You can pass a number greater than 2 to skip the song in that position.__
Command: **/skip**
__You can pass a number greater than 2 to skip the song in that position.__
2. Pause the player.
Command: **/pause**
2. Pause the player.
Command: **/pause**
3. Resume the player.
Command: **/resume**
3. Resume the player.
Command: **/resume**
4. Change Volume.
Command: **/volume**
__Pass the volume in between 1-200.__
4. Change Volume.
Command: **/volume**
__Pass the volume in between 1-200.__
5. Leave the VC.
Command: **/leave**
5. Leave the VC.
Command: **/leave**
6. Shuffle the playlist.
Command: **/shuffle**
6. Shuffle the playlist.
Command: **/shuffle**
7. Clear the current playlist queue.
Command: **/clearplaylist**
7. Clear the current playlist queue.
Command: **/clearplaylist**
8. Seek the video.
Command: **/seek**
__You can pass number of seconds to be skipped. Example: /seek 10 to skip 10 sec. /seek -10 to rewind 10 sec.__
8. Seek the video.
Command: **/seek**
__You can pass number of seconds to be skipped. Example: /seek 10 to skip 10 sec. /seek -10 to rewind 10 sec.__
9. Mute the player.
Command: **/mute**
9. Mute the player.
Command: **/mute**
10. Unmute the player.
Command : **/unmute**
10. Unmute the player.
Command : **/unmute**
11. Shows the playlist.
Command: **/playlist**
__Use /player to show with control buttons__
11. Shows the playlist.
Command: **/playlist**
__Use /player to show with control buttons__
"""

ADMIN_HELP="""
Expand Down Expand Up @@ -362,7 +384,9 @@ class Config:
6. `STARTUP_STREAM` : __This will be streamed on startups and restarts of bot.
You can use either any STREAM_URL or a direct link of any video or a Youtube Live link.
You can also use YouTube Playlist.Find a Telegram Link for your playlist from [PlayList Dumb](https://telegram.dog/DumpPlaylist) or get a PlayList from [PlayList Extract](https://telegram.dog/GetAPlaylistbot).
The PlayList link should in form `https://t.me/DumpPlaylist/xxx`.__
The PlayList link should in form `https://t.me/DumpPlaylist/xxx`
You can also use the files from a channel as startup stream. For that just use the channel id or channel username of channel as STARTUP_STREAM value.
For more info on channel play , read help from player section.__
**Recommended Optional Vars**
Expand All @@ -372,6 +396,8 @@ class Config:
3. `HEROKU_APP_NAME`: __Your heroku app's name.__
4. `FILTERS`: __Filters for channel play file search. Read help about cplay in player section.__
**Other Optional Vars**
1. `LOG_GROUP` : __Group to send Playlist, if CHAT is a Group__
Expand Down
23 changes: 8 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,15 @@
sync_from_db
)
from user import group_call, USER
from logger import LOGGER
from utils import LOGGER
from config import Config
from pyrogram import idle
from bot import bot
import asyncio
import os
if Config.DATABASE_URI:
from database import Database
db = Database()
from utils import db


if not os.path.isdir("./downloads"):
os.makedirs("./downloads")
else:
for f in os.listdir("./downloads"):
os.remove(f"./downloads/{f}")

async def main():
await bot.start()
Expand All @@ -52,19 +45,19 @@ async def main():
pass
await sync_from_db()
except Exception as e:
LOGGER.error(f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}")
LOGGER.error(f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}", exc_info=True)
Config.STARTUP_ERROR="Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}"
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
await bot.stop()
from debug import debug
from utils import debug
await debug.start()
await idle()
return

if Config.DEBUG:
LOGGER.info("Debugging enabled by user, Now in debug mode.")
Config.STARTUP_ERROR="Debugging enabled by user, Now in debug mode."
from debug import debug
from utils import debug
await bot.stop()
await debug.start()
await idle()
Expand All @@ -78,7 +71,7 @@ async def main():
LOGGER.error("Startup checks not passed , bot is quiting")
await bot.stop()
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
from debug import debug
from utils import debug
await debug.start()
await idle()
return
Expand All @@ -91,10 +84,10 @@ async def main():
LOGGER.info("Loop play enabled , starting playing startup stream.")
await start_stream()
except Exception as e:
LOGGER.error(f"Startup was unsuccesfull, Errors - {e}")
LOGGER.error(f"Startup was unsuccesfull, Errors - {e}", exc_info=True)
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
Config.STARTUP_ERROR=f"Startup was unsuccesfull, Errors - {e}"
from debug import debug
from utils import debug
await bot.stop()
await debug.start()
await idle()
Expand Down
Loading

0 comments on commit 6bbc2e4

Please sign in to comment.