Skip to content

Commit

Permalink
Merge pull request #167 from DominikPieper/fix/youtube-microdata-parsing
Browse files Browse the repository at this point in the history
fix: YouTube Schema.org parsing
  • Loading branch information
adamluckdev authored Sep 5, 2024
2 parents 3504fca + f159bde commit 9cbb9de
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/parsers/YoutubeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,20 @@ class YoutubeParser extends Parser {
});

const videoHTML = new DOMParser().parseFromString(response, 'text/html');
const videoSchemaElement = videoHTML.querySelector('[itemtype="http://schema.org/VideoObject"]');
const videoSchemaElement = videoHTML.querySelector('[itemtype*="http://schema.org/VideoObject"]');

if (videoSchemaElement === null) {
throw new Error('Unable to find Schema.org element in HTML.');
}

const videoId = videoSchemaElement?.querySelector('[itemprop="identifier"]')?.getAttribute('content') ?? '';
const personSchemaElement = videoSchemaElement.querySelector('[itemtype="http://schema.org/Person"]');

return {
id: videoId,
url: url,
title: videoSchemaElement?.querySelector('[itemprop="name"]')?.getAttribute('content') ?? '',
description: '',
description: videoSchemaElement?.querySelector('[itemprop="description"]')?.getAttribute('content') ?? '',
thumbnail: videoHTML.querySelector('meta[property="og:image"]')?.getAttribute('content') ?? '',
player: this.getEmbedPlayer(videoId),
duration: 0,
Expand Down

0 comments on commit 9cbb9de

Please sign in to comment.