# Path: lyric_engine/modules/j_total.py
# class JTotal(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.error('Failed to get lyric 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_lyric_html(self, url):
#         html = common.get_url_content(url, encoding="shift_jis")
#         if not html :
#             logging.error('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def find_lyric(self, html):
#         prefix = '<!--HPSTART-->'
#         suffix = '<!--HPEND-->'
# 
#         body = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         body = re.sub('     +', '', body)
#         body = body.replace('\r', '')
#         body = body.replace('\n', '')
#         body = body.replace('<br>', '\n')
#         body = common.strip_tags(body).strip()
# 
#         self.lyric = body
# 
#         return True
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         prefix = '<font size="4" color="#FFFFFF"><b>'
#         suffix = '</b></font>'
#         value = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         if value:
#             title = common.strip_tags(value).strip()
#             self.title = title
# 
#         prefix = '<font size="3" color="#FFFFFF">'
#         suffix = '</font>'
#         info = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info = re.sub('     +', '', info)
#         info = info.replace('\r', '').replace('\n', '')
# 
#         patterns = {
#             'artist': '歌：(.*?)/',
#             'lyricist': '詞：(.*?)/',
#             'composer': '曲：(.*?)<',
#         }
# 
#         self.set_attr(patterns, info)
# 
#         return ret


import unittest
from lyric_engine.modules.j_total import JTotal as Lyric

class JTotalTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://music.j-total.net/data/013su/029_sukima_switch/004.html'
        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), 1327)

    def test_url_02(self):
        url = 'http://music.j-total.net/data/026ha/048_hata_motohiro/010.html'

# Path: lyric_engine/modules/j_total.py
# class JTotal(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         html = self.get_lyric_html(url)
#         if not html:
#             logging.error('Failed to get lyric 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_lyric_html(self, url):
#         html = common.get_url_content(url, encoding="shift_jis")
#         if not html :
#             logging.error('Failed to get content of url [%s]', url)
#             return False
# 
#         return html
# 
#     def find_lyric(self, html):
#         prefix = '<!--HPSTART-->'
#         suffix = '<!--HPEND-->'
# 
#         body = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         body = re.sub('     +', '', body)
#         body = body.replace('\r', '')
#         body = body.replace('\n', '')
#         body = body.replace('<br>', '\n')
#         body = common.strip_tags(body).strip()
# 
#         self.lyric = body
# 
#         return True
# 
#     def find_song_info(self, html):
#         ret = True
# 
#         prefix = '<font size="4" color="#FFFFFF"><b>'
#         suffix = '</b></font>'
#         value = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         if value:
#             title = common.strip_tags(value).strip()
#             self.title = title
# 
#         prefix = '<font size="3" color="#FFFFFF">'
#         suffix = '</font>'
#         info = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info = re.sub('     +', '', info)
#         info = info.replace('\r', '').replace('\n', '')
# 
#         patterns = {
#             'artist': '歌：(.*?)/',
#             'lyricist': '詞：(.*?)/',
#             'composer': '曲：(.*?)<',
#         }
# 
#         self.set_attr(patterns, info)
# 
#         return ret


# Path: lyric_engine/tests/test_j_total.py
import unittest
from lyric_engine.modules.j_total import JTotal as Lyric


class JTotalTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://music.j-total.net/data/013su/029_sukima_switch/004.html'
        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), 1327)

    def test_url_02(self):
        url = 'http://music.j-total.net/data/026ha/048_hata_motohiro/010.html'

        obj = Lyric(url)