unload plugin loadplugin.py. youtube-preview now gets lyrics.
This commit is contained in:
@@ -11,7 +11,7 @@ from pytubefix import YouTube
|
||||
import simplematrixbotlib as botlib
|
||||
from youtube_title_parse import get_artist_title
|
||||
|
||||
LYRICIST_API_URL = "https://lyrist.vercel.app/api/song/{}"
|
||||
LYRICIST_API_URL = "https://lyrist.vercel.app/api/{}"
|
||||
|
||||
|
||||
def seconds_to_minutes_seconds(seconds):
|
||||
@@ -29,11 +29,12 @@ def seconds_to_minutes_seconds(seconds):
|
||||
return f"{minutes:02d}:{seconds:02d}"
|
||||
|
||||
|
||||
async def fetch_lyrics(artist):
|
||||
async def fetch_lyrics(song, artist):
|
||||
"""
|
||||
Asynchronously fetches lyrics for a song from the Lyricist API.
|
||||
|
||||
Args:
|
||||
song (str): The name of the song.
|
||||
artist (str): The name of the artist.
|
||||
|
||||
Returns:
|
||||
@@ -42,7 +43,7 @@ async def fetch_lyrics(artist):
|
||||
"""
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(LYRICIST_API_URL.format(artist)) as response:
|
||||
async with session.get(LYRICIST_API_URL.format(song, artist)) as response:
|
||||
data = await response.json()
|
||||
return data.get("lyrics")
|
||||
except Exception as e:
|
||||
@@ -50,6 +51,7 @@ async def fetch_lyrics(artist):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
async def fetch_youtube_info(youtube_url):
|
||||
"""
|
||||
Asynchronously fetches information about a YouTube video.
|
||||
@@ -73,7 +75,7 @@ async def fetch_youtube_info(youtube_url):
|
||||
description_with_breaks = description.replace('\n', '<br>')
|
||||
|
||||
# Fetching lyrics
|
||||
lyrics = await fetch_lyrics(artist)
|
||||
lyrics = await fetch_lyrics(song, artist)
|
||||
lyrics = lyrics.replace('\n', "<br>")
|
||||
|
||||
info_message = f"""<strong>🎬🎝 Title:</strong> {title} | <strong>Length</strong>: {length} minutes | <strong>Views</strong>: {views}\n<details><summary><strong>⤵︎Description⤵︎</strong></summary>{description_with_breaks}</details>"""
|
||||
|
Reference in New Issue
Block a user