used black
This commit is contained in:
@@ -10,26 +10,28 @@ async def get_url_after_redirect(url: str) -> str:
|
||||
|
||||
|
||||
async def get_id(recognised: RecognisedService):
|
||||
if recognised.name == 'yt':
|
||||
return recognised.parse_result.path.replace('/', '') if (
|
||||
recognised.parse_result.netloc.endswith('youtu.be')
|
||||
) else recognised.parse_result.query.split('=')[1].split('&')[0]
|
||||
if recognised.name == "yt":
|
||||
return (
|
||||
recognised.parse_result.path.replace("/", "")
|
||||
if (recognised.parse_result.netloc.endswith("youtu.be"))
|
||||
else recognised.parse_result.query.split("=")[1].split("&")[0]
|
||||
)
|
||||
|
||||
elif recognised.name == 'spot':
|
||||
if recognised.parse_result.netloc.endswith('open.spotify.com'):
|
||||
return recognised.parse_result.path.split('/')[2]
|
||||
elif recognised.name == "spot":
|
||||
if recognised.parse_result.netloc.endswith("open.spotify.com"):
|
||||
return recognised.parse_result.path.split("/")[2]
|
||||
else:
|
||||
url = await get_url_after_redirect(recognised.parse_result.geturl())
|
||||
return url.split('/')[-1].split('?')[0]
|
||||
return url.split("/")[-1].split("?")[0]
|
||||
|
||||
elif recognised.name == 'deez':
|
||||
if recognised.parse_result.netloc.endswith('deezer.com'):
|
||||
return recognised.parse_result.path.split('/')[-1]
|
||||
elif recognised.name == "deez":
|
||||
if recognised.parse_result.netloc.endswith("deezer.com"):
|
||||
return recognised.parse_result.path.split("/")[-1]
|
||||
else:
|
||||
url = await get_url_after_redirect(recognised.parse_result.geturl())
|
||||
return url.split('/')[-1].split('?')[0]
|
||||
return url.split("/")[-1].split("?")[0]
|
||||
|
||||
elif recognised.name == 'sc':
|
||||
if not recognised.parse_result.netloc.startswith('on'):
|
||||
elif recognised.name == "sc":
|
||||
if not recognised.parse_result.netloc.startswith("on"):
|
||||
return recognised.parse_result.geturl()
|
||||
return await get_url_after_redirect(recognised.parse_result.geturl())
|
||||
|
||||
@@ -14,7 +14,7 @@ from bot.modules.soundcloud import soundcloud
|
||||
|
||||
@dataclass
|
||||
class RecognisedService:
|
||||
name: Literal['yt', 'spot', 'deez', 'sc']
|
||||
name: Literal["yt", "spot", "deez", "sc"]
|
||||
db_table: DBDict
|
||||
by_id_func: Callable | Awaitable
|
||||
parse_result: ParseResult
|
||||
@@ -22,33 +22,33 @@ class RecognisedService:
|
||||
|
||||
def recognise_music_service(url: str) -> RecognisedService | None:
|
||||
url = urlparse(url)
|
||||
if url.netloc.endswith('youtube.com') or url.netloc.endswith('youtu.be'):
|
||||
if url.netloc.endswith("youtube.com") or url.netloc.endswith("youtu.be"):
|
||||
return RecognisedService(
|
||||
name='yt',
|
||||
name="yt",
|
||||
db_table=db.youtube,
|
||||
by_id_func=youtube.songs.from_id,
|
||||
parse_result=url
|
||||
parse_result=url,
|
||||
)
|
||||
elif url.netloc.endswith('open.spotify.com') or url.netloc.endswith('spotify.link'):
|
||||
elif url.netloc.endswith("open.spotify.com") or url.netloc.endswith("spotify.link"):
|
||||
return RecognisedService(
|
||||
name='spot',
|
||||
name="spot",
|
||||
db_table=db.spotify,
|
||||
by_id_func=spotify.songs.from_id,
|
||||
parse_result=url
|
||||
parse_result=url,
|
||||
)
|
||||
elif url.netloc.endswith('deezer.page.link') or url.netloc.endswith('deezer.com'):
|
||||
elif url.netloc.endswith("deezer.page.link") or url.netloc.endswith("deezer.com"):
|
||||
return RecognisedService(
|
||||
name='deez',
|
||||
name="deez",
|
||||
db_table=db.deezer,
|
||||
by_id_func=deezer.songs.from_id,
|
||||
parse_result=url
|
||||
parse_result=url,
|
||||
)
|
||||
elif url.netloc.endswith('soundcloud.com'):
|
||||
elif url.netloc.endswith("soundcloud.com"):
|
||||
return RecognisedService(
|
||||
name='sc',
|
||||
name="sc",
|
||||
db_table=db.soundcloud,
|
||||
by_id_func=soundcloud.songs.from_url,
|
||||
parse_result=url
|
||||
parse_result=url,
|
||||
)
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user