# Path: lyric_engine/modules/j_lyric.py
# class JLyric(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         content = common.get_url_content(url)
#         if not content:
#             logging.info('Failed to get content of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(content):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(content):
#             logging.info('Failed to get song info of url [%s]', url)
#             return False
# 
#         return True
# 
#     def find_lyric(self, content):
#         prefix = '<p id="Lyric">'
#         suffix = "</p>"
#         lyric = common.find_string_by_prefix_suffix(
#             content, prefix, suffix, False)
# 
#         if not lyric:
#             return False
# 
#         lyric = lyric.replace('<br>', '\n')
#         lyric = common.htmlspecialchars_decode(common.unicode2string(lyric))
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, content):
#         prefix = '<div class="cap">'
#         suffix = '<p id="Lyric">'
#         info_block = common.find_string_by_prefix_suffix(
#             content, prefix, suffix, False)
# 
#         patterns = {
#             'title': '<h2>(.*?)歌詞</h2>',
#             'artist': '>歌：(.*?)</p>',
#             'lyricist': '>作詞：(.*?)</p>',
#             'composer': '>作曲：(.*?)</p>'
#         }
# 
#         self.set_attr(patterns, info_block)
# 
#         return True


import unittest
from lyric_engine.modules.j_lyric import JLyric as Lyric

class JLyricTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://j-lyric.net/artist/a002723/l001e83.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'tune the rainbow')
        self.assertEqual(obj.artist, '坂本真綾')
        self.assertEqual(obj.lyricist, '岩里祐穂')
        self.assertEqual(obj.composer, '菅野よう子')
        self.assertEqual(len(obj.lyric), 447)

    def test_url_02(self):
        url = 'http://j-lyric.net/artist/a000673/l000bea.html'

# Path: lyric_engine/modules/j_lyric.py
# class JLyric(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         content = common.get_url_content(url)
#         if not content:
#             logging.info('Failed to get content of url [%s]', url)
#             return False
# 
#         if not self.find_lyric(content):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(content):
#             logging.info('Failed to get song info of url [%s]', url)
#             return False
# 
#         return True
# 
#     def find_lyric(self, content):
#         prefix = '<p id="Lyric">'
#         suffix = "</p>"
#         lyric = common.find_string_by_prefix_suffix(
#             content, prefix, suffix, False)
# 
#         if not lyric:
#             return False
# 
#         lyric = lyric.replace('<br>', '\n')
#         lyric = common.htmlspecialchars_decode(common.unicode2string(lyric))
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, content):
#         prefix = '<div class="cap">'
#         suffix = '<p id="Lyric">'
#         info_block = common.find_string_by_prefix_suffix(
#             content, prefix, suffix, False)
# 
#         patterns = {
#             'title': '<h2>(.*?)歌詞</h2>',
#             'artist': '>歌：(.*?)</p>',
#             'lyricist': '>作詞：(.*?)</p>',
#             'composer': '>作曲：(.*?)</p>'
#         }
# 
#         self.set_attr(patterns, info_block)
# 
#         return True


# Path: lyric_engine/tests/test_j_lyric.py
import unittest
from lyric_engine.modules.j_lyric import JLyric as Lyric


class JLyricTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://j-lyric.net/artist/a002723/l001e83.html'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'tune the rainbow')
        self.assertEqual(obj.artist, '坂本真綾')
        self.assertEqual(obj.lyricist, '岩里祐穂')
        self.assertEqual(obj.composer, '菅野よう子')
        self.assertEqual(len(obj.lyric), 447)

    def test_url_02(self):
        url = 'http://j-lyric.net/artist/a000673/l000bea.html'

        obj = Lyric(url)