From b98d2dbda2b7cb81e441e0a55234ea78d141dbc1 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sun, 4 Feb 2018 20:40:56 +0100 Subject: [PATCH] Fix get video extension from url --- .../__snapshots__/index.js.snap-shot | 26 ++++ packages/metascraper-video/index.js | 7 +- .../fixtures/providers/clip.twitch.tv.html | 140 ++++++++++++++++++ packages/metascraper-video/test/index.js | 16 ++ 4 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 packages/metascraper-video/test/fixtures/providers/clip.twitch.tv.html diff --git a/packages/metascraper-video/__snapshots__/index.js.snap-shot b/packages/metascraper-video/__snapshots__/index.js.snap-shot index 87698665e..f79f4f321 100644 --- a/packages/metascraper-video/__snapshots__/index.js.snap-shot +++ b/packages/metascraper-video/__snapshots__/index.js.snap-shot @@ -50,3 +50,29 @@ exports['src:poster 1'] = { "url": "https://gfycat.com/gifs/detail/timelyhealthyarmadillo" } +exports['clips.twitch.tv 1'] = { + "image": "https://clips-media-assets.twitch.tv/27434665136-offset-2366-preview.jpg", + "video": "https://clips-media-assets.twitch.tv/AT-27434665136-offset-2366-1280x720.mp4", + "author": null, + "date": null, + "description": "Shroud with the casual coffee sip to kill combo - Clipped by jpan11", + "lang": "en", + "logo": "https://www.twitch.tv/favicon.ico", + "publisher": "Twitch", + "title": "shroud Playing PLAYERUNKNOWN’S BATTLEGROUNDS - Twitch Clips", + "url": "https://clips.twitch.tv/AwkwardBoredWaffleItsBoshyTime" +} + +exports['play.tv 1'] = { + "image": "https://d1playscdntv-a.akamaihd.net/video/Ha35bprkDYG/processed/720.jpg", + "video": "https://d1playscdntv-a.akamaihd.net/video/Ha35bprkDYG/processed/480.mp4", + "author": "chineseouchie", + "date": "2018-02-04T00:00:00.000Z", + "description": "Publicado por chineseouchie", + "lang": "en", + "logo": "https://plays.tv/images/chrome/touch_icon_152x152.png", + "publisher": "Plays.tv", + "title": "Holy Shit", + "url": "https://plays.tv/video/5a6f64b1bef69a7fa9/holy-shit" +} + diff --git a/packages/metascraper-video/index.js b/packages/metascraper-video/index.js index b28d6665e..1fbae99d5 100644 --- a/packages/metascraper-video/index.js +++ b/packages/metascraper-video/index.js @@ -2,9 +2,14 @@ const { getUrl, isUrl } = require('@metascraper/helpers') const videoExtensions = require('video-extensions') +const { URL } = require('url') const path = require('path') -const isVideoUrl = url => videoExtensions.includes(path.extname(url).substring(1)) +const isVideoUrl = url => { + const { pathname } = new URL(url) + const ext = path.extname(pathname).substring(1) + return videoExtensions.includes(ext) +} /** * Wrap a rule with validation and formatting logic. diff --git a/packages/metascraper-video/test/fixtures/providers/clip.twitch.tv.html b/packages/metascraper-video/test/fixtures/providers/clip.twitch.tv.html new file mode 100644 index 000000000..e53e1493e --- /dev/null +++ b/packages/metascraper-video/test/fixtures/providers/clip.twitch.tv.html @@ -0,0 +1,140 @@ + + + Shroud with the casual coffee sip to kill combo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ + + + + diff --git a/packages/metascraper-video/test/index.js b/packages/metascraper-video/test/index.js index b7fc1aa20..973dcf526 100644 --- a/packages/metascraper-video/test/index.js +++ b/packages/metascraper-video/test/index.js @@ -45,6 +45,22 @@ describe('metascraper-video', () => { const metadata = await metascraper({ html, url }) snapshot(metadata) }) + + describe('specific providers', () => { + it('clips.twitch.tv', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/providers/clip.twitch.tv.html')) + const url = 'https://clips.twitch.tv/AwkwardBoredWaffleItsBoshyTime' + const metadata = await metascraper({ html, url }) + snapshot(metadata) + }) + + it('play.tv', async () => { + const html = await readFile(resolve(__dirname, 'fixtures/providers/play.tv.html')) + const url = 'https://plays.tv/video/5a6f64b1bef69a7fa9/holy-shit' + const metadata = await metascraper({ html, url }) + snapshot(metadata) + }) + }) }) describe('image', () => {