From 147c235ed0b33c900e0ed7dbb879c2775c3fedf0 Mon Sep 17 00:00:00 2001 From: Safone Date: Wed, 19 Jun 2024 21:22:04 +0000 Subject: [PATCH] further fixes. --- .github/workflows/pyLint.yml | 2 +- Dockerfile | 7 +++- core/__init__.py | 2 +- core/admins.py | 2 +- core/decorators.py | 4 +- core/funcs.py | 2 +- core/stream.py | 58 ++++++++++++++++++++------ main.py | 81 ++++++++++++------------------------ startup.sh | 4 ++ 9 files changed, 88 insertions(+), 74 deletions(-) diff --git a/.github/workflows/pyLint.yml b/.github/workflows/pyLint.yml index 41b3047..2e3ed7a 100644 --- a/.github/workflows/pyLint.yml +++ b/.github/workflows/pyLint.yml @@ -36,4 +36,4 @@ jobs: commit_user_email: 77989182+AsmSafone@users.noreply.github.com commit_options: '--no-verify' commit_message: 'auto: refactor' - commit_author: Safone + commit_author: Safone diff --git a/Dockerfile b/Dockerfile index 1c68e2d..587fdaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:latest +FROM python:3.9-slim-buster # Updating Packages RUN apt update && apt upgrade -y @@ -11,9 +11,14 @@ COPY requirements.txt /requirements.txt RUN cd / RUN pip3 install --upgrade pip RUN pip3 install -U -r requirements.txt + +# Setting up working directory RUN mkdir /MusicPlayer WORKDIR /MusicPlayer + +# Preparing for the Startup COPY startup.sh /startup.sh +RUN chmod +x /startup.sh # Running Music Player Bot CMD ["/bin/bash", "/startup.sh"] diff --git a/core/__init__.py b/core/__init__.py index 3022441..eb4143d 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -18,7 +18,7 @@ from core.song import Song from core.admins import is_sudo, is_admin -from core.stream import app, ydl, safone, pytgcalls, skip_stream, start_stream +from core.stream import app, ytdl, safone, pytgcalls, start_stream from core.groups import ( get_group, get_queue, set_group, set_title, all_groups, clear_queue, set_default, shuffle_queue) diff --git a/core/admins.py b/core/admins.py index a69ad61..6e93af8 100644 --- a/core/admins.py +++ b/core/admins.py @@ -33,7 +33,7 @@ async def is_admin(message: Message): user = await message.chat.get_member(message.from_user.id) if user.status in [ enums.ChatMemberStatus.OWNER, - enums.ChatMemberStatus.ADMINISTRATOR + enums.ChatMemberStatus.ADMINISTRATOR, ]: return True elif message.from_user.id in config.SUDOERS: diff --git a/core/decorators.py b/core/decorators.py index 3099d84..f251075 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -65,7 +65,9 @@ async def decorator(client: Client, message: Message, *args): in [ admin.user.id async for admin in ( - await message.chat.get_members(filter=enums.ChatMembersFilter.ADMINISTRATORS) + await message.chat.get_members( + filter=enums.ChatMembersFilter.ADMINISTRATORS + ) ) ] ): diff --git a/core/funcs.py b/core/funcs.py index dbed95e..fdc60e8 100644 --- a/core/funcs.py +++ b/core/funcs.py @@ -25,8 +25,8 @@ import asyncio import aiofiles from config import config -from pyrogram import enums from core.song import Song +from pyrogram import enums from pytube import Playlist from spotipy import Spotify from core.groups import get_group diff --git a/core/stream.py b/core/stream.py index f1a55bf..d16164a 100644 --- a/core/stream.py +++ b/core/stream.py @@ -37,8 +37,14 @@ "geo_bypass": True, "nocheckcertificate": True, } -ydl = YoutubeDL(ydl_opts) -app = Client(config.SESSION, api_id=config.API_ID, api_hash=config.API_HASH) +app = Client( + "MusicPlayerUB", + api_id=config.API_ID, + api_hash=config.API_HASH, + session_string=config.SESSION, + in_memory=True, +) +ytdl = YoutubeDL(ydl_opts) pytgcalls = PyTgCalls(app) @@ -82,9 +88,11 @@ async def start_stream(song: Song, lang): song.source, song.duration, song.request_msg.chat.id, - song.requested_by.mention - if song.requested_by - else song.request_msg.sender_chat.title, + ( + song.requested_by.mention + if song.requested_by + else song.request_msg.sender_chat.title + ), ), quote=False, ) @@ -98,36 +106,60 @@ def get_quality(song: Song) -> MediaStream: if group["stream_mode"] == "video": if config.QUALITY.lower() == "high": return MediaStream( - song.remote, AudioQuality.HIGH, VideoQuality.FHD_1080p, headers=song.headers + song.remote, + AudioQuality.HIGH, + VideoQuality.FHD_1080p, + headers=song.headers, ) elif config.QUALITY.lower() == "medium": return MediaStream( - song.remote, AudioQuality.MEDIUM, VideoQuality.HD_720p, headers=song.headers + song.remote, + AudioQuality.MEDIUM, + VideoQuality.HD_720p, + headers=song.headers, ) elif config.QUALITY.lower() == "low": return MediaStream( - song.remote, AudioQuality.LOW, VideoQuality.SD_480p, headers=song.headers + song.remote, + AudioQuality.LOW, + VideoQuality.SD_480p, + headers=song.headers, ) else: print("WARNING: Invalid Quality Specified. Defaulting to High!") return MediaStream( - song.remote, AudioQuality.HIGH, VideoQuality.FHD_1080p, headers=song.headers + song.remote, + AudioQuality.HIGH, + VideoQuality.FHD_1080p, + headers=song.headers, ) else: if config.QUALITY.lower() == "high": return MediaStream( - song.remote, AudioQuality.HIGH, video_flags=MediaStream.Flags.IGNORE, headers=song.headers + song.remote, + AudioQuality.HIGH, + video_flags=MediaStream.Flags.IGNORE, + headers=song.headers, ) elif config.QUALITY.lower() == "medium": return MediaStream( - song.remote, AudioQuality.MEDIUM, video_flags=MediaStream.Flags.IGNORE, headers=song.headers + song.remote, + AudioQuality.MEDIUM, + video_flags=MediaStream.Flags.IGNORE, + headers=song.headers, ) elif config.QUALITY.lower() == "low": return MediaStream( - song.remote, AudioQuality.LOW, video_flags=MediaStream.Flags.IGNORE, headers=song.headers + song.remote, + AudioQuality.LOW, + video_flags=MediaStream.Flags.IGNORE, + headers=song.headers, ) else: print("WARNING: Invalid Quality Specified. Defaulting to High!") return MediaStream( - song.remote, AudioQuality.HIGH, video_flags=MediaStream.Flags.IGNORE, headers=song.headers + song.remote, + AudioQuality.HIGH, + video_flags=MediaStream.Flags.IGNORE, + headers=song.headers, ) diff --git a/main.py b/main.py index 0711aae..2bdb778 100644 --- a/main.py +++ b/main.py @@ -29,8 +29,8 @@ from pytgcalls.types.stream import StreamAudioEnded, StreamVideoEnded from core.decorators import language, register, only_admins, handle_error from core import ( - app, ydl, safone, search, is_sudo, is_admin, get_group, get_queue, - pytgcalls, set_group, set_title, all_groups, clear_queue, check_yt_url, + app, ytdl, safone, search, is_sudo, is_admin, get_group, get_queue, + pytgcalls, set_group, set_title, all_groups, clear_queue, check_yt_url, extract_args, start_stream, shuffle_queue, delete_messages, get_spotify_playlist, get_youtube_playlist) @@ -47,49 +47,40 @@ api_id=config.API_ID, api_hash=config.API_HASH, bot_token=config.BOT_TOKEN, + in_memory=True, ) client = bot else: client = app -@client.on_message( - filters.command("repo", config.PREFIXES) & ~filters.bot -) +@client.on_message(filters.command("repo", config.PREFIXES) & ~filters.bot) @handle_error async def repo(_, message: Message): await message.reply_text(REPO, disable_web_page_preview=True) -@client.on_message( - filters.command("ping", config.PREFIXES) & ~filters.bot -) +@client.on_message(filters.command("ping", config.PREFIXES) & ~filters.bot) @handle_error async def ping(_, message: Message): await message.reply_text(f"🤖 **Pong!**\n`{await pytgcalls.ping} ms`") -@client.on_message( - filters.command("start", config.PREFIXES) & ~filters.bot -) +@client.on_message(filters.command("start", config.PREFIXES) & ~filters.bot) @language @handle_error async def start(_, message: Message, lang): await message.reply_text(lang["startText"] % message.from_user.mention) -@client.on_message( - filters.command("help", config.PREFIXES) & ~filters.private -) +@client.on_message(filters.command("help", config.PREFIXES) & ~filters.private) @language @handle_error async def help(_, message: Message, lang): await message.reply_text(lang["helpText"].replace("", config.PREFIXES[0])) -@client.on_message( - filters.command(["p", "play"], config.PREFIXES) & ~filters.private -) +@client.on_message(filters.command(["p", "play"], config.PREFIXES) & ~filters.private) @register @language @handle_error @@ -123,8 +114,7 @@ async def play_stream(_, message: Message, lang): @client.on_message( - filters.command(["radio", "stream"], config.PREFIXES) - & ~filters.private + filters.command(["radio", "stream"], config.PREFIXES) & ~filters.private ) @register @language @@ -146,7 +136,7 @@ async def live_stream(_, message: Message, lang): else: is_yt_url, url = check_yt_url(args) if is_yt_url: - meta = ydl.extract_info(url, download=False) + meta = ytdl.extract_info(url, download=False) formats = meta.get("formats", [meta]) for f in formats: ytstreamlink = f["url"] @@ -176,8 +166,7 @@ async def live_stream(_, message: Message, lang): @client.on_message( - filters.command(["skip", "next"], config.PREFIXES) - & ~filters.private + filters.command(["skip", "next"], config.PREFIXES) & ~filters.private ) @register @language @@ -210,9 +199,7 @@ async def skip_track(_, message: Message, lang): await delete_messages([message, k]) -@client.on_message( - filters.command(["m", "mute"], config.PREFIXES) & ~filters.private -) +@client.on_message(filters.command(["m", "mute"], config.PREFIXES) & ~filters.private) @register @language @only_admins @@ -228,8 +215,7 @@ async def mute_vc(_, message: Message, lang): @client.on_message( - filters.command(["um", "unmute"], config.PREFIXES) - & ~filters.private + filters.command(["um", "unmute"], config.PREFIXES) & ~filters.private ) @register @language @@ -245,10 +231,7 @@ async def unmute_vc(_, message: Message, lang): await delete_messages([message, k]) -@client.on_message( - filters.command(["ps", "pause"], config.PREFIXES) - & ~filters.private -) +@client.on_message(filters.command(["ps", "pause"], config.PREFIXES) & ~filters.private) @register @language @only_admins @@ -264,8 +247,7 @@ async def pause_vc(_, message: Message, lang): @client.on_message( - filters.command(["rs", "resume"], config.PREFIXES) - & ~filters.private + filters.command(["rs", "resume"], config.PREFIXES) & ~filters.private ) @register @language @@ -282,8 +264,7 @@ async def resume_vc(_, message: Message, lang): @client.on_message( - filters.command(["stop", "leave"], config.PREFIXES) - & ~filters.private + filters.command(["stop", "leave"], config.PREFIXES) & ~filters.private ) @register @language @@ -303,8 +284,7 @@ async def leave_vc(_, message: Message, lang): @client.on_message( - filters.command(["list", "queue"], config.PREFIXES) - & ~filters.private + filters.command(["list", "queue"], config.PREFIXES) & ~filters.private ) @register @language @@ -320,8 +300,7 @@ async def queue_list(_, message: Message, lang): @client.on_message( - filters.command(["mix", "shuffle"], config.PREFIXES) - & ~filters.private + filters.command(["mix", "shuffle"], config.PREFIXES) & ~filters.private ) @register @language @@ -338,8 +317,7 @@ async def shuffle_list(_, message: Message, lang): @client.on_message( - filters.command(["loop", "repeat"], config.PREFIXES) - & ~filters.private + filters.command(["loop", "repeat"], config.PREFIXES) & ~filters.private ) @register @language @@ -358,8 +336,7 @@ async def loop_stream(_, message: Message, lang): @client.on_message( - filters.command(["mode", "switch"], config.PREFIXES) - & ~filters.private + filters.command(["mode", "switch"], config.PREFIXES) & ~filters.private ) @register @language @@ -378,8 +355,7 @@ async def switch_mode(_, message: Message, lang): @client.on_message( - filters.command(["admins", "adminsonly"], config.PREFIXES) - & ~filters.private + filters.command(["admins", "adminsonly"], config.PREFIXES) & ~filters.private ) @register @language @@ -398,8 +374,7 @@ async def admins_only(_, message: Message, lang): @client.on_message( - filters.command(["lang", "language"], config.PREFIXES) - & ~filters.private + filters.command(["lang", "language"], config.PREFIXES) & ~filters.private ) @register @language @@ -425,8 +400,7 @@ async def set_lang(_, message: Message, lang): @client.on_message( - filters.command(["ep", "export"], config.PREFIXES) - & ~filters.private + filters.command(["ep", "export"], config.PREFIXES) & ~filters.private ) @register @language @@ -451,8 +425,7 @@ async def export_queue(_, message: Message, lang): @client.on_message( - filters.command(["ip", "import"], config.PREFIXES) - & ~filters.private + filters.command(["ip", "import"], config.PREFIXES) & ~filters.private ) @register @language @@ -500,8 +473,7 @@ async def import_queue(_, message: Message, lang): @client.on_message( - filters.command(["pl", "playlist"], config.PREFIXES) - & ~filters.private + filters.command(["pl", "playlist"], config.PREFIXES) & ~filters.private ) @register @language @@ -558,8 +530,7 @@ async def import_playlist(_, message: Message, lang): @client.on_message( - filters.command(["update", "restart"], config.PREFIXES) - & ~filters.private + filters.command(["update", "restart"], config.PREFIXES) & ~filters.private ) @language @handle_error diff --git a/startup.sh b/startup.sh index 52d7b42..66af093 100644 --- a/startup.sh +++ b/startup.sh @@ -1,8 +1,12 @@ +#!/bin/bash + echo ">> FETCHING UPSTREAM..." git clone -b dev https://github.com/AsmSafone/MusicPlayer /MusicPlayer + echo ">> INSTALLING REQUIREMENTS..." cd /MusicPlayer pip3 install -U -r requirements.txt + echo ">> STARTING MUSIC PLAYER USERBOT..." clear echo "