python-ox/ox/web/lyricsfly.py

24 lines
804 B
Python
Raw Normal View History

2010-07-07 23:25:57 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
2014-09-30 19:27:26 +00:00
from __future__ import print_function
from ox.cache import read_url
from ox.html import decode_html
from ox.text import find_re
2010-07-07 23:25:57 +00:00
2012-08-15 15:15:40 +00:00
def get_lyrics(title, artist):
html = read_url('http://lyricsfly.com/api/')
key = find_re(html, '<font color=green><b>(.*?)</b></font>')
2010-07-07 23:25:57 +00:00
url = 'http://lyricsfly.com/api/api.php?i=%s&a=%s&t=%s' % (key, artist, title)
xml = read_url(url)
2024-09-11 21:52:01 +00:00
lyrics = find_re(xml, r'<tx>(.*?)\[br\] Lyrics [a-z]* by lyricsfly.com')
2010-07-07 23:25:57 +00:00
lyrics = lyrics.replace('\n', '').replace('\r', '')
lyrics = lyrics.replace('[br]', '\n').strip()
lyrics.replace('\n\n\n', '\n\n')
lyrics = decode_html(lyrics.replace('&amp;', '&'))
2010-07-07 23:25:57 +00:00
return lyrics
if __name__ == '__main__':
2014-09-30 19:27:26 +00:00
print(get_lyrics('Election Day', 'Arcadia'))