# Path: lyric_engine/modules/kget.py
# class KGet(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             return False
# 
#         if not self.parse_lyric(url, html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.parse_song_info(url, html):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def get_html(self, url):
#         html = common.get_url_content(url, encoding="utf-8")
#         if not html:
#             logging.error('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def parse_lyric(self, url, html):
#         prefix = '<div id="lyric-trunk">'
#         suffix = '</div>'
#         lyric = common.get_string_by_start_end_string(prefix, suffix, html)
#         if not lyric:
#             logging.error('Failed to parse lyric')
#             return False
# 
#         lyric = common.strip_tags(lyric)
# 
#         lyric = common.unicode2string(lyric).strip()
# 
#         self.lyric = lyric
#         return True
# 
#     def parse_song_info(self, url, html):
#         ret = True
# 
#         pattern = '<h1.*?>(.*)</h1>'
#         title = common.get_first_group_by_pattern(html, pattern)
#         if title:
#             title = common.htmlspecialchars_decode(
#                 common.strip_tags(title)).strip()
#             self.title = title
#         else:
#             logging.warning('Failed to parse title of url [%s]', url)
#             ret = False
# 
#         prefix = '<table class="lyric-data">'
#         suffix = '</table>'
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info_table = info_table.replace('\n', '')
# 
#         patterns = {
#             'artist': '">([^<]*)</a></span></td></tr>',
#             'lyricist': 'td>([^<]*)<br></td></tr><tr>',
#             'composer': 'td>([^<]*)<br></td></tr></table>',
#         }
# 
#         self.set_attr(patterns, info_table)
# 
#         return ret


import unittest
from lyric_engine.modules.kget import KGet as Lyric

class KGetTest(unittest.TestCase):
    def test_url_zutto(self):
        url = 'http://www.kget.jp/lyric/188989/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'ずっと feat.HAN-KUN & TEE')
        self.assertEqual(obj.artist, 'SPICY CHOCOLATE, HAN-KUN, TEE')
        self.assertEqual(obj.lyricist, 'HAN-KUN, TEE')
        self.assertEqual(obj.composer, 'DJ CONTROLER, U.M.E.D.Y., WolfJunk')
        self.assertEqual(len(obj.lyric), 769)

    def test_url_kanjani8(self):
        url = 'http://www.kget.jp/lyric/185146/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'ビースト!!')
        self.assertEqual(obj.artist, '関ジャニ∞')
        self.assertEqual(obj.lyricist, '錦戸亮')
        self.assertEqual(obj.composer, '朱鷺羽ソウ')
        self.assertEqual(len(obj.lyric), 924)

    def test_url_maaya(self):
        url = 'http://www.kget.jp/lyric/11066/'

# Path: lyric_engine/modules/kget.py
# class KGet(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             return False
# 
#         if not self.parse_lyric(url, html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.parse_song_info(url, html):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def get_html(self, url):
#         html = common.get_url_content(url, encoding="utf-8")
#         if not html:
#             logging.error('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def parse_lyric(self, url, html):
#         prefix = '<div id="lyric-trunk">'
#         suffix = '</div>'
#         lyric = common.get_string_by_start_end_string(prefix, suffix, html)
#         if not lyric:
#             logging.error('Failed to parse lyric')
#             return False
# 
#         lyric = common.strip_tags(lyric)
# 
#         lyric = common.unicode2string(lyric).strip()
# 
#         self.lyric = lyric
#         return True
# 
#     def parse_song_info(self, url, html):
#         ret = True
# 
#         pattern = '<h1.*?>(.*)</h1>'
#         title = common.get_first_group_by_pattern(html, pattern)
#         if title:
#             title = common.htmlspecialchars_decode(
#                 common.strip_tags(title)).strip()
#             self.title = title
#         else:
#             logging.warning('Failed to parse title of url [%s]', url)
#             ret = False
# 
#         prefix = '<table class="lyric-data">'
#         suffix = '</table>'
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info_table = info_table.replace('\n', '')
# 
#         patterns = {
#             'artist': '">([^<]*)</a></span></td></tr>',
#             'lyricist': 'td>([^<]*)<br></td></tr><tr>',
#             'composer': 'td>([^<]*)<br></td></tr></table>',
#         }
# 
#         self.set_attr(patterns, info_table)
# 
#         return ret


# Path: lyric_engine/tests/test_kget.py
import unittest
from lyric_engine.modules.kget import KGet as Lyric


class KGetTest(unittest.TestCase):
    def test_url_zutto(self):
        url = 'http://www.kget.jp/lyric/188989/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'ずっと feat.HAN-KUN & TEE')
        self.assertEqual(obj.artist, 'SPICY CHOCOLATE, HAN-KUN, TEE')
        self.assertEqual(obj.lyricist, 'HAN-KUN, TEE')
        self.assertEqual(obj.composer, 'DJ CONTROLER, U.M.E.D.Y., WolfJunk')
        self.assertEqual(len(obj.lyric), 769)

    def test_url_kanjani8(self):
        url = 'http://www.kget.jp/lyric/185146/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'ビースト!!')
        self.assertEqual(obj.artist, '関ジャニ∞')
        self.assertEqual(obj.lyricist, '錦戸亮')
        self.assertEqual(obj.composer, '朱鷺羽ソウ')
        self.assertEqual(len(obj.lyric), 924)

    def test_url_maaya(self):
        url = 'http://www.kget.jp/lyric/11066/'

        obj = Lyric(url)