* Play API prototype * Web app * Drag and drop support * Handle different urls * Fix redirect * Increase max connections * changelog * Limit timeout * Use fetch * Redirects * Formatting
164 lines
5.1 KiB
HTML
164 lines
5.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Playlet</title>
|
|
</head>
|
|
|
|
<body ondrop="OnDrop(event);" ondragover="OnDragover(event);">
|
|
<h2>Playlet - Youtube Player for Roku</h2>
|
|
<h4 id="app-version">Version: </h4>
|
|
<h4>Invidious Instance: <a id="host" target="_blank">None</a></h4>
|
|
|
|
<button onclick="PlayVideo()">Play Video</button>
|
|
<label for="video-id">Video ID:</label>
|
|
<input type="text" id="video-id" name="video-id" style="min-width:300px;">
|
|
|
|
<h4 id="logged-in">Logged In: </h4>
|
|
<button style="visibility: hidden" id="login-button" onclick="Login()">Login</button>
|
|
<button style="visibility: hidden" id="logout-button">Logout</button>
|
|
|
|
<h5>Instructions</h5>
|
|
<ul>
|
|
<li>Make sure you are logged in the Invidious instance before logging in on this page</li>
|
|
<li>If this is your first time using this invidious Instance, you might want to create an account</li>
|
|
<li>Once you are logged in to your current instance, click "Login" on this page, and authorize the token</li>
|
|
<li>Once logged in, this page should show "Logged In: true"</li>
|
|
<li>After login, the home page should refresh automatically. You should then be able to see your Subscription feed
|
|
and Playlists, if you have any.</li>
|
|
</ul>
|
|
<p>
|
|
This is a barebone page for now, stay tuned for a redesigned page!
|
|
</p>
|
|
<h5>Feedback is welcome over at: <a id="feedback-url" href="https://github.com/iBicha/playlet"
|
|
target="_blank">https://github.com/iBicha/playlet</a></h5>
|
|
|
|
<script>
|
|
function Login() {
|
|
if (!window.appState) {
|
|
alert("Error with login, please refresh the page.")
|
|
}
|
|
window.location = window.appState.invidious.auth_url
|
|
}
|
|
|
|
function PlayVideo() {
|
|
let v = document.getElementById('video-id').value
|
|
if (IsValidHttpUrl(v)) {
|
|
v = GetVideoId(v)
|
|
}
|
|
if (!v || v.length < 8) {
|
|
alert("Please set video id")
|
|
return
|
|
}
|
|
fetch(`/api/command/play?v=${v}`)
|
|
.catch(function (err) {
|
|
alert(err)
|
|
});
|
|
}
|
|
|
|
function CreateGithubIssueUrl() {
|
|
title = "[Feedback] Playlet"
|
|
body = `### Feedback
|
|
_insert feedback here_
|
|
|
|
#### App Info
|
|
\`\`\`
|
|
${JSON.stringify(window.appState.app, null, 2)}
|
|
\`\`\`
|
|
|
|
#### Device Info
|
|
\`\`\`
|
|
${JSON.stringify(window.appState.device, null, 2)}
|
|
\`\`\``;
|
|
return `https://github.com/iBicha/playlet/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
|
|
}
|
|
|
|
function IsValidHttpUrl(string) {
|
|
let url;
|
|
try {
|
|
url = new URL(string);
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
}
|
|
|
|
function GetVideoId(url) {
|
|
// Share/Short url
|
|
const YoutubeUrls = [
|
|
"https://youtu.be/",
|
|
"http://youtu.be/",
|
|
"https://www.youtu.be/",
|
|
"http://www.youtu.be/",
|
|
"https://youtube.com/shorts/",
|
|
"http://youtube.com/shorts/",
|
|
"https://www.youtube.com/shorts/",
|
|
"http://www.youtube.com/shorts/",
|
|
]
|
|
for (var i in YoutubeUrls) {
|
|
let youtubeUrl = YoutubeUrls[i];
|
|
if (url.startsWith(youtubeUrl)) {
|
|
url = url.replace(youtubeUrl, "")
|
|
if (url.includes("?")) {
|
|
url = url.substring(0, url.indexOf("?"))
|
|
}
|
|
return url
|
|
}
|
|
}
|
|
|
|
// regular url
|
|
url = new URL(url)
|
|
const urlSearchParams = new URLSearchParams(url.search);
|
|
return urlSearchParams.get('v')
|
|
}
|
|
|
|
function Initialize() {
|
|
fetch("/api/state")
|
|
.then(function (response) {
|
|
return response.json();
|
|
})
|
|
.then(function (appState) {
|
|
window.appState = appState
|
|
console.log(appState)
|
|
|
|
document.getElementById("app-version").innerText = `Version: ${appState.app.version}`
|
|
document.getElementById("logged-in").innerText = `Logged In: ${appState.invidious.logged_in}`
|
|
document.getElementById("host").innerText = appState.invidious.host
|
|
document.getElementById("host").href = appState.invidious.host
|
|
|
|
document.getElementById("login-button").style.visibility = appState.invidious.logged_in ? "hidden" : "visible";
|
|
// TODO: log out feature
|
|
// document.getElementById("logout-button").style.visibility = appState.invidious.logged_in ? "hidden" : "visible";
|
|
|
|
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
|
})
|
|
.catch(function (err) {
|
|
alert(err)
|
|
});
|
|
}
|
|
|
|
function OnDrop(event) {
|
|
for (var i in event.dataTransfer.items) {
|
|
let item = event.dataTransfer.items[i]
|
|
if (item.kind = 'string' && item.getAsString) {
|
|
item.getAsString((dataString) => {
|
|
if (IsValidHttpUrl(dataString)) {
|
|
document.getElementById('video-id').value = dataString
|
|
}
|
|
});
|
|
}
|
|
}
|
|
event.preventDefault();
|
|
}
|
|
|
|
function OnDragover(event) {
|
|
event.preventDefault();
|
|
}
|
|
|
|
Initialize();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |