-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathThemisMedia.js
50 lines (44 loc) · 1.61 KB
/
ThemisMedia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
addKiller("ThemisMedia", {
"canKill": function(data) {
return data.src.indexOf("themis-media.com/") !== -1;
},
"process": function(data, callback) {
var configUrl = parseFlashVariables(data.params.flashvars).config;
if (configUrl) {
var xhr = new XMLHttpRequest();
xhr.open('GET', configUrl, true);
var _this = this;
xhr.onload = function(event) {
// Fix the response data. They send something that looks like JSON, but really isn't:
// they mostly use the ' character for strings and keys instead of ". This should turn
// it into valid JSON.
var response = JSON.parse(event.target.response.replace(/'/g, '"'));
var title = "Video";
var posterUrl = null;
var sourceUrl;
response.playlist.forEach(function(elem) {
if (elem.eventCategory === "Video") {
sourceUrl = elem.url;
} else if (elem.eventCategory === "Video Splash") {
posterUrl = elem.url;
}
});
if ("viral" in response.plugins) {
title = unescapeHTML(response.plugins.viral.share.description);
}
if (sourceUrl) {
callback({"playlist": [{
"title": title,
"poster": posterUrl,
"sources": [{
"url": sourceUrl,
"format": "MP4",
"isNative": true
}]
}]});
}
};
xhr.send(null);
}
}
});