# Buggy code
def is_page_candidate(self, url_link, url_title, title, artist):
    """Return True if the URL title makes it a good candidate to be a
    page that contains lyrics of title by artist.
    """
    title = self.slugify(title.lower())
    artist = self.slugify(artist.lower())
    sitename = re.search("//([^/]+)/.*", self.slugify(url_link.lower())).group(1)
    url_title = self.slugify(url_title.lower())
    # Check if URL title contains song title (exact match)
    if url_title.find(title) != -1:
        return True
    # or try extracting song title from URL title and check if
    # they are close enough
    tokens = (
        [by + "_" + artist for by in self.BY_TRANS]
        + [artist, sitename, sitename.replace("www.", "")]
        + self.LYRICS_TRANS
    )
    song_title = re.sub("(%s)" % "|".join(tokens), "", url_title)
    song_title = song_title.strip("_|")
    typo_ratio = 0.9
    ratio = difflib.SequenceMatcher(None, song_title, title).ratio()
    return ratio >= typo_ratio


# Traceback (sre_constants.error)
Traceback (most recent call last):
File "/usr/local/bin/beet", line 9, in <module>
load_entry_point('beets==1.3.14', 'console_scripts', 'beet')()
File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1140, in main
_raw_main(args)
File "/usr/local/lib/python2.7/dist-packages/beets/ui/__init__.py", line 1130, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 875, in import_func
import_files(lib, paths, query)
File "/usr/local/lib/python2.7/dist-packages/beets/ui/commands.py", line 852, in import_files
session.run()
File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 316, in run
pl.run_parallel(QUEUE_SIZE)
File "/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py", line 301, in run
out = self.coro.send(msg)
File "/usr/local/lib/python2.7/dist-packages/beets/util/pipeline.py", line 183, in coro
func(*(args + (task,)))
File "/usr/local/lib/python2.7/dist-packages/beets/importer.py", line 1353, in plugin_stage
func(session, task)
File "/usr/local/lib/python2.7/dist-packages/beets/plugins.py", line 123, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/beetsplug/lyrics.py", line 509, in imported
False, self.config['force'])
File "/usr/local/lib/python2.7/dist-packages/beetsplug/lyrics.py", line 521, in fetch_item_lyrics
lyrics = [self.get_lyrics(artist, title) for title in titles]
File "/usr/local/lib/python2.7/dist-packages/beetsplug/lyrics.py", line 548, in get_lyrics
lyrics = backend.fetch(artist, title)
File "/usr/local/lib/python2.7/dist-packages/beetsplug/lyrics.py", line 433, in fetch
title, artist):
File "/usr/local/lib/python2.7/dist-packages/beetsplug/lyrics.py", line 409, in is_page_candidate
songTitle = re.sub(u'(%s)' % u'|'.join(tokens), u'', urlTitle)
File "/usr/lib/python2.7/re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/lib/python2.7/re.py", line 244, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis

# Fixed code
def is_page_candidate(self, url_link, url_title, title, artist):
    """Return True if the URL title makes it a good candidate to be a
    page that contains lyrics of title by artist.
    """
    title = self.slugify(title.lower())
    artist = self.slugify(artist.lower())
    sitename = re.search("//([^/]+)/.*", self.slugify(url_link.lower())).group(1)
    url_title = self.slugify(url_title.lower())

    # Check if URL title contains song title (exact match)
    if url_title.find(title) != -1:
        return True

    # or try extracting song title from URL title and check if
    # they are close enough
    tokens = (
        [by + "_" + artist for by in self.BY_TRANS]
        + [artist, sitename, sitename.replace("www.", "")]
        + self.LYRICS_TRANS
    )
    tokens = [re.escape(t) for t in tokens]
    song_title = re.sub("(%s)" % "|".join(tokens), "", url_title)

    song_title = song_title.strip("_|")
    typo_ratio = 0.9
    ratio = difflib.SequenceMatcher(None, song_title, title).ratio()
    return ratio >= typo_ratio