def extract_species_name(value):
    """
    This function extracts the most common species name from a text
    string such as:

    Genus names applied to this BIN: Cerconota (59) Species names \
    applied to this BIN: Cerconota Janzen217 (14), Cerconota Janzen233 \
    (4), Cerconota Janzen82 (41)

    or

    Species names applied to this BIN: Melanchra adjuncta (98)

    :param value: string to extract from
    :return: most common species name
    """
    items = value.split("Species names applied to this BIN: ")[1]
    sp_names = items.split("), ")
    max_count = 0
    sp_name = ""
    for n in sp_names:
        # Extract species names, making sure to cath cases where, e.g.
        # n = 'Squalus megalops (vbs) (2)'
        # as well as
        # n = 'Squalus megalops (34)'
        species = "(".join(n.split("(")[0:-1]).rstrip()
        count = n.split("(")[-1]
        try:
            count = int(count.rstrip(")"))
        except ValueError:
            continue
        if count >= max_count:
            sp_name = species
            max_count = count
    return sp_name