used black
This commit is contained in:
@@ -12,4 +12,4 @@ router.include_routers(
|
||||
suppress_verify.router,
|
||||
)
|
||||
|
||||
__all__ = ['router']
|
||||
__all__ = ["router"]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, URLInputFile, InputMediaAudio,
|
||||
BufferedInputFile,
|
||||
URLInputFile,
|
||||
InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
@@ -11,11 +13,11 @@ from bot.modules.database import db
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(F.result_id.startswith('deez::'))
|
||||
@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()
|
||||
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,
|
||||
@@ -34,5 +36,5 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
reply_markup=None
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, InputMediaAudio,
|
||||
BufferedInputFile,
|
||||
InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
@@ -16,42 +17,37 @@ router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(
|
||||
F.result_id.startswith('spotc::') | F.result_id.startswith('ytc::')
|
||||
F.result_id.startswith("spotc::") | F.result_id.startswith("ytc::")
|
||||
)
|
||||
async def on_cached_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
settings: UserSettings):
|
||||
if settings['recode_youtube'].value != 'yes':
|
||||
async def on_cached_chosen(
|
||||
chosen_result: ChosenInlineResult, bot: Bot, settings: UserSettings
|
||||
):
|
||||
if settings["recode_youtube"].value != "yes":
|
||||
await bot.edit_message_reply_markup(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
reply_markup=None
|
||||
inline_message_id=chosen_result.inline_message_id, reply_markup=None
|
||||
)
|
||||
return
|
||||
|
||||
if (
|
||||
type(
|
||||
db.recoded.get(
|
||||
song_id := chosen_result.result_id
|
||||
.removeprefix('spotc::')
|
||||
.removeprefix('ytc::')
|
||||
if type(
|
||||
db.recoded.get(
|
||||
song_id := chosen_result.result_id.removeprefix("spotc::").removeprefix(
|
||||
"ytc::"
|
||||
)
|
||||
) in [bool, type(None)]
|
||||
):
|
||||
)
|
||||
) in [bool, type(None)]:
|
||||
await bot.edit_message_reply_markup(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
reply_markup=None
|
||||
inline_message_id=chosen_result.inline_message_id, reply_markup=None
|
||||
)
|
||||
return
|
||||
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🔄 Recoding...',
|
||||
reply_markup=None
|
||||
caption="🔄 Recoding...",
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
message = await bot.forward_message(
|
||||
config.telegram.files_chat,
|
||||
config.telegram.files_chat,
|
||||
db.recoded[song_id]
|
||||
config.telegram.files_chat, config.telegram.files_chat, db.recoded[song_id]
|
||||
)
|
||||
|
||||
song_io: BytesIO = await bot.download( # type: ignore
|
||||
@@ -76,7 +72,7 @@ async def on_cached_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
),
|
||||
thumbnail=BufferedInputFile(
|
||||
file=(await bot.download(message.audio.thumbnail.file_id)).read(),
|
||||
filename='thumbnail.jpg'
|
||||
filename="thumbnail.jpg",
|
||||
),
|
||||
performer=message.audio.performer,
|
||||
title=message.audio.title,
|
||||
@@ -85,15 +81,15 @@ async def on_cached_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='',
|
||||
caption="",
|
||||
reply_markup=None,
|
||||
)
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id)
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
)
|
||||
|
||||
if chosen_result.result_id.startswith('spotc::'):
|
||||
if chosen_result.result_id.startswith("spotc::"):
|
||||
db.spotify[song_id] = audio.audio.file_id
|
||||
else:
|
||||
db.youtube[song_id] = audio.audio.file_id
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, URLInputFile, InputMediaAudio,
|
||||
BufferedInputFile,
|
||||
URLInputFile,
|
||||
InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
@@ -11,11 +13,13 @@ from bot.modules.database import db
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(F.result_id.startswith('sc::'))
|
||||
@router.chosen_inline_result(F.result_id.startswith("sc::"))
|
||||
async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
bytestream: SoundCloudBytestream = await (await soundcloud.downloader.from_id(
|
||||
chosen_result.result_id.removeprefix('sc::')
|
||||
)).to_bytestream()
|
||||
bytestream: SoundCloudBytestream = await (
|
||||
await soundcloud.downloader.from_id(
|
||||
chosen_result.result_id.removeprefix("sc::")
|
||||
)
|
||||
).to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
@@ -33,5 +37,5 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
reply_markup=None
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, URLInputFile, InputMediaAudio,
|
||||
BufferedInputFile,
|
||||
URLInputFile,
|
||||
InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
@@ -16,16 +18,17 @@ router = Router()
|
||||
|
||||
|
||||
def not_strict_name(song, yt_song):
|
||||
if 'feat' in yt_song.name.lower():
|
||||
if "feat" in yt_song.name.lower():
|
||||
return any(artist.lower() in yt_song.name.lower() for artist in song.artists)
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
@router.chosen_inline_result(F.result_id.startswith('spot::'))
|
||||
async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
settings: UserSettings):
|
||||
song = spotify.songs.from_id(chosen_result.result_id.removeprefix('spot::'))
|
||||
@router.chosen_inline_result(F.result_id.startswith("spot::"))
|
||||
async def on_new_chosen(
|
||||
chosen_result: ChosenInlineResult, bot: Bot, settings: UserSettings
|
||||
):
|
||||
song = spotify.songs.from_id(chosen_result.result_id.removeprefix("spot::"))
|
||||
|
||||
bytestream = None
|
||||
audio = None
|
||||
@@ -34,14 +37,15 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
song.full_name,
|
||||
exact_match=True,
|
||||
)
|
||||
if settings['exact_spotify_search'].value == 'yes':
|
||||
if ((song.all_artists != yt_song.all_artists or song.name != yt_song.name)
|
||||
and not not_strict_name(song, yt_song)):
|
||||
if settings["exact_spotify_search"].value == "yes":
|
||||
if (
|
||||
song.all_artists != yt_song.all_artists or song.name != yt_song.name
|
||||
) and not not_strict_name(song, yt_song):
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🙄 Cannot find this song on YouTube, trying Deezer...',
|
||||
caption="🙄 Cannot find this song on YouTube, trying Deezer...",
|
||||
reply_markup=None,
|
||||
parse_mode='HTML',
|
||||
parse_mode="HTML",
|
||||
)
|
||||
yt_song = None
|
||||
bytestream = False
|
||||
@@ -66,9 +70,9 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
except AgeRestrictedError:
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🔞 This song is age restricted, trying Deezer...',
|
||||
caption="🔞 This song is age restricted, trying Deezer...",
|
||||
reply_markup=None,
|
||||
parse_mode='HTML',
|
||||
parse_mode="HTML",
|
||||
)
|
||||
yt_song = None
|
||||
|
||||
@@ -99,29 +103,29 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
assert e
|
||||
|
||||
if audio:
|
||||
if settings['exact_spotify_search'].value == 'yes':
|
||||
if settings["exact_spotify_search"].value == "yes":
|
||||
db.spotify[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
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
else:
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🤷♂️ Cannot download this song',
|
||||
caption="🤷♂️ Cannot download this song",
|
||||
reply_markup=None,
|
||||
parse_mode='HTML',
|
||||
parse_mode="HTML",
|
||||
)
|
||||
|
||||
if yt_song and settings['recode_youtube'].value == 'yes':
|
||||
if yt_song and settings["recode_youtube"].value == "yes":
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🔄 Recoding...',
|
||||
caption="🔄 Recoding...",
|
||||
reply_markup=None,
|
||||
parse_mode='HTML',
|
||||
parse_mode="HTML",
|
||||
)
|
||||
await bytestream.rerender()
|
||||
|
||||
@@ -139,20 +143,20 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
db.youtube[yt_song.id] = audio.audio.file_id
|
||||
db.recoded[yt_song.id] = True
|
||||
|
||||
if settings['exact_spotify_search'].value == 'yes':
|
||||
if settings["exact_spotify_search"].value == "yes":
|
||||
db.spotify[song.id] = audio.audio.file_id
|
||||
db.recoded[song.id] = True
|
||||
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='',
|
||||
caption="",
|
||||
reply_markup=None,
|
||||
)
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id)
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
)
|
||||
elif yt_song and settings['recode_youtube'].value == 'no':
|
||||
elif yt_song and settings["recode_youtube"].value == "no":
|
||||
db.recoded[yt_song.id] = audio.message_id
|
||||
if settings['exact_spotify_search'].value == 'yes':
|
||||
if settings["exact_spotify_search"].value == "yes":
|
||||
db.recoded[song.id] = audio.message_id
|
||||
|
||||
@@ -7,10 +7,9 @@ router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(
|
||||
F.result_id.startswith('deezc::') | F.result_id.startswith('scc::')
|
||||
F.result_id.startswith("deezc::") | F.result_id.startswith("scc::")
|
||||
)
|
||||
async def on_unneeded_cached_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
await bot.edit_message_reply_markup(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
reply_markup=None
|
||||
inline_message_id=chosen_result.inline_message_id, reply_markup=None
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from aiogram import Router, Bot, F
|
||||
from aiogram.types import (
|
||||
BufferedInputFile, URLInputFile, InputMediaAudio,
|
||||
BufferedInputFile,
|
||||
URLInputFile,
|
||||
InputMediaAudio,
|
||||
ChosenInlineResult,
|
||||
)
|
||||
|
||||
@@ -12,19 +14,20 @@ from bot.modules.settings import UserSettings
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.chosen_inline_result(F.result_id.startswith('yt::'))
|
||||
async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
settings: UserSettings):
|
||||
song = youtube.songs.from_id(chosen_result.result_id.removeprefix('yt::'))
|
||||
@router.chosen_inline_result(F.result_id.startswith("yt::"))
|
||||
async def on_new_chosen(
|
||||
chosen_result: ChosenInlineResult, bot: Bot, settings: UserSettings
|
||||
):
|
||||
song = youtube.songs.from_id(chosen_result.result_id.removeprefix("yt::"))
|
||||
|
||||
try:
|
||||
bytestream = await song.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
|
||||
caption="🔞 This song is age restricted, so I can't download it. "
|
||||
"Try downloading it from Deezer or SoundCloud",
|
||||
reply_markup=None,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -45,14 +48,14 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
reply_markup=None
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
if settings['recode_youtube'].value == 'yes':
|
||||
if settings["recode_youtube"].value == "yes":
|
||||
await bot.edit_message_caption(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
caption='🔄 Recoding...',
|
||||
reply_markup=None
|
||||
caption="🔄 Recoding...",
|
||||
reply_markup=None,
|
||||
)
|
||||
|
||||
await bytestream.rerender()
|
||||
@@ -75,7 +78,7 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot,
|
||||
await bot.edit_message_media(
|
||||
inline_message_id=chosen_result.inline_message_id,
|
||||
media=InputMediaAudio(media=audio.audio.file_id),
|
||||
reply_markup=None
|
||||
reply_markup=None,
|
||||
)
|
||||
else:
|
||||
db.recoded[song.id] = audio.message_id
|
||||
|
||||
Reference in New Issue
Block a user