# Path: lyric_engine/modules/animap.py
# class AniMap(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.animap.jp/kasi/phpflash/flashphp.php?unum=" + song_id
#         data = common.get_url_content(song_url, encoding="shift_jis")
#         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")
# 
#         prefix = '<TABLE cellspacing="1"'
#         suffix = "</TABLE>"
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info_table = info_table.replace(r"\n", "")
# 
#         print(info_table)
# 
#         patterns = {
#             "title": r"曲名</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "artist": r"歌手</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "lyricist": r"作詞</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "composer": r"作曲</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#         }
# 
#         self.set_attr(patterns, info_table)
# 
#         return ret


import os
import sys
import unittest
from lyric_engine.modules.animap import AniMap as Lyric


class AniMapTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://www.animap.jp/kasi/showkasi.php?surl=B38260'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, "Don't be long")
        self.assertEqual(obj.artist, '水樹奈々')
        self.assertEqual(obj.lyricist, '矢吹俊郎')
        self.assertEqual(obj.composer, '矢吹俊郎')
        self.assertEqual(len(obj.lyric), 541)

    def test_url_02(self):
        url = 'http://www.animap.jp/kasi/showkasi.php?surl=dk130730_30'

# Path: lyric_engine/modules/animap.py
# class AniMap(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.animap.jp/kasi/phpflash/flashphp.php?unum=" + song_id
#         data = common.get_url_content(song_url, encoding="shift_jis")
#         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")
# 
#         prefix = '<TABLE cellspacing="1"'
#         suffix = "</TABLE>"
#         info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
#         info_table = info_table.replace(r"\n", "")
# 
#         print(info_table)
# 
#         patterns = {
#             "title": r"曲名</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "artist": r"歌手</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "lyricist": r"作詞</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#             "composer": r"作曲</TD>\s*<TD .+?>&nbsp;(.+?)</TD>",
#         }
# 
#         self.set_attr(patterns, info_table)
# 
#         return ret


# Path: lyric_engine/tests/test_animap.py
import os
import sys
import unittest
from lyric_engine.modules.animap import AniMap as Lyric



class AniMapTest(unittest.TestCase):
    def test_url_01(self):
        url = 'http://www.animap.jp/kasi/showkasi.php?surl=B38260'
        obj = Lyric(url)
        obj.parse()

        self.assertEqual(obj.title, "Don't be long")
        self.assertEqual(obj.artist, '水樹奈々')
        self.assertEqual(obj.lyricist, '矢吹俊郎')
        self.assertEqual(obj.composer, '矢吹俊郎')
        self.assertEqual(len(obj.lyric), 541)

    def test_url_02(self):
        url = 'http://www.animap.jp/kasi/showkasi.php?surl=dk130730_30'

        obj = Lyric(url)