Detecting the key of a song/project

Hey y’all,

I’m trying to figure out how to detect the key a project/song with some dsp.

I assume this is not a trivial task, but maybe I’m wrong. Anyone have any general pointers as to how to do this? And are there any open source projects that do this?

Edit : Jk, after reading up more on this seems like its incredibly daunting task lol