-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
function Wistia() { | ||
this.provider = 'wistia'; | ||
this.alternatives = []; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl, | ||
embedjsonp: this.createEmbedJsonpUrl, | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video', | ||
EMBEDVIDEO: 'embedvideo', | ||
}; | ||
} | ||
|
||
Wistia.prototype.parseUrl = function (url, params) { | ||
var match = url.match( | ||
/(?:(?:medias|iframe)\/|wvideo=)([\w-]+)/ | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
|
||
Wistia.prototype.parseChannel = function (url, params) { | ||
var match = url.match( | ||
/(?:(?:https?:)?\/\/)?([^\.]*)\.wistia\./ | ||
); | ||
var channel = match ? match[1] : undefined; | ||
if (channel === 'fast' || channel === 'content') { | ||
return undefined; | ||
} | ||
return channel; | ||
}; | ||
|
||
Wistia.prototype.parseParameters = function (params, result) { | ||
if (params.wtime) { | ||
params.start = getTime(params.wtime); | ||
delete params.wtime; | ||
} | ||
if (params.wvideo === result.id) { | ||
delete params.wvideo; | ||
} | ||
return params; | ||
}; | ||
|
||
Wistia.prototype.parseMediaType = function (result) { | ||
if (result.id && result.channel) { | ||
return this.mediaTypes.VIDEO; | ||
} else if (result.id) { | ||
delete result.channel; | ||
return this.mediaTypes.EMBEDVIDEO; | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
|
||
Wistia.prototype.parse = function (url, params) { | ||
var _this = this; | ||
var result = { | ||
params: params, | ||
id: _this.parseUrl(url), | ||
channel: _this.parseChannel(url) | ||
}; | ||
result.params = _this.parseParameters(params, result); | ||
result.mediaType = _this.parseMediaType(result); | ||
|
||
if (!result.id) { | ||
return undefined; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
Wistia.prototype.createUrl = function (vi, params, url) { | ||
if (params.start) { | ||
params.wtime = params.start; | ||
delete params.start; | ||
} | ||
|
||
url += combineParams({ | ||
params: params | ||
}); | ||
|
||
return url; | ||
}; | ||
|
||
Wistia.prototype.createLongUrl = function (vi, params) { | ||
if (vi.mediaType !== this.mediaTypes.VIDEO) { | ||
return; | ||
} | ||
var url = 'https://' + vi.channel + '.wistia.com/medias/' + vi.id; | ||
return this.createUrl(vi, params, url); | ||
}; | ||
|
||
Wistia.prototype.createEmbedUrl = function (vi, params) { | ||
var url = 'https://fast.wistia.com/embed/iframe/' + vi.id; | ||
return this.createUrl(vi, params, url); | ||
}; | ||
|
||
Wistia.prototype.createEmbedJsonpUrl = function (vi, params) { | ||
return 'https://fast.wistia.com/embed/medias/' + vi.id + '.jsonp'; | ||
}; | ||
|
||
urlParser.bind(new Wistia()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
QUnit.test('Long Urls', function (assert) { | ||
var vi = { | ||
provider: 'wistia', | ||
id: 'lpu6bgplle', | ||
mediaType: 'video', | ||
channel: 'appboss', | ||
params: { | ||
start: 30 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://appboss.wistia.com/medias/lpu6bgplle', | ||
embed: 'https://fast.wistia.com/embed/iframe/lpu6bgplle', | ||
embedjsonp: 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp' | ||
}, | ||
urls: [ | ||
'https://appboss.wistia.com/medias/lpu6bgplle', | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://appboss.wistia.com/medias/lpu6bgplle?wtime=30', | ||
embed: 'https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=30', | ||
embedjsonp: 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp', | ||
}, | ||
urls: [ | ||
'https://appboss.wistia.com/medias/lpu6bgplle?wtime=30s' | ||
] | ||
}]; | ||
delete tests[0].videoInfo.params; | ||
assertUrlTest(assert, tests); | ||
}); | ||
|
||
QUnit.test('Embed Urls', function (assert) { | ||
var vi = { | ||
provider: 'wistia', | ||
id: 'lpu6bgplle', | ||
mediaType: 'embedvideo', | ||
params: { | ||
start: 30 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://fast.wistia.com/embed/iframe/lpu6bgplle', | ||
embedjsonp: 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp' | ||
}, | ||
urls: [ | ||
'https://fast.wistia.com/embed/iframe/lpu6bgplle', | ||
'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp', | ||
'https://content.wistia.com/customer-stories/bizzabo?wvideo=lpu6bgplle', | ||
'https://wistia.com/blog/soapbox-videos-for-the-holidays?wvideo=lpu6bgplle', | ||
'https://wistia.com/library/how-to-look-good-on-a-webcam?wvideo=lpu6bgplle', | ||
'https://wistia.com/solutions/sales?wvideo=lpu6bgplle' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=30', | ||
embedjsonp: 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp', | ||
}, | ||
urls: [ | ||
'https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=30' | ||
] | ||
}]; | ||
delete tests[0].videoInfo.params; | ||
assertUrlTest(assert, tests); | ||
}); |