Web Clipper convert Youtube "duration" from seconds to hours, mins and secs

I have for some hours now tried to figure out how to get Schema VideoObject:Duration to display the length of a Youtube in hours, minutes and seconds - and not just in only total seconds.

This is the specific line i want to change.

"value": "{{schema:@VideoObject:duration|replace:\\\"PT\\\",\\\"\\\",\\\"S\\\",\\\"\\\"}}",

Is there an easy way to do this ?

1 Like

For the later visitors.

I found a way around this by targeting the Selector for the Duration:

{{selector:ytd-player .ytp-time-duration}}

2 Likes

Don’t know how ‘clean’ this is, but it also seems to work:

{{selector:#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > div.ytp-time-display.notranslate > span.ytp-time-wrapper > span.ytp-time-duration}}

Thanks for this!

Building on this, the code

{{selector:ytd-player .ytp-time-duration}}

returns duration in “HH:MM:SS” or “MM:SS” format depending on the length of the video, but this format is not recognized by Dataview. The below code adjusts for this by formatting the duration “HH:MM:SS” as “HHh MMm” so it is sortable in Dataview.

{{selector:ytd-player .ytp-time-duration|split:":"|slice:-3,-2|first|replace:"[]":"0"}}h {{selector:ytd-player .ytp-time-duration|split:":"|slice:-2,-1|first}}m

Examples

  • 12:34 → 0h 12m
  • 1:45:17 → 1h 45m