MythTV  master
lyricsScraper.py
Go to the documentation of this file.
1 #-*- coding: UTF-8 -*-
2 import sys
3 import re
4 import requests
5 import html
6 import xbmc
7 import xbmcaddon
8 from lib.utils import *
9 
10 __title__ = 'azlyrics'
11 __priority__ = '230'
12 __lrc__ = False
13 
14 
16  def __init__(self, *args, **kwargs):
17  self.DEBUG = kwargs['debug']
18  self.settings = kwargs['settings']
19  self.url = 'https://www.azlyrics.com/lyrics/%s/%s.html'
20 
21  def get_lyrics(self, song):
22  log('%s: searching lyrics for %s - %s' % (__title__, song.artist, song.title), debug=self.DEBUG)
23  lyrics = Lyrics(settings=self.settings)
24  lyrics.song = song
25  lyrics.source = __title__
26  lyrics.lrc = __lrc__
27  artist = re.sub("[^a-zA-Z0-9]+", "", song.artist).lower().lstrip('the ')
28  title = re.sub("[^a-zA-Z0-9]+", "", song.title).lower()
29  try:
30  req = requests.get(self.url % (artist, title), timeout=10)
31  response = req.text
32  except:
33  return None
34  req.close()
35  try:
36  lyricscode = response.split('t. -->')[1].split('</div')[0]
37  lyricstext = html.unescape(lyricscode).replace('<br />', '\n')
38  lyr = re.sub('<[^<]+?>', '', lyricstext)
39  lyrics.lyrics = lyr
40  return lyrics
41  except:
42  return None
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher.get_lyrics
def get_lyrics(self, song)
Definition: lyricsScraper.py:21
utils
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher.settings
settings
Definition: lyricsScraper.py:18
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher.__init__
def __init__(self, *args, **kwargs)
Definition: lyricsScraper.py:16
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher.url
url
Definition: lyricsScraper.py:19
xbmc.log
None log(str msg, int level=LOGDEBUG)
Definition: xbmc.py:9
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher.DEBUG
DEBUG
Definition: lyricsScraper.py:17
culrcscrapers.azlyrics.lyricsScraper.LyricsFetcher
Definition: lyricsScraper.py:15