def case_or_page_barcode_from_s3_key(input):
    """
        Transform s3 keys to case or page barcodes:
            32044142600386_redacted/alto/32044142600386_redacted_ALTO_00009_0.xml  ->  32044142600386_00009_0
            32044142600386_redacted/casemets/32044142600386_redacted_CASEMETS_0001.xml  -> 32044142600386_0001
    """
    if ('CASEMETS' in input or 'ALTO' in input) and input.endswith("xml"):
        return input.split('/')[-1].split('.')[0]\
            .replace('unredacted', 'redacted')\
            .replace('_redacted_ALTO', '')\
            .replace('_redacted_CASEMETS', '')
    raise Exception("Not an ALTO or CASEMETS s3_key")