Add deezer as default search
This commit is contained in:
@@ -1,39 +1,16 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
InlineQuery, InlineQueryResultDocument, InlineQueryResultCachedAudio,
|
||||
InlineKeyboardMarkup, InlineKeyboardButton,
|
||||
)
|
||||
from aiogram import Router, F
|
||||
|
||||
from bot.modules.spotify import spotify
|
||||
from bot.modules.database import db
|
||||
from aiogram.types import InlineQuery
|
||||
|
||||
from bot.markups.deezer import get_deezer_search_results
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.inline_query(F.query != '')
|
||||
async def default_inline_query(inline_query: InlineQuery, bot: Bot):
|
||||
async def default_inline_query(inline_query: InlineQuery):
|
||||
await inline_query.answer(
|
||||
[
|
||||
InlineQueryResultDocument(
|
||||
id='spot::' + audio.id,
|
||||
title=audio.name,
|
||||
description=audio.all_artists,
|
||||
thumb_url=audio.thumbnail,
|
||||
document_url=audio.preview_url or audio.thumbnail,
|
||||
mime_type='application/zip',
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[InlineKeyboardButton(text='Downloading...', callback_data='.')]
|
||||
]
|
||||
),
|
||||
caption=audio.full_name,
|
||||
) if audio.id not in list(db.spotify.keys()) else
|
||||
InlineQueryResultCachedAudio(
|
||||
id='spotc::' + audio.id,
|
||||
audio_file_id=db.spotify[audio.id],
|
||||
)
|
||||
for audio in spotify.songs.search(inline_query.query, limit=50)
|
||||
],
|
||||
await get_deezer_search_results(inline_query.query),
|
||||
cache_time=0,
|
||||
is_personal=True
|
||||
)
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
from .spotify import router
|
||||
from aiogram import Router
|
||||
from . import spotify, deezer
|
||||
|
||||
router = Router()
|
||||
|
||||
router.include_routers(
|
||||
spotify.router,
|
||||
deezer.router,
|
||||
)
|
||||
|
||||
__all__ = ['router']
|
||||
|
||||
40
bot/handlers/on_chosen/deezer.py
Normal file
40
bot/handlers/on_chosen/deezer.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, URLInputFile, InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
from bot.modules.deezer import deezer, DeezerBytestream
|
||||
from bot.utils.config import config
|
||||
from bot.modules.database import db
|
||||
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(F.result_id.startswith('deez::'))
|
||||
async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
bytestream: DeezerBytestream = await (await deezer.downloader.from_id(
|
||||
chosen_result.result_id.removeprefix('deez::')
|
||||
)).to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
),
|
||||
thumbnail=URLInputFile(bytestream.song.thumbnail),
|
||||
performer=bytestream.song.all_artists,
|
||||
title=bytestream.song.name,
|
||||
duration=bytestream.song.duration,
|
||||
)
|
||||
|
||||
db.spotify[bytestream.song.id] = audio.audio.file_id
|
||||
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
reply_markup=None
|
||||
)
|
||||
|
||||
await db.occasionally_write()
|
||||
Reference in New Issue
Block a user