Skip to content

Commit

Permalink
Fix get video extension from url
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 4, 2018
1 parent fa47e32 commit b98d2db
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/metascraper-video/__snapshots__/index.js.snap-shot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

7 changes: 6 additions & 1 deletion packages/metascraper-video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit b98d2db

Please sign in to comment.