# На модуль распространяется лицензия "GNU General Public License v3.0" # https://github.com/all-licenses/GNU-General-Public-License-v3.0 # meta developer: @PyModule # requires: lyricsgenius===3.7.0 from lyricsgenius import Genius from .. import loader, utils @loader.tds class LyricsMod(loader.Module): """Модуль для поиска текста песни через Genius API""" strings = {"name": "Lyrics"} def __init__(self): self.config = loader.ModuleConfig( "GENIUS_TOKEN", None, lambda: "Токен для доступа к Genius API. Получите его на https://genius.com/api-clients", ) def get_genius(self): token = self.config["GENIUS_TOKEN"] if not token: return None return Genius(token, timeout=10) @loader.command() async def lyrics(self, message): """[запрос] - Найти текст песни по запросу""" genius = self.get_genius() if not genius: return await message.edit( " Токен Genius API не установлен. Используйте .cfg Lyrics, чтобы добавить токен." ) args = utils.get_args_raw(message) if not args: return await message.edit("👁 Использование: .lyrics [запрос]") await message.edit(f"👁 Ищу текст песни по запросу: {args}...") try: search_results = genius.search_songs(args) if not search_results or not search_results["hits"]: return await message.edit(" Ничего не найдено.") song_info = search_results["hits"][0]["result"] song = genius.search_song(song_info["title"], song_info["primary_artist"]["name"]) if not song: return await message.edit(" Не удалось загрузить текст песни.") lyrics = song.lyrics if len(lyrics) > 4096: lyrics = lyrics[:4000] + "\n\nТекст обрезан из-за ограничения Telegram." await message.edit( f"🎶 {song.title} — {song.artist}\n\n" f"
{lyrics}
" ) except Exception as e: await message.edit(f"Ошибка: {str(e)}")