Skip to content

Commit

Permalink
Less aggressive URL matching
Browse files Browse the repository at this point in the history
  • Loading branch information
happydev829 committed Jan 10, 2018
1 parent 032561e commit 485d559
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/players/DailyMotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { callPlayer, getSDK, parseStartTime } from '../utils'
const SDK_URL = 'https://api.dmcdn.net/all.js'
const SDK_GLOBAL = 'DM'
const SDK_GLOBAL_READY = 'dmAsyncInit'
const MATCH_URL = /^.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/
const MATCH_URL = /dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/

export default class DailyMotion extends Component {
static displayName = 'DailyMotion'
Expand Down
2 changes: 1 addition & 1 deletion src/players/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { callPlayer, getSDK, randomString } from '../utils'
const SDK_URL = '//connect.facebook.net/en_US/sdk.js'
const SDK_GLOBAL = 'FB'
const SDK_GLOBAL_READY = 'fbAsyncInit'
const MATCH_URL = /^https:\/\/www\.facebook\.com\/([^/?].+\/)?video(s|\.php)[/?].*$/
const MATCH_URL = /facebook\.com\/([^/?].+\/)?video(s|\.php)[/?].*$/
const PLAYER_ID_PREFIX = 'facebook-player-'

export default class Facebook extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/players/SoundCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { callPlayer, getSDK } from '../utils'

const SDK_URL = 'https://w.soundcloud.com/player/api.js'
const SDK_GLOBAL = 'SC'
const MATCH_URL = /^https?:\/\/(soundcloud.com|snd.sc)\/([a-z0-9-_]+\/[a-z0-9-_]+)$/
const MATCH_URL = /(soundcloud.com|snd.sc)\/([a-z0-9-_]+\/[a-z0-9-_]+)$/

export default class SoundCloud extends Component {
static displayName = 'SoundCloud'
Expand Down
2 changes: 1 addition & 1 deletion src/players/Streamable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { callPlayer, getSDK } from '../utils'

const SDK_URL = '//cdn.embed.ly/player-0.0.12.min.js'
const SDK_GLOBAL = 'playerjs'
const MATCH_URL = /^https?:\/\/streamable.com\/([a-z0-9]+)$/
const MATCH_URL = /streamable.com\/([a-z0-9]+)$/

export default class Streamable extends Component {
static displayName = 'Streamable'
Expand Down
4 changes: 2 additions & 2 deletions src/players/Twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { callPlayer, getSDK, randomString } from '../utils'

const SDK_URL = '//player.twitch.tv/js/embed/v1.js'
const SDK_GLOBAL = 'Twitch'
const MATCH_VIDEO_URL = /^(?:https?:\/\/)?(?:www\.|go\.)?twitch\.tv\/videos\/(\d+)($|\?)/
const MATCH_CHANNEL_URL = /^(?:https?:\/\/)?(?:www\.|go\.)?twitch\.tv\/([a-z0-9_]+)($|\?)/
const MATCH_VIDEO_URL = /(?:www\.|go\.)?twitch\.tv\/videos\/(\d+)($|\?)/
const MATCH_CHANNEL_URL = /(?:www\.|go\.)?twitch\.tv\/([a-z0-9_]+)($|\?)/
const PLAYER_ID_PREFIX = 'twitch-player-'

export default class Twitch extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/players/Vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { callPlayer, getSDK } from '../utils'

const SDK_URL = 'https://player.vimeo.com/api/player.js'
const SDK_GLOBAL = 'Vimeo'
const MATCH_URL = /https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:(?:channels|ondemand)\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/
const MATCH_URL = /(?:www\.|player\.)?vimeo.com\/(?:(?:channels|ondemand)\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/

export default class Vimeo extends Component {
static displayName = 'Vimeo'
Expand Down
4 changes: 2 additions & 2 deletions src/players/Wistia.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { callPlayer, getSDK } from '../utils'

const SDK_URL = '//fast.wistia.com/assets/external/E-v1.js'
const SDK_GLOBAL = 'Wistia'
const MATCH_URL = /^https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/(.*)$/
const MATCH_URL = /(?:wistia.com|wi.st)\/(?:medias|embed)\/(.*)$/

export default class Wistia extends Component {
static displayName = 'Wistia'
Expand All @@ -13,7 +13,7 @@ export default class Wistia extends Component {

callPlayer = callPlayer
getID (url) {
return url && url.match(MATCH_URL)[4]
return url && url.match(MATCH_URL)[1]
}
load (url) {
const { controls, onReady, onPlay, onPause, onSeek, onEnded, config } = this.props
Expand Down
2 changes: 1 addition & 1 deletion src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { callPlayer, getSDK, parseStartTime } from '../utils'
const SDK_URL = 'https://www.youtube.com/iframe_api'
const SDK_GLOBAL = 'YT'
const SDK_GLOBAL_READY = 'onYouTubeIframeAPIReady'
const MATCH_URL = /^(?:https?:\/\/)?(?:www\.|m\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
const MATCH_URL = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})$/

export default class YouTube extends Component {
static displayName = 'YouTube'
Expand Down
13 changes: 13 additions & 0 deletions test/specs/canPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const { describe, it, expect } = window
describe('canPlay', () => {
describe('YouTube', () => {
it('knows what it can play', () => {
expect(YouTube.canPlay('youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('//www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('https://www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('https://www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('http://www.youtube.com/watch?v=12345678901')).to.be.true
expect(YouTube.canPlay('https://youtube.com/watch?v=12345678901')).to.be.true
Expand All @@ -26,6 +30,8 @@ describe('canPlay', () => {

describe('SoundCloud', () => {
it('knows what it can play', () => {
expect(SoundCloud.canPlay('soundcloud.com/artist-name/title-name')).to.be.true
expect(SoundCloud.canPlay('//soundcloud.com/artist-name/title-name')).to.be.true
expect(SoundCloud.canPlay('http://soundcloud.com/artist-name/title-name')).to.be.true
expect(SoundCloud.canPlay('http://soundcloud.com/artist_name/title_name')).to.be.true
expect(SoundCloud.canPlay('http://snd.sc/artist-name/title-name')).to.be.true
Expand All @@ -40,6 +46,8 @@ describe('canPlay', () => {

describe('Vimeo', () => {
it('knows what it can play', () => {
expect(Vimeo.canPlay('vimeo.com/1234')).to.be.true
expect(Vimeo.canPlay('//vimeo.com/1234')).to.be.true
expect(Vimeo.canPlay('http://vimeo.com/1234')).to.be.true
expect(Vimeo.canPlay('https://vimeo.com/1234')).to.be.true
expect(Vimeo.canPlay('https://www.vimeo.com/1234')).to.be.true
Expand All @@ -58,6 +66,8 @@ describe('canPlay', () => {

describe('Wistia', () => {
it('knows what it can play', () => {
expect(Wistia.canPlay('fast.wistia.com/medias/e4a27b971d')).to.be.true
expect(Wistia.canPlay('//fast.wistia.com/medias/e4a27b971d')).to.be.true
expect(Wistia.canPlay('https://fast.wistia.com/medias/e4a27b971d')).to.be.true
expect(Wistia.canPlay('http://fast.wistia.com/medias/e4a27b971d')).to.be.true
expect(Wistia.canPlay('https://fast.wi.st/medias/e4a27b971d')).to.be.true
Expand All @@ -77,6 +87,9 @@ describe('canPlay', () => {

describe('Twitch', () => {
it('knows what it can play', () => {
expect(Twitch.canPlay('twitch.tv/videos/106400740')).to.be.true
expect(Twitch.canPlay('www.twitch.tv/videos/106400740')).to.be.true
expect(Twitch.canPlay('//www.twitch.tv/videos/106400740')).to.be.true
expect(Twitch.canPlay('https://www.twitch.tv/videos/106400740')).to.be.true
expect(Twitch.canPlay('https://www.twitch.tv/kronovi')).to.be.true
expect(Twitch.canPlay('https://twitch.tv/videos/106400740')).to.be.true
Expand Down

0 comments on commit 485d559

Please sign in to comment.