Skip to content

Commit 63ce77d

Browse files
committed
Get the highest image size
1 parent 06fa950 commit 63ce77d

File tree

5 files changed

+1588
-25
lines changed

5 files changed

+1588
-25
lines changed

packages/metascraper-youtube/__snapshots__/index.js.snap-shot

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
exports['youtube video 1'] = {
22
"publisher": "YouTube",
3-
"image": "https://i.ytimg.com/vi/hwMkbaS_M_c/maxresdefault.jpg",
3+
"image": "https://img.youtube.com/vi/hwMkbaS_M_c/maxresdefault.jpg",
44
"author": "ONE Media",
55
"date": "2017-04-14T12:00:00.000Z",
66
"description": "Star Wars 8 El Ultimo JEDI Trailer Espanol (Subtitulado) - 2017 © 2017 - Disney",
@@ -12,7 +12,7 @@ exports['youtube video 1'] = {
1212

1313
exports['youtube video old 1'] = {
1414
"publisher": "YouTube",
15-
"image": "https://i.ytimg.com/vi/GDRd-BFTYIg/maxresdefault.jpg",
15+
"image": "https://img.youtube.com/vi/GDRd-BFTYIg/maxresdefault.jpg",
1616
"author": "Andrew JRT",
1717
"date": "2017-07-07T00:00:00.000Z",
1818
"description": "👍 Subscribe - http://bit.do/AndrewJRT 🐦 Twitter - https://twitter.com/andrew_jrt 🎮 Twitch - https://twitch.tv/andrewjrt ❤ Patreon - https://www.patreon.com/a...",
@@ -33,3 +33,14 @@ exports['youtube channel 1'] = {
3333
"url": "https://www.youtube.com/channel/UCzcRQ3vRNr6fJ1A9rqFn7QA"
3434
}
3535

36+
exports['get the high image size 1'] = {
37+
"author": "Elon Musk Viral Videos",
38+
"publisher": "YouTube",
39+
"image": "https://img.youtube.com/vi/rXyKq7izYCQ/sddefault.jpg",
40+
"description": "Subscribe for daily Elon Musk videos.",
41+
"lang": "es",
42+
"logo": "https://www.youtube.com/yts/img/favicon_144-vfliLAfaB.png",
43+
"title": "Neil DeGrasse Tyson Comments on SpaceXs Falcon Heavy Launch",
44+
"url": "https://www.youtube.com/watch?v=rXyKq7izYCQ"
45+
}
46+

packages/metascraper-youtube/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
const getVideoId = require('get-video-id')
44

55
const { getValue, isUrl, titleize } = require('@metascraper/helpers')
6+
const isReachable = require('is-reachable')
67
const { isString } = require('lodash')
8+
const pLocate = require('p-locate')
79

8-
const getThumbnailUrl = id => `https://i.ytimg.com/vi/${id}/maxresdefault.jpg`
10+
const THUMBAILS_RESOLUTIONS = [
11+
'maxresdefault.jpg',
12+
'sddefault.jpg',
13+
'hqdefault.jpg',
14+
'mqdefault.jpg',
15+
'default.jpg'
16+
]
17+
18+
const getThumbnailUrl = id => {
19+
const urls = THUMBAILS_RESOLUTIONS.map(res => `https://img.youtube.com/vi/${id}/${res}`)
20+
return pLocate(urls, isReachable)
21+
}
922

1023
const wrap = rule => ({ htmlDom }) => {
1124
const value = rule(htmlDom)

packages/metascraper-youtube/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
"metascraper"
2222
],
2323
"dependencies": {
24-
"get-video-id": "~3.0.0"
24+
"@metascraper/helpers": "~3.8.0",
25+
"get-video-id": "~3.0.0",
26+
"is-reachable": "~2.4.0",
27+
"lodash": "~4.17.5",
28+
"p-locate": "~2.0.0"
2529
},
2630
"devDependencies": {
27-
"lodash": "latest",
2831
"metascraper": "latest",
2932
"mocha": "latest",
3033
"nyc": "latest",

0 commit comments

Comments
 (0)