# Path: lyric_engine/modules/utaten.py
# class UtaTen(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         content = common.get_url_content(url)
# 
#         if not content:
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         logging.debug('web content length [%d]', len(content))
#         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 get_lyric_content(self, url):
#         content = common.get_url_content(url)
# 
#         return content
# 
#     def find_lyric(self, content):
#         prefix = '<div class="lyricBody">'
#         suffix = '</div>'
# 
#         lyric = common.find_string_by_prefix_suffix(content, prefix, suffix)
# 
#         pattern = '<span class="rt">(.*?)</span>'
#         lyric = re.sub(pattern, r'(\1)', lyric)
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, content):
#         pattern = '<meta property="og:title" content="(.*?)　歌詞【'
#         title = common.get_first_group_by_pattern(content, pattern)
#         title = common.htmlspecialchars_decode(title)
#         self.title = title
# 
#         pattern = '<meta property="og:description" content="(.*?)が歌う'
#         artist = common.get_first_group_by_pattern(content, pattern)
#         artist = common.htmlspecialchars_decode(artist)
#         self.artist = artist
# 
#         prefixes = {
#             'lyricist': '作詞</dt>',
#             'composer': '作曲</dt>',
#         }
#         suffix = '</dd>'
# 
#         for key in prefixes:
#             prefix = prefixes[key]
#             value = common.find_string_by_prefix_suffix(
#                 content, prefix, suffix, False)
#             if value:
#                 value = common.strip_tags(value).strip()
#                 value = common.htmlspecialchars_decode(value)
#                 setattr(self, key, value)
# 
#         return True


import unittest
from lyric_engine.modules.utaten import UtaTen as Lyric

class UtaTenTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://utaten.com/lyric/BUMP+OF+CHICKEN/beautiful+glider/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'beautiful glider')
        self.assertEqual(obj.artist, 'BUMP OF CHICKEN')
        self.assertEqual(obj.lyricist, '藤原基央')
        self.assertEqual(obj.composer, '藤原基央')
        self.assertEqual(len(obj.lyric), 959)

    def test_url_shiranai(self):
        url = 'http://utaten.com/lyric/AAA/Charge+%26++Go%21/'

# Path: lyric_engine/modules/utaten.py
# class UtaTen(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         content = common.get_url_content(url)
# 
#         if not content:
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         logging.debug('web content length [%d]', len(content))
#         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 get_lyric_content(self, url):
#         content = common.get_url_content(url)
# 
#         return content
# 
#     def find_lyric(self, content):
#         prefix = '<div class="lyricBody">'
#         suffix = '</div>'
# 
#         lyric = common.find_string_by_prefix_suffix(content, prefix, suffix)
# 
#         pattern = '<span class="rt">(.*?)</span>'
#         lyric = re.sub(pattern, r'(\1)', lyric)
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, content):
#         pattern = '<meta property="og:title" content="(.*?)　歌詞【'
#         title = common.get_first_group_by_pattern(content, pattern)
#         title = common.htmlspecialchars_decode(title)
#         self.title = title
# 
#         pattern = '<meta property="og:description" content="(.*?)が歌う'
#         artist = common.get_first_group_by_pattern(content, pattern)
#         artist = common.htmlspecialchars_decode(artist)
#         self.artist = artist
# 
#         prefixes = {
#             'lyricist': '作詞</dt>',
#             'composer': '作曲</dt>',
#         }
#         suffix = '</dd>'
# 
#         for key in prefixes:
#             prefix = prefixes[key]
#             value = common.find_string_by_prefix_suffix(
#                 content, prefix, suffix, False)
#             if value:
#                 value = common.strip_tags(value).strip()
#                 value = common.htmlspecialchars_decode(value)
#                 setattr(self, key, value)
# 
#         return True


# Path: lyric_engine/tests/test_utaten.py
import unittest
from lyric_engine.modules.utaten import UtaTen as Lyric


class UtaTenTest(unittest.TestCase):
    def test_url_guren(self):
        url = 'http://utaten.com/lyric/BUMP+OF+CHICKEN/beautiful+glider/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'beautiful glider')
        self.assertEqual(obj.artist, 'BUMP OF CHICKEN')
        self.assertEqual(obj.lyricist, '藤原基央')
        self.assertEqual(obj.composer, '藤原基央')
        self.assertEqual(len(obj.lyric), 959)

    def test_url_shiranai(self):
        url = 'http://utaten.com/lyric/AAA/Charge+%26++Go%21/'

        obj = Lyric(url)