add kodi queue

This commit is contained in:
Roy Olav Purser 2022-03-06 08:54:23 +01:00
parent 487e15e429
commit 0d0a61003a
Signed by: roypur
GPG Key ID: E14D26A036F21656
3 changed files with 80 additions and 64 deletions

View File

@ -7,7 +7,7 @@
"48": "icon-48.png", "48": "icon-48.png",
"128": "icon-128.png" "128": "icon-128.png"
}, },
"version": "108.0", "version": "109.0",
"manifest_version": 3, "manifest_version": 3,
"host_permissions": ["http://127.0.0.1:4000/jsonrpc"], "host_permissions": ["http://127.0.0.1:4000/jsonrpc"],
"permissions": ["tabs"], "permissions": ["tabs"],

View File

@ -4,7 +4,8 @@
<title>Proxy Stream</title> <title>Proxy Stream</title>
</head> </head>
<body> <body>
<button>Proxy Stream</button> <button id="proxy-button">Proxy Stream</button>
<button>Play on kodi</button> <button id="kodi-play-button">Play on kodi</button>
<button id="kodi-queue-button">Queue on kodi</button>
</body> </body>
</html> </html>

View File

@ -12,13 +12,17 @@ const random = () => {
} }
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
let [proxyButton, kodiButton] = document.getElementsByTagName("button") const proxyButton = document.getElementById("proxy-button")
proxyButton.addEventListener("click", (ev) => { const kodiPlayButton = document.getElementById("kodi-play-button")
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { const kodiQueueButton = document.getElementById("kodi-queue-button")
let oldurl = new URL(tabs[0].url)
async function handleProxyButton(ev) {
const [tab] = chrome.tabs.query({currentWindow: true, active: true})
const oldurl = new URL(tab.url)
const search = new URLSearchParams()
const hostname = oldurl.hostname.toLowerCase()
let newurl = new URL("https://stream.purser.it") let newurl = new URL("https://stream.purser.it")
let search = new URLSearchParams()
let hostname = oldurl.hostname.toLowerCase()
if(providers.has(hostname)) { if(providers.has(hostname)) {
if(hostname.includes("youtube.com")) { if(hostname.includes("youtube.com")) {
let newpath = oldurl.searchParams.get("v") let newpath = oldurl.searchParams.get("v")
@ -31,17 +35,18 @@ document.addEventListener("DOMContentLoaded", () => {
search.append("provider", providers.get(hostname)) search.append("provider", providers.get(hostname))
} }
newurl.search = search.toString() newurl.search = search.toString()
let tab = {} const newtab = {}
tab.url = newurl.href newtab.url = newurl.href
chrome.tabs.create(tab) chrome.tabs.create(newtab)
}) }
})
kodiButton.addEventListener("click", (ev) => { async function handleKodiButton(ev, method, playlistid) {
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { const [tab] = await chrome.tabs.query({currentWindow: true, active: true})
let oldurl = new URL(tabs[0].url) const oldurl = new URL(tab.url)
const search = new URLSearchParams()
const hostname = oldurl.hostname.toLowerCase()
let newurl = new URL("https://stream.purser.it") let newurl = new URL("https://stream.purser.it")
let search = new URLSearchParams()
let hostname = oldurl.hostname.toLowerCase()
if(providers.has(hostname)) { if(providers.has(hostname)) {
if(hostname.includes("youtube.com")) { if(hostname.includes("youtube.com")) {
newurl = new URL("plugin://plugin.video.youtube") newurl = new URL("plugin://plugin.video.youtube")
@ -59,9 +64,9 @@ document.addEventListener("DOMContentLoaded", () => {
newurl.search = search.toString() newurl.search = search.toString()
let req = { const req = {
jsonrpc: "2.0", jsonrpc: "2.0",
method: "Player.Open", method: method,
id: random(), id: random(),
params: { params: {
item: { item: {
@ -70,17 +75,27 @@ document.addEventListener("DOMContentLoaded", () => {
} }
} }
try { if(playlistid) {
fetch("http://127.0.0.1:4000/jsonrpc", { req.params.playlistid = 1
}
const resp = await fetch("http://127.0.0.1:4000/jsonrpc", {
method: "POST", method: "POST",
body: JSON.stringify(req), body: JSON.stringify(req),
headers: { headers: {
"Content-Type": "application/json; charset=utf-8" "Content-Type": "application/json; charset=utf-8"
} }
}).then(resp => console.log(resp)) })
} catch(e) { console.log(resp)
console.log(e)
} }
kodiPlayButton.addEventListener("click", async ev => {
await handleKodiButton(ev, "Player.Open")
}) })
kodiQueueButton.addEventListener("click", async ev => {
await handleKodiButton(ev, "Playlist.Add", 1)
}) })
proxyButton.addEventListener("click", handleProxyButton)
}) })