Skip to content

Commit cfbcad3

Browse files
committed
Add support for video detection.
1 parent 2710e64 commit cfbcad3

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/Models/HtmlPreview.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class HtmlPreview implements PreviewInterface
3131
*/
3232
private $title;
3333

34+
/**
35+
* @var string $video Video for the page (chosen by the webmaster)
36+
*/
37+
private $video;
38+
39+
/**
40+
* @var string $videoType If there is video, what type it is
41+
*/
42+
private $videoType;
43+
3444
/**
3545
* Fields exposed
3646
* @var array
@@ -39,6 +49,8 @@ class HtmlPreview implements PreviewInterface
3949
'cover',
4050
'images',
4151
'title',
42-
'description'
52+
'description',
53+
'video',
54+
'videoType',
4355
];
44-
}
56+
}

src/Parsers/HtmlParser.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,34 @@ class HtmlParser extends BaseParser implements ParserInterface
2424
*/
2525
private $tags = [
2626
'cover' => [
27-
['selector' => 'meta[itemprop="image"]', 'attribute' => 'content'],
27+
['selector' => 'meta[property="twitter:image"]', 'attribute' => 'value'],
2828
['selector' => 'meta[property="og:image"]', 'attribute' => 'content'],
29-
['selector' => 'meta[property="twitter:image"]', 'attribute' => 'value']
29+
['selector' => 'meta[itemprop="image"]', 'attribute' => 'content'],
3030
],
3131

3232
'title' => [
33-
['selector' => 'meta[itemprop="name"]', 'attribute' => 'content'],
34-
['selector' => 'meta[property="og:title"]', 'attribute' => 'content'],
3533
['selector' => 'meta[property="twitter:title"]', 'attribute' => 'value'],
34+
['selector' => 'meta[property="og:title"]', 'attribute' => 'content'],
35+
['selector' => 'meta[itemprop="name"]', 'attribute' => 'content'],
3636
['selector' => 'title']
3737
],
3838

3939
'description' => [
40-
['selector' => 'meta[itemprop="description"]', 'attribute' => 'content'],
40+
['selector' => 'meta[property="twitter:description"]', 'attribute' => 'content'],
4141
['selector' => 'meta[property="og:description"]', 'attribute' => 'content'],
42-
['selector' => 'meta[name="description"]', 'attribute' => 'content']
43-
]
42+
['selector' => 'meta[itemprop="description"]', 'attribute' => 'content'],
43+
['selector' => 'meta[name="description"]', 'attribute' => 'content'],
44+
],
45+
46+
'video' => [
47+
['selector' => 'meta[property="twitter:player:stream"]', 'attribute' => 'content'],
48+
['selector' => 'meta[property="og:video"]', 'attribute' => 'content'],
49+
],
50+
51+
'videoType' => [
52+
['selector' => 'meta[property="twitter:player:stream:content_type"]', 'attribute' => 'content'],
53+
['selector' => 'meta[property="og:video:type"]', 'attribute' => 'content'],
54+
],
4455
];
4556

4657
/**
@@ -168,6 +179,6 @@ protected function parseHtml(LinkInterface $link)
168179

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

171-
return compact('cover', 'title', 'description', 'images');
182+
return compact('cover', 'title', 'description', 'images', 'video', 'videoType');
172183
}
173-
}
184+
}

0 commit comments

Comments
 (0)