Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3fbe68db0 | ||
|
|
a248318c54 | ||
|
|
1d9dc3ecda | ||
|
|
740440c3a7 | ||
|
|
22dfe785f1 | ||
|
|
8aa1d1ae51 | ||
|
|
b113fcfe7e | ||
|
|
adfcfabad1 | ||
|
|
651bb54dee | ||
|
|
192eec9519 | ||
|
|
713d7fba5d | ||
|
|
cb0a5d0e17 | ||
|
|
b5f01a10e9 | ||
|
|
93e59fee65 | ||
|
|
069b8377d6 |
No files matched your search
@@ -3,3 +3,4 @@ out/
|
|||||||
node_modules
|
node_modules
|
||||||
.vscode/.env
|
.vscode/.env
|
||||||
**/roku_modules/**
|
**/roku_modules/**
|
||||||
|
release/playlet.zip
|
||||||
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.4.0] - 2022-11-24
|
||||||
|
### Added
|
||||||
|
- Play video API
|
||||||
|
- Play video by ID/URL in web app
|
||||||
|
- Metadata to Video Player
|
||||||
|
- Support for DASH and Live videos
|
||||||
|
- Log out button to web app
|
||||||
|
- Search Screen
|
||||||
|
- Very basic UI to customize/change invidious instance
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Bug where Settings page and home page are both visible, if settings page is selected, and user logs in.
|
||||||
|
|
||||||
## [0.3.0] - 2022-11-19
|
## [0.3.0] - 2022-11-19
|
||||||
### Changed
|
### Changed
|
||||||
- App name! new name: **Playlet**
|
- App name! new name: **Playlet**
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
# Playlet
|
# Playlet
|
||||||
Unofficial Youtube client for Roku.
|
Unofficial Youtube client for Roku 📺
|
||||||
|
|
||||||
|
<img src="screenshot.jpg" alt="Screenshot of Playlet" width="350"/>
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- No Ads (I guess that's a feature)
|
- 🔥 No Ads (Not now, not ever)
|
||||||
- Privacy driven (uses Invidious backend)
|
- 🕵️ No Tracking
|
||||||
- SponsorBlock integration (skips undesirable sections in videos)
|
- 🛡️ Privacy driven (uses Invidious backend)
|
||||||
|
- ⚔️ SponsorBlock integration (skips undesirable sections in videos)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -13,7 +17,7 @@ First, you need to enable developer mode on your Roku TV (if you have not done t
|
|||||||
|
|
||||||
Using your Roku remote, enter the following sequence:
|
Using your Roku remote, enter the following sequence:
|
||||||
|
|
||||||

|
<img src="https://image.roku.com/ZHZscHItMTc2/dev-startup1.png" alt="DevSequence" width="350"/>
|
||||||
|
|
||||||
For full instructions, see [Set up your Roku device to enable Developer Settings](https://developer.roku.com/en-ca/docs/developer-program/getting-started/developer-setup.md#step-1-set-up-your-roku-device-to-enable-developer-settings)
|
For full instructions, see [Set up your Roku device to enable Developer Settings](https://developer.roku.com/en-ca/docs/developer-program/getting-started/developer-setup.md#step-1-set-up-your-roku-device-to-enable-developer-settings)
|
||||||
|
|
||||||
@@ -63,3 +67,23 @@ ROKU_DEVPASSWORD=REPLACE_PASSWORD_HERE
|
|||||||
```
|
```
|
||||||
|
|
||||||
Then you can open the project using VS Code and deploy to your Roku TV using the Debug button.
|
Then you can open the project using VS Code and deploy to your Roku TV using the Debug button.
|
||||||
|
|
||||||
|
## Why Playlet
|
||||||
|
```
|
||||||
|
playlet - noun
|
||||||
|
play•let /ˈplālət/
|
||||||
|
: a short play
|
||||||
|
```
|
||||||
|
|
||||||
|
**Playlet** is about keeping the time you spend on Youtube short and useful. It values your time, so it does not show you ads, and allows you to skip sponsored sections and other irrelevant information that's designed to monitize you and/or waste your time.
|
||||||
|
|
||||||
|
There's a cliché about how a lot of open source software is **`"Made with ♡"`**. This project in particular is **not**.<br/>
|
||||||
|
**Playlet** was created out of **spite**, because I believe I have watched enough back-to-back, unskippable Youtube ads for a lifetime.
|
||||||
|
|
||||||
|
By removing all the bloat, the ads, the tracking, we could end up with an even faster app than the official one.
|
||||||
|
|
||||||
|
In any case, I hope you find **Playlet** useful, and pleasant to use.
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
**Playlet** does not serve or distribute any material from unauthorized sources.<br/>
|
||||||
|
**Playlet** is simply a frontend to other systems (such as https://github.com/iv-org/invidious), bringing the watching experience to the TV, as opposed to the existing frontends that are web and mobile focused.
|
||||||
+3
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet",
|
"name": "playlet",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"description": "Unofficial Youtube client for Roku",
|
"description": "Unofficial Youtube client for Roku",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
|
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
"prebuild": "rm -rf dist",
|
"prebuild": "rm -rf dist",
|
||||||
"build": "bsc",
|
"build": "bsc",
|
||||||
"build:prod": "npm run build -- --sourceMap=false",
|
"build:prod": "npm run build -- --sourceMap=false",
|
||||||
|
"build:release": "npm run format:fix && npm run lint:fix && npm run manifest-version && npm run generate-images && npm run build:prod && npm run zip-package",
|
||||||
"lint": "bslint --project config/bsconfig.lint.json --lintConfig config/bslint.jsonc",
|
"lint": "bslint --project config/bsconfig.lint.json --lintConfig config/bslint.jsonc",
|
||||||
"lint:fix": "npm run lint -- --fix",
|
"lint:fix": "npm run lint -- --fix",
|
||||||
"format:base": "bsfmt \"src/**/*.brs\" \"src/**/*.bs\" \"!src/components/lib/**/*\" \"!src/source/lib/**/*\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" --bsfmt-path \"config/bsfmt.jsonc\"",
|
"format:base": "bsfmt \"src/**/*.brs\" \"src/**/*.bs\" \"!src/components/lib/**/*\" \"!src/source/lib/**/*\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" --bsfmt-path \"config/bsfmt.jsonc\"",
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
"format:fix": "npm run format:base -- --write",
|
"format:fix": "npm run format:base -- --write",
|
||||||
"generate-images": "node scripts/generate-images.js",
|
"generate-images": "node scripts/generate-images.js",
|
||||||
"manifest-version": "node scripts/update-manifest-version.js",
|
"manifest-version": "node scripts/update-manifest-version.js",
|
||||||
|
"zip-package": "node scripts/zip-package.js",
|
||||||
"postinstall": "npx ropm copy"
|
"postinstall": "npx ropm copy"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 599 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
var rokuDeploy = require('roku-deploy');
|
||||||
|
|
||||||
|
const zip_name = 'playlet.zip'
|
||||||
|
|
||||||
|
rokuDeploy.zipPackage({
|
||||||
|
outDir: 'release',
|
||||||
|
outFile: zip_name,
|
||||||
|
//BUG: rokuDeploy does not read stagingFolderPath properly fron config
|
||||||
|
stagingFolderPath: 'dist/build'
|
||||||
|
}).then(function(){
|
||||||
|
console.log(`${zip_name} created`)
|
||||||
|
}, function(error) {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
@@ -5,6 +5,7 @@ function Init()
|
|||||||
m.rowList = m.top.FindNode("rowList")
|
m.rowList = m.top.FindNode("rowList")
|
||||||
m.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
m.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
||||||
m.top.ObserveField("focus", "OnFocusChange")
|
m.top.ObserveField("focus", "OnFocusChange")
|
||||||
|
m.top.ObserveField("playvideo", "OnPlayVideoCommand")
|
||||||
|
|
||||||
m.top.focus = true
|
m.top.focus = true
|
||||||
|
|
||||||
@@ -92,7 +93,6 @@ function StartFetchTask() as void
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnHomeGridScreenContentLoaded()
|
function OnHomeGridScreenContentLoaded()
|
||||||
m.top.SetFocus(true)
|
|
||||||
m.global.loadingIndicator.visible = false
|
m.global.loadingIndicator.visible = false
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ function OnHomeGridScreenVideoSelected(event as object) as void
|
|||||||
rowContent = grid.content.GetChild(selectedRow)
|
rowContent = grid.content.GetChild(selectedRow)
|
||||||
itemContent = rowContent.GetChild(selectedRowItem)
|
itemContent = rowContent.GetChild(selectedRowItem)
|
||||||
|
|
||||||
videoId = itemContent.id
|
videoId = itemContent.videoId
|
||||||
|
|
||||||
if m.videoPlayer <> invalid
|
if m.videoPlayer <> invalid
|
||||||
if m.videoPlayer.videoId = videoId
|
if m.videoPlayer.videoId = videoId
|
||||||
@@ -120,7 +120,7 @@ function OnHomeGridScreenVideoSelected(event as object) as void
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
ShowVideoScreenFull(videoId)
|
ShowVideoScreenFull(videoId, m.top)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function CloseVideo()
|
function CloseVideo()
|
||||||
@@ -132,12 +132,13 @@ function CloseVideo()
|
|||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function OnPlayVideoCommand()
|
||||||
|
videoId = m.top.playvideo
|
||||||
|
CloseVideo()
|
||||||
|
ShowVideoScreenFull(videoId, m.top)
|
||||||
|
end function
|
||||||
|
|
||||||
function OnHomeGridScreenVideoFocused(event as object) as void
|
function OnHomeGridScreenVideoFocused(event as object) as void
|
||||||
' Skip loading the video after first load
|
|
||||||
if m.firstFocus = invalid
|
|
||||||
m.firstFocus = true
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
if m.videoPlayer <> invalid
|
if m.videoPlayer <> invalid
|
||||||
m.videoPlayer.control = "stop"
|
m.videoPlayer.control = "stop"
|
||||||
m.videoPlayer.visible = false
|
m.videoPlayer.visible = false
|
||||||
@@ -153,7 +154,7 @@ function OnHomeGridScreenVideoFocused(event as object) as void
|
|||||||
rowContent = grid.content.GetChild(selectedRow)
|
rowContent = grid.content.GetChild(selectedRow)
|
||||||
itemContent = rowContent.GetChild(selectedRowItem)
|
itemContent = rowContent.GetChild(selectedRowItem)
|
||||||
|
|
||||||
videoId = itemContent.id
|
videoId = itemContent.videoId
|
||||||
thumbnail = GetThumbnailPoster(videoId)
|
thumbnail = GetThumbnailPoster(videoId)
|
||||||
ShowVideoScreenEmbedded(videoId, thumbnail)
|
ShowVideoScreenEmbedded(videoId, thumbnail)
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<field id="jumpToRowItem" type="intarray" alias="RowList.jumpToRowItem" />
|
<field id="jumpToRowItem" type="intarray" alias="RowList.jumpToRowItem" />
|
||||||
<field id="escape" type="string" alwaysNotify="true" />
|
<field id="escape" type="string" alwaysNotify="true" />
|
||||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||||
|
<field id="playvideo" type="string" alwaysNotify="true" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<RowList
|
<RowList
|
||||||
|
|||||||
@@ -56,27 +56,7 @@ function GetItemData(video as object) as object
|
|||||||
if video.videoId = invalid
|
if video.videoId = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
item = {}
|
|
||||||
|
|
||||||
item.title = video.title
|
return video
|
||||||
item.description = video.description
|
|
||||||
item.hdPosterURL = GetThumbnailUrl(video.videoThumbnails)
|
|
||||||
item.releaseDate = video.publishedText
|
|
||||||
item.id = video.videoId
|
|
||||||
item.length = video.lengthSeconds
|
|
||||||
item.author = video.author
|
|
||||||
item.viewCount = video.viewCount
|
|
||||||
return item
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetThumbnailUrl(videoThumbnails as object, quality = "medium" as string) as string
|
|
||||||
if videoThumbnails.Count() = 0
|
|
||||||
return ""
|
|
||||||
end if
|
|
||||||
for each thumbnail in videoThumbnails
|
|
||||||
if thumbnail.quality = quality
|
|
||||||
return thumbnail.url
|
|
||||||
end if
|
|
||||||
end for
|
|
||||||
return videoThumbnails[0].url
|
|
||||||
end function
|
|
||||||
@@ -15,7 +15,9 @@ function Init()
|
|||||||
m.homeGridScreen.SetFocus(true)
|
m.homeGridScreen.SetFocus(true)
|
||||||
|
|
||||||
m.settingsScreen = m.top.findNode("SettingsScreen")
|
m.settingsScreen = m.top.findNode("SettingsScreen")
|
||||||
|
|
||||||
m.searchScreen = m.top.findNode("SearchScreen")
|
m.searchScreen = m.top.findNode("SearchScreen")
|
||||||
|
m.searchScreen.ObserveField("escape", "OnSearchScreenEscape")
|
||||||
|
|
||||||
m.navBar = m.top.findNode("NavBar")
|
m.navBar = m.top.findNode("NavBar")
|
||||||
m.navBar.ObserveField("escapeIndex", "OnNavBarEscape")
|
m.navBar.ObserveField("escapeIndex", "OnNavBarEscape")
|
||||||
@@ -28,9 +30,15 @@ function InitWebServer()
|
|||||||
m.serverTask = createObject("roSGNode", "WebServerTask")
|
m.serverTask = createObject("roSGNode", "WebServerTask")
|
||||||
m.serverTask.id = "WebServerTask"
|
m.serverTask.id = "WebServerTask"
|
||||||
m.serverTask.ObserveField("login", "OnWebServerLogin")
|
m.serverTask.ObserveField("login", "OnWebServerLogin")
|
||||||
|
m.serverTask.ObserveField("command", "OnWebServerCommand")
|
||||||
m.serverTask.control = "RUN"
|
m.serverTask.control = "RUN"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function OnSearchScreenEscape()
|
||||||
|
m.navBar.SetFocus(true)
|
||||||
|
m.navBar.focusIndex = 0
|
||||||
|
end function
|
||||||
|
|
||||||
function OnHomeGridScreenEscape()
|
function OnHomeGridScreenEscape()
|
||||||
m.navBar.SetFocus(true)
|
m.navBar.SetFocus(true)
|
||||||
m.navBar.focusIndex = 1
|
m.navBar.focusIndex = 1
|
||||||
@@ -76,7 +84,31 @@ function OnWebServerLogin()
|
|||||||
m.homeGridScreen = newHomeGridScreen
|
m.homeGridScreen = newHomeGridScreen
|
||||||
m.homeGridScreen.id = "HomeGridScreen"
|
m.homeGridScreen.id = "HomeGridScreen"
|
||||||
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
||||||
m.homeGridScreen.SetFocus(true)
|
|
||||||
|
' Selecting home
|
||||||
|
m.navBar.focusIndex = -1
|
||||||
|
m.homeGridScreen.focus = true
|
||||||
|
|
||||||
|
m.searchScreen.visible = false
|
||||||
|
m.homeGridScreen.visible = true
|
||||||
|
m.settingsScreen.visible = false
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnWebServerCommand()
|
||||||
|
if m.serverTask.command.StartsWith("play:")
|
||||||
|
' Selecting home
|
||||||
|
m.navBar.focusIndex = -1
|
||||||
|
m.homeGridScreen.focus = true
|
||||||
|
|
||||||
|
m.searchScreen.visible = false
|
||||||
|
m.homeGridScreen.visible = true
|
||||||
|
m.settingsScreen.visible = false
|
||||||
|
' Trigger play video from home
|
||||||
|
' TODO: allow returning to current screen, instead of home
|
||||||
|
' BUG: if current video is playing in search screen, new video does not play
|
||||||
|
' TODO: Owner of video player needs to be independant
|
||||||
|
m.homeGridScreen.playvideo = m.serverTask.command.Mid(5)
|
||||||
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetIndexOfChild(parent as object, childId as string) as integer
|
function GetIndexOfChild(parent as object, childId as string) as integer
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ function onKeyEvent(key as string, press as boolean) as boolean
|
|||||||
m.top.focusIndex = target
|
m.top.focusIndex = target
|
||||||
return true
|
return true
|
||||||
else if key = "right"
|
else if key = "right"
|
||||||
' Can only escape to home screen, at index 1
|
' Can only escape to search screen or home screen
|
||||||
allowedEscapes = { "1": true }
|
allowedEscapes = { "0": true, "1": true }
|
||||||
if allowedEscapes[StrI(m.top.focusIndex).Trim()] = true
|
if allowedEscapes[StrI(m.top.focusIndex).Trim()] = true
|
||||||
m.top.escapeIndex = m.top.focusIndex
|
m.top.escapeIndex = m.top.focusIndex
|
||||||
m.top.focusIndex = -1
|
m.top.focusIndex = -1
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
function SaveSearchHistory(q as string, maxItems = 10 as integer)
|
||||||
|
history = RegistryUtils.Read("search_history")
|
||||||
|
if history <> invalid
|
||||||
|
history = ParseJson(history)
|
||||||
|
else
|
||||||
|
history = []
|
||||||
|
end if
|
||||||
|
|
||||||
|
index = ArrayIndexOf(history, q)
|
||||||
|
if index <> -1
|
||||||
|
history.Delete(index)
|
||||||
|
end if
|
||||||
|
|
||||||
|
history.Unshift(q)
|
||||||
|
|
||||||
|
if history.Count() > maxItems
|
||||||
|
history.Pop()
|
||||||
|
end if
|
||||||
|
|
||||||
|
history = FormatJson(history)
|
||||||
|
|
||||||
|
RegistryUtils.Write("search_history", history)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetSavedSearchHistory(q as string) as object
|
||||||
|
history = RegistryUtils.Read("search_history")
|
||||||
|
if history = invalid
|
||||||
|
return []
|
||||||
|
end if
|
||||||
|
history = ParseJson(history)
|
||||||
|
if q = ""
|
||||||
|
return history
|
||||||
|
end if
|
||||||
|
result = []
|
||||||
|
for each keyword in history
|
||||||
|
if keyword.InStr(q) = 0
|
||||||
|
result.push(keyword)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return result
|
||||||
|
end function
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
import "pkg:/source/roku_modules/rokupromise/Promise.brs"
|
||||||
|
import "pkg:/components/VideoPlayer/Video.bs"
|
||||||
|
import "pkg:/components/SearchScreen/SearchHistory.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.container = m.top.FindNode("container")
|
||||||
|
m.scrollAnimation = m.top.FindNode("scrollAnimation")
|
||||||
|
m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator")
|
||||||
|
m.keyboard = m.top.FindNode("keyboard")
|
||||||
|
m.suggestions = m.top.FindNode("suggestions")
|
||||||
|
m.rowList = m.top.FindNode("rowList")
|
||||||
|
|
||||||
|
m.keyboard.ObserveField("text", "OnTextChange")
|
||||||
|
m.suggestions.ObserveField("buttonSelected", "OnSearchButtonSelected")
|
||||||
|
m.rowList.ObserveField("rowItemSelected", "OnSearchVideoSelected")
|
||||||
|
m.top.ObserveField("focus", "OnFocusChange")
|
||||||
|
m.top.ObserveField("visible", "OnVisibilityChange")
|
||||||
|
|
||||||
|
' Trigger suggestions
|
||||||
|
OnTextChange()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusChange() as void
|
||||||
|
if m.top.focus = true
|
||||||
|
if m.rowlist.content <> invalid
|
||||||
|
m.rowlist.SetFocus(true)
|
||||||
|
ScrollDown()
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
if m.suggestions.buttons.Count() > 0
|
||||||
|
m.suggestions.SetFocus(true)
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.keyboard.SetFocus(true)
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnTextChange() as void
|
||||||
|
text = m.keyboard.text
|
||||||
|
|
||||||
|
createTaskPromise("SearchSuggestionsTask", {
|
||||||
|
input: {
|
||||||
|
q: text
|
||||||
|
}
|
||||||
|
}).then(function(task as object) as void
|
||||||
|
' In case this is an old request, discard suggestions
|
||||||
|
if task.output.q <> m.keyboard.text
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
suggestions = task.output.response
|
||||||
|
if suggestions <> invalid
|
||||||
|
' TODO: fix race condition where button group gains focus before suggestions are set
|
||||||
|
m.suggestions.buttons = suggestions
|
||||||
|
end if
|
||||||
|
end function)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSearchButtonSelected()
|
||||||
|
selected = m.suggestions.buttonSelected
|
||||||
|
text = m.suggestions.buttons[selected]
|
||||||
|
Search(text)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function Search(text as string)
|
||||||
|
SaveSearchHistory(text)
|
||||||
|
createTaskPromise("SearchTask", {
|
||||||
|
input: {
|
||||||
|
q: text
|
||||||
|
}
|
||||||
|
}).then(function(task as object) as void
|
||||||
|
rootChildren = task.output.rootChildren
|
||||||
|
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||||
|
contentNode.Update({
|
||||||
|
children: rootChildren
|
||||||
|
}, true)
|
||||||
|
m.rowList.content = contentNode
|
||||||
|
m.rowList.SetFocus(true)
|
||||||
|
m.rowList.jumpToRowItem = [0, 0]
|
||||||
|
ScrollDown()
|
||||||
|
end function)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnVisibilityChange()
|
||||||
|
if m.top.visible = false
|
||||||
|
ClearSearch()
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ClearSearch()
|
||||||
|
m.keyboard.text = ""
|
||||||
|
m.rowlist.content = invalid
|
||||||
|
ScrollUp()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function IsNodeFocused(id as string) as boolean
|
||||||
|
return m.top.focusedChild.id = id or m.container.focusedChild.id = id
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ScrollUp() as void
|
||||||
|
destination = m.scrollAnimationInterpolator.keyValue[0][1]
|
||||||
|
current = m.container.translation[1]
|
||||||
|
if current = destination
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.scrollAnimationInterpolator.reverse = true
|
||||||
|
m.scrollAnimation.control = "start"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ScrollDown() as void
|
||||||
|
destination = m.scrollAnimationInterpolator.keyValue[2][1]
|
||||||
|
current = m.container.translation[1]
|
||||||
|
if current = destination
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.scrollAnimationInterpolator.reverse = false
|
||||||
|
m.scrollAnimation.control = "start"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSearchVideoSelected(event as object)
|
||||||
|
grid = event.GetRoSGNode()
|
||||||
|
|
||||||
|
selectedPair = event.GetData()
|
||||||
|
selectedRow = selectedPair[0]
|
||||||
|
selectedRowItem = selectedPair[1]
|
||||||
|
|
||||||
|
rowContent = grid.content.GetChild(selectedRow)
|
||||||
|
itemContent = rowContent.GetChild(selectedRowItem)
|
||||||
|
|
||||||
|
videoId = itemContent.videoId
|
||||||
|
ShowVideoScreenFull(videoId, m.top)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
|
if press = false
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
if key = "back"
|
||||||
|
ScrollUp()
|
||||||
|
m.top.escape = key
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
if key = "left"
|
||||||
|
if IsNodeFocused("keyboard") and m.suggestions.buttons.Count() > 0
|
||||||
|
m.suggestions.SetFocus(true)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
ScrollUp()
|
||||||
|
m.top.escape = key
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
if key = "right"
|
||||||
|
if IsNodeFocused("suggestions")
|
||||||
|
m.keyboard.SetFocus(true)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
if key = "down"
|
||||||
|
if m.rowlist.content <> invalid
|
||||||
|
ScrollDown()
|
||||||
|
m.rowlist.SetFocus(true)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
if key = "up"
|
||||||
|
if IsNodeFocused("rowList")
|
||||||
|
ScrollUp()
|
||||||
|
m.suggestions.SetFocus(true)
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
return false
|
||||||
|
end function
|
||||||
@@ -1,15 +1,47 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<component name="SearchScreen" extends="Group">
|
<component name="SearchScreen" extends="Group">
|
||||||
|
<interface>
|
||||||
|
<field id="escape" type="string" alwaysNotify="true" />
|
||||||
|
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||||
|
</interface>
|
||||||
|
|
||||||
<children>
|
<children>
|
||||||
<Label
|
<Group id="container">
|
||||||
text="Search feature coming soon..."
|
<MiniKeyboard
|
||||||
width="1280"
|
id="keyboard"
|
||||||
height="720"
|
translation="[670,110]"
|
||||||
translation="[0, 0]"
|
|
||||||
horizAlign="center"
|
|
||||||
vertAlign="center"
|
|
||||||
font="font:MediumBoldSystemFont"
|
|
||||||
/>
|
/>
|
||||||
|
<ButtonGroup
|
||||||
|
id="suggestions"
|
||||||
|
maxWidth="450"
|
||||||
|
buttonHeight="50"
|
||||||
|
translation="[160,100]"
|
||||||
|
/>
|
||||||
|
<RowList
|
||||||
|
itemComponentName="VideoRowCell"
|
||||||
|
id="rowList"
|
||||||
|
translation="[0,620]"
|
||||||
|
numRows="1"
|
||||||
|
rowitemSize="[[350,196]]"
|
||||||
|
rowItemSpacing="[[25,0]]"
|
||||||
|
itemSize="[1280,326]"
|
||||||
|
itemSpacing="[0,65]"
|
||||||
|
rowLabelOffset="[[95,20]]"
|
||||||
|
focusXOffset="[95]"
|
||||||
|
showRowLabel="[true]"
|
||||||
|
rowFocusAnimationStyle="floatingfocus"
|
||||||
|
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||||
|
/>
|
||||||
|
<Animation
|
||||||
|
id="scrollAnimation"
|
||||||
|
duration="0.3">
|
||||||
|
<Vector2DFieldInterpolator
|
||||||
|
id="scrollAnimationInterpolator"
|
||||||
|
key="[ 0.0, 0.5, 1.0 ]"
|
||||||
|
keyValue="[ [0.0,0.0], [0.0,-160.0], [0.0,-320.0]]"
|
||||||
|
fieldToInterp="container.translation" />
|
||||||
|
</Animation>
|
||||||
|
</Group>
|
||||||
</children>
|
</children>
|
||||||
</component>
|
</component>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import "pkg:/source/services/Invidious.bs"
|
||||||
|
import "pkg:/components/SearchScreen/SearchHistory.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.top.functionName = "TaskMain"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function TaskMain()
|
||||||
|
input = m.top.getField("input")
|
||||||
|
q = input.q
|
||||||
|
|
||||||
|
searchSuggestsions = q <> "" ? Invidious.SearchSuggestions(q) : invalid
|
||||||
|
|
||||||
|
history = GetSavedSearchHistory(q)
|
||||||
|
|
||||||
|
if searchSuggestsions <> invalid
|
||||||
|
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.setField("output", {
|
||||||
|
q: q,
|
||||||
|
response: history
|
||||||
|
})
|
||||||
|
end function
|
||||||
|
|
||||||
|
function MergeSearchSuggestions(history as object, queryResults as object, maxItems = 10 as integer) as object
|
||||||
|
if queryResults = invalid
|
||||||
|
return history
|
||||||
|
end if
|
||||||
|
while history.Count() < maxItems and queryResults.Count() > 0
|
||||||
|
history.push(queryResults.shift())
|
||||||
|
end while
|
||||||
|
return history
|
||||||
|
end function
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<component name="SearchSuggestionsTask" extends="Task">
|
||||||
|
<interface>
|
||||||
|
<field id="input" type="assocarray" />
|
||||||
|
<field id="output" type="assocarray" />
|
||||||
|
</interface>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import "pkg:/source/services/Invidious.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.top.functionName = "TaskMain"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function TaskMain()
|
||||||
|
input = m.top.getField("input")
|
||||||
|
q = input.q
|
||||||
|
|
||||||
|
rootChildren = []
|
||||||
|
|
||||||
|
response = Invidious.Search(q, { type: "video" })
|
||||||
|
|
||||||
|
rowContent = GetCategoryContent(`Search - ${q}`, response)
|
||||||
|
if rowContent <> invalid
|
||||||
|
rootChildren.Push(rowContent)
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.setField("output", {
|
||||||
|
q: q,
|
||||||
|
rootChildren: rootChildren
|
||||||
|
})
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetCategoryContent(category as string, json as object) as object
|
||||||
|
if json <> invalid and json.Count() > 0
|
||||||
|
row = {}
|
||||||
|
row.title = category
|
||||||
|
row.children = []
|
||||||
|
for each item in json ' parse items and push them to row
|
||||||
|
itemData = GetItemData(item)
|
||||||
|
if itemData <> invalid
|
||||||
|
row.children.Push(itemData)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return row
|
||||||
|
end if
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetItemData(video as object) as object
|
||||||
|
' TODO: handle playlists and channels
|
||||||
|
if video.videoId = invalid
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
return video
|
||||||
|
end function
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<component name="SearchTask" extends="Task">
|
||||||
|
<interface>
|
||||||
|
<field id="input" type="assocarray" />
|
||||||
|
<field id="output" type="assocarray" />
|
||||||
|
</interface>
|
||||||
|
</component>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import "pkg:/source/utils/General.bs"
|
import "pkg:/source/utils/General.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.top.url = `http:/${GetLocalIpAddress()}:8888/index.html?tab=settings`
|
m.top.url = `http:/${GetLocalIpAddress()}:8888`
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnUrlSet()
|
function OnUrlSet()
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ function ShowVideoScreenEmbedded(videoId as string, thumbnailNode as object)
|
|||||||
ShowVideoScreen(videoId)
|
ShowVideoScreen(videoId)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ShowVideoScreenFull(videoId as string)
|
function ShowVideoScreenFull(videoId as string, sender as object)
|
||||||
m.videoPlayer = CreateObject("roSGNode", "VideoPlayer")
|
m.videoPlayer = CreateObject("roSGNode", "VideoPlayer")
|
||||||
|
m.videoPlayer.sender = sender
|
||||||
AddVideoFields()
|
AddVideoFields()
|
||||||
m.videoPlayer.embedded = false
|
m.videoPlayer.embedded = false
|
||||||
|
|
||||||
@@ -79,13 +80,17 @@ function OnVideoPlayerStateChange() as void
|
|||||||
' A hack to see if we could use the proxy here
|
' A hack to see if we could use the proxy here
|
||||||
if m.videoPlayingSuccess <> true
|
if m.videoPlayingSuccess <> true
|
||||||
errorInfo = m.videoPlayer.errorInfo
|
errorInfo = m.videoPlayer.errorInfo
|
||||||
if errorInfo.category = "http"
|
' http for stream format, mediaerror for DASH
|
||||||
videoId = m.videoPlayer.videoId
|
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
||||||
itag = m.videoPlayer.content.itag
|
|
||||||
url = m.videoPlayer.content.url
|
url = m.videoPlayer.content.url
|
||||||
if url.InStr("local=true") = -1
|
if url.InStr("local=true") = -1
|
||||||
print(`Video ${url} failed to play. Trying a proxy (local=true)`)
|
print(`Video ${url} failed to play. Trying a proxy (local=true)`)
|
||||||
m.videoPlayer.content.url = Invidious.GetVideoUrl(videoId, itag, true)
|
if url.InStr("?") = -1
|
||||||
|
url += "?local=true"
|
||||||
|
else
|
||||||
|
url += "&local=true"
|
||||||
|
end if
|
||||||
|
m.videoPlayer.content.url = url
|
||||||
' This video errored, and is about to finish, so don't close the video yet
|
' This video errored, and is about to finish, so don't close the video yet
|
||||||
' TODO: perhaps creating a second player is better?
|
' TODO: perhaps creating a second player is better?
|
||||||
m.videoPlayer.ignoreNextFinishedState = true
|
m.videoPlayer.ignoreNextFinishedState = true
|
||||||
@@ -123,10 +128,22 @@ function StartVideoDetailsTask(videoId as string)
|
|||||||
videoId = task.output.videoId
|
videoId = task.output.videoId
|
||||||
metadata = task.output.metadata
|
metadata = task.output.metadata
|
||||||
if metadata <> invalid
|
if metadata <> invalid
|
||||||
stream = metadata.formatStreams[metadata.formatStreams.Count() - 1]
|
|
||||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||||
contentNode.addFields({ videoId: videoId, itag: stream.itag })
|
contentNode.addFields({ videoId: videoId })
|
||||||
contentNode.url = stream.url
|
|
||||||
|
if metadata.hlsUrl <> invalid
|
||||||
|
contentNode.url = metadata.hlsUrl
|
||||||
|
else if metadata.dashUrl <> invalid
|
||||||
|
contentNode.url = metadata.dashUrl
|
||||||
|
else
|
||||||
|
stream = metadata.formatStreams[metadata.formatStreams.Count() - 1]
|
||||||
|
itag = stream.itag
|
||||||
|
' Use an url relative to the host, so we can proxy(local=true) in case it fails
|
||||||
|
contentNode.url = Invidious.GetVideoUrl(videoId, itag)
|
||||||
|
end if
|
||||||
|
|
||||||
|
contentNode.title = metadata.title
|
||||||
|
contentNode.secondaryTitle = metadata.author
|
||||||
SetCaptions(metadata, m.videoPlayer, contentNode)
|
SetCaptions(metadata, m.videoPlayer, contentNode)
|
||||||
m.videoPlayer.content = contentNode
|
m.videoPlayer.content = contentNode
|
||||||
m.videoPlayer.control = "play"
|
m.videoPlayer.control = "play"
|
||||||
@@ -174,13 +191,14 @@ function SetCaptions(metadata as object, videoPlayer as object, contentNode as o
|
|||||||
|
|
||||||
contentNode.SubtitleConfig = {
|
contentNode.SubtitleConfig = {
|
||||||
ShowSubtitle: 1,
|
ShowSubtitle: 1,
|
||||||
TrackName: Invidious.GetCurrentHost() + selectedCaption.url
|
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
function OnPositionChangeSkipSponsorBlockSections() as void
|
||||||
segments = m.videoPlayer.skipSegments
|
segments = m.videoPlayer.skipSegments
|
||||||
for each segment in segments
|
for each segment in segments
|
||||||
|
' TODO: handle other action types
|
||||||
if segment["actionType"] = "skip"
|
if segment["actionType"] = "skip"
|
||||||
segmentRange = segment["segment"]
|
segmentRange = segment["segment"]
|
||||||
segmentStart = segmentRange[0]
|
segmentStart = segmentRange[0]
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function CloseVideo()
|
function CloseVideo()
|
||||||
homeGridScreen = m.top.getParent().findNode("HomeGridScreen")
|
sender = m.top.sender
|
||||||
m.top.control = "stop"
|
m.top.control = "stop"
|
||||||
m.top.visible = false
|
m.top.visible = false
|
||||||
m.top.getParent().removeChild(m.videoPlayer)
|
m.top.getParent().removeChild(m.videoPlayer)
|
||||||
homeGridScreen.focus = true
|
sender.focus = true
|
||||||
end function
|
end function
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<component name="VideoPlayer" extends="Video">
|
<component name="VideoPlayer" extends="Video">
|
||||||
|
<interface>
|
||||||
|
<field id="sender" type="node" />
|
||||||
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -7,23 +7,51 @@ function OnContentSet()
|
|||||||
m.top.FindNode("titleLabel").text = content.title
|
m.top.FindNode("titleLabel").text = content.title
|
||||||
m.top.FindNode("authorLabel").text = content.author
|
m.top.FindNode("authorLabel").text = content.author
|
||||||
|
|
||||||
releaseDate = validstr(content.releaseDate)
|
publishedText = validstr(content.publishedText)
|
||||||
viewCount = FormatViewCount(content.viewCount)
|
viewCount = FormatViewCount(content.viewCount)
|
||||||
if releaseDate = "" and viewCount = ""
|
if publishedText = "" and viewCount = ""
|
||||||
m.top.FindNode("viewCountDateLabel").text = ""
|
m.top.FindNode("viewCountDateLabel").text = ""
|
||||||
else
|
else
|
||||||
m.top.FindNode("viewCountDateLabel").text = `${releaseDate} • ${viewCount}`
|
m.top.FindNode("viewCountDateLabel").text = `${publishedText} • ${viewCount}`
|
||||||
end if
|
end if
|
||||||
|
|
||||||
thumbnail = m.top.FindNode("thumbnail")
|
thumbnail = m.top.FindNode("thumbnail")
|
||||||
thumbnail.uri = content.hdPosterUrl
|
thumbnail.uri = GetThumbnailUrl(content.videoThumbnails)
|
||||||
thumbnail.id = `thumbnail-${content.id}`
|
thumbnail.id = `thumbnail-${content.videoId}`
|
||||||
if content.length <> invalid and content.length <> 0
|
|
||||||
m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.length)
|
if IsVideoLive(content)
|
||||||
|
m.top.FindNode("liveRect").visible = true
|
||||||
|
m.top.FindNode("durationRect").visible = false
|
||||||
|
else
|
||||||
|
m.top.FindNode("liveRect").visible = false
|
||||||
|
if content.lengthSeconds <> invalid and content.lengthSeconds <> 0
|
||||||
|
m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.lengthSeconds)
|
||||||
|
m.top.FindNode("durationRect").visible = true
|
||||||
else
|
else
|
||||||
m.top.FindNode("durationRect").visible = false
|
m.top.FindNode("durationRect").visible = false
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetThumbnailUrl(videoThumbnails as object, quality = "medium" as string) as string
|
||||||
|
if videoThumbnails.Count() = 0
|
||||||
|
return ""
|
||||||
|
end if
|
||||||
|
for each thumbnail in videoThumbnails
|
||||||
|
if thumbnail.quality = quality
|
||||||
|
return thumbnail.url
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return videoThumbnails[0].url
|
||||||
|
end function
|
||||||
|
|
||||||
|
function IsVideoLive(metadata as object) as boolean
|
||||||
|
if metadata.liveNow = true
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
' TODO: metadata.liveNow is returning false for live videos...
|
||||||
|
return metadata.lengthSeconds = 0 and metadata.viewCount = 0
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function FormatViewCount(viewCount as dynamic) as string
|
function FormatViewCount(viewCount as dynamic) as string
|
||||||
|
|||||||
@@ -32,6 +32,24 @@
|
|||||||
inheritParentOpacity="true"
|
inheritParentOpacity="true"
|
||||||
/>
|
/>
|
||||||
</Rectangle>
|
</Rectangle>
|
||||||
|
<Rectangle
|
||||||
|
id="liveRect"
|
||||||
|
width="60"
|
||||||
|
height="25"
|
||||||
|
color="0xFF0000"
|
||||||
|
translation="[290, 162]"
|
||||||
|
>
|
||||||
|
<Label
|
||||||
|
width="60"
|
||||||
|
height="25"
|
||||||
|
id="liveLabel"
|
||||||
|
horizAlign="center"
|
||||||
|
vertAlign="center"
|
||||||
|
font="font:SmallestBoldSystemFont"
|
||||||
|
inheritParentOpacity="true"
|
||||||
|
text="LIVE"
|
||||||
|
/>
|
||||||
|
</Rectangle>
|
||||||
</Poster>
|
</Poster>
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ namespace Http
|
|||||||
m.source = Http.HttpResponseSource.GENERATED
|
m.source = Http.HttpResponseSource.GENERATED
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Redirect(where as string)
|
function Redirect(where as string, code = 301 as integer)
|
||||||
m.location = where
|
m.location = where
|
||||||
message = "Moved to: <a href=" + Quote() + where + Quote() + ">" + where + "</a>"
|
message = "Moved to: <a href=" + Quote() + where + Quote() + ">" + where + "</a>"
|
||||||
m.Default(301, message)
|
m.Default(code, message)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Json(data as object)
|
function Json(data as object)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Http
|
|||||||
PackageName = "Playlet"
|
PackageName = "Playlet"
|
||||||
Port = 8888
|
Port = 8888
|
||||||
MessagePort = invalid
|
MessagePort = invalid
|
||||||
MaxConnections = 3
|
MaxConnections = 10
|
||||||
Timeout = 60 * 1000
|
Timeout = 60 * 1000
|
||||||
MaxRequestLength = 4000
|
MaxRequestLength = 4000
|
||||||
Idletime = 60
|
Idletime = 60
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
namespace Http
|
||||||
|
|
||||||
|
class CommandsApiRouter extends HttpRouter
|
||||||
|
|
||||||
|
function new()
|
||||||
|
super()
|
||||||
|
|
||||||
|
m.Get("/api/command/logout", function(context as object) as boolean
|
||||||
|
response = context.response
|
||||||
|
server = context.server
|
||||||
|
|
||||||
|
if Invidious.Logout()
|
||||||
|
server.task.top.login = false
|
||||||
|
end if
|
||||||
|
|
||||||
|
response.Default(204, "OK")
|
||||||
|
return true
|
||||||
|
end function)
|
||||||
|
|
||||||
|
m.Get("*", function(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
server = context.server
|
||||||
|
|
||||||
|
route = request.uri
|
||||||
|
|
||||||
|
if route.StartsWith("/api/command/play")
|
||||||
|
components = WebUtils.UrlQueryComponents(route)
|
||||||
|
if components["v"] = invalid
|
||||||
|
response.Default(400, "Missing arg 'v'")
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
server.task.top.command = `play:${components["v"]}`
|
||||||
|
if components["redirect"] = "true"
|
||||||
|
' 302 to prevent redirection to current host permanently
|
||||||
|
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${components["v"]}`, 302)
|
||||||
|
else
|
||||||
|
response.Default(204, "OK")
|
||||||
|
end if
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
return false
|
||||||
|
end function)
|
||||||
|
end function
|
||||||
|
|
||||||
|
end class
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -10,12 +10,12 @@ namespace Http
|
|||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
method = request.method
|
method = request.method
|
||||||
route = request.uri
|
uri = request.uri
|
||||||
|
|
||||||
if method = ""
|
if method = ""
|
||||||
response.Default(400, "You sent a request that the server couldn't understand.")
|
response.Default(400, "You sent a request that the server couldn't understand.")
|
||||||
else
|
else
|
||||||
response.Default(404, `Cannot ${method} ${route}`)
|
response.Default(404, `Cannot ${method} ${uri}`)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -5,25 +5,57 @@ namespace Http
|
|||||||
function new()
|
function new()
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
' TODO: use POST once supported
|
||||||
|
m.Get("*", function(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
route = request.uri
|
||||||
|
if not route.StartsWith("/invidious/set-instances")
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
|
||||||
|
components = WebUtils.UrlQueryComponents(route)
|
||||||
|
|
||||||
|
instances = []
|
||||||
|
if components.DoesExist("instances")
|
||||||
|
instances = components["instances"]
|
||||||
|
if GetInterface(instances, "ifArray") = invalid
|
||||||
|
instances = [instances]
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
for i = 0 to instances.Count() - 1
|
||||||
|
if instances[i].right(1) = "/"
|
||||||
|
instances[i] = instances[i].left(instances[i].len() - 1)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
InvidiousSettings.SetRegistryInstances(instances)
|
||||||
|
response.Default(200, "OK")
|
||||||
|
return true
|
||||||
|
end function)
|
||||||
|
|
||||||
m.Get("*", function(context as object) as boolean
|
m.Get("*", function(context as object) as boolean
|
||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
server = context.server
|
server = context.server
|
||||||
|
|
||||||
uri = request.uri
|
route = request.uri
|
||||||
if uri.StartsWith(Invidious.TOKEN_CALLBACK)
|
if not route.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||||
components = WebUtils.UrlQueryComponents(uri)
|
return false
|
||||||
if components["token"] <> invalid
|
end if
|
||||||
|
|
||||||
|
components = WebUtils.UrlQueryComponents(route)
|
||||||
|
if components["token"] <> invalid and components["referer"] <> invalid
|
||||||
' Token is encoded twice for some reason
|
' Token is encoded twice for some reason
|
||||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||||
print(`Got Token: ${token}`)
|
referer = WebUtils.UrlUnescape(components["referer"])
|
||||||
RegistryUtils.Write("invidious_token", token)
|
InvidiousSettings.SetAuthToken(token, referer)
|
||||||
server.task.top.login = true
|
server.task.top.login = true
|
||||||
end if
|
end if
|
||||||
response.Redirect("/index.html?tab=settings")
|
response.Redirect("/", 302)
|
||||||
return true
|
return true
|
||||||
end if
|
|
||||||
return false
|
|
||||||
end function)
|
end function)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -8,18 +8,47 @@ namespace Http
|
|||||||
function new()
|
function new()
|
||||||
super()
|
super()
|
||||||
|
|
||||||
m.Get("/api/state", function(context as object) as boolean
|
m.Get("*", function(context as object) as boolean
|
||||||
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
state = {
|
route = request.uri
|
||||||
app: GetAppInfo(),
|
' TODO: this is not the right filtering. /api/state/something will go through, which is not correct
|
||||||
device: GetDeviceInfo(),
|
if not route.StartsWith("/api/state")
|
||||||
invidious: {
|
return false
|
||||||
host: Invidious.GetCurrentHost(),
|
end if
|
||||||
|
|
||||||
|
keys = ["app", "device", "invidious"]
|
||||||
|
|
||||||
|
components = WebUtils.UrlQueryComponents(route)
|
||||||
|
if components.DoesExist("key")
|
||||||
|
keys = components["key"]
|
||||||
|
if GetInterface(keys, "ifArray") = invalid
|
||||||
|
keys = [keys]
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
state = {}
|
||||||
|
|
||||||
|
if ArrayIndexOf(keys, "app") <> -1
|
||||||
|
state["app"] = GetAppInfo()
|
||||||
|
end if
|
||||||
|
|
||||||
|
if ArrayIndexOf(keys, "device") <> -1
|
||||||
|
state["device"] = GetDeviceInfo()
|
||||||
|
end if
|
||||||
|
|
||||||
|
if ArrayIndexOf(keys, "invidious") <> -1
|
||||||
|
authToken = InvidiousSettings.GetAuthToken()
|
||||||
|
state["invidious"] = {
|
||||||
|
instances: InvidiousSettings.GetCurrentInstances(),
|
||||||
|
selected_instance: InvidiousSettings.GetSelectedInstance(),
|
||||||
auth_url: Invidious.GetAuthorizeTokenLink(),
|
auth_url: Invidious.GetAuthorizeTokenLink(),
|
||||||
logged_in: Invidious.GetAuthenticationHeaders() <> invalid
|
logged_in: authToken <> invalid,
|
||||||
}
|
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
||||||
}
|
}
|
||||||
|
end if
|
||||||
|
|
||||||
response.Json(state)
|
response.Json(state)
|
||||||
return true
|
return true
|
||||||
end function)
|
end function)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import "pkg:/components/WebServer/Middleware/HttpDefaultRouter.bs"
|
|||||||
import "pkg:/components/WebServer/Middleware/InvidiousRouter.bs"
|
import "pkg:/components/WebServer/Middleware/InvidiousRouter.bs"
|
||||||
import "pkg:/components/WebServer/Middleware/RegistryApiRouter.bs"
|
import "pkg:/components/WebServer/Middleware/RegistryApiRouter.bs"
|
||||||
import "pkg:/components/WebServer/Middleware/StateApiRouter.bs"
|
import "pkg:/components/WebServer/Middleware/StateApiRouter.bs"
|
||||||
|
import "pkg:/components/WebServer/Middleware/CommandsApiRouter.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.top.functionName = "WebServerLoop"
|
m.top.functionName = "WebServerLoop"
|
||||||
@@ -16,8 +17,18 @@ function WebServerLoop()
|
|||||||
m.settings = new Http.HttpSettings(m.webServerPort)
|
m.settings = new Http.HttpSettings(m.webServerPort)
|
||||||
' Root at www to get http://IP_ADDRESS:PORT/index.html
|
' Root at www to get http://IP_ADDRESS:PORT/index.html
|
||||||
m.settings.WwwRoot = "pkg:/www"
|
m.settings.WwwRoot = "pkg:/www"
|
||||||
|
m.settings.Timeout = 5000
|
||||||
m.server = new Http.HttpServer(m.settings, m)
|
m.server = new Http.HttpServer(m.settings, m)
|
||||||
|
|
||||||
|
homeRouter = new Http.HttpRouter()
|
||||||
|
homeRouter.Get("/", function(context as object) as boolean
|
||||||
|
response = context.response
|
||||||
|
response.Redirect("/index.html?tab=settings", 302)
|
||||||
|
return true
|
||||||
|
end function)
|
||||||
|
|
||||||
|
m.server.UseRouter(homeRouter)
|
||||||
|
m.server.UseRouter(new Http.CommandsApiRouter())
|
||||||
m.server.UseRouter(new Http.StateApiRouter())
|
m.server.UseRouter(new Http.StateApiRouter())
|
||||||
m.server.UseRouter(new Http.RegistryApiRouter())
|
m.server.UseRouter(new Http.RegistryApiRouter())
|
||||||
m.server.UseRouter(new Http.InvidiousRouter())
|
m.server.UseRouter(new Http.InvidiousRouter())
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
<component name="WebServerTask" extends="Task">
|
<component name="WebServerTask" extends="Task">
|
||||||
<interface>
|
<interface>
|
||||||
<field id="login" type="boolean" alwaysNotify="true" />
|
<field id="login" type="boolean" alwaysNotify="true" />
|
||||||
|
<field id="command" type="string" alwaysNotify="true" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import "pkg:/source/services/Invidious.bs"
|
|
||||||
|
|
||||||
sub init()
|
|
||||||
m.instructions = m.top.findNode("instructions")
|
|
||||||
|
|
||||||
text = "- Scan the QR Code" + chr(10)
|
|
||||||
text += "- Login (Create account if needed)" + chr(10)
|
|
||||||
text += "- Scan the QR Code again" + chr(10)
|
|
||||||
text += "- Click ""Authorize""" + chr(10)
|
|
||||||
text += "- If the error ""Invalid signature"" shows, press back and ""Authorize"" again" + chr(10)
|
|
||||||
text += "- Your TV should go to home screen automatically" + chr(10)
|
|
||||||
text += chr(10) + chr(10) + chr(10)
|
|
||||||
text += "Invidious instance: " + Invidious.GetCurrentHost()
|
|
||||||
|
|
||||||
m.instructions.text = text
|
|
||||||
end sub
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<component
|
|
||||||
name='QRTestScene'
|
|
||||||
extends='Scene'>
|
|
||||||
<children>
|
|
||||||
<!-- This is example use of QRPoster: show QRCode centered on screen -->
|
|
||||||
<QRPoster
|
|
||||||
id='TestQRPoster'
|
|
||||||
loadWidth='500'
|
|
||||||
loadHeight='500'
|
|
||||||
loadPadding='20'
|
|
||||||
translation='[100, 110]' />
|
|
||||||
<Label
|
|
||||||
id='instructionsTitle'
|
|
||||||
height='50'
|
|
||||||
width='500'
|
|
||||||
text='Instructions'
|
|
||||||
font='font:MediumBoldSystemFont'
|
|
||||||
wrap='true'
|
|
||||||
translation='[650,110]' />
|
|
||||||
<Label
|
|
||||||
id='instructions'
|
|
||||||
height='500'
|
|
||||||
width='500'
|
|
||||||
font='font:MediumSystemFont'
|
|
||||||
wrap='true'
|
|
||||||
translation='[650,160]' />
|
|
||||||
</children>
|
|
||||||
|
|
||||||
</component>
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@ title=Playlet
|
|||||||
|
|
||||||
# Do not update version manually, it is auto updated from package.json
|
# Do not update version manually, it is auto updated from package.json
|
||||||
major_version=0
|
major_version=0
|
||||||
minor_version=3
|
minor_version=4
|
||||||
build_version=00000
|
build_version=00000
|
||||||
|
|
||||||
## Channel Assets
|
## Channel Assets
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import "pkg:/source/utils/StringUtils.bs"
|
|||||||
import "pkg:/source/utils/General.bs"
|
import "pkg:/source/utils/General.bs"
|
||||||
import "pkg:/source/utils/TimeUtils.bs"
|
import "pkg:/source/utils/TimeUtils.bs"
|
||||||
import "pkg:/source/utils/WebUtils.bs"
|
import "pkg:/source/utils/WebUtils.bs"
|
||||||
|
import "pkg:/source/services/InvidiousSettings.bs"
|
||||||
|
|
||||||
namespace Invidious
|
namespace Invidious
|
||||||
const API_URL = "https://vid.puffyan.us"
|
' TODO: query server status, check if it supports APIs and/or signups
|
||||||
|
|
||||||
const TOKEN_CALLBACK = "/invidious/token_callback"
|
const TOKEN_CALLBACK = "/invidious/token_callback"
|
||||||
|
|
||||||
const POPULAR_ENDPOINT = "/api/v1/popular"
|
const POPULAR_ENDPOINT = "/api/v1/popular"
|
||||||
@@ -18,9 +18,10 @@ namespace Invidious
|
|||||||
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
||||||
const SEARCH_ENDPOINT = "/api/v1/search"
|
const SEARCH_ENDPOINT = "/api/v1/search"
|
||||||
|
|
||||||
const AUTH_SCOPE = "GET:feed,GET:playlists"
|
const AUTH_SCOPE = "GET:feed,GET:playlists,POST:tokens/unregister"
|
||||||
const AUTH_FEED = "/api/v1/auth/feed"
|
const AUTH_FEED = "/api/v1/auth/feed"
|
||||||
const AUTH_PLAYLISTS = "/api/v1/auth/playlists"
|
const AUTH_PLAYLISTS = "/api/v1/auth/playlists"
|
||||||
|
const AUTH_TOKENS_UNREGISTER = "/api/v1/auth/tokens/unregister"
|
||||||
|
|
||||||
function DefaultArgs() as object
|
function DefaultArgs() as object
|
||||||
return {
|
return {
|
||||||
@@ -31,7 +32,8 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetPopular() as object
|
function GetPopular() as object
|
||||||
url = `${Invidious.API_URL}${Invidious.POPULAR_ENDPOINT}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}${Invidious.POPULAR_ENDPOINT}`
|
||||||
|
|
||||||
args = Invidious.DefaultArgs()
|
args = Invidious.DefaultArgs()
|
||||||
response = Requests().get(url, args)
|
response = Requests().get(url, args)
|
||||||
@@ -43,7 +45,8 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetTrending(trendingType = "" as string) as object
|
function GetTrending(trendingType = "" as string) as object
|
||||||
url = `${Invidious.API_URL}${Invidious.TRENDING_ENDPOINT}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}${Invidious.TRENDING_ENDPOINT}`
|
||||||
|
|
||||||
args = Invidious.DefaultArgs()
|
args = Invidious.DefaultArgs()
|
||||||
if trendingType <> ""
|
if trendingType <> ""
|
||||||
@@ -59,7 +62,8 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetVideoUrl(videoId as string, itag as string, local as boolean) as string
|
function GetVideoUrl(videoId as string, itag as string, local as boolean) as string
|
||||||
url = `${Invidious.API_URL}/latest_version?id=${videoId}&itag=${itag}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}/latest_version?id=${videoId}&itag=${itag}`
|
||||||
if local
|
if local
|
||||||
url = url + "&local=true"
|
url = url + "&local=true"
|
||||||
end if
|
end if
|
||||||
@@ -67,31 +71,22 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetVideoMetadata(videoId as string) as object
|
function GetVideoMetadata(videoId as string) as object
|
||||||
url = `${Invidious.API_URL}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||||
|
|
||||||
args = Invidious.DefaultArgs()
|
args = Invidious.DefaultArgs()
|
||||||
response = Requests().get(url, args)
|
response = Requests().get(url, args)
|
||||||
|
|
||||||
' TODO: handle 500 {"error":"This video is unavailable"}
|
' TODO: handle 500 {"error":"This video is unavailable"}
|
||||||
if response.statuscode = 200
|
if response.statuscode = 200
|
||||||
videoMetadata = response.json
|
return response.json
|
||||||
lastItag = videoMetadata.formatStreams[videoMetadata.formatStreams.Count() - 1].itag
|
|
||||||
|
|
||||||
' GetVideoUrl returns a url that redirects to the video stream
|
|
||||||
' TODO: is this reliable?
|
|
||||||
videoUrl = Invidious.GetVideoUrl(videoId, lastItag, false)
|
|
||||||
|
|
||||||
videoMetadata.formatStreams.push({
|
|
||||||
itag: lastItag,
|
|
||||||
url: videoUrl
|
|
||||||
})
|
|
||||||
return videoMetadata
|
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function SearchSuggestions(q as string) as object 'SearchSuggestionResult
|
function SearchSuggestions(q as string) as object 'SearchSuggestionResult
|
||||||
url = `${Invidious.API_URL}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||||
|
|
||||||
args = Invidious.DefaultArgs()
|
args = Invidious.DefaultArgs()
|
||||||
args.params.q = q
|
args.params.q = q
|
||||||
@@ -104,7 +99,8 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function Search(q as string, args = invalid as dynamic) as object
|
function Search(q as string, args = invalid as dynamic) as object
|
||||||
url = `${Invidious.API_URL}${Invidious.SEARCH_ENDPOINT}`
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
url = `${instance}${Invidious.SEARCH_ENDPOINT}`
|
||||||
|
|
||||||
_args = Invidious.DefaultArgs()
|
_args = Invidious.DefaultArgs()
|
||||||
_args.params.q = q
|
_args.params.q = q
|
||||||
@@ -137,39 +133,33 @@ namespace Invidious
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetCurrentHost() as string
|
|
||||||
return Invidious.API_URL
|
|
||||||
end function
|
|
||||||
|
|
||||||
function GetAuthorizeTokenLink() as string
|
function GetAuthorizeTokenLink() as string
|
||||||
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
||||||
invidiousHost = `${Invidious.API_URL}`.Replace("https://", "http://")
|
invidiousHost = instance.Replace("https://", "http://")
|
||||||
|
|
||||||
localIp = GetLocalIpAddress()
|
localIp = GetLocalIpAddress()
|
||||||
webServerPort = 8888
|
webServerPort = 8888
|
||||||
expire = TimeUtils.Now().AsSeconds() + 60 * 60 * 24 * 30 'A month from now
|
expire = TimeUtils.Now().AsSeconds() + 60 * 60 * 24 * 30 'A month from now
|
||||||
|
|
||||||
callbackUrl = WebUtils.UrlEncode(`http://${localIp}:${webServerPort}${Invidious.TOKEN_CALLBACK}`)
|
callbackUrl = WebUtils.UrlEncode(`http://${localIp}:${webServerPort}${Invidious.TOKEN_CALLBACK}?referer=${instance}`)
|
||||||
return `${invidiousHost}/authorize_token?scopes=${Invidious.AUTH_SCOPE}&callback_url=${callbackUrl}&expire=${expire}`
|
return `${invidiousHost}/authorize_token?scopes=${Invidious.AUTH_SCOPE}&callback_url=${callbackUrl}&expire=${expire}`
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAuthenticationHeaders() as object
|
function GetAuthenticationHeaders(token as string) as object
|
||||||
token = RegistryUtils.Read("invidious_token")
|
|
||||||
if token = invalid
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
return {
|
return {
|
||||||
"Authorization": `Bearer ${token}`
|
"Authorization": `Bearer ${token}`
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetUserFeed() as object
|
function GetUserFeed() as object
|
||||||
headers = Invidious.GetAuthenticationHeaders()
|
authToken = InvidiousSettings.GetAuthToken()
|
||||||
if headers = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return false
|
||||||
end if
|
end if
|
||||||
|
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||||
|
|
||||||
url = `${Invidious.API_URL}${Invidious.AUTH_FEED}`
|
url = `${authToken.instance}${Invidious.AUTH_FEED}`
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@@ -179,7 +169,7 @@ namespace Invidious
|
|||||||
response = Requests().get(url, args)
|
response = Requests().get(url, args)
|
||||||
|
|
||||||
if response.statuscode = 403
|
if response.statuscode = 403
|
||||||
RegistryUtils.Delete("invidious_token")
|
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
end if
|
end if
|
||||||
if response.statuscode = 200
|
if response.statuscode = 200
|
||||||
return response.json.videos
|
return response.json.videos
|
||||||
@@ -188,12 +178,13 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function GetUserPlaylists() as object
|
function GetUserPlaylists() as object
|
||||||
headers = Invidious.GetAuthenticationHeaders()
|
authToken = InvidiousSettings.GetAuthToken()
|
||||||
if headers = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return false
|
||||||
end if
|
end if
|
||||||
|
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||||
|
|
||||||
url = `${Invidious.API_URL}${Invidious.AUTH_PLAYLISTS}`
|
url = `${authToken.instance}${Invidious.AUTH_PLAYLISTS}`
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@@ -203,11 +194,33 @@ namespace Invidious
|
|||||||
response = Requests().get(url, args)
|
response = Requests().get(url, args)
|
||||||
|
|
||||||
if response.statuscode = 403
|
if response.statuscode = 403
|
||||||
RegistryUtils.Delete("invidious_token")
|
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
end if
|
end if
|
||||||
if response.statuscode = 200
|
if response.statuscode = 200
|
||||||
return response.json
|
return response.json
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function Logout() as boolean
|
||||||
|
authToken = InvidiousSettings.GetAuthToken()
|
||||||
|
if authToken = invalid
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||||
|
|
||||||
|
url = `${authToken.instance}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||||
|
|
||||||
|
' authToken.token is already valid json that contains the "session" key needed by the unregister endpoint
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
args = {
|
||||||
|
headers: headers,
|
||||||
|
data: authToken.token
|
||||||
|
}
|
||||||
|
|
||||||
|
Requests().post(url, args)
|
||||||
|
|
||||||
|
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
|
return true
|
||||||
|
end function
|
||||||
end namespace
|
end namespace
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||||
import "pkg:/source/utils/RegistryUtils.bs"
|
import "pkg:/source/utils/RegistryUtils.bs"
|
||||||
import "pkg:/source/utils/General.bs"
|
import "pkg:/source/utils/General.bs"
|
||||||
|
import "pkg:/source/services/InvidiousSettings.bs"
|
||||||
|
|
||||||
class InvidiousService
|
class InvidiousService
|
||||||
API_URL = "https://vid.puffyan.us"
|
|
||||||
|
|
||||||
private endpoints
|
private endpoints
|
||||||
private responseHanlders
|
private responseHanlders
|
||||||
|
|
||||||
@@ -29,16 +28,19 @@ class InvidiousService
|
|||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
|
|
||||||
url = m.API_URL + endpoint.url
|
instance = InvidiousSettings.GetSelectedInstance()
|
||||||
|
|
||||||
|
url = instance + endpoint.url
|
||||||
|
|
||||||
args = { params: {} }
|
args = { params: {} }
|
||||||
|
|
||||||
if endpoint.authenticated = true
|
if endpoint.authenticated = true
|
||||||
auth_headers = m.GetAuthenticationHeaders()
|
authToken = InvidiousSettings.GetAuthToken()
|
||||||
if auth_headers = invalid
|
if authToken = invalid
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
args.headers = auth_headers
|
url = authToken.instance + endpoint.url
|
||||||
|
args.headers = m.GetAuthenticationHeaders(authToken.token)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if endpoint.queryParams <> invalid
|
if endpoint.queryParams <> invalid
|
||||||
@@ -73,11 +75,7 @@ class InvidiousService
|
|||||||
return responseHandler(m, requestData, response)
|
return responseHandler(m, requestData, response)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetAuthenticationHeaders() as object
|
function GetAuthenticationHeaders(token as string) as object
|
||||||
token = RegistryUtils.Read("invidious_token")
|
|
||||||
if token = invalid
|
|
||||||
return invalid
|
|
||||||
end if
|
|
||||||
return {
|
return {
|
||||||
"Authorization": `Bearer ${token}`
|
"Authorization": `Bearer ${token}`
|
||||||
}
|
}
|
||||||
@@ -118,7 +116,7 @@ class InvidiousService
|
|||||||
if response.statuscode = 403
|
if response.statuscode = 403
|
||||||
print(`Server responded with 403: ${response.text}`)
|
print(`Server responded with 403: ${response.text}`)
|
||||||
print("deleting token...")
|
print("deleting token...")
|
||||||
RegistryUtils.Delete("invidious_token")
|
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
namespace InvidiousSettings
|
||||||
|
|
||||||
|
const DEFAULT_INSTANCE = "https://vid.puffyan.us"
|
||||||
|
|
||||||
|
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,health,users,api"
|
||||||
|
|
||||||
|
function GetCurrentInstances() as object
|
||||||
|
' TODO: cache this call to avoid json parsing every time
|
||||||
|
instances = InvidiousSettings.GetRegistryInstances()
|
||||||
|
if instances.Count() > 0
|
||||||
|
return instances
|
||||||
|
end if
|
||||||
|
|
||||||
|
publicInstances = InvidiousSettings.GetPublicInstances()
|
||||||
|
if publicInstances <> invalid
|
||||||
|
for i = 0 to 4
|
||||||
|
if i < publicInstances.Count()
|
||||||
|
instances.push(publicInstances[i].uri)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
|
||||||
|
if instances.Count() > 0
|
||||||
|
InvidiousSettings.SetRegistryInstances(instances)
|
||||||
|
return instances
|
||||||
|
end if
|
||||||
|
|
||||||
|
return [InvidiousSettings.DEFAULT_INSTANCE]
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetSelectedInstance() as string
|
||||||
|
instances = InvidiousSettings.GetCurrentInstances()
|
||||||
|
return instances[0]
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SetAuthToken(token as string, instance as string)
|
||||||
|
json = FormatJson({
|
||||||
|
token: token,
|
||||||
|
instance: instance
|
||||||
|
})
|
||||||
|
RegistryUtils.Write(RegistryUtils.INVIDIOUS_TOKEN, json)
|
||||||
|
|
||||||
|
instances = InvidiousSettings.GetCurrentInstances()
|
||||||
|
index = ArrayIndexOf(instances, instance)
|
||||||
|
if index = -1
|
||||||
|
instances.push(instance)
|
||||||
|
InvidiousSettings.SetRegistryInstances(instances)
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetAuthToken() as dynamic
|
||||||
|
tokenPayload = RegistryUtils.Read(RegistryUtils.INVIDIOUS_TOKEN)
|
||||||
|
if tokenPayload = invalid
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
return ParseJson(tokenPayload)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetRegistryInstances() as object
|
||||||
|
instances = RegistryUtils.Read(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||||
|
if instances = invalid
|
||||||
|
return []
|
||||||
|
end if
|
||||||
|
return ParseJson(instances)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SetRegistryInstances(instances as object)
|
||||||
|
RegistryUtils.Write(RegistryUtils.INVIDIOUS_INSTANCES, FormatJson(instances))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetPublicInstances() as object
|
||||||
|
if m.invidiousPublicInstances <> invalid
|
||||||
|
return m.invidiousPublicInstances
|
||||||
|
end if
|
||||||
|
response = Requests().get(InvidiousSettings.INSTANCES_API)
|
||||||
|
if response.statuscode = 200
|
||||||
|
json = response.json
|
||||||
|
instances = []
|
||||||
|
|
||||||
|
for each instance in json
|
||||||
|
data = instance[1]
|
||||||
|
if data.monitor <> invalid and data.monitor.dailyRatios <> invalid
|
||||||
|
data.monitor.dailyRatios = invalid
|
||||||
|
end if
|
||||||
|
data["name"] = instance[0]
|
||||||
|
instances.push(data)
|
||||||
|
end for
|
||||||
|
|
||||||
|
m.invidiousPublicInstances = instances
|
||||||
|
end if
|
||||||
|
|
||||||
|
return m.invidiousPublicInstances
|
||||||
|
end function
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||||
|
import "pkg:/source/utils/WebUtils.bs"
|
||||||
|
|
||||||
namespace SponsorBlock
|
namespace SponsorBlock
|
||||||
const API_URL = "https://sponsor.ajay.app"
|
const API_URL = "https://sponsor.ajay.app"
|
||||||
const SKIP_SEGMENT_ENDPOINT = "/api/skipSegments"
|
const SKIP_SEGMENT_ENDPOINT = "/api/skipSegments"
|
||||||
const CATEGORIES = "&category=sponsor&category=selfpromo&category=interaction&category=intro&category=outro&category=preview&category=music_offtopic"
|
|
||||||
|
|
||||||
function GetSkipSegmentsForVideo(videoId as string) as object
|
function GetSkipSegmentsForVideo(videoId as string) as object
|
||||||
url = `${SponsorBlock.API_URL}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}?videoID=${videoId}${SponsorBlock.CATEGORIES}`
|
categories = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight", "chapter", "filler", "exclusive_access"]
|
||||||
|
actionTypes = ["skip", "mute", "chapter", "full", "poi"]
|
||||||
|
|
||||||
|
categoriesJson = WebUtils.UrlEscape(FormatJson(categories))
|
||||||
|
actionTypesJson = WebUtils.UrlEscape(FormatJson(actionTypes))
|
||||||
|
url = `${SponsorBlock.API_URL}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}?videoID=${videoId}&categories=${categoriesJson}&actionTypes=${actionTypesJson}`
|
||||||
response = Requests().get(url)
|
response = Requests().get(url)
|
||||||
|
|
||||||
if response.statuscode = 200
|
if response.statuscode = 200
|
||||||
|
|||||||
@@ -49,3 +49,12 @@ function GetDeviceInfo() as object
|
|||||||
end if
|
end if
|
||||||
return m.deviceInfo
|
return m.deviceInfo
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ArrayIndexOf(array as object, value as string) as integer
|
||||||
|
for i = 0 to array.Count() - 1
|
||||||
|
if array[i] = value
|
||||||
|
return i
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
return -1
|
||||||
|
end function
|
||||||
@@ -2,6 +2,9 @@ namespace RegistryUtils
|
|||||||
|
|
||||||
const DEFAULT_SECTION = "Playlet"
|
const DEFAULT_SECTION = "Playlet"
|
||||||
|
|
||||||
|
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||||
|
const INVIDIOUS_TOKEN = "invidious_token"
|
||||||
|
|
||||||
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
||||||
sec = CreateObject("roRegistrySection", section)
|
sec = CreateObject("roRegistrySection", section)
|
||||||
if sec.Exists(key)
|
if sec.Exists(key)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
namespace WebUtils
|
namespace WebUtils
|
||||||
function UrlEncode(url as string) as string
|
function UrlEncode(url as string) as string
|
||||||
ue = m.UrlEncoder
|
ue = m.UrlEncoder
|
||||||
@@ -32,12 +34,26 @@ namespace WebUtils
|
|||||||
url = Mid(url, index + 1)
|
url = Mid(url, index + 1)
|
||||||
components = url.split("&")
|
components = url.split("&")
|
||||||
for each component in components
|
for each component in components
|
||||||
|
key = component
|
||||||
|
value = ""
|
||||||
|
hasValue = false
|
||||||
if Instr(0, component, "=")
|
if Instr(0, component, "=")
|
||||||
keyValue = component.split("=")
|
keyValue = component.split("=")
|
||||||
query[keyValue[0]] = keyValue[1]
|
key = keyValue[0]
|
||||||
else
|
value = keyValue[1]
|
||||||
query[keyValue[0]] = ""
|
hasValue = true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
if query.DoesExist(key) and hasValue
|
||||||
|
oldValue = query[key]
|
||||||
|
if GetInterface(oldValue, "ifArray") = invalid
|
||||||
|
oldValue = [oldValue]
|
||||||
|
end if
|
||||||
|
oldValue.push(value)
|
||||||
|
value = oldValue
|
||||||
|
end if
|
||||||
|
|
||||||
|
query[key] = value
|
||||||
end for
|
end for
|
||||||
return query
|
return query
|
||||||
end function
|
end function
|
||||||
|
|||||||
+263
-31
@@ -5,15 +5,58 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Playlet</title>
|
<title>Playlet</title>
|
||||||
|
<style>
|
||||||
|
table,
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
border: 1px solid;
|
||||||
|
cursor: all-scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body ondrop="OnBodyDrop(event);" ondragover="OnBodyDragover(event);">
|
||||||
<h2>Playlet - Youtube Player for Roku</h2>
|
<h2>Playlet - Youtube Player for Roku</h2>
|
||||||
<h4 id="app-version">Version: </h4>
|
<h4 id="app-version">Version: </h4>
|
||||||
<h4>Invidious Instance: <a id="host" target="_blank">None</a></h4>
|
<h4>Invidious Instance: <a id="instance" 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>
|
<h4 id="logged-in">Logged In: </h4>
|
||||||
<button style="visibility: hidden" id="login-button" onclick="Login()">Login</button>
|
<button style="display: none" id="login-button" onclick="Login()">Login</button>
|
||||||
<button style="visibility: hidden" id="logout-button">Logout</button>
|
<button style="display: none" id="logout-button" onclick="Logout()">Logout</button>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<table id="instances">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Instances - find more at <a href="https://api.invidious.io/" target="_blank">api.invidious.io</a></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
<tbody>
|
||||||
|
<tr id="instance-input-row">
|
||||||
|
<td>
|
||||||
|
<input type="text" id="instance-input" name="new-instance" oninput="OnNewInstanceTextChanged()"
|
||||||
|
style="min-width:300px;">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button id="instance-add" disabled="true" onclick="AddInstance()">Add</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</br>
|
||||||
|
<button style="display: none" id="update-instances" onclick="UpdateInstances()">Update Instances</button>
|
||||||
|
|
||||||
<h5>Instructions</h5>
|
<h5>Instructions</h5>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -31,20 +74,6 @@
|
|||||||
target="_blank">https://github.com/iBicha/playlet</a></h5>
|
target="_blank">https://github.com/iBicha/playlet</a></h5>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function RequestGet(url, cb) {
|
|
||||||
const req = new XMLHttpRequest();
|
|
||||||
req.addEventListener("load", function () {
|
|
||||||
try {
|
|
||||||
cb(null, JSON.parse(this.responseText));
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
cb(err)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
req.open("GET", url);
|
|
||||||
req.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
function Login() {
|
function Login() {
|
||||||
if (!window.appState) {
|
if (!window.appState) {
|
||||||
alert("Error with login, please refresh the page.")
|
alert("Error with login, please refresh the page.")
|
||||||
@@ -52,6 +81,31 @@
|
|||||||
window.location = window.appState.invidious.auth_url
|
window.location = window.appState.invidious.auth_url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Logout() {
|
||||||
|
fetch('/api/command/logout')
|
||||||
|
.then(function (response) {
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
alert(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
function CreateGithubIssueUrl() {
|
||||||
title = "[Feedback] Playlet"
|
title = "[Feedback] Playlet"
|
||||||
body = `### Feedback
|
body = `### Feedback
|
||||||
@@ -69,24 +123,202 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
|||||||
return `https://github.com/iBicha/playlet/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
|
return `https://github.com/iBicha/playlet/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestGet("/api/state", function (err, response) {
|
function IsValidHttpUrl(string) {
|
||||||
if (err) {
|
let url;
|
||||||
alert(err)
|
try {
|
||||||
return
|
url = new URL(string);
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return url.protocol === "http:" || url.protocol === "https:";
|
||||||
}
|
}
|
||||||
window.appState = response
|
|
||||||
console.log(response)
|
|
||||||
document.getElementById("app-version").innerText = `Version: ${response.app.version}`
|
|
||||||
document.getElementById("logged-in").innerText = `Logged In: ${response.invidious.logged_in}`
|
|
||||||
document.getElementById("host").innerText = response.invidious.host
|
|
||||||
document.getElementById("host").href = response.invidious.host
|
|
||||||
|
|
||||||
document.getElementById("login-button").style.visibility = response.invidious.logged_in ? "hidden" : "visible";
|
function GetVideoId(url) {
|
||||||
// TODO: log out feature
|
// Share/Short url
|
||||||
// document.getElementById("logout-button").style.visibility = response.invidious.logged_in ? "hidden" : "visible";
|
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 OnNewInstanceTextChanged() {
|
||||||
|
document.getElementById("instance-add").disabled = !IsValidHttpUrl(document.getElementById("instance-input").value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AddInstance() {
|
||||||
|
instance = document.getElementById("instance-input").value
|
||||||
|
AddInstanceRow(instance)
|
||||||
|
document.getElementById("instance-input").value = ""
|
||||||
|
document.getElementById("update-instances").style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
function AddInstanceRow(instance) {
|
||||||
|
instances = document.getElementById("instances").getElementsByTagName('tbody')[0];
|
||||||
|
var row = instances.insertRow();
|
||||||
|
row.draggable = true
|
||||||
|
row.addEventListener('dragstart', OnTableRowDragStart);
|
||||||
|
row.addEventListener('dragover', OnTableRowDragover);
|
||||||
|
row.addEventListener('drop', OnTableRowDrop);
|
||||||
|
var cell = row.insertCell();
|
||||||
|
style = instance === window.appState.invidious.selected_instance ? `style="font-weight:bold"` : ""
|
||||||
|
cell.innerHTML = `<a href="${instance}" ${style} target="_blank">${instance}</a>`
|
||||||
|
cell = row.insertCell();
|
||||||
|
cell.innerHTML = `<button onclick="RemoveInstance('${instance}')">Remove</button>`
|
||||||
|
}
|
||||||
|
|
||||||
|
function RemoveInstance(instance) {
|
||||||
|
instanceRows = Array.from(document.getElementById("instances")
|
||||||
|
.getElementsByTagName('tbody')[0]
|
||||||
|
.getElementsByTagName('tr'));
|
||||||
|
|
||||||
|
for (const i in instanceRows) {
|
||||||
|
currentInstance = instanceRows[i].getElementsByTagName('a')[0].innerText
|
||||||
|
if (currentInstance === instance) {
|
||||||
|
instanceRows[i].remove()
|
||||||
|
document.getElementById("update-instances").style.display = "block";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateInstances() {
|
||||||
|
instances = Array.from(document.getElementById("instances")
|
||||||
|
.getElementsByTagName('tbody')[0]
|
||||||
|
.getElementsByTagName('td'))
|
||||||
|
.map(el => el.getElementsByTagName('a')[0])
|
||||||
|
.filter(a => !!a)
|
||||||
|
.map(a => a.innerText);
|
||||||
|
|
||||||
|
args = instances.map(instance => `instances=${instance}`).join("&")
|
||||||
|
|
||||||
|
fetch(`/invidious/set-instances?${args}`)
|
||||||
|
.then(function (response) {
|
||||||
|
alert("Instances updated. Restart Playlet to reflect changes.")
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
alert(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`
|
||||||
|
|
||||||
|
if (appState.invidious.logged_in) {
|
||||||
|
document.getElementById("logged-in").innerHTML = `Logged In: true (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
|
||||||
|
} else {
|
||||||
|
document.getElementById("logged-in").innerHTML = "Logged In: false"
|
||||||
|
}
|
||||||
|
|
||||||
|
instanceEl = document.getElementById("instance")
|
||||||
|
instanceEl.innerText = instanceEl.href = appState.invidious.selected_instance
|
||||||
|
|
||||||
|
for (var i in appState.invidious.instances) {
|
||||||
|
AddInstanceRow(appState.invidious.instances[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
loginButton = document.getElementById("login-button")
|
||||||
|
loginButton.innerText = `Login (${appState.invidious.selected_instance})`
|
||||||
|
loginButton.style.display = appState.invidious.logged_in ? "none" : "block";
|
||||||
|
|
||||||
|
document.getElementById("logout-button").style.display = !appState.invidious.logged_in ? "none" : "block";
|
||||||
|
|
||||||
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
||||||
})
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
alert(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var tableRow;
|
||||||
|
function OnTableRowDragStart(event) {
|
||||||
|
target = event.target;
|
||||||
|
while (target && target.tagName !== 'TR') {
|
||||||
|
target = target.parentNode
|
||||||
|
}
|
||||||
|
if (target.id === "instance-input-row") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tableRow = target
|
||||||
|
}
|
||||||
|
|
||||||
|
function OnTableRowDragover(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (!tableRow) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
target = event.target;
|
||||||
|
while (target && target.tagName !== 'TR') {
|
||||||
|
target = target.parentNode
|
||||||
|
}
|
||||||
|
if (!target || target.id === "instance-input-row") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let children = Array.from(target.parentNode.children);
|
||||||
|
|
||||||
|
if (children.indexOf(target) > children.indexOf(tableRow))
|
||||||
|
target.after(tableRow);
|
||||||
|
else
|
||||||
|
target.before(tableRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
function OnTableRowDrop(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
tableRow = undefined
|
||||||
|
document.getElementById("update-instances").style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
function OnBodyDrop(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) && GetVideoId(dataString)) {
|
||||||
|
document.getElementById('video-id').value = dataString
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function OnBodyDragover(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Initialize();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user