Add changing preview type when searching track

This commit is contained in:
BarsTiger
2023-11-07 18:45:41 +02:00
parent 06c327933f
commit e99ba9daa3
12 changed files with 54 additions and 23 deletions

View File

@@ -4,6 +4,7 @@ from aiogram.types import (
)
from bot.modules.database.db import DBDict
from bot.modules.settings import UserSettings
from bot.modules.common.song import BaseSongItem
from typing import TypeVar
@@ -15,7 +16,8 @@ BaseSongT = TypeVar('BaseSongT', bound=BaseSongItem)
async def get_common_search_result(
audio: BaseSongT,
db_table: DBDict,
service_id: str
service_id: str,
settings: UserSettings
) -> InlineQueryResultDocument | InlineQueryResultCachedAudio:
return (
InlineQueryResultDocument(
@@ -23,7 +25,8 @@ async def get_common_search_result(
title=audio.name,
description=audio.all_artists,
thumb_url=audio.thumbnail,
document_url=audio.preview_url or audio.thumbnail,
document_url=(audio.preview_url or audio.thumbnail) if
settings['search_preview'].value == 'preview' else audio.thumbnail,
mime_type='application/zip',
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[

View File

@@ -4,18 +4,20 @@ from aiogram.types import (
from bot.modules.deezer import deezer
from bot.modules.database import db
from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_deezer_search_results(query: str) -> list[
async def get_deezer_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
return [
await get_common_search_result(
audio=audio,
db_table=db.deezer,
service_id='deez'
service_id='deez',
settings=settings
)
for audio in await deezer.songs.search(query, limit=50)
]

View File

@@ -4,18 +4,20 @@ from aiogram.types import (
from bot.modules.spotify import spotify
from bot.modules.database import db
from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_spotify_search_results(query: str) -> list[
async def get_spotify_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
return [
await get_common_search_result(
audio=audio,
db_table=db.spotify,
service_id='spot'
service_id='spot',
settings=settings
)
for audio in spotify.songs.search(query, limit=50)
]

View File

@@ -3,13 +3,14 @@ from aiogram.types import (
)
from bot.modules.url import recognise_music_service, get_id
from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
import inspect
async def get_url_results(query: str) -> list[
async def get_url_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
service = recognise_music_service(query)
@@ -25,5 +26,6 @@ async def get_url_results(query: str) -> list[
audio=audio,
db_table=service.db_table,
service_id=service.name,
settings=settings
)
]

View File

@@ -4,18 +4,20 @@ from aiogram.types import (
from bot.modules.youtube import youtube
from bot.modules.database import db
from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_youtube_search_results(query: str) -> list[
async def get_youtube_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
return [
await get_common_search_result(
audio=audio,
db_table=db.youtube,
service_id='yt'
service_id='yt',
settings=settings
)
for audio in youtube.songs.search(query, limit=40)
]