# Path: lyric_engine/modules/lyricwiki.py
# class LyricWiki(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.info('Failed to get content 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):
#         html = common.get_url_content(url)
#         return html
# 
#     def find_lyric(self, html):
#         prefix = "<div class='lyricbox'>"
#         suffix = "<div class='lyricsbreak'>"
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         if not lyric:
#             return None
# 
#         lyric = lyric.replace('<br />', '\n')
#         lyric = common.unicode2string(lyric).strip()
#         lyric = common.strip_tags(lyric).strip()
# 
#         self.lyric = lyric
#         return True
# 
#     def find_song_info(self, html):
#         pattern = '<meta property="og:title" content="([^"]+)" />'
#         ogTitle = common.get_first_group_by_pattern(html, pattern)
# 
#         artist, title = ogTitle.split(':')
# 
#         self.title = title
#         self.artist = artist
# 
#         return True


import unittest
from lyric_engine.modules.lyricwiki import LyricWiki as Lyric

class LyricWikiTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://lyrics.wikia.com/%E5%9D%82%E6%9C%AC%E7%9C%9F%E7%B6%BE_(Maaya_Sakamoto):%E5%83%95%E3%81%9F%E3%81%A1%E3%81%8C%E6%81%8B%E3%82%92%E3%81%99%E3%82%8B%E7%90%86%E7%94%B1'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '僕たちが恋をする理由')
        self.assertEqual(obj.artist, 'Maaya Sakamoto')
        self.assertEqual(len(obj.lyric), 410)

    def test_url_02(self):
        url = 'http://lyrics.wikia.com/Zard:%E9%81%8B%E5%91%BD%E3%81%AE%E3%83%AB%E3%83%BC%E3%83%AC%E3%83%83%E3%83%88%E5%BB%BB%E3%81%97%E3%81%A6'

# Path: lyric_engine/modules/lyricwiki.py
# class LyricWiki(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.info('Failed to get content 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):
#         html = common.get_url_content(url)
#         return html
# 
#     def find_lyric(self, html):
#         prefix = "<div class='lyricbox'>"
#         suffix = "<div class='lyricsbreak'>"
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         if not lyric:
#             return None
# 
#         lyric = lyric.replace('<br />', '\n')
#         lyric = common.unicode2string(lyric).strip()
#         lyric = common.strip_tags(lyric).strip()
# 
#         self.lyric = lyric
#         return True
# 
#     def find_song_info(self, html):
#         pattern = '<meta property="og:title" content="([^"]+)" />'
#         ogTitle = common.get_first_group_by_pattern(html, pattern)
# 
#         artist, title = ogTitle.split(':')
# 
#         self.title = title
#         self.artist = artist
# 
#         return True


# Path: lyric_engine/tests/test_lyricwiki.py
import unittest
from lyric_engine.modules.lyricwiki import LyricWiki as Lyric


class LyricWikiTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://lyrics.wikia.com/%E5%9D%82%E6%9C%AC%E7%9C%9F%E7%B6%BE_(Maaya_Sakamoto):%E5%83%95%E3%81%9F%E3%81%A1%E3%81%8C%E6%81%8B%E3%82%92%E3%81%99%E3%82%8B%E7%90%86%E7%94%B1'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '僕たちが恋をする理由')
        self.assertEqual(obj.artist, 'Maaya Sakamoto')
        self.assertEqual(len(obj.lyric), 410)

    def test_url_02(self):
        url = 'http://lyrics.wikia.com/Zard:%E9%81%8B%E5%91%BD%E3%81%AE%E3%83%AB%E3%83%BC%E3%83%AC%E3%83%83%E3%83%88%E5%BB%BB%E3%81%97%E3%81%A6'

        obj = Lyric(url)