You can use lirc to achieve what you want. When you have installed it you can use its diagnose tool
mode2 to get low level information about the signals that are received from the remote control.
Then you need a configuration file that maps the lirc pulses to the buttons of your remote control. On the internet there is a database with many config files for remote controls. If you cannot find yours you have to training your remote control by yourself with:
rpi ~$ sudo irrecord -n -d /dev/lirc0 ~/lircd.conf
Next step is to use
irw to check which button of your remote control has what action (volume up/down etc.).
Finally you can use
irexec to map a script to each button on the remote control that is executed when the button is pressed. Within this script you can send commands through a web based interface to control a TV.
For details how to do all this using a Raspberry Pi you can look at Raspberry Pi 3 lirc running/working.
If you are looking for an alternative to lirc you can use direct kernel support with gpio-ir. Look at
/boot/overlay/README. There you will find:
Info: Use GPIO pin as rc-core style infrared receiver input. The rc-core-
based gpio_ir_recv driver maps received keys directly to a
/dev/input/event* device, all decoding is done by the kernel - LIRC is
not required! The key mapping and other decoding parameters can be
configured by "ir-keytable" tool.
Params: gpio_pin Input pin number. Default is 18.
gpio_pull Desired pull-up/down state (off, down, up)
Default is "up".
rc-map-name Default rc keymap (can also be changed by
ir-keytable), defaults to "rc-rc6-mce"
Info: Use GPIO pin as bit-banged infrared transmitter output.
This is an alternative to "pwm-ir-tx". gpio-ir-tx doesn't require
a PWM so it can be used together with onboard analog audio.
Params: gpio_pin Output GPIO (default 18)
invert "1" = invert the output (make it active-low).
Default is "0" (active-high).