Skip to content

Commit

Permalink
Merge pull request #7 from j3j5/master
Browse files Browse the repository at this point in the history
Add support for video detection.
  • Loading branch information
dusterio authored Nov 14, 2016
2 parents d475af2 + cfbcad3 commit 48dc4e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
16 changes: 14 additions & 2 deletions src/Models/HtmlPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class HtmlPreview implements PreviewInterface
*/
private $title;

/**
* @var string $video Video for the page (chosen by the webmaster)
*/
private $video;

/**
* @var string $videoType If there is video, what type it is
*/
private $videoType;

/**
* Fields exposed
* @var array
Expand All @@ -39,6 +49,8 @@ class HtmlPreview implements PreviewInterface
'cover',
'images',
'title',
'description'
'description',
'video',
'videoType',
];
}
}
29 changes: 20 additions & 9 deletions src/Parsers/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,34 @@ class HtmlParser extends BaseParser implements ParserInterface
*/
private $tags = [
'cover' => [
['selector' => 'meta[itemprop="image"]', 'attribute' => 'content'],
['selector' => 'meta[property="twitter:image"]', 'attribute' => 'value'],
['selector' => 'meta[property="og:image"]', 'attribute' => 'content'],
['selector' => 'meta[property="twitter:image"]', 'attribute' => 'value']
['selector' => 'meta[itemprop="image"]', 'attribute' => 'content'],
],

'title' => [
['selector' => 'meta[itemprop="name"]', 'attribute' => 'content'],
['selector' => 'meta[property="og:title"]', 'attribute' => 'content'],
['selector' => 'meta[property="twitter:title"]', 'attribute' => 'value'],
['selector' => 'meta[property="og:title"]', 'attribute' => 'content'],
['selector' => 'meta[itemprop="name"]', 'attribute' => 'content'],
['selector' => 'title']
],

'description' => [
['selector' => 'meta[itemprop="description"]', 'attribute' => 'content'],
['selector' => 'meta[property="twitter:description"]', 'attribute' => 'content'],
['selector' => 'meta[property="og:description"]', 'attribute' => 'content'],
['selector' => 'meta[name="description"]', 'attribute' => 'content']
]
['selector' => 'meta[itemprop="description"]', 'attribute' => 'content'],
['selector' => 'meta[name="description"]', 'attribute' => 'content'],
],

'video' => [
['selector' => 'meta[property="twitter:player:stream"]', 'attribute' => 'content'],
['selector' => 'meta[property="og:video"]', 'attribute' => 'content'],
],

'videoType' => [
['selector' => 'meta[property="twitter:player:stream:content_type"]', 'attribute' => 'content'],
['selector' => 'meta[property="og:video:type"]', 'attribute' => 'content'],
],
];

/**
Expand Down Expand Up @@ -168,6 +179,6 @@ protected function parseHtml(LinkInterface $link)

if (!isset($cover) && count($images)) $cover = $images[0];

return compact('cover', 'title', 'description', 'images');
return compact('cover', 'title', 'description', 'images', 'video', 'videoType');
}
}
}

0 comments on commit 48dc4e8

Please sign in to comment.