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
+2
-1
@@ -2,4 +2,5 @@ dist/
|
||||
out/
|
||||
node_modules
|
||||
.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/),
|
||||
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
|
||||
### Changed
|
||||
- App name! new name: **Playlet**
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
# Playlet
|
||||
Unofficial Youtube client for Roku.
|
||||
Unofficial Youtube client for Roku 📺
|
||||
|
||||
<img src="screenshot.jpg" alt="Screenshot of Playlet" width="350"/>
|
||||
|
||||
|
||||
## Features
|
||||
- No Ads (I guess that's a feature)
|
||||
- Privacy driven (uses Invidious backend)
|
||||
- SponsorBlock integration (skips undesirable sections in videos)
|
||||
- 🔥 No Ads (Not now, not ever)
|
||||
- 🕵️ No Tracking
|
||||
- 🛡️ Privacy driven (uses Invidious backend)
|
||||
- ⚔️ SponsorBlock integration (skips undesirable sections in videos)
|
||||
|
||||
## 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:
|
||||
|
||||

|
||||
<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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
## 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",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "Unofficial Youtube client for Roku",
|
||||
"dependencies": {
|
||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
|
||||
@@ -28,6 +28,7 @@
|
||||
"prebuild": "rm -rf dist",
|
||||
"build": "bsc",
|
||||
"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: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\"",
|
||||
@@ -35,6 +36,7 @@
|
||||
"format:fix": "npm run format:base -- --write",
|
||||
"generate-images": "node scripts/generate-images.js",
|
||||
"manifest-version": "node scripts/update-manifest-version.js",
|
||||
"zip-package": "node scripts/zip-package.js",
|
||||
"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.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
||||
m.top.ObserveField("focus", "OnFocusChange")
|
||||
m.top.ObserveField("playvideo", "OnPlayVideoCommand")
|
||||
|
||||
m.top.focus = true
|
||||
|
||||
@@ -92,7 +93,6 @@ function StartFetchTask() as void
|
||||
end function
|
||||
|
||||
function OnHomeGridScreenContentLoaded()
|
||||
m.top.SetFocus(true)
|
||||
m.global.loadingIndicator.visible = false
|
||||
end function
|
||||
|
||||
@@ -106,7 +106,7 @@ function OnHomeGridScreenVideoSelected(event as object) as void
|
||||
rowContent = grid.content.GetChild(selectedRow)
|
||||
itemContent = rowContent.GetChild(selectedRowItem)
|
||||
|
||||
videoId = itemContent.id
|
||||
videoId = itemContent.videoId
|
||||
|
||||
if m.videoPlayer <> invalid
|
||||
if m.videoPlayer.videoId = videoId
|
||||
@@ -120,7 +120,7 @@ function OnHomeGridScreenVideoSelected(event as object) as void
|
||||
end if
|
||||
end if
|
||||
|
||||
ShowVideoScreenFull(videoId)
|
||||
ShowVideoScreenFull(videoId, m.top)
|
||||
end function
|
||||
|
||||
function CloseVideo()
|
||||
@@ -132,12 +132,13 @@ function CloseVideo()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnPlayVideoCommand()
|
||||
videoId = m.top.playvideo
|
||||
CloseVideo()
|
||||
ShowVideoScreenFull(videoId, m.top)
|
||||
end function
|
||||
|
||||
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
|
||||
m.videoPlayer.control = "stop"
|
||||
m.videoPlayer.visible = false
|
||||
@@ -153,7 +154,7 @@ function OnHomeGridScreenVideoFocused(event as object) as void
|
||||
rowContent = grid.content.GetChild(selectedRow)
|
||||
itemContent = rowContent.GetChild(selectedRowItem)
|
||||
|
||||
videoId = itemContent.id
|
||||
videoId = itemContent.videoId
|
||||
thumbnail = GetThumbnailPoster(videoId)
|
||||
ShowVideoScreenEmbedded(videoId, thumbnail)
|
||||
end function
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<field id="jumpToRowItem" type="intarray" alias="RowList.jumpToRowItem" />
|
||||
<field id="escape" type="string" alwaysNotify="true" />
|
||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||
<field id="playvideo" type="string" alwaysNotify="true" />
|
||||
</interface>
|
||||
<children>
|
||||
<RowList
|
||||
|
||||
@@ -56,27 +56,7 @@ function GetItemData(video as object) as object
|
||||
if video.videoId = invalid
|
||||
return invalid
|
||||
end if
|
||||
item = {}
|
||||
|
||||
item.title = video.title
|
||||
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
|
||||
return video
|
||||
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.settingsScreen = m.top.findNode("SettingsScreen")
|
||||
|
||||
m.searchScreen = m.top.findNode("SearchScreen")
|
||||
m.searchScreen.ObserveField("escape", "OnSearchScreenEscape")
|
||||
|
||||
m.navBar = m.top.findNode("NavBar")
|
||||
m.navBar.ObserveField("escapeIndex", "OnNavBarEscape")
|
||||
@@ -28,9 +30,15 @@ function InitWebServer()
|
||||
m.serverTask = createObject("roSGNode", "WebServerTask")
|
||||
m.serverTask.id = "WebServerTask"
|
||||
m.serverTask.ObserveField("login", "OnWebServerLogin")
|
||||
m.serverTask.ObserveField("command", "OnWebServerCommand")
|
||||
m.serverTask.control = "RUN"
|
||||
end function
|
||||
|
||||
function OnSearchScreenEscape()
|
||||
m.navBar.SetFocus(true)
|
||||
m.navBar.focusIndex = 0
|
||||
end function
|
||||
|
||||
function OnHomeGridScreenEscape()
|
||||
m.navBar.SetFocus(true)
|
||||
m.navBar.focusIndex = 1
|
||||
@@ -76,7 +84,31 @@ function OnWebServerLogin()
|
||||
m.homeGridScreen = newHomeGridScreen
|
||||
m.homeGridScreen.id = "HomeGridScreen"
|
||||
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
|
||||
|
||||
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
|
||||
return true
|
||||
else if key = "right"
|
||||
' Can only escape to home screen, at index 1
|
||||
allowedEscapes = { "1": true }
|
||||
' Can only escape to search screen or home screen
|
||||
allowedEscapes = { "0": true, "1": true }
|
||||
if allowedEscapes[StrI(m.top.focusIndex).Trim()] = true
|
||||
m.top.escapeIndex = m.top.focusIndex
|
||||
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"?>
|
||||
|
||||
<component name="SearchScreen" extends="Group">
|
||||
<interface>
|
||||
<field id="escape" type="string" alwaysNotify="true" />
|
||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||
</interface>
|
||||
|
||||
<children>
|
||||
<Label
|
||||
text="Search feature coming soon..."
|
||||
width="1280"
|
||||
height="720"
|
||||
translation="[0, 0]"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:MediumBoldSystemFont"
|
||||
/>
|
||||
<Group id="container">
|
||||
<MiniKeyboard
|
||||
id="keyboard"
|
||||
translation="[670,110]"
|
||||
/>
|
||||
<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>
|
||||
</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"
|
||||
|
||||
function Init()
|
||||
m.top.url = `http:/${GetLocalIpAddress()}:8888/index.html?tab=settings`
|
||||
m.top.url = `http:/${GetLocalIpAddress()}:8888`
|
||||
end function
|
||||
|
||||
function OnUrlSet()
|
||||
|
||||
@@ -12,8 +12,9 @@ function ShowVideoScreenEmbedded(videoId as string, thumbnailNode as object)
|
||||
ShowVideoScreen(videoId)
|
||||
end function
|
||||
|
||||
function ShowVideoScreenFull(videoId as string)
|
||||
function ShowVideoScreenFull(videoId as string, sender as object)
|
||||
m.videoPlayer = CreateObject("roSGNode", "VideoPlayer")
|
||||
m.videoPlayer.sender = sender
|
||||
AddVideoFields()
|
||||
m.videoPlayer.embedded = false
|
||||
|
||||
@@ -79,13 +80,17 @@ function OnVideoPlayerStateChange() as void
|
||||
' A hack to see if we could use the proxy here
|
||||
if m.videoPlayingSuccess <> true
|
||||
errorInfo = m.videoPlayer.errorInfo
|
||||
if errorInfo.category = "http"
|
||||
videoId = m.videoPlayer.videoId
|
||||
itag = m.videoPlayer.content.itag
|
||||
' http for stream format, mediaerror for DASH
|
||||
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
||||
url = m.videoPlayer.content.url
|
||||
if url.InStr("local=true") = -1
|
||||
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
|
||||
' TODO: perhaps creating a second player is better?
|
||||
m.videoPlayer.ignoreNextFinishedState = true
|
||||
@@ -123,10 +128,22 @@ function StartVideoDetailsTask(videoId as string)
|
||||
videoId = task.output.videoId
|
||||
metadata = task.output.metadata
|
||||
if metadata <> invalid
|
||||
stream = metadata.formatStreams[metadata.formatStreams.Count() - 1]
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.addFields({ videoId: videoId, itag: stream.itag })
|
||||
contentNode.url = stream.url
|
||||
contentNode.addFields({ videoId: videoId })
|
||||
|
||||
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)
|
||||
m.videoPlayer.content = contentNode
|
||||
m.videoPlayer.control = "play"
|
||||
@@ -174,13 +191,14 @@ function SetCaptions(metadata as object, videoPlayer as object, contentNode as o
|
||||
|
||||
contentNode.SubtitleConfig = {
|
||||
ShowSubtitle: 1,
|
||||
TrackName: Invidious.GetCurrentHost() + selectedCaption.url
|
||||
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
|
||||
}
|
||||
end function
|
||||
|
||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
||||
segments = m.videoPlayer.skipSegments
|
||||
for each segment in segments
|
||||
' TODO: handle other action types
|
||||
if segment["actionType"] = "skip"
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
|
||||
@@ -13,9 +13,9 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
end function
|
||||
|
||||
function CloseVideo()
|
||||
homeGridScreen = m.top.getParent().findNode("HomeGridScreen")
|
||||
sender = m.top.sender
|
||||
m.top.control = "stop"
|
||||
m.top.visible = false
|
||||
m.top.getParent().removeChild(m.videoPlayer)
|
||||
homeGridScreen.focus = true
|
||||
sender.focus = true
|
||||
end function
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="VideoPlayer" extends="Video">
|
||||
<interface>
|
||||
<field id="sender" type="node" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -7,25 +7,53 @@ function OnContentSet()
|
||||
m.top.FindNode("titleLabel").text = content.title
|
||||
m.top.FindNode("authorLabel").text = content.author
|
||||
|
||||
releaseDate = validstr(content.releaseDate)
|
||||
publishedText = validstr(content.publishedText)
|
||||
viewCount = FormatViewCount(content.viewCount)
|
||||
if releaseDate = "" and viewCount = ""
|
||||
if publishedText = "" and viewCount = ""
|
||||
m.top.FindNode("viewCountDateLabel").text = ""
|
||||
else
|
||||
m.top.FindNode("viewCountDateLabel").text = `${releaseDate} • ${viewCount}`
|
||||
m.top.FindNode("viewCountDateLabel").text = `${publishedText} • ${viewCount}`
|
||||
end if
|
||||
|
||||
thumbnail = m.top.FindNode("thumbnail")
|
||||
thumbnail.uri = content.hdPosterUrl
|
||||
thumbnail.id = `thumbnail-${content.id}`
|
||||
if content.length <> invalid and content.length <> 0
|
||||
m.top.FindNode("durationLabel").text = TimeUtils.GetFormattedTime(content.length)
|
||||
else
|
||||
thumbnail.uri = GetThumbnailUrl(content.videoThumbnails)
|
||||
thumbnail.id = `thumbnail-${content.videoId}`
|
||||
|
||||
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
|
||||
m.top.FindNode("durationRect").visible = false
|
||||
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
|
||||
|
||||
function FormatViewCount(viewCount as dynamic) as string
|
||||
if viewCount = invalid
|
||||
return ""
|
||||
|
||||
@@ -32,6 +32,24 @@
|
||||
inheritParentOpacity="true"
|
||||
/>
|
||||
</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>
|
||||
|
||||
<Label
|
||||
|
||||
@@ -77,10 +77,10 @@ namespace Http
|
||||
m.source = Http.HttpResponseSource.GENERATED
|
||||
end function
|
||||
|
||||
function Redirect(where as string)
|
||||
function Redirect(where as string, code = 301 as integer)
|
||||
m.location = where
|
||||
message = "Moved to: <a href=" + Quote() + where + Quote() + ">" + where + "</a>"
|
||||
m.Default(301, message)
|
||||
m.Default(code, message)
|
||||
end function
|
||||
|
||||
function Json(data as object)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Http
|
||||
PackageName = "Playlet"
|
||||
Port = 8888
|
||||
MessagePort = invalid
|
||||
MaxConnections = 3
|
||||
MaxConnections = 10
|
||||
Timeout = 60 * 1000
|
||||
MaxRequestLength = 4000
|
||||
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
|
||||
|
||||
method = request.method
|
||||
route = request.uri
|
||||
uri = request.uri
|
||||
|
||||
if method = ""
|
||||
response.Default(400, "You sent a request that the server couldn't understand.")
|
||||
else
|
||||
response.Default(404, `Cannot ${method} ${route}`)
|
||||
response.Default(404, `Cannot ${method} ${uri}`)
|
||||
end if
|
||||
|
||||
return true
|
||||
|
||||
@@ -5,25 +5,57 @@ namespace Http
|
||||
function new()
|
||||
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
|
||||
request = context.request
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
uri = request.uri
|
||||
if uri.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
components = WebUtils.UrlQueryComponents(uri)
|
||||
if components["token"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
print(`Got Token: ${token}`)
|
||||
RegistryUtils.Write("invidious_token", token)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/index.html?tab=settings")
|
||||
return true
|
||||
route = request.uri
|
||||
if not route.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
return false
|
||||
end if
|
||||
return false
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components["token"] <> invalid and components["referer"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
referer = WebUtils.UrlUnescape(components["referer"])
|
||||
InvidiousSettings.SetAuthToken(token, referer)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
end function)
|
||||
end function
|
||||
|
||||
|
||||
@@ -8,18 +8,47 @@ namespace Http
|
||||
function new()
|
||||
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
|
||||
|
||||
state = {
|
||||
app: GetAppInfo(),
|
||||
device: GetDeviceInfo(),
|
||||
invidious: {
|
||||
host: Invidious.GetCurrentHost(),
|
||||
route = request.uri
|
||||
' TODO: this is not the right filtering. /api/state/something will go through, which is not correct
|
||||
if not route.StartsWith("/api/state")
|
||||
return false
|
||||
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(),
|
||||
logged_in: Invidious.GetAuthenticationHeaders() <> invalid
|
||||
logged_in: authToken <> invalid,
|
||||
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
||||
}
|
||||
}
|
||||
end if
|
||||
|
||||
response.Json(state)
|
||||
return true
|
||||
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/RegistryApiRouter.bs"
|
||||
import "pkg:/components/WebServer/Middleware/StateApiRouter.bs"
|
||||
import "pkg:/components/WebServer/Middleware/CommandsApiRouter.bs"
|
||||
|
||||
function Init()
|
||||
m.top.functionName = "WebServerLoop"
|
||||
@@ -16,8 +17,18 @@ function WebServerLoop()
|
||||
m.settings = new Http.HttpSettings(m.webServerPort)
|
||||
' Root at www to get http://IP_ADDRESS:PORT/index.html
|
||||
m.settings.WwwRoot = "pkg:/www"
|
||||
m.settings.Timeout = 5000
|
||||
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.RegistryApiRouter())
|
||||
m.server.UseRouter(new Http.InvidiousRouter())
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
<component name="WebServerTask" extends="Task">
|
||||
<interface>
|
||||
<field id="login" type="boolean" alwaysNotify="true" />
|
||||
<field id="command" type="string" alwaysNotify="true" />
|
||||
</interface>
|
||||
</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
|
||||
major_version=0
|
||||
minor_version=3
|
||||
minor_version=4
|
||||
build_version=00000
|
||||
|
||||
## Channel Assets
|
||||
|
||||
@@ -4,10 +4,10 @@ import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/utils/WebUtils.bs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
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 POPULAR_ENDPOINT = "/api/v1/popular"
|
||||
@@ -18,9 +18,10 @@ namespace Invidious
|
||||
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
||||
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_PLAYLISTS = "/api/v1/auth/playlists"
|
||||
const AUTH_TOKENS_UNREGISTER = "/api/v1/auth/tokens/unregister"
|
||||
|
||||
function DefaultArgs() as object
|
||||
return {
|
||||
@@ -31,7 +32,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetPopular() as object
|
||||
url = `${Invidious.API_URL}${Invidious.POPULAR_ENDPOINT}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.POPULAR_ENDPOINT}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
response = Requests().get(url, args)
|
||||
@@ -43,7 +45,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
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()
|
||||
if trendingType <> ""
|
||||
@@ -59,7 +62,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
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
|
||||
url = url + "&local=true"
|
||||
end if
|
||||
@@ -67,31 +71,22 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
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()
|
||||
response = Requests().get(url, args)
|
||||
|
||||
' TODO: handle 500 {"error":"This video is unavailable"}
|
||||
if response.statuscode = 200
|
||||
videoMetadata = 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
|
||||
return response.json
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
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.params.q = q
|
||||
@@ -104,7 +99,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
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.params.q = q
|
||||
@@ -137,39 +133,33 @@ namespace Invidious
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function GetCurrentHost() as string
|
||||
return Invidious.API_URL
|
||||
end function
|
||||
|
||||
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
|
||||
invidiousHost = `${Invidious.API_URL}`.Replace("https://", "http://")
|
||||
invidiousHost = instance.Replace("https://", "http://")
|
||||
|
||||
localIp = GetLocalIpAddress()
|
||||
webServerPort = 8888
|
||||
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}`
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders() as object
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
if token = invalid
|
||||
return invalid
|
||||
end if
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
return {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
end function
|
||||
|
||||
function GetUserFeed() as object
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
return invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_FEED}`
|
||||
url = `${authToken.instance}${Invidious.AUTH_FEED}`
|
||||
|
||||
args = {
|
||||
headers: headers,
|
||||
@@ -179,7 +169,7 @@ namespace Invidious
|
||||
response = Requests().get(url, args)
|
||||
|
||||
if response.statuscode = 403
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
if response.statuscode = 200
|
||||
return response.json.videos
|
||||
@@ -188,12 +178,13 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetUserPlaylists() as object
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
return invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_PLAYLISTS}`
|
||||
url = `${authToken.instance}${Invidious.AUTH_PLAYLISTS}`
|
||||
|
||||
args = {
|
||||
headers: headers,
|
||||
@@ -203,11 +194,33 @@ namespace Invidious
|
||||
response = Requests().get(url, args)
|
||||
|
||||
if response.statuscode = 403
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
if response.statuscode = 200
|
||||
return response.json
|
||||
end if
|
||||
return invalid
|
||||
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
|
||||
@@ -1,10 +1,9 @@
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
class InvidiousService
|
||||
API_URL = "https://vid.puffyan.us"
|
||||
|
||||
private endpoints
|
||||
private responseHanlders
|
||||
|
||||
@@ -29,16 +28,19 @@ class InvidiousService
|
||||
return invalid
|
||||
end if
|
||||
|
||||
url = m.API_URL + endpoint.url
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
|
||||
url = instance + endpoint.url
|
||||
|
||||
args = { params: {} }
|
||||
|
||||
if endpoint.authenticated = true
|
||||
auth_headers = m.GetAuthenticationHeaders()
|
||||
if auth_headers = invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return invalid
|
||||
end if
|
||||
args.headers = auth_headers
|
||||
url = authToken.instance + endpoint.url
|
||||
args.headers = m.GetAuthenticationHeaders(authToken.token)
|
||||
end if
|
||||
|
||||
if endpoint.queryParams <> invalid
|
||||
@@ -73,11 +75,7 @@ class InvidiousService
|
||||
return responseHandler(m, requestData, response)
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders() as object
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
if token = invalid
|
||||
return invalid
|
||||
end if
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
return {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
@@ -118,7 +116,7 @@ class InvidiousService
|
||||
if response.statuscode = 403
|
||||
print(`Server responded with 403: ${response.text}`)
|
||||
print("deleting token...")
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
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/utils/WebUtils.bs"
|
||||
|
||||
namespace SponsorBlock
|
||||
const API_URL = "https://sponsor.ajay.app"
|
||||
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
|
||||
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)
|
||||
|
||||
if response.statuscode = 200
|
||||
|
||||
@@ -49,3 +49,12 @@ function GetDeviceInfo() as object
|
||||
end if
|
||||
return m.deviceInfo
|
||||
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 INVIDIOUS_INSTANCES = "invidious_instances"
|
||||
const INVIDIOUS_TOKEN = "invidious_token"
|
||||
|
||||
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
||||
sec = CreateObject("roRegistrySection", section)
|
||||
if sec.Exists(key)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
namespace WebUtils
|
||||
function UrlEncode(url as string) as string
|
||||
ue = m.UrlEncoder
|
||||
@@ -32,12 +34,26 @@ namespace WebUtils
|
||||
url = Mid(url, index + 1)
|
||||
components = url.split("&")
|
||||
for each component in components
|
||||
key = component
|
||||
value = ""
|
||||
hasValue = false
|
||||
if Instr(0, component, "=")
|
||||
keyValue = component.split("=")
|
||||
query[keyValue[0]] = keyValue[1]
|
||||
else
|
||||
query[keyValue[0]] = ""
|
||||
key = keyValue[0]
|
||||
value = keyValue[1]
|
||||
hasValue = true
|
||||
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
|
||||
return query
|
||||
end function
|
||||
|
||||
+264
-32
@@ -5,15 +5,58 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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>
|
||||
|
||||
<body>
|
||||
<body ondrop="OnBodyDrop(event);" ondragover="OnBodyDragover(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>
|
||||
<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>
|
||||
<button style="visibility: hidden" id="login-button" onclick="Login()">Login</button>
|
||||
<button style="visibility: hidden" id="logout-button">Logout</button>
|
||||
<button style="display: none" id="login-button" onclick="Login()">Login</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>
|
||||
<ul>
|
||||
@@ -31,20 +74,6 @@
|
||||
target="_blank">https://github.com/iBicha/playlet</a></h5>
|
||||
|
||||
<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() {
|
||||
if (!window.appState) {
|
||||
alert("Error with login, please refresh the page.")
|
||||
@@ -52,6 +81,31 @@
|
||||
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() {
|
||||
title = "[Feedback] Playlet"
|
||||
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)}`
|
||||
}
|
||||
|
||||
RequestGet("/api/state", function (err, response) {
|
||||
if (err) {
|
||||
alert(err)
|
||||
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 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()
|
||||
})
|
||||
.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
|
||||
}
|
||||
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
|
||||
tableRow = target
|
||||
}
|
||||
|
||||
document.getElementById("login-button").style.visibility = response.invidious.logged_in ? "hidden" : "visible";
|
||||
// TODO: log out feature
|
||||
// document.getElementById("logout-button").style.visibility = response.invidious.logged_in ? "hidden" : "visible";
|
||||
function OnTableRowDragover(event) {
|
||||
event.preventDefault();
|
||||
|
||||
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
||||
})
|
||||
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>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in new issue
Block a user