# Path: lyric_engine/modules/songtexte.py
# class SongTexte(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.info('Failed to get lyric html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(html):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def get_lyric_html(self, url):
#         return common.get_url_content(url)
# 
#     def find_lyric(self, html):
#         prefix = '<div id="lyrics">'
#         suffix = '<div class="brightLink translation hidden-print">'
#         rawLyric = common.get_string_by_start_end_string(prefix, suffix, html)
# 
#         if not rawLyric:
#             # fall back to old finding </div>
#             suffix = '</div>'
#             rawLyric = common.get_string_by_start_end_string(
#                 prefix, suffix, html)
# 
#         rawLyric = rawLyric.replace(
#             '<div id="71M_inreadads"></div>\n<br />\n', '')
#         rawLyric = common.unicode2string(rawLyric)
#         rawLyric = common.htmlspecialchars_decode(rawLyric)
#         rawLyric = common.strip_tags(rawLyric).strip()
# 
#         self.lyric = rawLyric
# 
#         return True
# 
#     def sanitize(self, src):
#         return common.unicode2string(common.htmlspecialchars_decode(src))
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         pattern = 'og:title" content="(.*) - (.*) Songtext"'
# 
#         regex = common.get_matches_by_pattern(html, pattern)
#         if regex:
#             self.artist = self.sanitize(regex.group(1))
#             self.title = self.sanitize(regex.group(2))
# 
#         return ret


import unittest
from lyric_engine.modules.songtexte import SongTexte as Lyric

class SongTexteTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://www.songtexte.com/songtext/taylor-swift/begin-again-63a6de47.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'Begin Again')
        self.assertEqual(obj.artist, 'Taylor Swift')
        self.assertEqual(len(obj.lyric), 1608)

    def test_url_03(self):
        url = 'http://www.songtexte.com/songtext/bone-thugs-n-harmony-feat-mariah-carey-and-bow-wow/c-town-6ba75a7e.html'

# Path: lyric_engine/modules/songtexte.py
# class SongTexte(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.info('Failed to get lyric html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(html):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def get_lyric_html(self, url):
#         return common.get_url_content(url)
# 
#     def find_lyric(self, html):
#         prefix = '<div id="lyrics">'
#         suffix = '<div class="brightLink translation hidden-print">'
#         rawLyric = common.get_string_by_start_end_string(prefix, suffix, html)
# 
#         if not rawLyric:
#             # fall back to old finding </div>
#             suffix = '</div>'
#             rawLyric = common.get_string_by_start_end_string(
#                 prefix, suffix, html)
# 
#         rawLyric = rawLyric.replace(
#             '<div id="71M_inreadads"></div>\n<br />\n', '')
#         rawLyric = common.unicode2string(rawLyric)
#         rawLyric = common.htmlspecialchars_decode(rawLyric)
#         rawLyric = common.strip_tags(rawLyric).strip()
# 
#         self.lyric = rawLyric
# 
#         return True
# 
#     def sanitize(self, src):
#         return common.unicode2string(common.htmlspecialchars_decode(src))
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         pattern = 'og:title" content="(.*) - (.*) Songtext"'
# 
#         regex = common.get_matches_by_pattern(html, pattern)
#         if regex:
#             self.artist = self.sanitize(regex.group(1))
#             self.title = self.sanitize(regex.group(2))
# 
#         return ret


# Path: lyric_engine/tests/test_songtexte.py
import unittest
from lyric_engine.modules.songtexte import SongTexte as Lyric


class SongTexteTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://www.songtexte.com/songtext/taylor-swift/begin-again-63a6de47.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'Begin Again')
        self.assertEqual(obj.artist, 'Taylor Swift')
        self.assertEqual(len(obj.lyric), 1608)

    def test_url_03(self):
        url = 'http://www.songtexte.com/songtext/bone-thugs-n-harmony-feat-mariah-carey-and-bow-wow/c-town-6ba75a7e.html'

        obj = Lyric(url)