extract_info.py (1871B)
1 import yt_dlp 2 import pylast 3 from youtube_title_parse import get_artist_title 4 from functions.lastfm_init import lastfm_network 5 6 def get_video_info(url, isUrl=True): 7 ytdl_opts = {'source_address': '0.0.0.0'} 8 ydl = yt_dlp.YoutubeDL(ytdl_opts) 9 with ydl: 10 if isUrl: 11 video = ydl.extract_info(url, download=False) 12 else: 13 video = ydl.extract_info(f"ytsearch:{url}", download=False)['entries'][0] 14 15 title = video['title'] 16 description = video['description'] 17 weburl = video['webpage_url'] 18 19 try: 20 if video['artist']: 21 artist = video['artist'] 22 if video['track']: 23 song = video['track'] 24 except KeyError as e: 25 artist = None 26 song = None 27 28 return (title, description, weburl, artist, song) 29 30 def get_artist_song(title): 31 try: 32 artist, song = get_artist_title(title) 33 except TypeError as e: 34 artist = None 35 song = None 36 37 return artist, song 38 39 def get_artist_info(artist): 40 try: 41 info = lastfm_network.get_artist(artist).get_bio_summary() 42 except pylast.WSError as e: 43 info = None 44 45 return info 46 47 def get_similar_artists(artist): 48 try: 49 info = lastfm_network.get_artist(artist).get_similar(limit=3) 50 artist_list = [] 51 for t in info: 52 artist_list.append(t.item.get_name()) 53 54 format_tags = ', '.join(artist_list) 55 except pylast.WSError as e: 56 format_tags = None 57 58 return format_tags 59 60 def get_tags(artist): 61 try: 62 info = lastfm_network.get_artist(artist).get_top_tags(limit=2) 63 genre_list = [] 64 for t in info: 65 genre_list.append(t.item.get_name()) 66 67 format_tags = ', '.join(genre_list) 68 except pylast.WSError as e: 69 format_tags = None 70 71 return format_tags