# Proprietary License Agreement
# Copyright (c) 2024-29 CodWiz
# Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software for personal and non-commercial purposes, subject to the following conditions:
# 1. The Software may not be modified, altered, or otherwise changed in any way without the explicit written permission of the author.
# 2. Redistribution of the Software, in original or modified form, is strictly prohibited without the explicit written permission of the author.
# 3. 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 non-infringement. In no event shall the author or copyright holder 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.
# 4. Any use of the Software must include the above copyright notice and this permission notice in all copies or substantial portions of the Software.
# 5. By using the Software, you agree to be bound by the terms and conditions of this license.
# For any inquiries or requests for permissions, please contact codwiz@yandex.ru.
# ---------------------------------------------------------------------------------
# Name: Music
# Description: Searches for music using Telegram music bots
# Author: @hikka_mods
# meta developer: @hikka_mods
# scope: Music
# scope: Music 0.0.2
# ---------------------------------------------------------------------------------
# Thanks to @murpizz for the search code yandex
import logging
from telethon.errors.rpcerrorlist import (
BotMethodInvalidError,
FloodWaitError,
MessageNotModifiedError,
)
from telethon.tl.types import Message
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class MusicMod(loader.Module):
strings = {
"name": "Music",
"no_query": "🤷♂ Provide a search query!",
"searching": "⌨️ Searching...",
"found": "🗣 Possible match:",
"not_found": "😫 Track not found: {}",
"usage": "Usage: .music [track name]",
"error": "⚠️ Error: {}",
"no_results": "😫 No results: {}",
"flood_wait": "⏳ Wait {}s (Telegram limits)",
"bot_error": "🤖 Bot error: {}",
"no_audio": "🎵 No audio",
"generic_result": "ℹ️ Non-media result. Check the bot's chat",
"yafind_searching": "🔎 Searching Yandex.Music...",
"yafind_not_found": "🚫 Track not found on Yandex.Music",
"yafind_error": "🚫 Error (Yandex): {}",
}
strings_ru = {
"name": "Music",
"no_query": "🤷♂ Укажите запрос!",
"searching": "⌨️ Поиск...",
"found": "🗣 Возможно, это оно:",
"not_found": "😫 Трек не найден: {}",
"usage": "Использование: .music [название трека]",
"error": "⚠️ Ошибка: {}",
"no_results": "😫 Нет результатов: {}",
"flood_wait": "⏳ Подождите {}с (лимиты Telegram)",
"bot_error": "🤖 Ошибка бота: {}",
"no_audio": "🎵 Нет аудио",
"generic_result": "ℹ️ Немедийный результат. Проверьте чат с ботом",
"yafind_searching": "🔎 Поиск в Яндекс.Музыке...",
"yafind_not_found": "🚫 Трек не найден в Яндекс.Музыке",
"yafind_error": "🚫 Ошибка (Яндекс): {}",
}
def __init__(self):
self.murglar_bot = "@murglar_bot"
@loader.command(
ru_doc="Найти трек в Yandex.Music: `.music {название}`",
en_doc="Find a track in Yandex.Music: `.music yandex {name}`",
)
async def music(self, message):
args = utils.get_args(message)
if not args:
if reply := await message.get_reply_message():
await self._yafind(message, reply.raw_text.strip())
else:
await utils.answer(message, self.strings("usage", message))
return
await self._yafind(message, query=args)
async def _yafind(self, message: Message, query: str):
if not query:
return await utils.answer(message, self.strings("no_query", message))
await utils.answer(message, self.strings("yafind_searching", message))
try:
results = await message.client.inline_query(
self.murglar_bot, f"s:ynd {query}"
)
if not results:
return await utils.answer(
message, self.strings("yafind_not_found", message)
)
await results[0].click(
entity=message.chat_id,
hide_via=True,
reply_to=message.reply_to_msg_id if message.reply_to_msg_id else None,
)
await message.delete()
except Exception as e:
logger.exception("Yandex search error:")
await utils.answer(message, self.strings("yafind_error", message).format(e))