# Path: lyric_engine/modules/utamap.py
# class UtaMap(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 = 'surl=([^&=]+)'
# 
#         song_id = common.get_first_group_by_pattern(url, pattern)
# 
#         if not song_id:
#             logging.error('Failed to get id of url [%s]', url)
#             return False
# 
#         song_url = 'http://www.utamap.com/phpflash/flashfalsephp.php?unum=' + song_id
#         data = common.get_url_content(song_url)
#         if not data:
#             logging.error('Failed to get content of url [%s]', song_url)
#             return False
# 
#         prefix = 'test2='
#         pos = data.find(prefix)
#         if pos == -1:
#             logging.error('Failed to find lyric position of url [%s]', url)
#             return False
# 
#         lyric = data[pos + len(prefix):]
# 
#         # 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, encoding="euc_jp")
# 
#         keys = {
#             'title': 'title',
#             'artist': 'artist',
#             'lyricist': 'sakusi',
#             'composer': 'sakyoku',
#         }
# 
#         patterns = {}
#         for attr, key in keys.items():
#             patterns[attr] = '<INPUT type="hidden" name={} value="([^"]*)">'.format(key)
# 
#         self.set_attr(patterns, html)
# 
#         return ret


import unittest
from lyric_engine.modules.utamap import UtaMap as Lyric

class UtaMapTest(unittest.TestCase):
    def test_url_one_more(self):
        url = 'http://www.utamap.com/showkasi.php?surl=59709'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'One more time,One more chance')
        self.assertEqual(obj.artist, '山崎まさよし')
        self.assertEqual(obj.lyricist, '山崎将義')
        self.assertEqual(obj.composer, '山崎将義')
        self.assertEqual(len(obj.lyric), 794)

    def test_url_02(self):
        url = 'http://www.utamap.com/showkasi.php?surl=k-131226-001'

# Path: lyric_engine/modules/utamap.py
# class UtaMap(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 = 'surl=([^&=]+)'
# 
#         song_id = common.get_first_group_by_pattern(url, pattern)
# 
#         if not song_id:
#             logging.error('Failed to get id of url [%s]', url)
#             return False
# 
#         song_url = 'http://www.utamap.com/phpflash/flashfalsephp.php?unum=' + song_id
#         data = common.get_url_content(song_url)
#         if not data:
#             logging.error('Failed to get content of url [%s]', song_url)
#             return False
# 
#         prefix = 'test2='
#         pos = data.find(prefix)
#         if pos == -1:
#             logging.error('Failed to find lyric position of url [%s]', url)
#             return False
# 
#         lyric = data[pos + len(prefix):]
# 
#         # 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, encoding="euc_jp")
# 
#         keys = {
#             'title': 'title',
#             'artist': 'artist',
#             'lyricist': 'sakusi',
#             'composer': 'sakyoku',
#         }
# 
#         patterns = {}
#         for attr, key in keys.items():
#             patterns[attr] = '<INPUT type="hidden" name={} value="([^"]*)">'.format(key)
# 
#         self.set_attr(patterns, html)
# 
#         return ret


# Path: lyric_engine/tests/test_utamap.py
import unittest
from lyric_engine.modules.utamap import UtaMap as Lyric


class UtaMapTest(unittest.TestCase):
    def test_url_one_more(self):
        url = 'http://www.utamap.com/showkasi.php?surl=59709'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, 'One more time,One more chance')
        self.assertEqual(obj.artist, '山崎まさよし')
        self.assertEqual(obj.lyricist, '山崎将義')
        self.assertEqual(obj.composer, '山崎将義')
        self.assertEqual(len(obj.lyric), 794)

    def test_url_02(self):
        url = 'http://www.utamap.com/showkasi.php?surl=k-131226-001'

        obj = Lyric(url)