1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Getting lyrics from chartlyrics.com

This commit is contained in:
spl0k 2013-12-27 22:53:07 +01:00
parent 815944ca6f
commit 8fdba4c8c5

View File

@ -1,10 +1,12 @@
# coding: utf-8
from flask import request, send_file, Response
import requests
import os.path
from PIL import Image
import subprocess
import codecs
from xml.etree import ElementTree
import config, scanner
from web import app
@ -162,6 +164,20 @@ def lyrics():
'_value_': lyrics
} })
try:
r = requests.get("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect",
params = { 'artist': artist, 'song': title })
root = ElementTree.fromstring(r.content)
ns = { 'cl': 'http://api.chartlyrics.com/' }
return request.formatter({ 'lyrics': {
'artist': root.find('cl:LyricArtist', namespaces = ns).text,
'title': root.find('cl:LyricSong', namespaces = ns).text,
'_value_': root.find('cl:Lyric', namespaces = ns).text
} })
except requests.exceptions.RequestException, e:
app.logger.warn('Error while requesting the ChartLyrics API: ' + str(e))
return request.formatter({ 'lyrics': {} })
def read_file_as_unicode(path):