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.
{
"schemaVersion": "0.1.0",
"name": "YouTube",
"behavior": "create",
"noteContentFormat": "## About\n\ntype:: #type/video/youtube/new\n\n![{{title}}]({{meta:property:og:url}})\n\n## Description\n\n{{schema:@VideoObject:description}}\n\n## Notes\n\nYT=",
"properties": [
{
"name": "created",
"value": "{{time|date:\\\"YYYY-MM-DDTHH:mm:ssZ\\\"}}",
"type": "datetime"
},
{
"name": "reviewed",
"value": "",
"type": "datetime"
},
{
"name": "url",
"value": "{{meta:property:og:url}}",
"type": "text"
This file has been truncated. show original
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