Pharrell would’ve heard it before it was released; Weird Al gets copyright permission for everything he does and most acts WANT to be spoofed by him.
Dave Grohl said that he knew Nirvana made the big time when Weird Al parodied “Smells Like Teen Spirit.” They all loved it.