From cf1f1d89df1968dbdefad7f366e0e6942d3e945f Mon Sep 17 00:00:00 2001 From: Ivan Paramonau Date: Thu, 8 Oct 2026 09:42:34 -0400 Subject: [PATCH] ld: better video object finder in ld source --- lib/utils.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 6a80e9ade..97f71b1cd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -610,17 +610,23 @@ export function findMainLdObjectWithVideo(ld) { let json = ld.videoobject || ld.mediaobject; - /* - || (ld.newsarticle && (ld.newsarticle.video || ld.newsarticle.videoobject)) - || (ld.tvepisode && (ld.tvepisode.video || ld.tvepisode.videoobject)) - || (ld.movie && (ld.movie.video || ld.movie.videoobject)) - || (ld.tvclip && (ld.tvclip.video || ld.tvclip.videoobject)); - */ - if (!json) { // try to find video attached to main object - var mainObjWithVideo = ld && Object.values(ld).find((obj) => obj.video || obj.videoObject); - if (mainObjWithVideo) { - json = mainObjWithVideo.video || mainObjWithVideo.videoObject; - } + if (!json) { + // Let's find videos in objects with "@type" arrays: ["CreativeWork", "VideoObject"] + // or other embeddable entities + // or entiites attached to main object + json = Object.values(ld).find((obj) => { + const type = obj['@type']; + return Array.isArray(type) + && (type.indexOf('VideoObject') > -1 || type.indexOf('videoobject') > -1) + || obj.embedUrl + || obj.video || obj.videoObject; + }); + } + + // ex.: https://nypost.com/2025/12/16/us-news/obamas-planned-to-meet-with-rob-reiner-and-wife-the-night-couple-was-killed/ + // https://nypost.com/video/artist-jailed-for-letting-people-touch-her-privates-in-public/ + if (json && (json.video || json.videoObject)) { + json = json.video || json.videoObject; } if (json && Array.isArray(json) && json.length === 1) {