Skip to content

Commit

Permalink
Updated To Pyro 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTeamAlexa authored Nov 28, 2023
1 parent e7907cf commit 57e1481
Showing 1 changed file with 47 additions and 26 deletions.
73 changes: 47 additions & 26 deletions AlexaMusic/plugins/tools/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@

import os
import re
from yt_dlp import YoutubeDL

import yt_dlp
from pykeyboard import InlineKeyboard
from pyrogram import filters
from pyrogram.types import (
InlineKeyboardButton,
InlineKeyboardMarkup,
InputMediaAudio,
InputMediaVideo,
Message,
)
from pyrogram import enums, filters
from pyrogram.types import (InlineKeyboardButton,
InlineKeyboardMarkup, InputMediaAudio,
InputMediaVideo, Message)

from config import BANNED_USERS, SONG_DOWNLOAD_DURATION, SONG_DOWNLOAD_DURATION_LIMIT
from config import (BANNED_USERS, SONG_DOWNLOAD_DURATION,
SONG_DOWNLOAD_DURATION_LIMIT)
from strings import get_command
from AlexaMusic import YouTube, app
from AlexaMusic.utils.decorators.language import language, languageCB
from AlexaMusic.utils.formatters import convert_bytes
from AlexaMusic.utils.inline.song import song_markup


# Command
SONG_COMMAND = get_command("SONG_COMMAND")


@app.on_message(
filters.command(SONG_COMMAND) & filters.group & ~filters.edited & ~BANNED_USERS
filters.command(SONG_COMMAND)
& filters.group
& ~BANNED_USERS
)
@language
async def song_commad_group(client, message: Message, _):
Expand All @@ -57,7 +55,9 @@ async def song_commad_group(client, message: Message, _):


@app.on_message(
filters.command(SONG_COMMAND) & filters.private & ~filters.edited & ~BANNED_USERS
filters.command(SONG_COMMAND)
& filters.private
& ~BANNED_USERS
)
@language
async def song_commad_private(client, message: Message, _):
Expand All @@ -78,7 +78,9 @@ async def song_commad_private(client, message: Message, _):
return await mystic.edit_text(_["song_3"])
if int(duration_sec) > SONG_DOWNLOAD_DURATION_LIMIT:
return await mystic.edit_text(
_["play_4"].format(SONG_DOWNLOAD_DURATION, duration_min)
_["play_4"].format(
SONG_DOWNLOAD_DURATION, duration_min
)
)
buttons = song_markup(_, vidid)
await mystic.delete()
Expand Down Expand Up @@ -117,7 +119,9 @@ async def song_commad_private(client, message: Message, _):
)


@app.on_callback_query(filters.regex(pattern=r"song_back") & ~BANNED_USERS)
@app.on_callback_query(
filters.regex(pattern=r"song_back") & ~BANNED_USERS
)
@languageCB
async def songs_back_helper(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
Expand All @@ -129,7 +133,9 @@ async def songs_back_helper(client, CallbackQuery, _):
)


@app.on_callback_query(filters.regex(pattern=r"song_helper") & ~BANNED_USERS)
@app.on_callback_query(
filters.regex(pattern=r"song_helper") & ~BANNED_USERS
)
@languageCB
async def song_helper_cb(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
Expand All @@ -141,7 +147,9 @@ async def song_helper_cb(client, CallbackQuery, _):
pass
if stype == "audio":
try:
formats_available, link = await YouTube.formats(vidid, True)
formats_available, link = await YouTube.formats(
vidid, True
)
except:
return await CallbackQuery.edit_message_text(_["song_7"])
keyboard = InlineKeyboard()
Expand Down Expand Up @@ -169,16 +177,23 @@ async def song_helper_cb(client, CallbackQuery, _):
text=_["BACK_BUTTON"],
callback_data=f"song_back {stype}|{vidid}",
),
InlineKeyboardButton(text=_["CLOSE_BUTTON"], callback_data=f"close"),
InlineKeyboardButton(
text=_["CLOSE_BUTTON"], callback_data=f"close"
),
)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=keyboard
)
return await CallbackQuery.edit_message_reply_markup(reply_markup=keyboard)
else:
try:
formats_available, link = await YouTube.formats(vidid, True)
formats_available, link = await YouTube.formats(
vidid, True
)
except Exception as e:
print(e)
return await CallbackQuery.edit_message_text(_["song_7"])
keyboard = InlineKeyboard()
# AVC Formats Only [ Alexa MUSIC BOT ]
done = [160, 133, 134, 135, 136, 137, 298, 299, 264, 304, 266]
for x in formats_available:
check = x["format"]
Expand All @@ -200,15 +215,21 @@ async def song_helper_cb(client, CallbackQuery, _):
text=_["BACK_BUTTON"],
callback_data=f"song_back {stype}|{vidid}",
),
InlineKeyboardButton(text=_["CLOSE_BUTTON"], callback_data=f"close"),
InlineKeyboardButton(
text=_["CLOSE_BUTTON"], callback_data=f"close"
),
)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=keyboard
)
return await CallbackQuery.edit_message_reply_markup(reply_markup=keyboard)


# Downloading Songs Here


@app.on_callback_query(filters.regex(pattern=r"song_download") & ~BANNED_USERS)
@app.on_callback_query(
filters.regex(pattern=r"song_download") & ~BANNED_USERS
)
@languageCB
async def song_download_cb(client, CallbackQuery, _):
try:
Expand Down Expand Up @@ -252,7 +273,7 @@ async def song_download_cb(client, CallbackQuery, _):
await mystic.edit_text(_["song_11"])
await app.send_chat_action(
chat_id=CallbackQuery.message.chat.id,
action="upload_video",
action=enums.ChatAction.UPLOAD_VIDEO,
)
try:
await CallbackQuery.edit_message_media(media=med)
Expand Down Expand Up @@ -281,11 +302,11 @@ async def song_download_cb(client, CallbackQuery, _):
await mystic.edit_text(_["song_11"])
await app.send_chat_action(
chat_id=CallbackQuery.message.chat.id,
action="upload_audio",
action=enums.ChatAction.UPLOAD_AUDIO,
)
try:
await CallbackQuery.edit_message_media(media=med)
except Exception as e:
print(e)
return await mystic.edit_text(_["song_10"])
os.remove(filename)
os.remove(filename)

0 comments on commit 57e1481

Please sign in to comment.