Skip to content

Commit

Permalink
Update dailymotion regex
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorapple committed Sep 20, 2018
1 parent eee2514 commit 4cf235e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/players/DailyMotion.js
Expand Up @@ -6,21 +6,17 @@ import createSinglePlayer from '../singlePlayer'
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 = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?$/

export class DailyMotion extends Component {
static displayName = 'DailyMotion'
static canPlay = url => MATCH_URL.test(url)
static loopOnEnded = true

callPlayer = callPlayer
parseId (url) {
const m = url.match(MATCH_URL)
return m[4] || m[2]
}
load (url) {
const { controls, config, onError, playing } = this.props
const id = this.parseId(url)
const [, id] = url.match(MATCH_URL)
if (this.player) {
this.player.load(id, {
start: parseStartTime(url),
Expand Down
10 changes: 10 additions & 0 deletions test/players/DailyMotion.js
Expand Up @@ -30,10 +30,20 @@ testPlayerMethods(DailyMotion, {
unmute: 'setMuted'
})

test('canPlay()', async t => {
t.true(DailyMotion.canPlay(TEST_URL))
t.true(DailyMotion.canPlay('http://www.dailymotion.com/embed/video/x5s5r35'))
t.true(DailyMotion.canPlay('https://www.dailymotion.com/video/x5s5r35'))
t.true(DailyMotion.canPlay('https://dai.ly/x5s5r35'))
t.true(DailyMotion.canPlay('https://www.dailymotion.com/video/x5s5r35_test1234'))
t.true(DailyMotion.canPlay('http://dailymotion.com/embed/video/xq2cmn'))
})

test('load()', async t => {
class MockPlayer {
constructor (container, options) {
t.true(container === 'abc')
t.true(options.video === 'x5e9eog')
t.pass()
}
}
Expand Down

0 comments on commit 4cf235e

Please sign in to comment.