This commit is contained in:
Pulguer Gonzalo 2022-02-14 18:48:00 -03:00
commit 1b8bf28bc9
3 changed files with 73 additions and 1 deletions

36
azl.py Normal file
View File

@ -0,0 +1,36 @@
from bs4 import BeautifulSoup
import requests
from requests import get
def getLink(artist, title):
base_start = 'https://www.azlyrics.com/lyrics/'
artist = artist.lower()
artist = artist.replace(' ', '')
artist = artist.replace('-', '')
title = title.lower()
title = title.replace(' ', '')
title = title.replace('?', '')
title = title.replace("'", '')
link = base_start + artist + '/' + title + '.html'
return(link)
def getLyrics(link):
w = requests.get(link)
soup = BeautifulSoup(w.text, 'html.parser')
lyr = soup.find_all('div', class_=False)
let = str(lyr)
return(let)
def parsero(lyrics):
let = lyrics
let = let.replace('<br/>', ' ')
let = let.replace('<i>', '')
let = let.replace('</i>', '')
let = let.replace('<div>', '')
let = let.replace('</div>,', '')
let = let.replace('</div>', '')
let = let.replace('<div id="RTK_vQAi">', '')
let = let.replace('<div id="RTK_QZjx">', '')
let = let.replace('<div id="RTK_sdL2">', '')
let = let.replace('<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->', '')
return(let[1:-1])

34
letras.py Normal file
View File

@ -0,0 +1,34 @@
from bs4 import BeautifulSoup
import requests
from requests import get
def getLink(artist, title):
base_start = 'https://www.letras.com/'
artist = artist.lower()
artist = artist.replace(' ', '-')
title = title.lower()
title = title.replace(' ', '-')
link = base_start + artist + '/' + title
return(link)
def getLyrics(link):
w = requests.get(link)
soup = BeautifulSoup(w.text, 'html.parser')
lyr = soup.find_all('p', class_=False)
let = str(lyr)
return(let)
def parsero(lyrics):
lyrics = lyrics.replace('</p>,', '\n')
lyrics = lyrics.replace('<br/>,', '\n')
lyrics = lyrics.replace('<br/>', '\n')
lyrics = lyrics.replace('<p>', '')
lyrics = lyrics.replace('<br>', '\n')
lyrics = lyrics.replace('</br>', '\n')
lyrics = lyrics.replace('<p style="display: none;">Quiero recibir notificaciones de artistas destacados y noticias.<span class="bt-toggle" id="js-toggle-push"></span></p>', '')
lyrics = lyrics.replace('Música comienza con letras', '')
lyrics = lyrics.replace('Asociados:', '')
lyrics = lyrics.replace(' © 2003 - 2021, 3.1 millones de canciones', '')
lyrics = lyrics.replace(' Hecho con <b>amor</b> en Belo Horizonte - Brasil', '')
return('\n'+lyrics[1:-1])

View File

@ -21,7 +21,9 @@ while True:
song_url = letras.getLink(artist, title)
un_lyr = letras.getLyrics(song_url)
fin = letras.parsero(un_lyr)
print(fin)
letra = fin.split('©', 1)
fin_lyr = letra[0]
print(fin_lyr)
while True:
print('<------------------------------------------------------------->')
res = input("What's the move? (s to search for another song/q to quit): ")