fist commit

This commit is contained in:
siengrain 2023-07-25 21:27:19 -03:00
commit 4f7fe77b9b
2 changed files with 74 additions and 0 deletions

35
genius.py Normal file
View File

@ -0,0 +1,35 @@
from bs4 import BeautifulSoup
import requests
from requests import get
def deletebw(input_string, start_word, end_word):
start_index = input_string.find(start_word)
end_index = input_string.find(end_word)
if start_index == -1 or end_index == -1:
return input_string
output_string = input_string[:start_index] + input_string[end_index + len(end_word):]
return output_string
def getLyrics(link):
w = requests.get(link)
if w:
soup = BeautifulSoup(w.text, 'html.parser')
lyr = soup.find_all("div", class_="Lyrics__Container-sc-1ynbvzw-5 Dzxov")
let = str(lyr)
let = let.replace("<br/>","\n")
let = parsero('[', ']', let)
let = parsero('<', '>', let)
let = let.replace('[','')
let = let.replace(']','')
return(let)
else:
error = "\nCouldn't find that song"
return error
def parsero(word1, word2, lyrics):
while word1 in lyrics:
lyrics = deletebw(lyrics, word1, word2)
return lyrics

39
main.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import genius
r = ''
dic = {'á':'a', 'é':'e', 'í':'i','ó':'o','ú':'u',' ':'-'}
def replaceChar(input_string, char_replacement_dict):
output_string = ""
for char in input_string:
if char in char_replacement_dict:
output_string += char_replacement_dict[char]
else:
output_string += char
return output_string
def getLink(song, author):
song = song.lower()
song = replaceChar(song, dic)
author = author.lower()
author = author.capitalize()
author = replaceChar(author, dic)
base_url = f"https://genius.com/{author}-{song}-lyrics"
return base_url
while r != 'q':
song = input("Name of the song: ")
author = input("Name of the artist: ")
link = getLink(song, author)
lyrics = genius.getLyrics(link)
print("\n")
print(lyrics)
print("\n")
r = input("\n\nType q to quit, anything else to search a different song: ");