-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlyric_source.py
33 lines (26 loc) · 945 Bytes
/
lyric_source.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
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
import requests
class MusixMatchLyric(object):
ENDPOINT = "http://api.musixmatch.com/ws/1.1/matcher.lyrics.get"
def __init__(self, artist, title):
self.artist = artist
self.title = title
@property
def api_key(self):
from config import musixmatch_apikey
return musixmatch_apikey
@property
def lyric(self):
payload = {
'q_artist': self.artist,
'q_track': self.title,
'apikey': self.api_key,
}
try:
response = requests.get(self.ENDPOINT, payload).json()
lyric = response['message']['body']['lyrics']['lyrics_body']
except (requests.RequestException, KeyError, TypeError, ValueError):
return "### bad request ###\n{}\n{}".format(self.ENDPOINT, payload)
else:
return lyric