Skip to content

Commit

Permalink
Added support for twitch add-on v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
khloke committed Apr 13, 2017
1 parent a57d137 commit e70d756
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
6 changes: 6 additions & 0 deletions js/content_scripts/twitch-content-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action == "getChannelId") {
let channelId = $('figure[data-id!=""][data-id]').attr('data-id');
sendResponse({channelId: channelId});
}
});
48 changes: 32 additions & 16 deletions js/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,31 +576,47 @@ var TwitchTvModule = {
getPluginPath: function(url, getAddOnVersion, callback) {
getAddOnVersion('plugin.video.twitch', function(version) {
console.log(version);
var videoId;
var liveVideo = false;
var pluginPath;
var regexMatch;
let videoId;
let liveVideo = false;
let pluginPath;
let regexMatch;
let versionNumber = Number.parseFloat(version);

if (regexMatch = url.match('^(?:https|http)://(?:www\.)?twitch.tv/[^&/#\?]+/(b|v|c)/([^&/#\?]+).*$')) {
videoId = regexMatch[1] + regexMatch[2];
if (regexMatch = url.match('^(?:https|http)://(?:www\.)?twitch.tv/videos/([^&/#\?]+).*$')) {
videoId = regexMatch[1];
} else if (regexMatch = url.match('^(?:https|http)://(?:www\.)?twitch.tv/([^&/#\?]+).*$')) {
liveVideo = true;
videoId = regexMatch[1];
}

if (versionNumber >= 2.0) {
if (liveVideo) {
chrome.tabs.sendMessage(currentTabId, {action: 'getChannelId'}, function (response) {
if (response) {
let channelId = response.channelId;
callback('plugin://plugin.video.twitch/?mode=play&channel_id=' + channelId + '&name=' + videoId);
}
});
} else {
callback('plugin://plugin.video.twitch/?mode=play&video_id=' + videoId);
}

if (liveVideo) {
pluginPath = 'plugin://plugin.video.twitch/playLive/' + videoId + '/';
} else {
pluginPath = 'plugin://plugin.video.twitch/playVideo/' + videoId + '/';
}
if (liveVideo) {
pluginPath = 'plugin://plugin.video.twitch/playLive/' + videoId + '/';
} else {
pluginPath = 'plugin://plugin.video.twitch/playVideo/v' + videoId + '/';
}

if (Number.parseFloat(version) >= 1.4) {
//https://github.com/StateOfTheArt89/Twitch.tv-on-XBMC/blob/2baf7cffc582492f4a773ef34aa7cbec0a2cac72/resources/lib/routes.py
callback(pluginPath + '-2/');
} else {
//https://github.com/StateOfTheArt89/Twitch.tv-on-XBMC/blob/c5644e6d9ceac10b6d6ebf73c9538aee27a9e6f7/default.py#L157
callback(pluginPath);
if (versionNumber >= 1.4) {
//https://github.com/StateOfTheArt89/Twitch.tv-on-XBMC/blob/2baf7cffc582492f4a773ef34aa7cbec0a2cac72/resources/lib/routes.py
callback(pluginPath + '-2/');
} else {
//https://github.com/StateOfTheArt89/Twitch.tv-on-XBMC/blob/c5644e6d9ceac10b6d6ebf73c9538aee27a9e6f7/default.py#L157
callback(pluginPath);
}
}

});
}
};
Expand Down
3 changes: 3 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
}, {
"matches": ["*://*.seasonvar.ru/*"],
"js": ["js/jquery-2.1.4.min.js", "js/content_scripts/seasonvar-content-scripts.js"]
}, {
"matches": ["*://*.twitch.tv/*"],
"js": ["js/jquery-2.1.4.min.js", "js/content_scripts/twitch-content-scripts.js"]
}],
"web_accessible_resources": [
"images/*"
Expand Down

0 comments on commit e70d756

Please sign in to comment.