# Buggy code
def is_lyrics(text, artist=None):
    """Determine whether the text seems to be valid lyrics."""
    if not text:
        return
    badTriggersOcc = []
    nbLines = text.count("\n")
    if nbLines <= 1:
        log.debug("Ignoring too short lyrics '{0}'".format(text.decode("utf8")))
        return 0
    elif nbLines < 5:
        badTriggersOcc.append("too_short")
    else:
        # Lyrics look legit, remove credits to avoid being penalized further
        # down
        text = remove_credits(text)

    badTriggers = ["lyrics", "copyright", "property", "links"]
    if artist:
        badTriggersOcc += [artist]

    for item in badTriggers:
        badTriggersOcc += [item] * len(re.findall(r"\W%s\W" % item, text, re.I))

    if badTriggersOcc:
        log.debug("Bad triggers detected: {0}".format(badTriggersOcc))

    return len(badTriggersOcc) < 2


# Traceback (UnicodeEncodeError)
fetching Elephanz Stereo
Traceback (most recent call last):
File "/Users/flap/bin/beet", line 20, in <module>
beets.ui.main()
File "/Users/flap/Dev/beets/beets/ui/__init__.py", line 937, in main
_raw_main(args)
File "/Users/flap/Dev/beets/beets/ui/__init__.py", line 927, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "/Users/flap/Dev/beets/beets/ui/commands.py", line 872, in import_func
import_files(lib, paths, query)
File "/Users/flap/Dev/beets/beets/ui/commands.py", line 844, in import_files
session.run()
File "/Users/flap/Dev/beets/beets/importer.py", line 300, in run
pl.run_parallel(QUEUE_SIZE)
File "/Users/flap/Dev/beets/beets/util/pipeline.py", line 299, in run
out = self.coro.send(msg)
File "/Users/flap/Dev/beets/beets/util/pipeline.py", line 181, in coro
func(*(args + (task,)))
File "/Users/flap/Dev/beets/beets/importer.py", line 1263, in plugin_stage
func(session, task)
File "/Users/flap/Dev/beets/beetsplug/lyrics.py", line 457, in imported
False, False)
File "/Users/flap/Dev/beets/beetsplug/lyrics.py", line 473, in fetch_item_lyrics
lyrics = [self.get_lyrics(artist, title) for title in titles]
File "/Users/flap/Dev/beets/beetsplug/lyrics.py", line 503, in get_lyrics
lyrics = backend(artist, title)
File "/Users/flap/Dev/beets/beetsplug/lyrics.py", line 405, in fetch_google
if is_lyrics(lyrics, artist):
File "/Users/flap/Dev/beets/beetsplug/lyrics.py", line 302, in is_lyrics
text.decode('utf8')))
File "/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 61: ordinal not in range(128)

# Fixed code
def is_lyrics(text, artist=None):
    """Determine whether the text seems to be valid lyrics."""
    if not text:
        return
    badTriggersOcc = []
    nbLines = text.count("\n")
    if nbLines <= 1:
        log.debug("Ignoring too short lyrics '{0}'".format(text))
        return 0
    elif nbLines < 5:
        badTriggersOcc.append("too_short")
    else:
        # Lyrics look legit, remove credits to avoid being penalized further
        # down
        text = remove_credits(text)

    badTriggers = ["lyrics", "copyright", "property", "links"]
    if artist:
        badTriggersOcc += [artist]

    for item in badTriggers:
        badTriggersOcc += [item] * len(re.findall(r"\W%s\W" % item, text, re.I))

    if badTriggersOcc:
        log.debug("Bad triggers detected: {0}".format(badTriggersOcc))

    return len(badTriggersOcc) < 2