Add download by url
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .search import ServiceSearchFilter
|
||||
from .url import MusicUrlFilter
|
||||
|
||||
31
bot/filters/url.py
Normal file
31
bot/filters/url.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from aiogram.filters import BaseFilter
|
||||
from aiogram.types import InlineQuery
|
||||
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class MusicUrlFilter(BaseFilter):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
async def __call__(self, inline_query: InlineQuery):
|
||||
if not inline_query.query.strip().startswith('http'):
|
||||
return False
|
||||
|
||||
url = urlparse(inline_query.query)
|
||||
return (
|
||||
url.scheme in ['http', 'https'] and
|
||||
any(
|
||||
map(
|
||||
url.netloc.endswith,
|
||||
[
|
||||
'youtube.com',
|
||||
'youtu.be',
|
||||
'open.spotify.com',
|
||||
'spotify.link',
|
||||
'deezer.page.link',
|
||||
'deezer.com',
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user