How to calculate the Public key P2SH from hexadecimal script?
This is specified in BIP 13: https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki

You compute the Base58Check encoding of the P2SH version byte (5 for mainnet, 196 for testnet) followed by the 20-byte Hash160 of the script.

The code you're quoting is for P2PKH addresses, not P2SH.