You can use EventSub to monitor for stream end. (stream.offline)
So use stream.online to timestamp the start and stream.offline to timestamp the end and then do the math
if you have VOD’s enabled you could get the duration from the Get Videos endpoint (type archive)
I’d use channel.update on eventsub to capture the title/category and any changes of title/category
So Twitch will POST data to your server and then you can forward it to your google sheet or discord or whatever