diff --git a/packages/metascraper-youtube/__snapshots__/index.js.snap-shot b/packages/metascraper-youtube/__snapshots__/index.js.snap-shot index eeaebcc4b..3cc96ae8e 100644 --- a/packages/metascraper-youtube/__snapshots__/index.js.snap-shot +++ b/packages/metascraper-youtube/__snapshots__/index.js.snap-shot @@ -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", @@ -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...", @@ -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" +} + diff --git a/packages/metascraper-youtube/index.js b/packages/metascraper-youtube/index.js index 2e3b0ef0c..e2fded236 100644 --- a/packages/metascraper-youtube/index.js +++ b/packages/metascraper-youtube/index.js @@ -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) diff --git a/packages/metascraper-youtube/package.json b/packages/metascraper-youtube/package.json index a73938a96..22d0473eb 100644 --- a/packages/metascraper-youtube/package.json +++ b/packages/metascraper-youtube/package.json @@ -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", diff --git a/packages/metascraper-youtube/test/fixtures/image-size.html b/packages/metascraper-youtube/test/fixtures/image-size.html new file mode 100644 index 000000000..938d33764 --- /dev/null +++ b/packages/metascraper-youtube/test/fixtures/image-size.html @@ -0,0 +1,1525 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +Neil DeGrasse Tyson Comments on SpaceXs Falcon Heavy Launch - YouTube + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ +ES
+
+ +
+
+
+

+ + + +Cargando... + +

+ +
+
+
+ +
+ +
+
+
+ +Estás viendo YouTube en Español (España). +
+ + + +Cambiar a otro idioma: + + + + + + | + + + + + | + + + + + | + +Ver todo + +
+ +
+
+ + You're viewing YouTube in Spanish (Spain). +
+ + + + Switch to another language: + + + + + + | + + + + + | + + + + + | + + View all + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + +
+
+
+ +
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+

+ + + + + Neil DeGrasse Tyson Comments on SpaceXs Falcon Heavy Launch + + +

+
+
+ + +
+ + + + + +
+
579.353 visualizaciones
+
+
+
+
+
+ + + + + +
+
+ + + + +
+
+
+
+

+ + + +Cargando... + +

+ +
+
+
+ +
+ +
+
+
+

+ + + +Cargando... + +

+ +
+
+
+

+Transcripción +

+
+ +
+ + + +
+
+La transcripción interactiva no se ha podido cargar. +
+ + +
+
+ +
+ +
+
+

+ + + +Cargando... + +

+ +
+
+ +
+
+

+ + + +Cargando... + +

+ +
+
+ + +
+
+ Se podrá valorar cuando se haya alquilado el vídeo. +
+ +
+ +
+
+ Esta función no está disponible en este momento. Vuelve a intentarlo más tarde. +
+
+ + +
+ + +
+ + +
Publicado el 12 feb. 2018

Subscribe for daily Elon Musk videos.

+
    +
  • +

    + Categoría +

    + +
  • + +
  • +

    + Licencia +

    +
      +
    • Licencia de YouTube estándar
    • +
    +
  • + +
+
+
+ +
+ + + +
+
+

+ + + +Cargando... + +

+ +
+ +
+ + +
+
+
+ + + +
+
+ +
+ +
+
+
+Anuncio +
+
+
+
+ + +
+
+
+
+
+ + + +Si la reproducción automática está habilitada, se reproducirá automáticamente un vídeo a continuación. + + + +
+

+ Siguiente +

+ + +
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+ +
+ +
+
+ + +
+
+ + +
+ para añadir este vídeo a la lista Ver más tarde. + +
+
+

+Añadir a +

+
+
+

+ + + + Cargando listas de reproducción... + +

+ +
+
+ + + + + + + \ No newline at end of file diff --git a/packages/metascraper-youtube/test/index.js b/packages/metascraper-youtube/test/index.js index e7dbd1cc2..7b8af3da1 100644 --- a/packages/metascraper-youtube/test/index.js +++ b/packages/metascraper-youtube/test/index.js @@ -22,27 +22,38 @@ const metascraper = require('metascraper').load([ const readFile = promisify(fs.readFile) describe('metascraper-youtube', () => { - it('youtube video', async () => { - const html = await readFile(resolve(__dirname, 'fixtures/youtube-video.html')) - const url = 'https://www.youtube.com/watch?v=hwMkbaS_M_c' - - const metadata = await metascraper({ html, url }) - snapshot(metadata) + describe('urls', () => { + it('youtube video', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/youtube-video.html')) + const url = 'https://www.youtube.com/watch?v=hwMkbaS_M_c' + + const metadata = await metascraper({ html, url }) + snapshot(metadata) + }) + + it('youtube video old', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/youtube-video-old.html')) + const url = 'https://www.youtube.com/watch?v=GDRd-BFTYIg' + + const metadata = await metascraper({ html, url }) + snapshot(metadata) + }) + + it('youtube channel', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/youtube-channel.html')) + const url = 'https://www.youtube.com/channel/UCzcRQ3vRNr6fJ1A9rqFn7QA' + + const metadata = omit(await metascraper({ html, url }), ['date']) + snapshot(metadata) + }) }) - it('youtube video old', async () => { - const html = await readFile(resolve(__dirname, 'fixtures/youtube-video-old.html')) - const url = 'https://www.youtube.com/watch?v=GDRd-BFTYIg' - - const metadata = await metascraper({ html, url }) - snapshot(metadata) - }) - - it('youtube channel', async () => { - const html = await readFile(resolve(__dirname, 'fixtures/youtube-channel.html')) - const url = 'https://www.youtube.com/channel/UCzcRQ3vRNr6fJ1A9rqFn7QA' - - const metadata = omit(await metascraper({ html, url }), ['date']) - snapshot(metadata) + describe('image size', () => { + it('get the high image size', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/image-size.html')) + const url = 'https://www.youtube.com/watch?v=rXyKq7izYCQ' + const metadata = omit(await metascraper({ html, url }), ['date']) + snapshot(metadata) + }) }) })