-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.py
31 lines (30 loc) · 858 Bytes
/
music.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
import os
import requests
import bs4
import re
import urllib
from bs4 import BeautifulSoup
def lyric(song,artist):
addr = 'http://www.metrolyrics.com/%s-lyrics-%s.html' % (song,artist)
url=requests.get(addr)
lyrics= None
soup = BeautifulSoup(url.content,'html.parser')
lyrics = soup.findAll('p', class_='verse')
lyr= []
filename = song + ' - ' + artist + '.txt'
header = artist + ' - ' + song + ' lyrics\n'
if lyrics is not None:
with open(filename, "a") as curfile:
curfile.write(header)
for ver in lyrics:
print ver.get_text()
text=ver.get_text()
with open(filename, "a") as curfile:
curfile.write(text)
else:
print("Please enter correct information")
song= raw_input('Enter song name ')
s = song.lower().replace(' ','-')
artist = raw_input('Enter artist name ')
a = artist.lower().replace(' ','-')
lyric(s,a)