3 Scraper for http://music.163.com/
15 __title__ =
"Music163"
20 headers[
'User-Agent'] =
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0'
28 self.
LYRIC_URL =
'http://music.163.com/api/song/lyric'
31 log(
"%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.
DEBUG)
32 lyrics = Lyrics(settings=self.
settings)
34 lyrics.source = __title__
36 artist = song.artist.replace(
' ',
'+')
37 title = song.title.replace(
' ',
'+')
38 search =
'?s=%s+%s&type=1' % (artist, title)
41 response = requests.get(url, headers=headers, timeout=10)
42 result = response.json()
46 if 'result' in result
and 'songs' in result[
'result']:
47 for item
in result[
'result'][
'songs']:
48 artists =
"+&+".join([a[
"name"]
for a
in item[
"artists"]])
49 if (difflib.SequenceMatcher(
None, artist.lower(), artists.lower()).ratio() > 0.6)
and (difflib.SequenceMatcher(
None, title.lower(), item[
'name'].lower()).ratio() > 0.8):
50 links.append((artists +
' - ' + item[
'name'], self.
LYRIC_URL +
'?id=' + str(item[
'id']) +
'&lv=-1&kv=-1&tv=-1', artists, item[
'name']))
57 if lyr
and lyr.startswith(
'['):
63 title,url,artist,song = link
65 log(
'%s: search url: %s' % (__title__, url), debug=self.
DEBUG)
66 response = requests.get(url, headers=headers, timeout=10)
67 result = response.json()
71 return result[
'lrc'][
'lyric']