Skip to content

Commit

Permalink
Get the highest image size
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 13, 2018
1 parent 06fa950 commit 63ce77d
Show file tree
Hide file tree
Showing 5 changed files with 1,588 additions and 25 deletions.
15 changes: 13 additions & 2 deletions packages/metascraper-youtube/__snapshots__/index.js.snap-shot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports['youtube video 1'] = {
"publisher": "YouTube",
"image": "https://i.ytimg.com/vi/hwMkbaS_M_c/maxresdefault.jpg",
"image": "https://img.youtube.com/vi/hwMkbaS_M_c/maxresdefault.jpg",
"author": "ONE Media",
"date": "2017-04-14T12:00:00.000Z",
"description": "Star Wars 8 El Ultimo JEDI Trailer Espanol (Subtitulado) - 2017 © 2017 - Disney",
Expand All @@ -12,7 +12,7 @@ exports['youtube video 1'] = {

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

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

15 changes: 14 additions & 1 deletion packages/metascraper-youtube/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
const getVideoId = require('get-video-id')

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

const getThumbnailUrl = id => `https://i.ytimg.com/vi/${id}/maxresdefault.jpg`
const THUMBAILS_RESOLUTIONS = [
'maxresdefault.jpg',
'sddefault.jpg',
'hqdefault.jpg',
'mqdefault.jpg',
'default.jpg'
]

const getThumbnailUrl = id => {
const urls = THUMBAILS_RESOLUTIONS.map(res => `https://img.youtube.com/vi/${id}/${res}`)
return pLocate(urls, isReachable)
}

const wrap = rule => ({ htmlDom }) => {
const value = rule(htmlDom)
Expand Down
7 changes: 5 additions & 2 deletions packages/metascraper-youtube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
"metascraper"
],
"dependencies": {
"get-video-id": "~3.0.0"
"@metascraper/helpers": "~3.8.0",
"get-video-id": "~3.0.0",
"is-reachable": "~2.4.0",
"lodash": "~4.17.5",
"p-locate": "~2.0.0"
},
"devDependencies": {
"lodash": "latest",
"metascraper": "latest",
"mocha": "latest",
"nyc": "latest",
Expand Down
Loading

0 comments on commit 63ce77d

Please sign in to comment.