There is a library youtube-dl which is a command-line program to download videos from YouTube and other video sites. You can install it and use it to get the details about the youtube video.
If you are using Ubuntu, install the library using the following command:
$ sudo apt install youtube-dl
Now run youtube-dl command to get the duration.
$ youtube-dl --get-duration https://www.youtube.com/watch?v=xu9QRLERepI
The above command with show "12:28"