add kodi demo
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Roy Olav Purser 2022-03-05 17:49:14 +01:00
parent c1ae22edd3
commit f6b708b247
Signed by: roypur
GPG Key ID: E14D26A036F21656
3 changed files with 38 additions and 4 deletions

View File

@ -7,7 +7,7 @@
"48": "icon-48.png", "48": "icon-48.png",
"128": "icon-128.png" "128": "icon-128.png"
}, },
"version": "100.0", "version": "102.0",
"manifest_version": 3, "manifest_version": 3,
"permissions": ["tabs"], "permissions": ["tabs"],
"action": { "action": {

View File

@ -5,5 +5,6 @@
</head> </head>
<body> <body>
<button>Proxy Stream</button> <button>Proxy Stream</button>
<button>Play on kodi</button>
</body> </body>
</html> </html>

View File

@ -3,11 +3,11 @@ providers.set("www.youtube.com", "youtube");
providers.set("youtube.com", "youtube"); providers.set("youtube.com", "youtube");
providers.set("youtu.be", "youtube"); providers.set("youtu.be", "youtube");
providers.set("tv.nrk.no", "nrk"); providers.set("tv.nrk.no", "nrk");
providers.set("nx12210.your-storageshare.de", "nextcloud"); providers.set("seafile.purser.it", "seafile");
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
let [button] = document.getElementsByTagName("button"); let [proxyButton, kodiButton] = document.getElementsByTagName("button");
button.addEventListener("click", (ev) => { proxyButton.addEventListener("click", (ev) => {
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { chrome.tabs.query({currentWindow: true, active: true}, (tabs) => {
let oldurl = new URL(tabs[0].url); let oldurl = new URL(tabs[0].url);
let newurl = new URL("https://stream.purser.it"); let newurl = new URL("https://stream.purser.it");
@ -30,4 +30,37 @@ document.addEventListener("DOMContentLoaded", () => {
chrome.tabs.create(tab); chrome.tabs.create(tab);
}); });
}); });
kodiButton.addEventListener("click", (ev) => {
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => {
let oldurl = new URL(tabs[0].url);
let newurl = new URL(tabs[0].url);
let search = new URLSearchParams();
let hostname = oldurl.hostname.toLowerCase();
if(hostname.includes("youtube.com")) {
newurl = new URL("plugin://plugin.video.youtube")
search.append("action", "play_video")
let video_id = oldurl.searchParams.get("v");
if(newpath) {
search.append("videoid", video_id)
}
}
newurl.search = search.toString();
let req = {
jsonrpc: "2.0",
method: "Player.Open",
id: secrets.token_hex(),
params: {
item: {
file: newurl.href
}
}
}
fetch("http://127.0.0.1:8083/jsonrpc", {
method: "POST",
body: JSON.stringify(req)
}).then(resp => console.log(resp))
});
});
}); });