# Path: lyric_engine/modules/kasi_time.py
# class KasiTime(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             logging.error('Failed to get html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(html):
#             logging.error('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_html(self, url):
#         html = common.get_url_content(url)
#         if not html:
#             logging.info('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def find_lyric(self, html):
#         prefix = "var lyrics = '"
#         suffix = "';"
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         lyric = lyric.replace("<br>", "\n")
#         lyric = lyric.replace("&nbsp;", " ")
#         lyric = common.htmlspecialchars_decode(lyric)
#         lyric = common.unicode2string(lyric)
#         lyric = common.strip_slash(lyric)
#         lyric = lyric.strip()
# 
#         # test for half to full
#         lyric = common.half2full(lyric)
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         pattern = '<h1>(.*)</h1>'
#         value = common.get_first_group_by_pattern(html, pattern).strip()
#         if value:
#             self.title = value
#         else:
#             logging.error('Failed to find title of url [%s]', url)
#             ret = False
# 
#         prefix = '<div class="person_list">'
#         suffix = '</div>'
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
# 
#         patterns = {
#             'artist': '歌手',
#             'lyricist': '作詞',
#             'composer': '作曲',
#             'arranger': '編曲',
#         }
# 
#         for key in patterns:
#             pattern = patterns[key]
# 
#             prefix = '<th>%s</th>' % (pattern)
#             suffix = '</td>'
# 
#             value = common.find_string_by_prefix_suffix(
#                 info_table, prefix, suffix, False)
#             if not value:
#                 continue
#             pos = value.find('関連リンク:')
#             if pos > 0:
#                 value = value[0:pos]
# 
#             value = value.replace('\t', '').replace('\n', '')
#             value = common.strip_tags(value).strip()
#             value = common.htmlspecialchars_decode(value)
#             value = common.unicode2string(value)
#             if value:
#                 setattr(self, key, value)
# 
#         return ret


import unittest
from lyric_engine.modules.kasi_time import KasiTime as Lyric

class KasiTimeTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://www.kasi-time.com/item-67546.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '紅蓮の弓矢')
        self.assertEqual(obj.artist, 'Linked Horizon')
        self.assertEqual(obj.lyricist, 'Revo')
        self.assertEqual(obj.composer, 'Revo')
        self.assertEqual(obj.arranger, 'Revo')
        self.assertEqual(len(obj.lyric), 783)

    def test_url_shiranai(self):
        url = 'http://www.kasi-time.com/item-43855.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '君の知らない物語')
        self.assertEqual(obj.artist, 'supercell')
        self.assertEqual(obj.lyricist, 'ryo(supercell)')
        self.assertEqual(obj.composer, 'ryo(supercell)')
        self.assertEqual(obj.arranger, 'ryo(supercell)')
        self.assertEqual(len(obj.lyric), 565)

    def test_complex_artist(self):
        url = 'http://www.kasi-time.com/item-73971.html'

# Path: lyric_engine/modules/kasi_time.py
# class KasiTime(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             logging.error('Failed to get html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(html):
#             logging.error('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_html(self, url):
#         html = common.get_url_content(url)
#         if not html:
#             logging.info('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def find_lyric(self, html):
#         prefix = "var lyrics = '"
#         suffix = "';"
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         lyric = lyric.replace("<br>", "\n")
#         lyric = lyric.replace("&nbsp;", " ")
#         lyric = common.htmlspecialchars_decode(lyric)
#         lyric = common.unicode2string(lyric)
#         lyric = common.strip_slash(lyric)
#         lyric = lyric.strip()
# 
#         # test for half to full
#         lyric = common.half2full(lyric)
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         pattern = '<h1>(.*)</h1>'
#         value = common.get_first_group_by_pattern(html, pattern).strip()
#         if value:
#             self.title = value
#         else:
#             logging.error('Failed to find title of url [%s]', url)
#             ret = False
# 
#         prefix = '<div class="person_list">'
#         suffix = '</div>'
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
# 
#         patterns = {
#             'artist': '歌手',
#             'lyricist': '作詞',
#             'composer': '作曲',
#             'arranger': '編曲',
#         }
# 
#         for key in patterns:
#             pattern = patterns[key]
# 
#             prefix = '<th>%s</th>' % (pattern)
#             suffix = '</td>'
# 
#             value = common.find_string_by_prefix_suffix(
#                 info_table, prefix, suffix, False)
#             if not value:
#                 continue
#             pos = value.find('関連リンク:')
#             if pos > 0:
#                 value = value[0:pos]
# 
#             value = value.replace('\t', '').replace('\n', '')
#             value = common.strip_tags(value).strip()
#             value = common.htmlspecialchars_decode(value)
#             value = common.unicode2string(value)
#             if value:
#                 setattr(self, key, value)
# 
#         return ret


# Path: lyric_engine/tests/test_kasi_time.py
import unittest
from lyric_engine.modules.kasi_time import KasiTime as Lyric


class KasiTimeTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://www.kasi-time.com/item-67546.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '紅蓮の弓矢')
        self.assertEqual(obj.artist, 'Linked Horizon')
        self.assertEqual(obj.lyricist, 'Revo')
        self.assertEqual(obj.composer, 'Revo')
        self.assertEqual(obj.arranger, 'Revo')
        self.assertEqual(len(obj.lyric), 783)

    def test_url_shiranai(self):
        url = 'http://www.kasi-time.com/item-43855.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, '君の知らない物語')
        self.assertEqual(obj.artist, 'supercell')
        self.assertEqual(obj.lyricist, 'ryo(supercell)')
        self.assertEqual(obj.composer, 'ryo(supercell)')
        self.assertEqual(obj.arranger, 'ryo(supercell)')
        self.assertEqual(len(obj.lyric), 565)

    def test_complex_artist(self):
        url = 'http://www.kasi-time.com/item-73971.html'

        obj = Lyric(url)