# Path: lyric_engine/modules/uta_net.py
# class UtaNet(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         if not self.find_lyric(url):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(url):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def find_lyric(self, url):
#         pattern = '/[a-z]+/([0-9]+)/'
# 
#         song_id = common.get_first_group_by_pattern(url, pattern)
#         if not song_id:
#             # try old pattern
#             # http://www.uta-net.com/user/phplib/view_0.php?ID=17248
#             pattern = 'ID=([0-9]+)'
#             song_id = common.get_first_group_by_pattern(url, pattern)
# 
#         if not song_id:
#             logging.info('Failed to get id of url [%s]', url)
#             return False
# 
#         # http://www.uta-net.com/user/phplib/svg/showkasi.php?ID=17248&WIDTH=560&HEIGHT=756&FONTSIZE=15&t=1489258939
#         showkasi_pattern = 'http://www.uta-net.com/user/phplib/svg/showkasi.php?ID=%s'
#         song_url = showkasi_pattern % (song_id, )
#         data = common.get_url_content(song_url)
#         if not data:
#             logging.info('Failed to get content of url [%s]', song_url)
#             return False
# 
#         prefix = '<svg '
#         suffix = '</svg>'
#         lyric = common.find_string_by_prefix_suffix(data, prefix, suffix, True)
# 
#         if not lyric:
#             logging.error('Failed to get lyric of url [%s]', url)
#             return False
# 
#         lyric = lyric.replace('</text>', '\n')
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         # test for half to full
#         lyric = common.half2full(lyric)
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, url):
#         ret = True
#         html = common.get_url_content(url)
# 
#         patterns = {
#             'title': '<h2[^>]*>([^<]+)</h2>',
#             'artist': '歌手：<h3.*?><a href="/artist/[0-9]+/".*?>(.+?)</a></h3>',
#             'lyricist': '作詞：<h4.*?>([^<]+)</h4>',
#             'composer': '作曲：<h4.*?>([^<]+)</h4>'
#         }
# 
#         self.set_attr(patterns, html)
# 
#         return ret


import unittest
from lyric_engine.modules.uta_net import UtaNet as Lyric

class UtaNetTest(unittest.TestCase):
    def test_url_nekose(self):
        url = 'http://www.uta-net.com/song/138139/'
        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), 366)

    def test_url_rpg(self):
        url = 'http://www.uta-net.com/song/145480/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'RPG')
        self.assertEqual(obj.artist, 'SEKAI NO OWARI')
        self.assertEqual(obj.lyricist, 'Saori・Fukase')
        self.assertEqual(obj.composer, 'Fukase')
        self.assertEqual(len(obj.lyric), 574)

    def test_url_movie_format(self):
        url = 'http://www.uta-net.com/movie/162972/'

# Path: lyric_engine/modules/uta_net.py
# class UtaNet(LyricBase):
#     def parse_page(self):
#         url = self.url
# 
#         if not self.find_lyric(url):
#             logging.info('Failed to get lyric of url [%s]', url)
#             return False
# 
#         if not self.find_song_info(url):
#             logging.info('Failed to get song info of url [%s]', url)
# 
#         return True
# 
#     def find_lyric(self, url):
#         pattern = '/[a-z]+/([0-9]+)/'
# 
#         song_id = common.get_first_group_by_pattern(url, pattern)
#         if not song_id:
#             # try old pattern
#             # http://www.uta-net.com/user/phplib/view_0.php?ID=17248
#             pattern = 'ID=([0-9]+)'
#             song_id = common.get_first_group_by_pattern(url, pattern)
# 
#         if not song_id:
#             logging.info('Failed to get id of url [%s]', url)
#             return False
# 
#         # http://www.uta-net.com/user/phplib/svg/showkasi.php?ID=17248&WIDTH=560&HEIGHT=756&FONTSIZE=15&t=1489258939
#         showkasi_pattern = 'http://www.uta-net.com/user/phplib/svg/showkasi.php?ID=%s'
#         song_url = showkasi_pattern % (song_id, )
#         data = common.get_url_content(song_url)
#         if not data:
#             logging.info('Failed to get content of url [%s]', song_url)
#             return False
# 
#         prefix = '<svg '
#         suffix = '</svg>'
#         lyric = common.find_string_by_prefix_suffix(data, prefix, suffix, True)
# 
#         if not lyric:
#             logging.error('Failed to get lyric of url [%s]', url)
#             return False
# 
#         lyric = lyric.replace('</text>', '\n')
#         lyric = common.strip_tags(lyric)
#         lyric = lyric.strip()
# 
#         # test for half to full
#         lyric = common.half2full(lyric)
# 
#         self.lyric = lyric
# 
#         return True
# 
#     def find_song_info(self, url):
#         ret = True
#         html = common.get_url_content(url)
# 
#         patterns = {
#             'title': '<h2[^>]*>([^<]+)</h2>',
#             'artist': '歌手：<h3.*?><a href="/artist/[0-9]+/".*?>(.+?)</a></h3>',
#             'lyricist': '作詞：<h4.*?>([^<]+)</h4>',
#             'composer': '作曲：<h4.*?>([^<]+)</h4>'
#         }
# 
#         self.set_attr(patterns, html)
# 
#         return ret


# Path: lyric_engine/tests/test_uta_net.py
import unittest
from lyric_engine.modules.uta_net import UtaNet as Lyric


class UtaNetTest(unittest.TestCase):
    def test_url_nekose(self):
        url = 'http://www.uta-net.com/song/138139/'
        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), 366)

    def test_url_rpg(self):
        url = 'http://www.uta-net.com/song/145480/'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'RPG')
        self.assertEqual(obj.artist, 'SEKAI NO OWARI')
        self.assertEqual(obj.lyricist, 'Saori・Fukase')
        self.assertEqual(obj.composer, 'Fukase')
        self.assertEqual(len(obj.lyric), 574)

    def test_url_movie_format(self):
        url = 'http://www.uta-net.com/movie/162972/'

        obj = Lyric(url)