-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsongtitle.py
47 lines (40 loc) · 1.07 KB
/
songtitle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import spotilib
from bs4 import BeautifulSoup
import urllib.request
import re
#import main
#spotilib.generating(spotilib.artist(), spotilib.song(), save=False)
spotilib.printSong()
def lookupSong(artist, title):
title = str(title).split('(')[0].strip()
search = title + " " + artist
search = search.replace(' ', '+')
url = "https://genius.com/search?q=" + search
print(url)
link = getFirstSearch(url)
print(link)
print(type(link))
# lyrics = main.get_song_lyrics(artist, title)
#div = getLyrics(link)
#lyrics = re.findall(r'(.*?)\<.*?\>', div)
# print(lyrics)
def getLyrics(url):
soup = getUrl(url)
tags = soup('div')
for tag in tags:
print(tag)
# if re.match(r'.*<!-- Usage', tag):
# return tag
def getFirstSearch(url):
soup = getUrl(url)
tags = soup('li')
for tag in tags:
if re.match('search_result', tag.get('class', None)):
return tag.get('href', None)
def getUrl(url):
with urllib.request.urlopen(url) as url:
s = url.read()
soup = BeautifulSoup(s, 'lxml')
soup.prettify().encode("ascii")
return soup;
#lookupSong(spotilib.artist(), spotilib.song())