def releases_key(release, countries, original_year):
    """Used as a key to sort releases by date then preferred country
    """
    date = release.get('date')
    if date and original_year:
        year = date.get('year', 9999)
        month = date.get('month', 99)
        day = date.get('day', 99)
    else:
        year = 9999
        month = 99
        day = 99
    country_key = 99
    if release.get('country'):
        for i, country in enumerate(countries):
            if country.match(release['country']):
                country_key = i
                break
    return year, month, day, country_key
