<commit_before>from prismriver.plugin.common import Plugin
from prismriver.struct import Song


class LetrasPlugin(Plugin):
    def __init__(self):
        super(LetrasPlugin, self).__init__('letras', 'Letras')

    def search_song(self, artist, title):
        link = 'http://letras.mus.br/winamp.php?t={}{}{}'.format(
            self.prepare_url_parameter(artist),
            self.prepare_url_parameter(' - '),
            self.prepare_url_parameter(title)
        )

        page = self.download_webpage(link)
        if page:
            soup = self.prepare_soup(page)

            header = soup.find('div', {'id': 'cabecalho'})
            song_title = header.h1.a.text
            song_artist = header.h2.a.text

            lyric_block = soup.find('div', {'id': 'letra'})

            lyric = ''
            for elem in lyric_block.findAll('p', recursive=False):
                lyric += (self.parse_verse_block(elem) + '\n\n')

            return Song(song_artist, song_title, self.sanitize_lyrics([lyric]))
<commit_msg>[letras] Handle empty result page<commit_after>from prismriver.plugin.common import Plugin
from prismriver.struct import Song


class LetrasPlugin(Plugin):
    def __init__(self):
        super(LetrasPlugin, self).__init__('letras', 'Letras')

    def search_song(self, artist, title):
        link = 'http://letras.mus.br/winamp.php?t={}{}{}'.format(
            self.prepare_url_parameter(artist),
            self.prepare_url_parameter(' - '),
            self.prepare_url_parameter(title)
        )

        page = self.download_webpage(link)
        if page:
            soup = self.prepare_soup(page)

            header = soup.find('div', {'id': 'cabecalho'})

            # if header wasn't found - it's an empty page
            if header:
                song_title = header.h1.a.text
                song_artist = header.h2.a.text

                lyric_block = soup.find('div', {'id': 'letra'})

                lyric = ''
                for elem in lyric_block.findAll('p', recursive=False):
                    lyric += (self.parse_verse_block(elem) + '\n\n')

                return Song(song_artist, song_title, self.sanitize_lyrics([lyric]))

{'fraction_non_alphanumeric': 0.13105022831050228, 'fraction_numerical': 0.0018264840182648401, 'mean_word_length': 2.236336779911374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6616787', 'n_tokens_mistral': 702, 'n_tokens_neox': 665, 'n_words': 124}