Fix corrupted line endings in directory recursively in text files only (Linux, Mac, or Windows)

I’ve got a directory tree full of both text and binary files, some with Unix line endings (LF/n), some with Windows line endings (CRLF/rn) and some with corrupted line endings of the form CRCR+LF/rr+n (that is, LF preceded by more than one CR). I cannot disambiguate text and binary files by extension. Nor are all of the text files in the same encoding (though they are supposed to be). Most are UTF-8, but some are UTF-16 with a BOM, and some appear to be Latin-1. Preserving the encodings is not necessary, but preserving the non-line ending contents is.

I want to leave all of the binary files and Unix-ending text files alone, and I want to turn all of the CRCR+LF files into CRLF files. I do not want to turn everything into Unix-ending files, but I will if I have to.

Finally, I suspect that there is a stray CR (Classic Mac line ending) by itself in some of the files that have been corrupted. I want to remove this if it exists.

I can do this on Mac or Windows, however my previous attempts to fix the line endings with Powershell did not work, although it did bring the number of extra CRs down to just 1. To try to keep this problem under control, I’ve been find-and-replacing 0d0d0a with 0d0a in a hex editor repeatedly when I find one of these files, but this is getting old fast.