Fix downloader

This commit is contained in:
BarsTiger
2023-10-18 12:29:59 +03:00
parent 9348f1c19b
commit d6868f6570
4 changed files with 40 additions and 14 deletions

View File

@@ -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