Fix downloader
This commit is contained in:
@@ -5,7 +5,7 @@ from aiogram.types import (
|
||||
)
|
||||
|
||||
from bot.modules.spotify import spotify
|
||||
from bot.modules.youtube import youtube
|
||||
from bot.modules.youtube import youtube, AgeRestrictedError
|
||||
from bot.utils.config import config
|
||||
from bot.modules.database import db
|
||||
|
||||
@@ -16,7 +16,16 @@ router = Router()
|
||||
async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
song = spotify.songs.from_id(chosen_result.result_id.removeprefix('spot::'))
|
||||
|
||||
bytestream = youtube.songs.search_one(song.full_name).to_bytestream()
|
||||
try:
|
||||
bytestream = await youtube.songs.search_one(song.full_name).to_bytestream()
|
||||
except AgeRestrictedError:
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🔞 This song is age restricted, so I can\'t download it. '
|
||||
'Try downloading it from Deezer or SoundCloud',
|
||||
reply_markup=None
|
||||
)
|
||||
return
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
@@ -26,7 +35,8 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
),
|
||||
thumbnail=URLInputFile(song.thumbnail),
|
||||
performer=song.all_artists,
|
||||
title=song.name
|
||||
title=song.name,
|
||||
duration=bytestream.duration,
|
||||
)
|
||||
|
||||
db.spotify[song.id] = audio.audio.file_id
|
||||
|
||||
Reference in New Issue
Block a user