Пример #1
0
    def find_song_info(self, html):
        ret = True

        prefix = '<font color="#FFFFFF"><b>'
        suffix = "</b></font>"
        title = common.strip_tags(common.find_string_by_prefix_suffix(html, prefix, suffix)).strip()
        if title:
            self.title = title

        prefix = '<font size="-1" color="#FFFFFF">'
        suffix = "</font>"
        info = common.find_string_by_prefix_suffix(html, prefix, suffix)
        info = re.sub("     +", "", info)
        info = info.replace("\r", "").replace("\n", "")

        patterns = {"artist": u"歌:(.*?)/", "lyricist": u"詞:(.*?)/", "composer": u"曲:(.*?)<"}

        for key in patterns:
            pattern = patterns[key]

            value = common.get_first_group_by_pattern(info, pattern)
            if value:
                setattr(self, key, value)
            else:
                logging.info("Failed to get %s from info %s", key, info)
                return False

        return ret
Пример #2
0
    def find_song_info(self, content):
        prefix = "<div id='lyricBlock'>"
        suffix = '</table>'
        info_block = common.find_string_by_prefix_suffix(content, prefix, suffix, False)

        prefix = '<h2>'
        suffix = '</h2>'
        title = common.find_string_by_prefix_suffix(info_block, prefix, suffix, False)

        self.title = common.htmlspecialchars_decode(common.unicode2string(title))

        patterns = {
            'artist': u'>歌:(.*?)</td>',
            'lyricist': u'>作詞:(.*?)</td>',
            'composer': u'>作曲:(.*?)</td>'
        }

        for key in patterns:
            pattern = patterns[key]

            value = common.get_first_group_by_pattern(info_block, pattern)
            if value:
                value = common.strip_tags(common.htmlspecialchars_decode(value)).strip()
                setattr(self, key, value)
            else:
                logging.debug('Failed to get %s, pattern: %s' % (key, pattern, ))

        return True
Пример #3
0
    def get_lyric_json(self, content):
        line = content.replace('\r\n', '')

        prefix = 'function showLyric'
        suffix = '$.ajax'
        line = common.find_string_by_prefix_suffix(line, prefix, suffix)
        if not line:
            logging.error('Failed to find string in ')
            return False

        prefix = 'var data ='
        suffix = ';'
        line = common.find_string_by_prefix_suffix(line, prefix, suffix)
        if not line:
            logging.error('Failed to find string in ')
            return False

        post_data = self.convert_js_to_url(line)
        logging.debug('post data: %s' % (post_data, ))

        lyric_url = 'http://music-book.jp/music/MusicDetail/GetLyric'
        raw_json = common.get_url_content(lyric_url, data=post_data)
        if not raw_json:
            logging.error('Failed to get json of url [%s]' % (lyric_url, ))
            return False

        return json.loads(raw_json)
Пример #4
0
    def find_lyric(self, html):
        prefix = "<div class='lyricbox'>"
        suffix = '<!--'
        line = common.find_string_by_prefix_suffix(html, prefix, suffix, True)

        prefix = '</script>'
        suffix = '<!--'
        lyric = common.find_string_by_prefix_suffix(line, prefix, suffix, False)

        lyric = lyric.replace('<br />', '\n')
        lyric = common.unicode2string(lyric).strip()
        lyric = common.strip_tags(lyric).strip()

        self.lyric = lyric
        return True
Пример #5
0
    def find_song_info(self, content):
#         content = content.decode('utf-8', 'ignore')

        pattern = u'<meta property="og:title" content="(.*?) 歌詞 \|'
        title = common.get_first_group_by_pattern(content, pattern)
        title = common.htmlspecialchars_decode(title)
        self.title = title

        pattern = u'<meta property="og:description" content="(.*?)が歌う'
        artist = common.get_first_group_by_pattern(content, pattern)
        artist = common.htmlspecialchars_decode(artist)
        self.artist = artist

        prefixes = {
            'lyricist': u'作詞</dt>',
            'composer': u'作曲</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
Пример #6
0
    def parse_song_info(self, url, html):
        ret = True

        pattern = '<h1.*?>(.*)</h1>'
        title = common.get_first_group_by_pattern(html, pattern)
        if title:
            title = common.htmlspecialchars_decode(common.strip_tags(title)).strip()
            self.title = title
        else:
            logging.warning('Failed to parse title of url [%s]', url)
            ret = False

        patterns = {
            'artist': '">([^<]*)</a></span></td></tr>',
            'lyricist': 'td>([^<]*)<br></td></tr><tr>',
            'composer': 'td>([^<]*)<br></td></tr></table>',
        }

        prefix = '<table class="lyric-data">'
        suffix = '</table>'
        info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)
        info_table = info_table.replace('\n', '')

        for key in patterns:
            pattern = patterns[key]

            value = common.get_first_group_by_pattern(info_table, pattern)
            if value:
                value = common.htmlspecialchars_decode(common.strip_tags(value)).strip()
                setattr(self, key, value)
            else:
                logging.warning('Failed to get %s', key)
                ret = False

        return ret
Пример #7
0
    def parse_composer(self, html):
        prefix = '<b>&#20316;&#26354;&#65306;</b>'
        suffix = '\t'

        raw_string = common.find_string_by_prefix_suffix(html, prefix, suffix, False)
        if not raw_string:
            logging.debug('Failed to find composer')
            return False

        self.composer = common.htmlspecialchars_decode(common.unicode2string(raw_string)).strip()
Пример #8
0
    def find_lyric(self, content):
        prefix = "<p id='lyricBody'>"
        suffix = "</p>"
        lyric = common.find_string_by_prefix_suffix(content, prefix, suffix, False)

        lyric = lyric.replace('<br />', '')
        lyric = common.htmlspecialchars_decode(common.unicode2string(lyric))
        lyric = lyric.strip();

        self.lyric = lyric

        return True
Пример #9
0
    def parse_lyricist(self, html):
        prefix = '<b>&#20316;&#35422;&#65306;</b>'
        suffix = '\t'

        logging.debug('find me LYRICIST')

        raw_string = common.find_string_by_prefix_suffix(html, prefix, suffix, False)
        if not raw_string:
            logging.debug('Failed to find lyricist')
            return False

        self.lyricist = common.htmlspecialchars_decode(common.unicode2string(raw_string)).strip()
Пример #10
0
    def find_song_info(self, url):
        ret = True
        html = common.get_url_content(url)

        encoding = 'utf-8'
        html = html.decode(encoding, 'ignore')

        pattern = '<h1>(.*)</h1>'
        value = common.get_first_group_by_pattern(html, pattern).strip()
        if value:
            self.title = value
        else:
            logging.error('Failed to find title of url [%s]', url)
            ret = False

        prefix = '<div class="person_list">'
        suffix = '</div>'
        info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)

        patterns = {
            'artist': u'歌手',
            'lyricist': u'作詞者',
            'composer': u'作曲者',
            'arranger': u'編曲者',
        }

        for key in patterns:
            pattern = patterns[key]

            prefix = u'<th>%s</th>' % (pattern)
            suffix = '</td>'

            value = common.find_string_by_prefix_suffix(info_table, prefix, suffix, False)
            if not value:
                continue
            value = common.strip_tags(value).strip()
            if value:
                setattr(self, key, value)

        return ret
Пример #11
0
    def find_lyric(self, html):
        prefix = "<!--HPSTART-->"
        suffix = "<!--HPEND-->"

        body = common.find_string_by_prefix_suffix(html, prefix, suffix)
        body = re.sub("     +", "", body)
        body = body.replace("\r", "")
        body = body.replace("\n", "")
        body = body.replace("<br>", "\n")
        body = common.strip_tags(body).strip()

        self.lyric = body

        return True
Пример #12
0
    def find_lyric(self, content):
#         content = content.decode('utf-8', 'ignore')

        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
Пример #13
0
    def parse_lyric(self, html):
        prefix = '<PRE>'
        suffix = '</PRE>'
        raw_lyric = common.find_string_by_prefix_suffix(html, prefix, suffix, False)
        if not raw_lyric:
            logging.info('Failed to parse lyric from html [%s]', html)
            return False

        raw_lyric = raw_lyric.strip()

        pos = raw_lyric.find('\n\n')
        if pos < 0:
            logging.info('Failed to find two consecutive newlines')
            return False

        self.title = raw_lyric[0:pos]

        raw_lyric = raw_lyric[pos+2:]

        pos = raw_lyric.find('\n\n')
        if pos < 0:
            logging.info('Failed to find two consecutive newlines')
            return False

        info = raw_lyric[0:pos]
        self.lyric = raw_lyric[pos+2:]

        patterns = {
            'artist': u'歌:(.+)',
            'lyricist': u'作詞:(.+?)/',
            'composer': u'作曲:(.+?)/',
            'arranger': u'編曲:(.+?)/',
        }

        for key in patterns:
            pattern  = patterns[key]

            value = common.get_first_group_by_pattern(info, pattern)

            if not value:
                logging.info('Failed to get %s of url [%s]', key, url)
            else:
                value = common.htmlspecialchars_decode(value).strip()
                setattr(self, key, value)

        return True
Пример #14
0
    def parse_lyric(self, html):
        html = html.replace('\r\n', '')
        prefix = "<div class='body'><p>"
        suffix = '</p>'
        lyric = common.find_string_by_prefix_suffix(html, prefix, suffix, False)
        if not lyric:
            logging.info('Failed to parse lyric from html [%s]', html)
            return False

        lyric = lyric.replace('<br />', '\n')
        lyric = lyric.strip()
        lyric = common.unicode2string(lyric)
        lyric = common.half2full(lyric)

        self.lyric = lyric

        return True
Пример #15
0
    def find_song_info(self, url):
        ret = True
        html = common.get_url_content(url)

        encoding = 'euc_jp'
        html = html.decode(encoding, 'ignore')

        prefix = '<TABLE cellspacing="1"'
        suffix = '</TABLE>'
        info_table = common.find_string_by_prefix_suffix(html, prefix, suffix)

        def get_info_value_by_key(html, key):
            valuePrefix = '#ffffff>&nbsp;'
            valueSuffix = '</TD>'
            lenPrefix = len(valuePrefix)
            posKey = html.find(key)
            logging.debug('key position: %d' % (posKey))

            posStart = html.find(valuePrefix, posKey) + lenPrefix
            posEnd = html.find(valueSuffix, posStart)
            logging.debug('position [%d:%d]' % (posStart, posEnd))

            value = html[posStart:posEnd]
            return value

        patterns = {
            'title': u'曲名</TD>',
            'artist': u'歌手</TD>',
            'lyricist': u'作詞</TD>',
            'composer': u'作曲</TD>',
        }

        for key in patterns:
            pattern = patterns[key]
            value = get_info_value_by_key(info_table, pattern)

            if not value:
                logging.info('Failed to get %s of url [%s]', key, url)
                ret = False
            else:
                value = common.htmlspecialchars_decode(value).strip()
                setattr(self, key, value)

        return ret
Пример #16
0
    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

        showkasi_pattern = 'http://www.uta-net.com/user/phplib/swf/showkasi.php?ID=%s&WIDTH=530&HEIGHT=810'
        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 = '<\0\0'
        suffix = '\0'
        lyric = common.find_string_by_prefix_suffix(data, prefix, suffix, False)

        if not lyric:
            logging.error('Failed to get lyric of url [%s]', url)
            return False

        lyric = unicode(lyric, 'utf8')
        lyric = lyric.strip()

        # test for half to full
        lyric = common.half2full(lyric)

        self.lyric = lyric

        return True
Пример #17
0
    def find_song_info(self, content):
        pattern = 'og:description" content="(.*)"'
        og_desc = common.get_first_group_by_pattern(content, pattern)
        if og_desc:
            pattern = u'(.*?)「(.*?)」'
            matches = common.get_matches_by_pattern(og_desc, pattern)
            if matches:
                artist = matches.group(1)
                artist = artist.replace(u'歌詞サーチ ', '')
                self.artist = artist
                self.title  = matches.group(2)
            else:
                logging.debug('og desc: %s' % (og_desc))

        prefix = '="lyrics_info_text"'
        suffix = '</div>'
        info_text = common.find_string_by_prefix_suffix(content, prefix, suffix, False)
        if not info_text:
            logging.info('Failed to find lyrics info text')
        one_line = info_text.replace('\n', '')

        patterns = {
            'lyricist': u'>作詞</p><p class="info_detail">(.*?)</p>',
            'composer': u'>作曲</p><p class="info_detail">(.*?)</p>',
        }

        for key in patterns:
            pattern = patterns[key]

            value = common.get_first_group_by_pattern(one_line, pattern)
            if value:
                value = common.strip_tags(common.htmlspecialchars_decode(value)).strip()
                setattr(self, key, value)
            else:
                logging.debug('Failed to get %s, pattern: %s' % (key, pattern, ))

        return True