There is no "official" way of doing this (as I imagine it will scare people away). You have to export your watch history as JSON that contains watch date and video ID. Then you obtain API key from google and iterate over all video IDs and add up video lengths. Yes, this is inaccurate for cases when you scroll thorugh a video and not watch it completely.
For all of this there were multiple projects on github that do all of this + with plots.
For all of this there were multiple projects on github that do all of this + with plots.