1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-09-20 03:11:04 +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 # coding: utf-8
from flask import request, send_file, Response from flask import request, send_file, Response
import requests
import os.path import os.path
from PIL import Image from PIL import Image
import subprocess import subprocess
import codecs import codecs
from xml.etree import ElementTree
import config, scanner import config, scanner
from web import app from web import app
@ -162,6 +164,20 @@ def lyrics():
'_value_': 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': {} }) return request.formatter({ 'lyrics': {} })
def read_file_as_unicode(path): def read_file_as_unicode(path):