# Path: lyric_engine/modules/kashinavi.py
# class KashiNavi(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             logging.info('Failed to get html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(url, html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_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="shift_jis")
# 
#         return html
# 
#     def find_lyric(self, url, html):
#         prefix = '<p oncopy="return false;" unselectable="on;">'
#         suffix = '</p>'
# 
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         lyric = lyric.replace('<br>', '\n')
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, url, html):
#         ret = True
# 
#         prefix = '<table border=0 cellpadding=0 cellspacing=5>'
#         suffix = '</td></table>'
#         infoString = common.get_string_by_start_end_string(
#             prefix, suffix, html)
# 
#         self.title = common.strip_tags(
#             common.get_string_by_start_end_string('<td>', '</td>', infoString)
#         )
# 
#         self.artist = common.strip_tags(
#             common.get_string_by_start_end_string(
#                 '<td><h3><a href=', '</a></h3></td>', infoString)
#         )
# 
#         prefix = '<table border=0 cellpadding=0 cellspacing=0>'
#         suffix = '</td></table>'
#         lyricAndMusic = common.get_string_by_start_end_string(
#             prefix, suffix, infoString)
# 
#         pattern = '作詞　：　(.*)<br>'
#         self.lyricist = common.get_first_group_by_pattern(
#             lyricAndMusic, pattern)
# 
#         pattern = '作曲　：　(.*)</td>'
#         self.composer = common.get_first_group_by_pattern(
#             lyricAndMusic, pattern)
# 
#         return ret


import unittest
from lyric_engine.modules.kashinavi import KashiNavi as Lyric

class KashiNaviTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://kashinavi.com/song_view.html?65545'
        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), 358)

    def test_url_shiranai(self):
        url = 'http://kashinavi.com/song_view.html?77597'

# Path: lyric_engine/modules/kashinavi.py
# class KashiNavi(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_html(url)
#         if not html:
#             logging.info('Failed to get html of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(url, html):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_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="shift_jis")
# 
#         return html
# 
#     def find_lyric(self, url, html):
#         prefix = '<p oncopy="return false;" unselectable="on;">'
#         suffix = '</p>'
# 
#         lyric = common.find_string_by_prefix_suffix(
#             html, prefix, suffix, False)
#         lyric = lyric.replace('<br>', '\n')
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, url, html):
#         ret = True
# 
#         prefix = '<table border=0 cellpadding=0 cellspacing=5>'
#         suffix = '</td></table>'
#         infoString = common.get_string_by_start_end_string(
#             prefix, suffix, html)
# 
#         self.title = common.strip_tags(
#             common.get_string_by_start_end_string('<td>', '</td>', infoString)
#         )
# 
#         self.artist = common.strip_tags(
#             common.get_string_by_start_end_string(
#                 '<td><h3><a href=', '</a></h3></td>', infoString)
#         )
# 
#         prefix = '<table border=0 cellpadding=0 cellspacing=0>'
#         suffix = '</td></table>'
#         lyricAndMusic = common.get_string_by_start_end_string(
#             prefix, suffix, infoString)
# 
#         pattern = '作詞　：　(.*)<br>'
#         self.lyricist = common.get_first_group_by_pattern(
#             lyricAndMusic, pattern)
# 
#         pattern = '作曲　：　(.*)</td>'
#         self.composer = common.get_first_group_by_pattern(
#             lyricAndMusic, pattern)
# 
#         return ret


# Path: lyric_engine/tests/test_kashinavi.py
import unittest
from lyric_engine.modules.kashinavi import KashiNavi as Lyric


class KashiNaviTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://kashinavi.com/song_view.html?65545'
        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), 358)

    def test_url_shiranai(self):
        url = 'http://kashinavi.com/song_view.html?77597'

        obj = Lyric(url)