Skip to content

Commit

Permalink
Add Wistia support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Dec 17, 2017
1 parent d027628 commit c833e27
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 0 deletions.
119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Currently supports
- Canal+
- Youku
- Coub
- Wistia

# grunt

Expand Down Expand Up @@ -650,3 +651,121 @@ Run `grunt build test --template` to create the parser and test your plugin.
})
'embed': 'http://player.canalplus.fr/embed/?param=cplus&vid=1365175',
```

## Wistia

#### Supported media types:
* `'video'`: Regular videos.
* `'embedvideo'`: Any links that do not include the channel name are embedded links.

#### Supported url formats:
* `'long'`(default): Regular urls.
* `'embed'`: Regular embedded urls using iframe.
* `'embedjsonp'`: jsonp specific embedded urls.

#### Creating urls with different media types:

| mediaType/formats| long | embed | embedjsonp |
| ------------- | :--: | :--: | :--: |
| **video** ||||
| **embedvideo** | X |||

#### Special parameters:
* `'params.start'`: The number where the video should begin in seconds.

#### Parsing Examples:
```javascript
> urlParser.parse('https://appboss.wistia.com/medias/lpu6bgplle');
{ mediaType: 'video',
channel: 'appboss',
id: 'lpu6bgplle',
provider: 'wistia'
}

> urlParser.parse('https://fast.wistia.com/embed/iframe/lpu6bgplle');
> urlParser.parse('https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp');
> urlParser.parse('https://content.wistia.com/customer-stories/bizzabo?wvideo=lpu6bgplle');
> urlParser.parse('https://wistia.com/blog/soapbox-videos-for-the-holidays?wvideo=lpu6bgplle');
> urlParser.parse('https://wistia.com/library/how-to-look-good-on-a-webcam?wvideo=lpu6bgplle');
> urlParser.parse('https://wistia.com/solutions/sales?wvideo=lpu6bgplle');
{ mediaType: 'embedvideo',
id: 'lpu6bgplle',
provider: 'wistia'
}

> urlParser.parse('https://appboss.wistia.com/medias/lpu6bgplle?wtime=1m30s');
{ mediaType: 'video',
channel: 'appboss',
id: 'lpu6bgplle',
provider: 'wistia'
params: {
start: 90
}
}

> urlParser.parse('https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=30');
{ mediaType: 'embedvideo',
id: 'lpu6bgplle',
provider: 'wistia'
params: {
start: 90
}
}
```

#### Creation Examples:
```javascript
> urlParser.create({
videoInfo: {
provider: 'wistia',
channel: 'appboss',
id: 'lpu6bgplle',
mediaType: 'video'
},
format: <format>
})
'long': 'https://appboss.wistia.com/medias/lpu6bgplle'
'embed': 'https://fast.wistia.com/embed/iframe/lpu6bgplle'
'embedjsonp': 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp'

> urlParser.create({
videoInfo: {
provider: 'wistia',
channel: 'appboss',
id: 'lpu6bgplle',
mediaType: 'video'
},
params: {
start: 90
},
format: <format>
})
'long': 'https://appboss.wistia.com/medias/lpu6bgplle?wtime=90'
'embed': 'https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=90'
'embedjsonp': 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp'

> urlParser.create({
videoInfo: {
provider: 'wistia',
id: 'lpu6bgplle',
mediaType: 'embedvideo'
},
format: <format>
})
'embed': 'https://fast.wistia.com/embed/iframe/lpu6bgplle'
'embedjsonp': 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp'

> urlParser.create({
videoInfo: {
provider: 'wistia',
id: 'lpu6bgplle',
mediaType: 'embedvideo'
},
params: {
start: 90
},
format: <format>
})
'embed': 'https://fast.wistia.com/embed/iframe/lpu6bgplle?wtime=90'
'embedjsonp': 'https://fast.wistia.com/embed/medias/lpu6bgplle.jsonp'
```
103 changes: 103 additions & 0 deletions src/plugins/provider/Wistia.js
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());
71 changes: 71 additions & 0 deletions tests/src/plugins/provider/Wisia.js
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);
});

0 comments on commit c833e27

Please sign in to comment.