matrix-music-bot

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 0371aaa4f3e818533bc0430ae325a126ea36303e
parent a9083260920c9d5f85ef13a69a081b50dbba16ff
Author: John <mail@johnkubach.com>
Date:   Wed, 19 Oct 2022 19:43:30 -0400

More Robust Extraction

Artist - Title extraction now works on automated youtube music uploads.

Diffstat:
Mfunctions/extract_info.py | 10++++++++--
Mmusic.py | 12++++++++----
2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/functions/extract_info.py b/functions/extract_info.py @@ -4,14 +4,20 @@ from youtube_title_parse import get_artist_title from functions.lastfm_init import lastfm_network def get_video_info(url): + artist = None + Song = None ytdl_opts = {'source_address': '0.0.0.0'} - ydl = youtube_dl.YoutubeDL(ytdl_opts) + ydl = yt_dlp.YoutubeDL(ytdl_opts) with ydl: video = ydl.extract_info(url, download=False) title = video['title'] description = video['description'] + if video['artist']: + artist = video['artist'] + if video['track']: + song = video['track'] - return (title, description) + return (title, description, artist, song) def get_artist_song(title): try: diff --git a/music.py b/music.py @@ -34,21 +34,25 @@ def youtube(event): message = message.split() url = message[0] - title, desc = get_video_info(url) + title, desc, artist, song = get_video_info(url) song_info = [title] - artist, song = get_artist_song(title) - if artist: + if artist and song: + fulltitle = artist + " - " + song tags = get_tags(artist) bio = get_artist_info(artist) similar_artists = get_similar_artists(artist) + song_info = [fulltitle] if tags and bio: song_info.append("Genre: " + tags) song_info.append("Similar Artists: " + similar_artists) song_info.append(re.sub('<.*?>', '', bio)) else: - song_info.append(desc) + artist, song = get_artist_song(title) + + if artist == None: + song_info.append(desc) return song_info