Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheChampu committed Aug 30, 2024
2 parents 08d1e39 + 6623877 commit 7233dc4
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 128 deletions.
23 changes: 19 additions & 4 deletions ChampuXMusic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@

from .logging import LOGGER

EMOJIS = ["PPLAY_1", "PPLAY_2", "PPLAY_3", "PPLAY_4", "PPLAY_5",
"PPLAY_6", "PPLAY_7", "PPLAY_8", "PPLAY_9", "PPLAY_10",
"PPLAY_11", "PPLAY_12", "PPLAY_13", "PPLAY_14", "PPLAY_15",
"PPLAY_16", "PPLAY_17"]
EMOJIS = [
"PPLAY_1",
"PPLAY_2",
"PPLAY_3",
"PPLAY_4",
"PPLAY_5",
"PPLAY_6",
"PPLAY_7",
"PPLAY_8",
"PPLAY_9",
"PPLAY_10",
"PPLAY_11",
"PPLAY_12",
"PPLAY_13",
"PPLAY_14",
"PPLAY_15",
"PPLAY_16",
"PPLAY_17",
]

dirr()
git()
Expand Down
14 changes: 6 additions & 8 deletions ChampuXMusic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ async def init():
and not config.STRING4
and not config.STRING5
):
LOGGER(__name__).error(
"ᴀssɪsᴛᴀɴᴛ ᴄʟɪᴇɴᴛ ᴠᴀʀɪᴀʙʟᴇs ɴᴏᴛ ᴅᴇғɪɴᴇᴅ, ᴇxɪᴛɪɴɢ..."
)
LOGGER(__name__).error("ᴀssɪsᴛᴀɴᴛ ᴄʟɪᴇɴᴛ ᴠᴀʀɪᴀʙʟᴇs ɴᴏᴛ ᴅᴇғɪɴᴇᴅ, ᴇxɪᴛɪɴɢ...")

await sudo()
try:
Expand All @@ -51,18 +49,18 @@ async def init():
LOGGER("ChampuXMusic.plugins").info("sᴜᴄᴄᴇssғᴜʟʟʏ ɪᴍᴘᴏʀᴛᴇᴅ ᴍᴏᴅᴜʟᴇs...")

await userbot.start()

await Champu.start()
await Champu.decorators()
LOGGER("ChampuXMusic").info("\x43\x68\x61\x6D\x70\x75\x20\x42\x6F\x74\x20\x68\x61\x73\x20\x62\x65\x65\x6E\x20\x73\x75\x63\x63\x65\x73\x73\x66\x75\x6C\x6C\x79\x20\x73\x74\x61\x72\x74\x65\x64\x2E\x0A\x0A\x40\x54\x68\x65\x43\x68\x61\x6D\x70\x75\x20")
LOGGER("ChampuXMusic").info(
"\x43\x68\x61\x6D\x70\x75\x20\x42\x6F\x74\x20\x68\x61\x73\x20\x62\x65\x65\x6E\x20\x73\x75\x63\x63\x65\x73\x73\x66\x75\x6C\x6C\x79\x20\x73\x74\x61\x72\x74\x65\x64\x2E\x0A\x0A\x40\x54\x68\x65\x43\x68\x61\x6D\x70\x75\x20"
)
await idle()

await app.stop()
await userbot.stop()

LOGGER("ChampuXMusic").info(
" sᴛᴏᴘᴘɪɴɢ ᴄʜᴀᴍᴘᴜ ᴍᴜsɪᴄ ʙᴏᴛ..."
)
LOGGER("ChampuXMusic").info(" sᴛᴏᴘᴘɪɴɢ ᴄʜᴀᴍᴘᴜ ᴍᴜsɪᴄ ʙᴏᴛ...")


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion ChampuXMusic/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
set_loop,
)
from ChampuXMusic.utils.exceptions import AssistantErr
from ChampuXMusic.utils.formatters import check_duration, seconds_to_min, speed_converter
from ChampuXMusic.utils.formatters import (
check_duration,
seconds_to_min,
speed_converter,
)
from ChampuXMusic.utils.inline.play import stream_markup, stream_markup2
from ChampuXMusic.utils.stream.autoclear import auto_clean
from ChampuXMusic.utils.thumbnails import get_thumb
Expand Down
2 changes: 1 addition & 1 deletion ChampuXMusic/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def sudo():
SUDOERS.add(user_id)
LOGGER(__name__).info(f"ᴏᴡɴᴇʀ + sᴜᴅᴏ ᴜsᴇʀ ʟᴏᴀᴅᴇᴅ...")


def heroku():
global HAPP
if is_heroku:
Expand All @@ -71,4 +72,3 @@ def heroku():
LOGGER(__name__).warning(
f"ʏᴏᴜ ʜᴀᴠᴇ ɴᴏᴛ ғɪʟʟᴇᴅ ʜᴇʀᴏᴋᴜ ᴀᴘɪ ᴋᴇʏ ᴀɴᴅ ʜᴇʀᴏᴋᴜ ᴀᴘᴘ ɴᴀɴᴇ ᴄᴏʀʀᴇᴄᴛ... "
)

69 changes: 37 additions & 32 deletions ChampuXMusic/platforms/Youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,60 @@
from ChampuXMusic.utils.formatters import time_to_seconds



import os
import glob
import random
import logging


def cookie_txt_file():
folder_path = f"{os.getcwd()}/cookies"
filename = f"{os.getcwd()}/cookies/logs.csv"
txt_files = glob.glob(os.path.join(folder_path, '*.txt'))
txt_files = glob.glob(os.path.join(folder_path, "*.txt"))
if not txt_files:
raise FileNotFoundError("No .txt files found in the specified folder.")
cookie_txt_file = random.choice(txt_files)
with open(filename, 'a') as file:
file.write(f'Choosen File : {cookie_txt_file}\n')
with open(filename, "a") as file:
file.write(f"Choosen File : {cookie_txt_file}\n")
return f"""cookies/{str(cookie_txt_file).split("/")[-1]}"""



async def check_file_size(link):
async def get_format_info(link):
proc = await asyncio.create_subprocess_exec(
"yt-dlp",
"--cookies", cookie_txt_file(),
"--cookies",
cookie_txt_file(),
"-J",
link,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await proc.communicate()
if proc.returncode != 0:
print(f'Error:\n{stderr.decode()}')
print(f"Error:\n{stderr.decode()}")
return None
return json.loads(stdout.decode())

def parse_size(formats):
total_size = 0
for format in formats:
if 'filesize' in format:
total_size += format['filesize']
if "filesize" in format:
total_size += format["filesize"]
return total_size

info = await get_format_info(link)
if info is None:
return None
formats = info.get('formats', [])

formats = info.get("formats", [])
if not formats:
print("No formats found.")
return None

total_size = parse_size(formats)
return total_size


async def shell_cmd(cmd):
proc = await asyncio.create_subprocess_shell(
cmd,
Expand Down Expand Up @@ -176,7 +176,8 @@ async def video(self, link: str, videoid: Union[bool, str] = None):
link = link.split("&")[0]
proc = await asyncio.create_subprocess_exec(
"yt-dlp",
"--cookies",cookie_txt_file(),
"--cookies",
cookie_txt_file(),
"-g",
"-f",
"best[height<=?720][width<=?1280]",
Expand Down Expand Up @@ -233,7 +234,7 @@ async def formats(self, link: str, videoid: Union[bool, str] = None):
link = self.base + link
if "&" in link:
link = link.split("&")[0]
ytdl_opts = {"quiet": True, "cookiefile" : cookie_txt_file()}
ytdl_opts = {"quiet": True, "cookiefile": cookie_txt_file()}
ydl = yt_dlp.YoutubeDL(ytdl_opts)
with ydl:
formats_available = []
Expand Down Expand Up @@ -296,14 +297,15 @@ async def download(
if videoid:
link = self.base + link
loop = asyncio.get_running_loop()

def audio_dl():
ydl_optssx = {
"format": "bestaudio/best",
"outtmpl": "downloads/%(id)s.%(ext)s",
"geo_bypass": True,
"nocheckcertificate": True,
"quiet": True,
"cookiefile" : cookie_txt_file(),
"cookiefile": cookie_txt_file(),
"no_warnings": True,
}
x = yt_dlp.YoutubeDL(ydl_optssx)
Expand All @@ -321,7 +323,7 @@ def video_dl():
"geo_bypass": True,
"nocheckcertificate": True,
"quiet": True,
"cookiefile" : cookie_txt_file(),
"cookiefile": cookie_txt_file(),
"no_warnings": True,
}
x = yt_dlp.YoutubeDL(ydl_optssx)
Expand All @@ -342,7 +344,7 @@ def song_video_dl():
"nocheckcertificate": True,
"quiet": True,
"no_warnings": True,
"cookiefile" : cookie_txt_file(),
"cookiefile": cookie_txt_file(),
"prefer_ffmpeg": True,
"merge_output_format": "mp4",
}
Expand All @@ -358,7 +360,7 @@ def song_audio_dl():
"nocheckcertificate": True,
"quiet": True,
"no_warnings": True,
"cookiefile" : cookie_txt_file(),
"cookiefile": cookie_txt_file(),
"prefer_ffmpeg": True,
"postprocessors": [
{
Expand Down Expand Up @@ -386,7 +388,8 @@ def song_audio_dl():
else:
proc = await asyncio.create_subprocess_exec(
"yt-dlp",
"--cookies",cookie_txt_file(),
"--cookies",
cookie_txt_file(),
"-g",
"-f",
"best[height<=?720][width<=?1280]",
Expand All @@ -399,17 +402,19 @@ def song_audio_dl():
downloaded_file = stdout.decode().split("\n")[0]
direct = False
else:
file_size = await check_file_size(link)
if not file_size:
print("None file Size")
return
total_size_mb = file_size / (1024 * 1024)
if total_size_mb > 250:
print(f"File size {total_size_mb:.2f} MB exceeds the 100MB limit.")
return None
direct = True
downloaded_file = await loop.run_in_executor(None, video_dl)
file_size = await check_file_size(link)
if not file_size:
print("None file Size")
return
total_size_mb = file_size / (1024 * 1024)
if total_size_mb > 250:
print(
f"File size {total_size_mb:.2f} MB exceeds the 100MB limit."
)
return None
direct = True
downloaded_file = await loop.run_in_executor(None, video_dl)
else:
direct = True
downloaded_file = await loop.run_in_executor(None, audio_dl)
return downloaded_file, direct
return downloaded_file, direct
1 change: 0 additions & 1 deletion ChampuXMusic/plugins/USERBOT/userbotjoin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio

from pyrogram import Client, filters
from pyrogram.enums import ChatMemberStatus

from ChampuXMusic.misc import SUDOERS
from ChampuXMusic.utils.database import get_assistant
Expand Down
2 changes: 0 additions & 2 deletions ChampuXMusic/plugins/USERBOT/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from time import time
from urllib.parse import urlparse

import wget
from pyrogram import Client, filters
from pyrogram.types import Message
from youtubesearchpython import SearchVideos
from yt_dlp import YoutubeDL

# Define a dictionary to track the last message timestamp for each user
Expand Down
2 changes: 1 addition & 1 deletion ChampuXMusic/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __list_all_modules():
).replace(os.sep, ".")
)[:-3]
for f in mod_paths
if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py")
if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") and f in HELPABLE
]
all_modules.extend(modules)

Expand Down
18 changes: 16 additions & 2 deletions ChampuXMusic/plugins/play/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@

import config
from config import BANNED_USERS, lyrical
from ChampuXMusic import Apple, Resso, SoundCloud, Spotify, Telegram, YouTube, app, EMOJIS
from ChampuXMusic import (
Apple,
Resso,
SoundCloud,
Spotify,
Telegram,
YouTube,
app,
EMOJIS,
)
from ChampuXMusic.core.call import Champu
from ChampuXMusic.utils import seconds_to_min, time_to_seconds
from ChampuXMusic.utils.channelplay import get_channeplayCB
Expand Down Expand Up @@ -769,7 +778,12 @@ async def slider_queries(client, CallbackQuery, _):
from ChampuXMusic.misc import db
from ChampuXMusic.utils.database import add_active_video_chat, is_active_chat
from ChampuXMusic.utils.exceptions import AssistantErr
from ChampuXMusic.utils.inline import aq_markup, close_markup, stream_markup, stream_markup2
from ChampuXMusic.utils.inline import (
aq_markup,
close_markup,
stream_markup,
stream_markup2,
)
from ChampuXMusic.utils.pastebin import ChampuBin
from ChampuXMusic.utils.stream.queue import put_queue, put_queue_index

Expand Down
6 changes: 5 additions & 1 deletion ChampuXMusic/plugins/sudo/blchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from config import BANNED_USERS
from ChampuXMusic import app
from ChampuXMusic.misc import SUDOERS
from ChampuXMusic.utils.database import blacklist_chat, blacklisted_chats, whitelist_chat
from ChampuXMusic.utils.database import (
blacklist_chat,
blacklisted_chats,
whitelist_chat,
)
from ChampuXMusic.utils.decorators.language import language


Expand Down
2 changes: 2 additions & 0 deletions ChampuXMusic/plugins/sudo/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ async def logger(client, message, _):
else:
await message.reply_text(usage)


@app.on_message(filters.command(["cookies"]) & SUDOERS)
@language
async def logger(client, message, _):
await message.reply_document("cookies/logs.csv")
await message.reply_text("Please check given file to cookies file choosing logs...")


__MODULE__ = "Logger"
__HELP__ = """
- `/logger enable`: Enable logging.
Expand Down
9 changes: 7 additions & 2 deletions ChampuXMusic/plugins/sudo/sudoers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ async def check_sudo_list(client, callback_query: CallbackQuery):
keyboard = []
if callback_query.from_user.id not in SUDOERS:
return await callback_query.answer(
"sᴏʀʀʏ ᴏɴʟʏ ᴏᴡɴᴇʀ ᴀɴᴅ sᴜᴅᴏᴜsᴇʀs ᴄᴀɴ sʜᴏᴡ sᴜᴅᴏʟɪsᴛ ᴀsᴋ ʜɪᴍ ғᴏʀ sᴜᴅᴏʟɪsᴛ...", show_alert=True
"sᴏʀʀʏ ᴏɴʟʏ ᴏᴡɴᴇʀ ᴀɴᴅ sᴜᴅᴏᴜsᴇʀs ᴄᴀɴ sʜᴏᴡ sᴜᴅᴏʟɪsᴛ ᴀsᴋ ʜɪᴍ ғᴏʀ sᴜᴅᴏʟɪsᴛ...",
show_alert=True,
)
else:
user = await app.get_users(OWNER_ID)
Expand Down Expand Up @@ -140,7 +141,11 @@ async def back_to_main_menu(client, callback_query: CallbackQuery):
reply_markup=reply_markupes,
)

@app.on_message(filters.command(["delallsudo"], prefixes=["/", "!", "%", ",", "", ".", "@", "#"]) & filters.user(OWNER_ID))

@app.on_message(
filters.command(["delallsudo"], prefixes=["/", "!", "%", ",", "", ".", "@", "#"])
& filters.user(OWNER_ID)
)
@language
async def del_all_sudo(client, message: Message, _):
count = len(SUDOERS) - 1 # Exclude the admin from the count
Expand Down
Loading

0 comments on commit 7233dc4

Please sign in to comment.