diff --git a/CHANGELOG.md b/CHANGELOG.md index 1945f007..f8cd2dc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Bookmarks: different items can now be bookmarked, and be found in the `Bookmarks` screen. + Things that can be bookmarked: + - A video + - A channel + - A playlist + - Subscriptions + - Trending + - Popular + - Playlists + - Search results + - Channel tabs (latest videos, live streams, playlists, shorts, podcasts, related channels) +- Context menu: press and hold `OK` to show a context menu to: + - Play/queue a video or a playlist + - Open the channel of a playlist or of a video + - Manage bookmarks - Local DASH manifest generation - This adds support for multi languages audio tracks - Also adds thumbnails/preview in trick play mode @@ -17,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Layout in channel view so that the upload time and view count of videos is visible +- A few things in the logger ### Changed diff --git a/docs/README.md b/docs/README.md index 6a3cf257..becc3286 100644 --- a/docs/README.md +++ b/docs/README.md @@ -210,13 +210,13 @@ Additionally, the web server exposes the settings under `/api/preferences`, whic When Playlet starts, it shows a video feed on the screen. Subscription, Trending videos, and so on. -The layout is defined under [playlet-lib/src/config/default_home_layout.json5](/playlet-lib/src/config/default_home_layout.json5). +The layout is defined under [playlet-lib/src/config/default_home_layout.yaml](/playlet-lib/src/config/default_home_layout.yaml). This could allow users to define custom layouts, so they can see what they find relevant in the home page. This can include Subscription, Trending, Popular videos, Search per keywords, or Playlists. Additionally each feed has information on how it is fetched. For now, only Invidious can be data source, but other systems should be configured in the same way. -Invidious API definitions are defined under [playlet-lib/src/config/invidious_video_api.json5](/playlet-lib/src/config/invidious_video_api.json5), and Playlet parses these at runtime and make the right API calls to fetch the data. +Invidious API definitions are defined under [playlet-lib/src/config/invidious_video_api.yaml](/playlet-lib/src/config/invidious_video_api.yaml), and Playlet parses these at runtime and make the right API calls to fetch the data. Finally, this layout system is what allows both the BrightScript app and the Web app to display the same homepage. diff --git a/docs/models.md b/docs/models.md new file mode 100644 index 00000000..cedb6b2c --- /dev/null +++ b/docs/models.md @@ -0,0 +1,48 @@ + + +# Models + +ApiEndpoint: + +- id +- url +- queryParams +- pathParams +- cacheSeconds +- paginationType +- authenticated +- responseHandler + +FeedSource: + +- id +- title +- apiType: string ("Invidious") +- endpoint: ApiEndpoint +- pathParams +- queryParams +- state: + - paginationtype (Runtime field) + - page (Runtime field) + - continuation (Runtime field) + - queryParams.page (Runtime field) + - queryParams.continuation (Runtime field) + +Feed/FeedContentNode: + +- Title +- feedSources: FeedSource[] +- feedSourceIndex (Runtime field) + +RowListLayout + +- Feed[] + +Bookmarks + +- BookmarkGroup[] + +BookmarkGroup + +- title +- feedSources: FeedSource[] diff --git a/playlet-app/src/components/BootstrapScene/BootstrapScene.xml b/playlet-app/src/components/BootstrapScene/BootstrapScene.xml index b062dfeb..04a32c73 100644 --- a/playlet-app/src/components/BootstrapScene/BootstrapScene.xml +++ b/playlet-app/src/components/BootstrapScene/BootstrapScene.xml @@ -4,7 +4,7 @@ - + diff --git a/playlet-app/src/source/Main.bs b/playlet-app/src/source/Main.bs index 9db3819a..e8d577ce 100644 --- a/playlet-app/src/source/Main.bs +++ b/playlet-app/src/source/Main.bs @@ -66,7 +66,9 @@ function Main(args as object) as void msg = wait(0, port) msgType = type(msg) if msgType = "roSystemLogEvent" - scene.systemLogEvent = msg.GetInfo() + info = msg.GetInfo() + info.DateTime = info.DateTime.ToISOString() + scene.systemLogEvent = info else if msgType = "roSGScreenEvent" if msg.isScreenClosed() return diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs index 22cdb3fe..f045e27a 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.bs +++ b/playlet-lib/src/components/ChannelView/ChannelView.bs @@ -12,8 +12,10 @@ function Init() m.thumbnail = m.top.findNode("thumbnail") m.authorLabel = m.top.findNode("authorLabel") m.rowList = m.top.FindNode("rowList") + m.rowList.screen = m.top m.banner.ObserveField("loadStatus", FuncName(OnBannerLoadStatus)) + m.author = "" m.authorId = "" InitializeTabs() @@ -39,7 +41,6 @@ function OnContentSet() as void ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. m.authorLabel.text = content._author - ' TODO:P1 handle case where there's no banner - a big portion of the screen is blank m.banner.uri = content.banner if StringUtils.IsNullOrEmpty(content.thumbnail) m.thumbnail.uri = "" @@ -53,13 +54,15 @@ function OnContentSet() as void content@.LoadChannel(m.invidious) authorId = ValidString(content.authorId) - if authorId <> m.authorId and IsArray(content.tabs) + author = ValidString(content._author) + if (authorId <> m.authorId or author <> m.author) and IsArray(content.tabs) m.authorId = authorId - m.rowList.contentData = CreateChannelFeeds(m.authorId, content.tabs) + m.author = author + m.rowList.feeds = CreateChannelFeeds(m.authorId, author, content.tabs) end if end function -function CreateChannelFeeds(authorId as string, tabs as object) as object +function CreateChannelFeeds(authorId as string, author as string, tabs as object) as object if authorId = "" return invalid end if @@ -68,7 +71,7 @@ function CreateChannelFeeds(authorId as string, tabs as object) as object for i = 0 to tabs.count() - 1 tabName = tabs[i] if m.tabs.DoesExist(tabName) - feeds.Push(m.tabs[tabName](authorId)) + feeds.Push(m.tabs[tabName](authorId, author)) end if end for return feeds @@ -119,34 +122,47 @@ end function function InitializeTabs() m.tabs = { - videos: function(authorId as string) as object - return CreateChannelFeed("Latest videos", "channel_videos", authorId) + videos: function(authorId as string, author as string) as object + return CreateChannelFeed("Latest videos", "channel_videos", authorId, author) end function, - shorts: function(authorId as string) as object - return CreateChannelFeed("Shorts", "channel_shorts", authorId) + shorts: function(authorId as string, author as string) as object + return CreateChannelFeed("Shorts", "channel_shorts", authorId, author) end function, - streams: function(authorId as string) as object - return CreateChannelFeed("Live", "channel_streams", authorId) + streams: function(authorId as string, author as string) as object + return CreateChannelFeed("Live", "channel_streams", authorId, author) end function, - podcasts: function(authorId as string) as object - return CreateChannelFeed("Podcasts", "channel_podcasts", authorId) + podcasts: function(authorId as string, author as string) as object + return CreateChannelFeed("Podcasts", "channel_podcasts", authorId, author) end function, - playlists: function(authorId as string) as object - return CreateChannelFeed("Playlists", "channel_playlists", authorId) + playlists: function(authorId as string, author as string) as object + return CreateChannelFeed("Playlists", "channel_playlists", authorId, author) end function, - channels: function(authorId as string) as object - return CreateChannelFeed("Channels", "channel_channels", authorId) + channels: function(authorId as string, author as string) as object + return CreateChannelFeed("Channels", "channel_channels", authorId, author) end function } end function -function CreateChannelFeed(title as string, endpoint as string, ucid as string) as object +function CreateChannelFeed(title as string, endpoint as string, ucid as string, author as string) as object return { title: title, - apiType: "Invidious", - endpoint: endpoint, - pathParams: { - ucid: ucid - } + feedSources: [{ + id: `inv_${endpoint}_${ucid}`, + title: `${author} - ${title}`, + apiType: "Invidious", + endpoint: endpoint, + pathParams: { + ucid: ucid + } + }] } end function + +function GetContextMenuOptionsForItem(video as object) as object + content = m.top.content + if content = invalid or StringUtils.IsNullOrEmpty(content.authorId) + return [] + end if + + return m.bookmarks@.GetMenuForChannel(content) +end function diff --git a/playlet-lib/src/components/ChannelView/ChannelView.xml b/playlet-lib/src/components/ChannelView/ChannelView.xml index b304bf1c..83ae63fa 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.xml +++ b/playlet-lib/src/components/ChannelView/ChannelView.xml @@ -1,8 +1,9 @@ - + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml index 5a29053f..5b484f1d 100644 --- a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml +++ b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml @@ -3,7 +3,8 @@ - + + diff --git a/playlet-lib/src/components/ContentNode/ContextMenuItemContentNode.xml b/playlet-lib/src/components/ContentNode/ContextMenuItemContentNode.xml new file mode 100644 index 00000000..1b95484f --- /dev/null +++ b/playlet-lib/src/components/ContentNode/ContextMenuItemContentNode.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/ContentNode/FeedContentNode.xml b/playlet-lib/src/components/ContentNode/FeedContentNode.xml index fdd8dde5..88ae1c5e 100644 --- a/playlet-lib/src/components/ContentNode/FeedContentNode.xml +++ b/playlet-lib/src/components/ContentNode/FeedContentNode.xml @@ -1,9 +1,7 @@ - + + - - - \ No newline at end of file diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml index 19176626..491c4cac 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml +++ b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml @@ -2,6 +2,8 @@ + + + diff --git a/playlet-lib/src/components/ContentNode/VideoContentNode.xml b/playlet-lib/src/components/ContentNode/VideoContentNode.xml index 3607fea9..925352ca 100644 --- a/playlet-lib/src/components/ContentNode/VideoContentNode.xml +++ b/playlet-lib/src/components/ContentNode/VideoContentNode.xml @@ -3,9 +3,12 @@ + + + diff --git a/playlet-lib/src/components/ContextMenu/ContextMenu.bs b/playlet-lib/src/components/ContextMenu/ContextMenu.bs new file mode 100644 index 00000000..63fb91d7 --- /dev/null +++ b/playlet-lib/src/components/ContextMenu/ContextMenu.bs @@ -0,0 +1,171 @@ +import "pkg:/source/utils/FocusManagement.bs" +import "pkg:/source/utils/Logging.bs" +import "pkg:/source/utils/StringUtils.bs" +import "pkg:/source/utils/Types.bs" + +' TODO:P0 Web app support +' TODO:P0 Web apis and open api spec updates +' +' From the main screen: +' When a video is selected: +' - "Play" - DONE +' - "Queue" - DONE +' - "Open Channel" - DONE +' - "Add to "Videos" bookmark" - DONE +' - If video is already in a bookmark, "Remove from Bookmarks" - DONE +' +' When a channel is selected: +' - "Open" - DONE +' - "Add to "Channels" bookmark" - DONE +' - "Add to bookmark" - DONE +' - If channel is already in a bookmark, "Remove from Bookmarks" - DONE +' - PlaylistId starting with "IV" cannot be added to a bookmark - DONE +' +' When a playlist is selected: +' - "Play" - DONE +' - "Queue" - DONE +' - "Open" - DONE +' - "Add to "Playlists" bookmark" - DONE +' - "Add to bookmark" - DONE +' - If playlist is already in a bookmark, "Remove from Bookmarks" - DONE +' When any: +' - "Reload feed" - DONE +' +' From Playlist view: +' When a video is selected: +' - "Play" - DONE +' - "Queue" - DONE +' - "Play video" - DONE +' - "Queue video" - DONE +' - "Open Channel" - DONE +' - "Add to "Playlists" bookmark" - DONE +' - "Add to bookmark" - DONE +' - "Add to "Videos" bookmark" - DONE +' +' From Channel view: +' When a video is selected: +' - "Play" - DONE +' - "Queue" - DONE +' - "Add to "Channels" bookmark" - DONE +' - "Add to - bookmark" feed being latest videos, live, shorts, etc - DONE +' - "Add to "Videos" bookmark" - DONE +' +' When a playlist is selected: +' - "Play" - DONE +' - "Queue" - DONE +' - "Open" - DONE +' - "Add to "Channels" bookmark" - DONE +' - "Add to - bookmark" feed being latest videos, live, shorts, etc - DONE +' - "Add to "Playlists" bookmark" - DONE +' - "Add to bookmark" - DONE +' +' From search view: +' When a video/channel/playlist is selected: +' - Inherit options - DONE +' - "Add to "Search - ${q}" bookmark" - this includes the search filters used - DONE +' +' From bookmarks view: +' When a video/channel/playlist is selected: +' - Inherit options +' - "Remove item from Bookmarks" +' - "Remove group from Bookmarks" +' - "Reload bookmarks" - DONE +' +' TODO:P1 Playlist item seletected from the bookmarks need to play as a playlist, not as a single video +' TODO:P1 Context menu might need to be scrollable (both horizontally and vertically) +' TODO:P1 Context menu might need sections. Example: +' In a Channel view, while selecting a playlist: +' - Channel +' - Add to "Channels" bookmark +' - Other "Channels" related context menu items +' - Playlist +' - Add to "Playlists" bookmark +' - "Play/Queue" +' - Other "Playlists" related context menu items + +function Init() + m.optionsList = m.top.findNode("optionsList") + m.showAnimation = m.top.findNode("showAnimation") +end function + +function Show(unsued as dynamic) + m.optionsList.ObserveField("itemSelected", FuncName(OnItemSelected)) + m.showAnimation.control = "start" +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + NodeSetFocus(m.optionsList, true) +end function + +function OnOptionsSet() as void + options = m.top.options + if options = invalid + return + end if + + content = CreateObject("roSGNode", "ContentNode") + for each option in options + optionNode = CreateObject("roSGNode", "ContentNode") + optionNode.title = option.title + content.appendChild(optionNode) + end for + + m.optionsList.content = content +end function + +function OnItemSelected(event as object) as void + index = event.getData() + button = m.optionsList.content.getChild(index) + Close() + LogInfo("Menu button selected:", button.title) + + options = m.top.options + if index >= options.count() + LogError("Menu button index out of range:", index) + return + end if + + option = options[index] + + node = option.node + func = option.func + args = option.args + + if node = invalid or StringUtils.IsNullOrEmpty(func) or args = invalid + LogError("Menu button action is invalid") + return + end if + + if args.count() = 1 + node.callFunc(func, args[0]) + else if args.count() = 2 + node.callFunc(func, args[0], args[1]) + else if args.count() = 3 + node.callFunc(func, args[0], args[1], args[2]) + else if args.count() = 4 + node.callFunc(func, args[0], args[1], args[2], args[3]) + else if args.count() = 5 + node.callFunc(func, args[0], args[1], args[2], args[3], args[4]) + else + LogError("Menu button action has too many arguments") + end if +end function + +function OnkeyEvent(key as string, press as boolean) as boolean + if press = false + return false + end if + + if key = "back" + Close() + return true + end if + return false +end function + +function Close() + m.top.appController@.PopScreen(invalid) +end function diff --git a/playlet-lib/src/components/ContextMenu/ContextMenu.xml b/playlet-lib/src/components/ContextMenu/ContextMenu.xml new file mode 100644 index 00000000..d75bff31 --- /dev/null +++ b/playlet-lib/src/components/ContextMenu/ContextMenu.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/ContextMenu/ContextMenuRow.bs b/playlet-lib/src/components/ContextMenu/ContextMenuRow.bs new file mode 100644 index 00000000..5a740848 --- /dev/null +++ b/playlet-lib/src/components/ContextMenu/ContextMenuRow.bs @@ -0,0 +1,29 @@ +function OnContentSet() as void + content = m.top.itemContent + if content = invalid + return + end if + + m.top.text = content.title +end function + +function OnItemHasFocus() + hasFocus = m.top.itemHasFocus + if hasFocus + m.top.font = "font:SmallestBoldSystemFont" + m.top.color = "0x262626ff" + else + m.top.font = "font:SmallestSystemFont" + m.top.color = "0xddddddff" + end if +end function + +function OnFocusPercent() + if m.top.focusPercent > 0.5 + m.top.font = "font:SmallestBoldSystemFont" + m.top.color = "0x262626ff" + else + m.top.font = "font:SmallestSystemFont" + m.top.color = "0xddddddff" + end if +end function diff --git a/playlet-lib/src/components/ContextMenu/ContextMenuRow.xml b/playlet-lib/src/components/ContextMenu/ContextMenuRow.xml new file mode 100644 index 00000000..74266d6d --- /dev/null +++ b/playlet-lib/src/components/ContextMenu/ContextMenuRow.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/ContextMenu/ContextMenuUtils.bs b/playlet-lib/src/components/ContextMenu/ContextMenuUtils.bs new file mode 100644 index 00000000..aa03afb6 --- /dev/null +++ b/playlet-lib/src/components/ContextMenu/ContextMenuUtils.bs @@ -0,0 +1,76 @@ +import "pkg:/source/utils/Logging.bs" + +namespace ContextMenuUtils + function Open(providers as object, appController as object, item as object) as object + if item = invalid + return invalid + end if + + options = GetOptions(item, providers) + if options.Count() = 0 + LogWarn("No context menu options available for item") + return invalid + end if + + contextMenu = CreateObject("roSGNode", "ContextMenu") + contextMenu.appController = appController + appController@.PushScreen(contextMenu) + + ContextMenuUtils.SetItem(contextMenu, item) + contextMenu.options = options + + contextMenu@.Show(invalid) + return contextMenu + end function + + function SetItem(contextMenu as object, item as object) + title = "" + subtitle = "" + thumbnail = "" + + if item.type = "video" + LogInfo("Opening context menu for video:", item.videoId) + title = item.title + subtitle = item.author + thumbnail = item.thumbnail + else if item.type = "playlist" + LogInfo("Opening context menu for playlist:", item.playlistId) + title = item.title + subtitle = item._author + thumbnail = item.thumbnail + else if item.type = "channel" + LogInfo("Opening context menu for channel:", item.authorId) + title = item._author + thumbnail = item.thumbnail + end if + + contextMenu.title = title + contextMenu.subtitle = subtitle + contextMenu.thumbnail = thumbnail + end function + + function GetOptions(item as object, providers as object) as object + allOptions = [] + + for each provider in providers + if provider <> invalid and provider.hasField("supportsContextMenu") and provider.supportsContextMenu = true + options = provider@.GetContextMenuOptionsForItem(item) + if options <> invalid + allOptions.append(options) + end if + end if + + end for + + return allOptions + end function + + function CreateOption(title as string, node as object, func as string, args as object) as object + option = CreateObject("roSGNode", "ContextMenuItemContentNode") + option.title = title + option.node = node + option.func = func + option.args = args + return option + end function +end namespace diff --git a/playlet-lib/src/components/EcpArgs.bs b/playlet-lib/src/components/EcpArgs.bs index 57208e49..cbb898ba 100644 --- a/playlet-lib/src/components/EcpArgs.bs +++ b/playlet-lib/src/components/EcpArgs.bs @@ -1,4 +1,5 @@ import "pkg:/components/VideoPlayer/VideoUtils.bs" +import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/utils/Types.bs" diff --git a/playlet-lib/src/components/Logger/Logger.bs b/playlet-lib/src/components/Logger/Logger.bs index 0132a079..b6e626f0 100644 --- a/playlet-lib/src/components/Logger/Logger.bs +++ b/playlet-lib/src/components/Logger/Logger.bs @@ -1,3 +1,4 @@ +import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/Types.bs" function Init() @@ -13,6 +14,18 @@ function Init() end if m.port = port + + StartLogger(m.top) +end function + +function StartLogger(logger as object, logLevel = LogLevel.Info as LogLevel) as void + if m.global.logger <> invalid + return + end if + + logger.logLevel = logLevel + m.global.addFields({ logger: logger }) + logger.control = "run" end function function LoggerLoop() @@ -54,7 +67,7 @@ function OnLineSysLog(event as object, logsFile as string, buffer as object) as if info.LogType <> "http.error" return end if - line = `[SysLog] ${FormatJson(info)}` + line = "[ERROR][SysLog] " + ToString(info) ' bs:disable-next-line LINT3012 print line diff --git a/playlet-lib/src/components/Logger/Logger.xml b/playlet-lib/src/components/Logger/Logger.xml index 64b13198..39ff9bbc 100644 --- a/playlet-lib/src/components/Logger/Logger.xml +++ b/playlet-lib/src/components/Logger/Logger.xml @@ -1,7 +1,7 @@ - + diff --git a/playlet-lib/src/components/MainScene.bs b/playlet-lib/src/components/MainScene.bs index c854608d..77f512d7 100644 --- a/playlet-lib/src/components/MainScene.bs +++ b/playlet-lib/src/components/MainScene.bs @@ -1,11 +1,8 @@ import "pkg:/components/EcpArgs.bs" import "pkg:/components/parts/AutoBind/AutoBind.part.bs" import "pkg:/source/utils/LoadingScreen.bs" -import "pkg:/source/utils/Logging.bs" function Init() - InitializeLogger() - m.scene = m.top.getScene() ' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet. ' Let's wait until it has one. diff --git a/playlet-lib/src/components/MainScene.transpiled.brs b/playlet-lib/src/components/MainScene.transpiled.brs index fa932e3a..ef408e6d 100644 --- a/playlet-lib/src/components/MainScene.transpiled.brs +++ b/playlet-lib/src/components/MainScene.transpiled.brs @@ -1,11 +1,9 @@ 'import "pkg:/components/EcpArgs.bs" 'import "pkg:/components/parts/AutoBind/AutoBind.part.bs" 'import "pkg:/source/utils/LoadingScreen.bs" -'import "pkg:/source/utils/Logging.bs" function Init() InitializeBindings() ' auto-generated! - InitializeLogger() m.scene = m.top.getScene() ' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet. ' Let's wait until it has one. diff --git a/playlet-lib/src/components/MainScene.transpiled.xml b/playlet-lib/src/components/MainScene.transpiled.xml index 1acb0cf1..49c6246a 100644 --- a/playlet-lib/src/components/MainScene.transpiled.xml +++ b/playlet-lib/src/components/MainScene.transpiled.xml @@ -9,24 +9,26 @@ - + + - - - + + + + @@ -38,6 +40,7 @@ + diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml index 15823b6d..7824da23 100644 --- a/playlet-lib/src/components/MainScene.xml +++ b/playlet-lib/src/components/MainScene.xml @@ -1,5 +1,7 @@ + + @@ -8,20 +10,22 @@ + icon="pkg:/images/icons/search.png"> + icon="pkg:/images/icons/home.png"> + + + icon="pkg:/images/icons/settings.png"> + true - return false - end if screen = m.appController@.GetRootScreen(navBarItem.screen) if screen = invalid return false end if + if not screen.focusable + return false + end if NodeSetFocus(screen, true) return true end if diff --git a/playlet-lib/src/components/NavBar/NavBar.xml b/playlet-lib/src/components/NavBar/NavBar.xml index 7ab360ea..c6650970 100644 --- a/playlet-lib/src/components/NavBar/NavBar.xml +++ b/playlet-lib/src/components/NavBar/NavBar.xml @@ -8,7 +8,7 @@ - \ No newline at end of file diff --git a/playlet-lib/src/components/Navigation/LongPress.bs b/playlet-lib/src/components/Navigation/LongPress.bs new file mode 100644 index 00000000..2f2529ab --- /dev/null +++ b/playlet-lib/src/components/Navigation/LongPress.bs @@ -0,0 +1,39 @@ +const LONG_PRESS_KEY = "OK_LONG_PRESS" + +function InitializeLongPressTimer(duration = 1.0 as float) + m._longPressTimer = CreateObject("roSGNode", "Timer") + m._longPressTimer.duration = duration + m._longPressFired = false + m._longPressTimer.ObserveField("fire", FuncName(LongPressTimerFired)) +end function + +function LongPressHandler(key as string, press as boolean) as boolean + #if DEBUG + if key = "Lit_l" + LogInfo("Simulating long press using key:", key, "press:", press) + m._longPressFired = true + return OnkeyEvent(LONG_PRESS_KEY, press) + end if + #end if + if key = "OK" and press + m._longPressTimer.control = "stop" + m._longPressTimer.control = "start" + m._longPressFired = false + return true + end if + + if key = "OK" and not press + m._longPressTimer.control = "stop" + if m._longPressFired = true + m._longPressFired = false + return true + end if + end if + + return false +end function + +function LongPressTimerFired() + m._longPressFired = true + OnkeyEvent(LONG_PRESS_KEY, true) +end function diff --git a/playlet-lib/src/components/PlaylistView/PlaylistView.bs b/playlet-lib/src/components/PlaylistView/PlaylistView.bs index 0f7d5930..f84b80f6 100644 --- a/playlet-lib/src/components/PlaylistView/PlaylistView.bs +++ b/playlet-lib/src/components/PlaylistView/PlaylistView.bs @@ -1,4 +1,7 @@ +import "pkg:/components/ChannelView/ChannelUtils.bs" +import "pkg:/components/ContextMenu/ContextMenuUtils.bs" import "pkg:/components/Dialog/DialogUtils.bs" +import "pkg:/components/Navigation/LongPress.bs" import "pkg:/components/PlaylistView/PlaylistContentTask.bs" import "pkg:/components/VideoFeed/FeedLoadState.bs" import "pkg:/components/VideoPlayer/VideoUtils.bs" @@ -21,7 +24,7 @@ end function function OnNodeReady() m.list.ObserveField("itemFocused", FuncName(OnItemFocused)) - m.list.observeField("itemSelected", FuncName(OnItemSelected)) + InitializeLongPressTimer() end function function OnFocusChange() as void @@ -58,6 +61,20 @@ function OnContentSet() as void end function function OnkeyEvent(key as string, press as boolean) as boolean + if LongPressHandler(key, press) + return true + end if + + if key = LONG_PRESS_KEY and press + OnItemLongPressed(m.list.itemFocused) + return true + end if + + if key = "OK" and not press + OnItemSelected(m.list.itemFocused) + return true + end if + if press = false return false end if @@ -81,18 +98,94 @@ function OnItemFocused() LoadPlaylistIfNeeded() end function -function OnItemSelected(event as object) - index = event.getData() +function OnItemSelected(index as integer) as void playlist = m.list.content + if playlist = invalid + return + end if + + if index < 0 or index >= playlist.getChildCount() + return + end if + playlistId = playlist.playlistId video = playlist.getChild(index) videoId = video.videoId if not StringUtils.IsNullOrEmpty(videoId) - LogInfo("Play playlist: " + playlistId + " video: " + videoId) + LogInfo("Play playlist:", playlistId, "video:", videoId) m.playQueue@.Play(playlist, index) end if end function +function OnItemLongPressed(index as integer) as void + playlist = m.list.content + if playlist = invalid + return + end if + + if index < 0 or index >= playlist.getChildCount() + return + end if + + playlistId = playlist.playlistId + video = playlist.getChild(index) + videoId = video.videoId + if StringUtils.IsNullOrEmpty(videoId) + LogWarn("Long press video with no id in playlist/ playlist:", playlistId, "video:", videoId) + return + end if + + LogInfo("Long press: playlist:", playlistId, "video:", videoId) + + contextMenuProviders = [m.top] + ContextMenuUtils.Open(contextMenuProviders, m.appController, video) +end function + +function GetContextMenuOptionsForItem(video as object) as object + playlist = m.list.content + if playlist = invalid + return [] + end if + + index = m.list.itemFocused + if index < 0 or index >= playlist.getChildCount() + return [] + end if + + selectedVideo = playlist.getChild(m.list.itemFocused) + if selectedVideo = invalid or not selectedVideo.isSameNode(video) + return [] + end if + + options = [ + ContextMenuUtils.CreateOption("Play", m.playQueue, "Play", [playlist, index]), + ContextMenuUtils.CreateOption("Queue", m.playQueue, "AddToQueue", [playlist]) + ContextMenuUtils.CreateOption("Play video", m.playQueue, "Play", [video, -1]), + ContextMenuUtils.CreateOption("Queue video", m.playQueue, "AddToQueue", [video]), + ] + + if not StringUtils.IsNullOrEmpty(playlist.authorId) + options.push(ContextMenuUtils.CreateOption("Open channel", m.top, "OpenPlaylistChannel", [playlist])) + end if + + options.append(m.bookmarks@.GetMenuForPlaylist(playlist)) + options.append(m.bookmarks@.GetMenuForVideo(video)) + + return options +end function + +function OpenPlaylistChannel(playlist as object) as void + authorId = playlist.authorId + if StringUtils.IsNullOrEmpty(authorId) + LogWarn("Invalid authorId:", authorId) + return + end if + channel = InvidiousContent.ToChannelContentNode(invalid, { authorId: authorId }, invalid) + ChannelUtils.Open(channel) +end function + +'TODO:P1 a playlist could have been opened from the bookmarks, which can be as old as 3 days +' We should make a request in this case, and let the cache handle freshness. function LoadPlaylistIfNeeded() as void content = m.top.content if content = invalid diff --git a/playlet-lib/src/components/PlaylistView/PlaylistView.xml b/playlet-lib/src/components/PlaylistView/PlaylistView.xml index cf5dccb0..ddc6f216 100644 --- a/playlet-lib/src/components/PlaylistView/PlaylistView.xml +++ b/playlet-lib/src/components/PlaylistView/PlaylistView.xml @@ -1,16 +1,17 @@ - + + + - + color="0x242424" /> 0 + m.noBookmarks.visible = not hasBookmarks + m.yesBookmarks.visible = hasBookmarks + m.top.focusable = hasBookmarks + + if hasBookmarks + SetRowListContent(m.bookmarks.content) + else + if m.rowList.hasFocus() + NodeSetFocus(m.navBar, true) + end if + end if +end function + +function SetRowListContent(bookmarksContent as object) + bookmarkGroupNodes = bookmarksContent.getChildren(-1, 0) + + feeds = [] + for each bookmarkGroupNode in bookmarkGroupNodes + bookmarkNodes = bookmarkGroupNode.getChildren(-1, 0) + feed = { + title: bookmarkGroupNode.title, + feedSources: [] + } + + for each bookmarkNode in bookmarkNodes + feed.feedSources.push(bookmarkNode.feedSource) + end for + + feeds.push(feed) + end for + + m.rowList.feeds = feeds +end function + +function OnkeyEvent(key as string, press as boolean) as boolean + if NavigationKeyHandler(key, press).handled + return true + end if + return false +end function + +function GetContextMenuOptionsForItem(rowItem as object) as object + refreshItem = ContextMenuUtils.CreateOption("Refresh Bookmarks", m.top, "Refresh", [invalid]) + return [refreshItem] +end function diff --git a/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.xml b/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.xml new file mode 100644 index 00000000..ba4dcf72 --- /dev/null +++ b/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs index a8df34e2..8eb37d5b 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs @@ -1,8 +1,11 @@ +import "pkg:/components/ContextMenu/ContextMenuUtils.bs" import "pkg:/components/Navigation/Navigation.bs" import "pkg:/source/utils/FocusManagement.bs" function Init() + m.top.focusable = true m.rowList = m.top.FindNode("rowList") + m.rowList.screen = m.top m.pendingLoadTasks = {} end function @@ -11,7 +14,7 @@ function OnNodeReady() SetNavigation(invalid, "left", m.navBar) m.rowList@.BindNode(invalid) - m.rowList.contentData = ParseJson(ReadAsciiFile(m.top.feedFile)) + m.rowList.feeds = ParseJson(ReadAsciiFile(m.top.feedFile)) end function function OnFocusChange() as void @@ -27,3 +30,8 @@ function OnkeyEvent(key as string, press as boolean) as boolean end if return false end function + +function GetContextMenuOptionsForItem(rowItem as object) as object + refresh = ContextMenuUtils.CreateOption("Refresh Home", m.rowList, "Refresh", [invalid]) + return [refresh] +end function diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml index 0cce7229..1bc3da92 100644 --- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml +++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml @@ -1,8 +1,8 @@ - + - + 0 - requestData.queryParams[filter] = value + feedSource.queryParams[filter] = value else if IsArray(value) and value.Count() > 0 ' TODO:P1 this is http client implementation details leaking ' We need a declarative way to set array types - requestData.queryParams[filter] = { + feedSource.queryParams[filter] = { value: value, __arrayType: HttpClient.QueryParamArrayType.CommaSeparated } end if end for - m.rowList.contentData = [requestData] + m.rowList.feeds = [{ + title: `Search - ${text}`, + feedSources: [feedSource] + }] end function function OnSearchContentReady() as void @@ -243,7 +250,7 @@ function OnSearchContentReady() as void end function function OnSearchError() - m.rowlist.contentData = invalid + m.rowlist.feeds = invalid m.rowlist.focusable = false HideLoadingScreen() end function @@ -258,7 +265,7 @@ end function function ClearSearch() m.keyboard.text = "" - m.rowlist.contentData = invalid + m.rowlist.feeds = invalid m.rowlist.focusable = false ScrollUp() end function diff --git a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml index 51e5d72c..8bb780b1 100644 --- a/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml +++ b/playlet-lib/src/components/Screens/SearchScreen/SearchScreen.xml @@ -40,8 +40,8 @@ rowItemSpacing="[[25,0]]" itemSize="[1280,326]" itemSpacing="[0,65]" - rowLabelOffset="[[115,20]]" - focusXOffset="[115]" + rowLabelOffset="[[125,20]]" + focusXOffset="[125]" showRowLabel="[true]" rowFocusAnimationStyle="floatingfocus" variableWidthItems="true" diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SettingsScreen.bs b/playlet-lib/src/components/Screens/SettingsScreen/SettingsScreen.bs index f4dab286..73c2280a 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/SettingsScreen.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/SettingsScreen.bs @@ -3,6 +3,7 @@ import "pkg:/components/Navigation/ScrollTo.bs" import "pkg:/source/utils/FocusManagement.bs" function Init() + m.top.focusable = true m.container = m.top.findNode("Container") m.scrollAnimation = m.top.findNode("scrollAnimation") m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator") diff --git a/playlet-lib/src/components/Services/Bookmarks/Bookmarks.bs b/playlet-lib/src/components/Services/Bookmarks/Bookmarks.bs new file mode 100644 index 00000000..7b16e32d --- /dev/null +++ b/playlet-lib/src/components/Services/Bookmarks/Bookmarks.bs @@ -0,0 +1,326 @@ +import "pkg:/components/ContextMenu/ContextMenuUtils.bs" +import "pkg:/source/utils/CryptoUtils.bs" +import "pkg:/source/utils/Logging.bs" +import "pkg:/source/utils/RegistryUtils.bs" +import "pkg:/source/utils/StringUtils.bs" +import "pkg:/source/utils/Types.bs" + +const VIDEOS_GROUP = "Videos" +const CHANNELS_GROUP = "Channels" +const PLAYLISTS_GROUP = "Playlists" + +function Init() + m.top.content = m.top.findNode("content") + m.bookmarksString = "" + Load() + m.top.ObserveField("contentChange", FuncName(OnContentChange)) +end function + +function Load() as void + bookmarksString = RegistryUtils.Read(RegistryUtils.BOOKMARKS) + if bookmarksString = invalid + return + end if + + m.bookmarksString = bookmarksString + bookmarks = ParseJson(bookmarksString) + if bookmarks = invalid + return + end if + + for each bookmarkGroup in bookmarks.groups + bookmarkGroupNode = GetOrCreateBookmarkGroup(bookmarkGroup.title) + for each bookmark in bookmarkGroup.bookmarks + AddFeedSourceBookmark(bookmark.feedSource, bookmark.id, bookmarkGroupNode) + end for + end for +end function + +function Save() as void + bookmarkGroupNodes = m.top.content.getChildren(-1, 0) + if bookmarkGroupNodes.Count() = 0 + RegistryUtils.Delete(RegistryUtils.BOOKMARKS) + return + end if + + groups = [] + for each bookmarkGroupNode in bookmarkGroupNodes + bookmarks = [] + bookmarkNodes = bookmarkGroupNode.getChildren(-1, 0) + for each bookmarkNode in bookmarkNodes + bookmarks.push({ + id: bookmarkNode.id, + feedSource: bookmarkNode.feedSource + }) + end for + groups.push({ + title: bookmarkGroupNode.title, + bookmarks: bookmarks + }) + end for + + bookmarksString = FormatJson({ + __version: m.top.__version, + groups: groups + }) + + if m.bookmarksString = bookmarksString + return + end if + + RegistryUtils.Write(RegistryUtils.BOOKMARKS, bookmarksString) + m.bookmarksString = bookmarksString +end function + +function GetOrCreateBookmarkGroup(groupName as string) as object + id = CryptoUtils.GetMd5(groupName) + node = m.top.content.findNode(id) + if node <> invalid + return node + end if + node = CreateObject("roSGNode", "ContentNode") + node.id = id + node.title = groupName + m.top.content.appendChild(node) + LogInfo("Added bookmark group:", groupName) + return node +end function + +function AddFeedSourceBookmark(feedSource as object, id as string, bookmarkGroupNode as dynamic) + if IsString(bookmarkGroupNode) + bookmarkGroupNode = GetOrCreateBookmarkGroup(bookmarkGroupNode) + end if + + feedSource.Delete("state") + + bookmarkNode = CreateObject("roSGNode", "BookmarkContentNode") + bookmarkNode.id = id + bookmarkNode.feedSource = feedSource + + bookmarkGroupNode.insertChild(bookmarkNode, 0) + LogInfo("Added feedSource bookmark:", feedSource.title, "id:", id) + m.top.contentChange = true +end function + +function AddVideoBookmark(id as string, groupName as string) + bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName) + + feedSource = { + apiType: "Invidious", + endpoint: "video_info", + pathParams: { + id: id + } + } + AddFeedSourceBookmark(feedSource, id, bookmarkGroupNode) +end function + +function AddPlaylistBookmark(id as string, groupName as string) + bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName) + + feedSource = { + apiType: "Invidious", + endpoint: "playlist_info", + pathParams: { + plid: id + } + } + AddFeedSourceBookmark(feedSource, id, bookmarkGroupNode) +end function + +function AddPlaylistBookmarkWithSpread(id as string, groupName as string) + bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName) + + feedSource = { + id: `inv_playlist_${id}`, + title: `${groupName} videos`, + apiType: "Invidious", + endpoint: "playlist", + pathParams: { + plid: id + } + } + AddFeedSourceBookmark(feedSource, `inv_playlist_${id}`, bookmarkGroupNode) + + feedSource = { + apiType: "Invidious", + endpoint: "playlist_info", + pathParams: { + plid: id + } + } + AddFeedSourceBookmark(feedSource, id, bookmarkGroupNode) +end function + +function AddChannelBookmark(id as string, groupName as string) + bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName) + + feedSource = { + apiType: "Invidious", + endpoint: "channel_info", + pathParams: { + ucid: id + } + } + AddFeedSourceBookmark(feedSource, id, bookmarkGroupNode) +end function + +function AddChannelBookmarkWithSpread(id as string, groupName as string) + bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName) + + feedSource = { + id: `inv_channel_videos_${id}`, + title: `${groupName} videos`, + apiType: "Invidious", + endpoint: "channel_videos", + pathParams: { + ucid: id + } + } + AddFeedSourceBookmark(feedSource, `inv_channel_videos_${id}`, bookmarkGroupNode) + + feedSource = { + apiType: "Invidious", + endpoint: "channel_info", + pathParams: { + ucid: id + } + } + AddFeedSourceBookmark(feedSource, id, bookmarkGroupNode) +end function + +function RemoveBookmark(id as string) as void + node = m.top.content.findNode(id) + if node = invalid + return + end if + + group = node.getParent() + group.removeChild(node) + LogInfo("Removed bookmark:", id) + + if group.getChildCount() = 0 + m.top.content.removeChild(group) + LogInfo("Removed bookmark group:", group.title) + end if + m.top.contentChange = true +end function + +function OnContentChange(event as object) as void + Save() +end function + +function GetContextMenuOptionsForItem(item as object) as object + options = [] + if item.type = "video" + options.append(GetMenuForVideo(item)) + else if item.type = "playlist" + options.append(GetMenuForPlaylist(item)) + else if item.type = "channel" + options.append(GetMenuForChannel(item)) + end if + options.append(GetMenuForParentFeedSource(item)) + return options +end function + +function GetMenuForVideo(videoNode as object) as object + videoId = videoNode.videoId + if StringUtils.IsNullOrEmpty(videoId) + return [] + end if + + menu = [] + bookmark = m.top.content.findNode(videoId) + isInBookmarks = bookmark <> invalid + if isInBookmarks + bookmarkGroup = bookmark.getParent() + item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [videoId]) + menu.push(item) + else + item = ContextMenuUtils.CreateOption(`Add to "${VIDEOS_GROUP}" bookmark`, m.top, "AddVideoBookmark", [videoId, VIDEOS_GROUP]) + menu.push(item) + end if + return menu +end function + +function GetMenuForPlaylist(playlistNode as object) as object + playlistId = playlistNode.playlistId + if StringUtils.IsNullOrEmpty(playlistId) or playlistId.StartsWith("IV") + return [] + end if + + menu = [] + bookmark = m.top.content.findNode(playlistId) + isInBookmarks = bookmark <> invalid + if isInBookmarks + bookmarkGroup = bookmark.getParent() + item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [playlistId]) + menu.push(item) + else + item = ContextMenuUtils.CreateOption(`Add to "${PLAYLISTS_GROUP}" bookmark`, m.top, "AddPlaylistBookmark", [playlistId, PLAYLISTS_GROUP]) + menu.push(item) + + item = ContextMenuUtils.CreateOption(`Add to "${playlistNode.title}" bookmark`, m.top, "AddPlaylistBookmarkWithSpread", [playlistId, playlistNode.title]) + menu.push(item) + end if + return menu +end function + +function GetMenuForChannel(channelNode as object) as object + authorId = channelNode.authorId + if StringUtils.IsNullOrEmpty(authorId) + return [] + end if + + menu = [] + bookmark = m.top.content.findNode(authorId) + isInBookmarks = bookmark <> invalid + if isInBookmarks + bookmarkGroup = bookmark.getParent() + item = ContextMenuUtils.CreateOption(`Remove from "${bookmarkGroup.title}" bookmarks`, m.top, "RemoveBookmark", [authorId]) + menu.push(item) + else + item = ContextMenuUtils.CreateOption(`Add to "${CHANNELS_GROUP}" bookmark`, m.top, "AddChannelBookmark", [authorId, CHANNELS_GROUP]) + menu.push(item) + + item = ContextMenuUtils.CreateOption(`Add to "${channelNode._author}" bookmark`, m.top, "AddChannelBookmarkWithSpread", [authorId, channelNode._author]) + menu.push(item) + end if + return menu +end function + +function GetMenuForParentFeedSource(itemNode as object) as object + if itemNode = invalid + return [] + end if + if itemNode.type <> "video" and itemNode.type <> "playlist" and itemNode.type <> "channel" + return [] + end if + if not IsInt(itemNode.feedSourcesIndex) or itemNode.feedSourcesIndex = -1 + return [] + end if + feedContentNode = itemNode.getParent() + if feedContentNode = invalid or feedContentNode.subtype() <> "FeedContentNode" + return [] + end if + + feedSource = feedContentNode.feedSources[itemNode.feedSourcesIndex] + if StringUtils.IsNullOrEmpty(feedSource.title) or StringUtils.IsNullOrEmpty(feedSource.id) + return [] + end if + + title = feedSource.title + feedSourceId = feedSource.id + + menu = [] + isInBookmarks = m.top.content.findNode(feedSourceId) <> invalid + + if isInBookmarks + item = ContextMenuUtils.CreateOption(`Remove "${feedSource.title}" from bookmarks`, m.top, "RemoveBookmark", [feedSourceId]) + menu.push(item) + else + item = ContextMenuUtils.CreateOption(`Add to "${title}" bookmark`, m.top, "AddFeedSourceBookmark", [feedSource, feedSourceId, title]) + menu.push(item) + end if + return menu +end function diff --git a/playlet-lib/src/components/Services/Bookmarks/Bookmarks.xml b/playlet-lib/src/components/Services/Bookmarks/Bookmarks.xml new file mode 100644 index 00000000..89e6bf93 --- /dev/null +++ b/playlet-lib/src/components/Services/Bookmarks/Bookmarks.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Services/Invidious/Invidious.bs b/playlet-lib/src/components/Services/Invidious/Invidious.bs index 8ceddb99..383c7097 100644 --- a/playlet-lib/src/components/Services/Invidious/Invidious.bs +++ b/playlet-lib/src/components/Services/Invidious/Invidious.bs @@ -1,7 +1,7 @@ import "InvidiousService.bs" function Init() - m.top.apiDefinitions = ParseJson(ReadAsciiFile("libpkg:/config/invidious_video_api.json5")) + m.top.apiDefinitions = ParseJson(ReadAsciiFile("libpkg:/config/invidious_video_api.yaml")) m.service = new Invidious.InvidiousService(m.top) m.top.authToken = m.service.GetAuthToken() end function diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs index a1a1fa84..269784af 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs @@ -36,19 +36,16 @@ namespace Invidious function new(node as object) m.node = node - ' TODO:P2 api definitions are not needed everytime, move them to a separate function and lazy load - apiDefinitions = node.apiDefinitions - m.endpoints = {} - - for each apiDefinition in apiDefinitions.endpoints - m.endpoints[apiDefinition.name] = apiDefinition - end for + m.endpoints = node.apiDefinitions m.responseHanlders = { DefaultHandler: m.DefaultHandler, AuthFeedHandler: m.AuthFeedHandler, PlaylistHandler: m.PlaylistHandler, + VideoInfoHandler: m.VideoInfoHandler, + PlaylistInfoHandler: m.PlaylistInfoHandler, + ChannelInfoHandler: m.ChannelInfoHandler, ChannelVideosHandler: m.ChannelVideosHandler, ChannelPlaylistsHandler: m.ChannelPlaylistsHandler, ChannelRelatedChannelsHandler: m.ChannelRelatedChannelsHandler @@ -149,6 +146,7 @@ namespace Invidious request = HttpClient.Get(url) request.QueryParams(m.DefaultQueryParams()) request.Cancellation(cancellation) + request.CacheSeconds(60 * 60 * 24)' 24 hours return request.Await() end function @@ -158,39 +156,50 @@ namespace Invidious return `${instance}/latest_version?id=${videoId}` end function - function MarkFeedPagination(contentNode as object) as void - requestData = contentNode.feed + function MarkFeedPagination(feedContentNode as object) as object + feedSources = feedContentNode.feedSources + feedSourcesIndex = feedContentNode.feedSourcesIndex - endpoint = m.endpoints[requestData.endpoint] + feedSource = feedSources[feedSourcesIndex] + + endpoint = m.endpoints[feedSource.endpoint] if endpoint = invalid or StringUtils.IsNullOrEmpty(endpoint.paginationType) - return + return feedSource end if - if not requestData.DoesExist("queryParams") - requestData.queryParams = {} + feedSourceState = feedSource.state + if not feedSourceState.DoesExist("queryParams") + feedSourceState.queryParams = {} end if - contentNode.paginationType = endpoint.paginationType - - if endpoint.paginationType = PaginationType.Pages - contentNode.page += 1 - requestData.queryParams.page = contentNode.page - else if endpoint.paginationType = PaginationType.Continuation - continuation = contentNode.continuation + feedSourceState.paginationType = endpoint.paginationType + if feedSourceState.paginationType = PaginationType.Pages + if not IsInt(feedSourceState.page) + feedSourceState.page = 0 + end if + feedSourceState.page += 1 + feedSourceState.queryParams.page = feedSourceState.page + else if feedSourceState.paginationType = PaginationType.Continuation + continuation = feedSourceState.continuation if not StringUtils.IsNullOrEmpty(continuation) - requestData.queryParams.continuation = continuation + feedSourceState.queryParams.continuation = continuation + else + feedSourceState.queryParams.Delete("continuation") end if end if - contentNode.feed = requestData + feedSource.state = feedSourceState + feedSources[feedSourcesIndex] = feedSource + feedContentNode.feedSources = feedSources + return feedSource end function - function MakeRequest(requestData as object, cancellation = invalid as object) as object - endpoint = m.endpoints[requestData.endpoint] + function MakeRequest(feedSource as object, additionalQueryParams = invalid as object, cancellation = invalid as object) as object + endpoint = m.endpoints[feedSource.endpoint] if endpoint = invalid return { success: false, - error: `Endpoint ${requestData.endpoint} not found` + error: `Endpoint ${feedSource.endpoint} not found` } end if @@ -233,18 +242,22 @@ namespace Invidious end for end if - if requestData.cacheSeconds <> invalid - request.CacheSeconds(requestData.cacheSeconds) + if feedSource.cacheSeconds <> invalid + request.CacheSeconds(feedSource.cacheSeconds) else if endpoint.cacheSeconds <> invalid request.CacheSeconds(endpoint.cacheSeconds) end if - if requestData.queryParams <> invalid - request.QueryParams(requestData.queryParams) + if feedSource.queryParams <> invalid + request.QueryParams(feedSource.queryParams) end if - if requestData.pathParams <> invalid - request.PathParams(requestData.pathParams) + if additionalQueryParams <> invalid + request.QueryParams(additionalQueryParams) + end if + + if feedSource.pathParams <> invalid + request.PathParams(feedSource.pathParams) end if request.Cancellation(cancellation) @@ -253,7 +266,7 @@ namespace Invidious responseHandler = endpoint.responseHandler <> invalid ? m.responseHanlders[endpoint.responseHandler] : m.responseHanlders["DefaultHandler"] - result = responseHandler(m, requestData, response) + result = responseHandler(m, feedSource, response) if response.IsSuccess() and result <> invalid return { @@ -268,7 +281,7 @@ namespace Invidious end if end function - function DefaultHandler(m as object, requestData as object, response as object) as object + function DefaultHandler(m as object, feedSource as object, response as object) as object if response.StatusCode() = 200 json = response.Json() return { @@ -278,7 +291,7 @@ namespace Invidious return invalid end function - function PlaylistHandler(m as object, requestData as object, response as object) as object + function PlaylistHandler(m as object, feedSource as object, response as object) as object if response.StatusCode() = 200 json = response.Json() return { @@ -288,7 +301,7 @@ namespace Invidious return invalid end function - function ChannelVideosHandler(m as object, requestData as object, response as object) as object + function ChannelVideosHandler(m as object, feedSource as object, response as object) as object if response.StatusCode() = 200 json = response.Json() return { @@ -299,7 +312,7 @@ namespace Invidious return invalid end function - function ChannelPlaylistsHandler(m as object, requestData as object, response as object) as object + function ChannelPlaylistsHandler(m as object, feedSource as object, response as object) as object if response.StatusCode() = 200 json = response.Json() return { @@ -310,7 +323,7 @@ namespace Invidious return invalid end function - function ChannelRelatedChannelsHandler(m as object, requestData as object, response as object) as object + function ChannelRelatedChannelsHandler(m as object, feedSource as object, response as object) as object if response.StatusCode() = 200 json = response.Json() return { @@ -321,7 +334,40 @@ namespace Invidious return invalid end function - function AuthFeedHandler(m as object, requestData as object, response as object) as object + function VideoInfoHandler(m as object, feedSource as object, response as object) as object + if response.StatusCode() = 200 + json = response.Json() + json.type = "video" + return { + items: [json] + } + end if + return invalid + end function + + function PlaylistInfoHandler(m as object, feedSource as object, response as object) as object + if response.StatusCode() = 200 + json = response.Json() + json.type = "playlist" + return { + items: [json] + } + end if + return invalid + end function + + function ChannelInfoHandler(m as object, feedSource as object, response as object) as object + if response.StatusCode() = 200 + json = response.Json() + json.type = "channel" + return { + items: [json] + } + end if + return invalid + end function + + function AuthFeedHandler(m as object, feedSource as object, response as object) as object m.DeleteExpiredToken(response) if response.StatusCode() = 200 diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index a3ab30ef..a29c0ba2 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -34,6 +34,7 @@ namespace InvidiousContent node.type = "video" SetIfExists(node, "author", item, "author") + SetIfExists(node, "authorId", item, "authorId") SetIfExists(node, "hlsUrl", item, "hlsUrl") SetIfExists(node, "isUpcoming", item, "isUpcoming") SetIfExists(node, "lengthSeconds", item, "lengthSeconds") @@ -62,6 +63,7 @@ namespace InvidiousContent ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. SetIfExists(node, "_author", item, "author") + SetIfExists(node, "authorId", item, "authorId") SetIfExists(node, "description", item, "description") SetIfExists(node, "playlistId", item, "playlistId") SetIfExists(node, "title", item, "title") diff --git a/playlet-lib/src/components/VideoFeed/VideoRowList.bs b/playlet-lib/src/components/VideoFeed/VideoRowList.bs index 68a5ef60..96b63b98 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowList.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowList.bs @@ -1,5 +1,7 @@ import "pkg:/components/ChannelView/ChannelUtils.bs" +import "pkg:/components/ContextMenu/ContextMenuUtils.bs" import "pkg:/components/Dialog/DialogUtils.bs" +import "pkg:/components/Navigation/LongPress.bs" import "pkg:/components/PlaylistView/PlaylistUtils.bs" import "pkg:/components/VideoFeed/VideoRowListContentTask.bs" import "pkg:/components/VideoFeed/VideoRowListRowContentTask.bs" @@ -18,11 +20,11 @@ end function function OnNodeReady() m.top.ObserveField("itemFocused", FuncName(OnItemFocused)) m.top.ObserveField("rowItemFocused", FuncName(OnRowItemFocused)) - m.top.ObserveField("rowItemSelected", FuncName(OnRowItemSelected)) m.top.observeField("focusedChild", FuncName(OnFocusedChildChange)) m.top.ObserveField("visible", FuncName(OnVisibilityChange)) m.invidious.ObserveFieldScoped("authToken", FuncName(OnAuthTokenChange)) + InitializeLongPressTimer() end function function OnFocusedChildChange() as void @@ -37,7 +39,7 @@ function OnVisibilityChange() end if end function -function OnContentData() as void +function OnFeedsChange() as void InitContent() end function @@ -47,6 +49,11 @@ end function function OnRowItemFocused(event as object) as void index = event.GetData() + if index = invalid or index.count() <> 2 + LogWarn("Invalid index:", index) + return + end if + rowIndex = index[0] rowItemIndex = index[1] @@ -60,12 +67,30 @@ function OnRowItemFocused(event as object) as void end if end function -function OnRowItemSelected(event as object) - index = event.GetData() +function OnRowItemSelected(index as object) as void + content = m.top.content + if content = invalid + return + end if + + if index = invalid or index.count() <> 2 + LogWarn("Invalid index:", index) + return + end if + rowIndex = index[0] rowItemIndex = index[1] - row = m.top.content.GetChild(rowIndex) + if rowIndex < 0 or rowIndex >= content.GetChildCount() + LogWarn("Invalid row index:", rowIndex) + return + end if + row = content.GetChild(rowIndex) + + if rowItemIndex < 0 or rowItemIndex >= row.GetChildCount() + LogWarn("Invalid row item index:", rowItemIndex) + return + end if rowItem = row.GetChild(rowItemIndex) if rowItem.type = "video" @@ -75,11 +100,11 @@ function OnRowItemSelected(event as object) else if rowItem.type = "playlist" playlistId = rowItem.playlistId LogInfo("Open playlist: " + playlistId) - PlaylistUtils.Open(rowItem) + OpenPlaylist(rowItem) else if rowItem.type = "channel" authorId = rowItem.authorId LogInfo("Open channel: " + authorId) - ChannelUtils.Open(rowItem) + OpenChannel(rowItem) else if rowItem.type = "action" if rowItem.action = "LoginDialog" dialog = CreateObject("roSGNode", "LoginDialog") @@ -89,6 +114,82 @@ function OnRowItemSelected(event as object) end if end function +function OnRowItemLongPressed(index as object) as void + content = m.top.content + if content = invalid + return + end if + + rowIndex = index[0] + rowItemIndex = index[1] + + if rowIndex < 0 or rowIndex >= content.GetChildCount() + LogWarn("Invalid row index:", rowIndex) + return + end if + row = content.GetChild(rowIndex) + + if rowItemIndex < 0 or rowItemIndex >= row.GetChildCount() + LogWarn("Invalid row item index:", rowItemIndex) + return + end if + rowItem = row.GetChild(rowItemIndex) + + contextMenuProviders = [m.top, m.bookmarks, m.top.screen] + ContextMenuUtils.Open(contextMenuProviders, m.appController, rowItem) +end function + +function GetContextMenuOptionsForItem(rowItem as object) as object + options = [] + + playAction = ContextMenuUtils.CreateOption("Play", m.playQueue, "Play", [rowItem, -1]) + queueAction = ContextMenuUtils.CreateOption("Queue", m.playQueue, "AddToQueue", [rowItem]) + + if rowItem.type = "video" + options.push(playAction) + options.push(queueAction) + + item = ContextMenuUtils.CreateOption("Open channel", m.top, "OpenVideoChannel", [rowItem]) + options.push(item) + else if rowItem.type = "playlist" + options.push(playAction) + options.push(queueAction) + + item = ContextMenuUtils.CreateOption("Open", m.top, "OpenPlaylist", [rowItem]) + options.push(item) + else if rowItem.type = "channel" + item = ContextMenuUtils.CreateOption("Open", m.top, "OpenChannel", [rowItem]) + options.push(item) + else + LogWarn("Unknown long pressed item type:", rowItem.type) + return [] + end if + + return options +end function + +function OpenPlaylist(playlist as object) + PlaylistUtils.Open(playlist) +end function + +function OpenChannel(channel as object) + ChannelUtils.Open(channel) +end function + +function OpenVideoChannel(video as object) as void + authorId = video.authorId + if StringUtils.IsNullOrEmpty(authorId) + LogWarn("Invalid authorId:", authorId) + return + end if + channel = InvidiousContent.ToChannelContentNode(invalid, { authorId: authorId }, invalid) + ChannelUtils.Open(channel) +end function + +function Refresh(unsued as dynamic) + InitContent() +end function + function OnAuthTokenChange() ' TODO:P2: Reload only content that is authenticated ' Should not reload if the page is not visible. Instead, capture state and reload when the page becomes visible @@ -99,14 +200,14 @@ function InitContent() as void CancelCurrentTasks() m.top.someContentReady = false - if m.top.contentData = invalid + if m.top.feeds = invalid m.top.content = invalid return end if task = StartAsyncTask(VideoRowListContentTask, { node: m.top, - contentData: m.top.contentData + feeds: m.top.feeds }, OnVideoRowListContentTaskResult) m.pendingLoadTasks[task.id] = task end function @@ -178,8 +279,8 @@ function LoadRowContent(contentNode as object) contentNode.loadState = FeedLoadState.Loading task = StartAsyncTask(VideoRowListRowContentTask, { - node: m.top, - contentNode: contentNode, + rowList: m.top, + feedContentNode: contentNode, invidious: m.invidious }, OnVideoRowListRowContentTaskResult) m.pendingLoadTasks[task.id] = task @@ -191,19 +292,22 @@ function OnVideoRowListRowContentTaskResult(output as object) as void return end if - if not output.success or not output.result.success - ' output.error for unhandled exception - error = output.error - if error = invalid - ' output.result.error for network errors - error = output.result.error - end if - error = ErrorUtils.Format(error) - LogError(error) - m.top.onError = error - message = `Failed to load feed\n${error}` - DialogUtils.ShowDialog(message, "Feed load fail", true) - end if - LoadRowsIfNeeded() end function + +function OnkeyEvent(key as string, press as boolean) as boolean + if LongPressHandler(key, press) + return true + end if + + if key = LONG_PRESS_KEY and press + OnRowItemLongPressed(m.top.rowItemFocused) + return true + end if + + if key = "OK" and not press + OnRowItemSelected(m.top.rowItemFocused) + return true + end if + return false +end function diff --git a/playlet-lib/src/components/VideoFeed/VideoRowList.xml b/playlet-lib/src/components/VideoFeed/VideoRowList.xml index f350503a..3231e7ec 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowList.xml +++ b/playlet-lib/src/components/VideoFeed/VideoRowList.xml @@ -1,10 +1,16 @@ - + - + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/VideoFeed/VideoRowListContentTask.bs b/playlet-lib/src/components/VideoFeed/VideoRowListContentTask.bs index f8f2d584..190f2658 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowListContentTask.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowListContentTask.bs @@ -1,17 +1,25 @@ import "FeedLoadState.bs" +import "pkg:/source/utils/StringUtils.bs" @asynctask function VideoRowListContentTask(input as object) - contentData = input.contentData + feeds = input.feeds rowList = input.node contentNode = CreateObject("roSGNode", "ContentNode") - for each feed in contentData + for each feed in feeds feedContentNode = CreateObject("roSGNode", "FeedContentNode") - feedContentNode.feed = feed - feedContentNode.loadState = FeedLoadState.None feedContentNode.title = feed.title + feedContentNode.feedSourcesIndex = 0 + feedContentNode.loadState = FeedLoadState.None + feedSources = feed.feedSources + for i = 0 to feedSources.count() - 1 + feedSources[i].state = { + loadState: FeedLoadState.None + } + end for + feedContentNode.feedSources = feedSources for i = 1 to 4 feedContentNode.createChild("LoadingContentNode") diff --git a/playlet-lib/src/components/VideoFeed/VideoRowListRowContentTask.bs b/playlet-lib/src/components/VideoFeed/VideoRowListRowContentTask.bs index a9b0645d..5bceb720 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowListRowContentTask.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowListRowContentTask.bs @@ -1,93 +1,156 @@ +import "pkg:/components/Dialog/DialogUtils.bs" import "pkg:/components/Services/Invidious/InvidiousService.bs" import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs" @asynctask function VideoRowListRowContentTask(input as object) as object - rowList = input.node - contentNode = input.contentNode - invidiousNode = input.invidious + try + rowList = input.rowList + feedContentNode = input.feedContentNode + invidiousNode = input.invidious - if m.top.cancel - contentNode.loadState = FeedLoadState.None - return invalid - end if + service = new Invidious.InvidiousService(invidiousNode) + instance = service.GetInstance() - service = new Invidious.InvidiousService(invidiousNode) + totalfetchedItems = 0 - service.MarkFeedPagination(contentNode) - response = service.MakeRequest(contentNode.feed, m.top.cancellation) + while true + if m.top.cancel + feedContentNode.loadState = FeedLoadState.None + return invalid + end if - if m.top.cancel - contentNode.loadState = FeedLoadState.None - return invalid - end if + feedSources = feedContentNode.feedSources + feedSourcesIndex = feedContentNode.feedSourcesIndex - if not response.success - if response.error = Invidious.ERROR_NOT_AUTHENTICATED - RemovePlaceHolderItems(contentNode) - actionNode = CreateObject("roSGNode", "ActionContentNode") - actionNode.title = `Login to view ${contentNode.title}` - actionNode.action = "LoginDialog" + if feedSourcesIndex >= feedSources.Count() + feedContentNode.loadState = FeedLoadState.Loaded + return { + success: true + } + end if - contentNode.appendChild(actionNode) - contentNode.loadState = FeedLoadState.Loaded + feedSource = feedSources[feedSourcesIndex] - return { - success: true - } - end if + if feedSource.state.loadState = FeedLoadState.Loaded or feedSource.state.loadState = FeedLoadState.Error + feedSourcesIndex += 1 + if feedSourcesIndex >= feedSources.Count() + feedContentNode.loadState = FeedLoadState.Loaded + return { + success: true + } + end if + feedContentNode.feedSourcesIndex = feedSourcesIndex + continue while + end if - ' Invidious returns 500 and "{"error":"Closed stream"}" when the Popular feed is disabled - ' TODO:P2 check the endpoint.name instead of contentNode.title to avoid conflict with other feeds - if contentNode.title = "Popular" and response.error.instr("Closed stream") > 0 - LogWarn("Deleting feed", contentNode.title, "-", response.error) - parent = contentNode.getParent() - parent.removeChild(contentNode) - return { - success: true - } - end if + feedSource = service.MarkFeedPagination(feedContentNode) - contentNode.loadState = FeedLoadState.Error - contentNode.title += " (Failed to load)" - return response - end if + response = service.MakeRequest(feedSource, feedSource.state.queryParams, m.top.cancellation) - instance = service.GetInstance() - itemNodes = [] - for each item in response.result.items - itemNode = InvidiousContent.ToRowCellContentNode(item, instance) - if itemNode <> invalid - itemNodes.Push(itemNode) - end if - end for + if not response.success + if response.error = Invidious.ERROR_NOT_AUTHENTICATED + RemovePlaceHolderItems(feedContentNode) + actionNode = CreateObject("roSGNode", "ActionContentNode") + actionNode.title = `Login to view ${feedSource.title}` + actionNode.action = "LoginDialog" - RemovePlaceHolderItems(contentNode) - contentNode.appendChildren(itemNodes) + feedSource.state.loadState = FeedLoadState.Loaded + feedSources[feedSourcesIndex] = feedSource + feedContentNode.feedSources = feedSources - hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation) - if hasContinuation - contentNode.continuation = response.result.continuation - end if + feedContentNode.appendChild(actionNode) + feedContentNode.loadState = FeedLoadState.Loaded - if response.result.items.Count() > 0 - pageType = contentNode.paginationType - if pageType = PaginationType.Continuation and hasContinuation - contentNode.loadState = FeedLoadState.LoadedPage - else if pageType = PaginationType.Pages - contentNode.loadState = FeedLoadState.LoadedPage - else - contentNode.loadState = FeedLoadState.Loaded - end if - else - contentNode.loadState = FeedLoadState.Loaded - end if + continue while + end if - if itemNodes.Count() > 0 - rowList.someContentReady = true - end if + ' Invidious returns 500 and "{"error":"Closed stream"}" when the Popular feed is disabled + if feedSource.endpoint = "popular" and response.error.instr("Closed stream") > -1 + LogWarn("Popular feedSource not available:", response.error) + if feedSources.Count() = 1 + parent = feedContentNode.getParent() + parent.removeChild(feedContentNode) + return { + success: true + } + end if - return response + continue while + end if + + feedSource.state.loadState = FeedLoadState.Error + feedSources[feedSourcesIndex] = feedSource + feedContentNode.feedSources = feedSources + + if feedContentNode.title.instr(" (Failed to load)") = -1 + feedContentNode.title += " (Failed to load)" + end if + + HandleFeedLoadErrorDialog(response.error, rowList) + continue while + end if + + itemNodes = [] + for each item in response.result.items + itemNode = InvidiousContent.ToRowCellContentNode(item, instance) + if itemNode <> invalid + itemNode.feedSourcesIndex = feedSourcesIndex + itemNodes.Push(itemNode) + end if + end for + + RemovePlaceHolderItems(feedContentNode) + feedContentNode.appendChildren(itemNodes) + + hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation) + if hasContinuation + feedSource.state.continuation = response.result.continuation + end if + + if response.result.items.Count() > 0 + pageType = feedSource.state.paginationType + if pageType = PaginationType.Continuation and hasContinuation + feedSource.state.loadState = FeedLoadState.LoadedPage + else if pageType = PaginationType.Pages + feedSource.state.loadState = FeedLoadState.LoadedPage + else + feedSource.state.loadState = FeedLoadState.Loaded + end if + else + feedSource.state.loadState = FeedLoadState.Loaded + end if + + feedSources[feedSourcesIndex] = feedSource + feedContentNode.feedSources = feedSources + + if feedSource.state.loadState = FeedLoadState.Loaded and feedSourcesIndex = feedSources.Count() - 1 + feedContentNode.loadState = FeedLoadState.Loaded + else + feedContentNode.loadState = FeedLoadState.LoadedPage + end if + + if itemNodes.Count() > 0 + rowList.someContentReady = true + end if + + totalfetchedItems += response.result.items.Count() + if totalfetchedItems > 3 + exit while + end if + end while + + catch error + HandleFeedLoadErrorDialog(error, rowList) + return { + success: false, + error: error + } + end try + + return { + success: true + } end function function RemovePlaceHolderItems(contentNode as object) @@ -101,3 +164,10 @@ function RemovePlaceHolderItems(contentNode as object) end if end while end function + +function HandleFeedLoadErrorDialog(error as object, rowList as object) + error = ErrorUtils.Format(error) + LogError(error) + rowList.onError = error + DialogUtils.ShowDialog(error, "Failed to load feed", true) +end function diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs index 5ea6d743..3455cd9b 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs @@ -66,7 +66,7 @@ namespace Http requestData = ParseJson(requestData) - ' TODO:P1 handle pagination + ' TODO:P0 handle pagination ' Perhaps the page arg can be added to queryParam of requestData directly invService = new Invidious.InvidiousService(invidiousNode) invResponse = invService.MakeRequest(requestData) diff --git a/playlet-lib/src/components/parts/ContextMenuProvider/ContextMenuProvider.part.xml b/playlet-lib/src/components/parts/ContextMenuProvider/ContextMenuProvider.part.xml new file mode 100644 index 00000000..54a47e5e --- /dev/null +++ b/playlet-lib/src/components/parts/ContextMenuProvider/ContextMenuProvider.part.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/config/default_home_layout.json5 b/playlet-lib/src/config/default_home_layout.json5 deleted file mode 100644 index 15f99a44..00000000 --- a/playlet-lib/src/config/default_home_layout.json5 +++ /dev/null @@ -1,64 +0,0 @@ -[ - { - title: "Subscriptions", - apiType: "Invidious", - endpoint: "auth_feed", - }, - { - title: "Trending", - apiType: "Invidious", - endpoint: "trending", - }, - { - title: "Trending - Music", - apiType: "Invidious", - endpoint: "trending", - queryParams: { - type: "Music", - }, - }, - { - title: "Trending - Gaming", - apiType: "Invidious", - endpoint: "trending", - queryParams: { - type: "Gaming", - }, - }, - { - title: "Trending - Movies", - apiType: "Invidious", - endpoint: "trending", - queryParams: { - type: "Movies", - }, - }, - { - title: "Popular", - apiType: "Invidious", - endpoint: "popular", - }, - { - title: "Funny", - apiType: "Invidious", - endpoint: "search", - queryParams: { - q: "Funny", - sort_by: "upload_date", - }, - }, - { - title: "News", - apiType: "Invidious", - endpoint: "search", - queryParams: { - q: "News", - sort_by: "upload_date", - }, - }, - { - title: "Playlists", - apiType: "Invidious", - endpoint: "playlists", - }, -] diff --git a/playlet-lib/src/config/default_home_layout.yaml b/playlet-lib/src/config/default_home_layout.yaml new file mode 100644 index 00000000..7c7f53e8 --- /dev/null +++ b/playlet-lib/src/config/default_home_layout.yaml @@ -0,0 +1,74 @@ +- title: Subscriptions + feedSources: + - id: inv_auth_feed + title: Subscriptions + apiType: Invidious + endpoint: auth_feed + +- title: Trending + feedSources: + - id: inv_trending + title: Trending + apiType: Invidious + endpoint: trending + +- title: Trending - Music + feedSources: + - id: inv_trending_music + title: Trending - Music + apiType: Invidious + endpoint: trending + queryParams: + type: Music + +- title: Trending - Gaming + feedSources: + - id: inv_trending_gaming + title: Trending - Gaming + apiType: Invidious + endpoint: trending + queryParams: + type: Gaming + +- title: Trending - Movies + feedSources: + - id: inv_trending_movies + title: Trending - Movies + apiType: Invidious + endpoint: trending + queryParams: + type: Movies + +- title: Popular + feedSources: + - id: inv_popular + title: Popular + apiType: Invidious + endpoint: popular + +- title: Funny + feedSources: + - id: inv_search_funny + title: Search - Funny + apiType: Invidious + endpoint: search + queryParams: + q: Funny + sort_by: upload_date + +- title: News + feedSources: + - id: inv_search_news + title: Search - News + apiType: Invidious + endpoint: search + queryParams: + q: News + sort_by: upload_date + +- title: Playlists + feedSources: + - id: inv_auth_playlists + title: Playlists + apiType: Invidious + endpoint: auth_playlists diff --git a/playlet-lib/src/config/invidious_video_api.json5 b/playlet-lib/src/config/invidious_video_api.json5 deleted file mode 100644 index eb5d9ddc..00000000 --- a/playlet-lib/src/config/invidious_video_api.json5 +++ /dev/null @@ -1,195 +0,0 @@ -{ - endpoints: [ - { - name: "trending", - displayName: "Trending", - url: "/api/v1/trending", - queryParams: { - type: { - required: false, - type: ["Music", "Gaming", "Movies"], - }, - region: { - required: false, - type: "#ISO3166", - default: "GetUserCountryCode", - }, - fields: { - required: false, - type: [], - arrayType: "comma-separated", - default: [ - "title", - "videoId", - "videoThumbnails", - "lengthSeconds", - "viewCount", - "author", - "publishedText", - "liveNow", - "isUpcoming", - "premiereTimestamp", - ], - }, - }, - cacheSeconds: 21600, // 6 hours - }, - { - name: "popular", - displayName: "Popular", - url: "/api/v1/popular", - queryParams: { - fields: { - required: false, - type: [], - arrayType: "comma-separated", - default: [ - "title", - "videoId", - "videoThumbnails", - "lengthSeconds", - "viewCount", - "author", - "publishedText", - "liveNow", - "isUpcoming", - "premiereTimestamp", - ], - }, - }, - }, - { - name: "search", - displayName: "Search", - url: "/api/v1/search", - paginationType: "Pages", - queryParams: { - q: { - required: true, - type: "string", - }, - sort_by: { - required: false, - type: ["relevance", "rating", "upload_date", "view_count"], - }, - date: { - required: false, - type: ["hour", "today", "week", "month", "year"], - }, - duration: { - required: false, - type: ["short", "long"], - }, - type: { - required: false, - type: ["video", "playlist", "channel", "all"], - arrayType: "comma-separated", - default: ["video", "playlist", "channel"], - }, - features: { - required: false, - type: [ - "hd", - "subtitles", - "creative_commons", - "3d", - "live", - "purchased", - "4k", - "360", - "location", - "hdr", - ], - }, - region: { - required: false, - type: "#ISO3166", - default: "GetUserCountryCode", - }, - }, - cacheSeconds: 900, // 15 minutes - }, - { - name: "auth_feed", - displayName: "User Feed", - url: "/api/v1/auth/feed", - authenticated: true, - responseHandler: "AuthFeedHandler", - queryParams: { - max_results: { - required: false, - type: "number", - default: 20, - }, - }, - paginationType: "Pages", - }, - { - name: "playlists", - displayName: "Playlists", - url: "/api/v1/auth/playlists", - authenticated: true, - }, - { - name: "playlist", - displayName: "Playlist", - url: "/api/v1/playlists/{plid}", - responseHandler: "PlaylistHandler", - paginationType: "Pages", - }, - { - name: "channel_videos", - displayName: "Channel videos", - url: "/api/v1/channels/{ucid}/videos", - responseHandler: "ChannelVideosHandler", - paginationType: "Continuation", - queryParams: { - sort_by: { - required: false, - type: ["newest", "oldest", "popular"], - }, - }, - }, - { - name: "channel_playlists", - displayName: "Channel playlists", - url: "/api/v1/channels/{ucid}/playlists", - responseHandler: "ChannelPlaylistsHandler", - paginationType: "Continuation", - queryParams: { - sort_by: { - required: false, - type: ["newest", "oldest", "last"], - }, - }, - }, - { - name: "channel_shorts", - displayName: "Channel shorts", - url: "/api/v1/channels/{ucid}/shorts", - responseHandler: "ChannelVideosHandler", - paginationType: "Continuation", - }, - { - name: "channel_streams", - displayName: "Channel livestreams", - url: "/api/v1/channels/{ucid}/streams", - responseHandler: "ChannelVideosHandler", - paginationType: "Continuation", - }, - { - name: "channel_podcasts", - displayName: "Channel podcasts", - url: "/api/v1/channels/{ucid}/podcasts", - responseHandler: "ChannelPlaylistsHandler", - paginationType: "Continuation", - }, - { - name: "channel_channels", - displayName: "Related channels", - url: "/api/v1/channels/{ucid}/channels", - responseHandler: "ChannelRelatedChannelsHandler", - paginationType: "Continuation", - }, - ], -} diff --git a/playlet-lib/src/config/invidious_video_api.yaml b/playlet-lib/src/config/invidious_video_api.yaml new file mode 100644 index 00000000..fe4de3ac --- /dev/null +++ b/playlet-lib/src/config/invidious_video_api.yaml @@ -0,0 +1,195 @@ +trending: + title: Trending + url: /api/v1/trending + cacheSeconds: 21600 # 6 hours + queryParams: + type: + type: + - Music + - Gaming + - Movies + region: + type: "#ISO3166" + default: GetUserCountryCode + fields: + type: [] + arrayType: "comma-separated" + default: + - title + - videoId + - videoThumbnails + - lengthSeconds + - viewCount + - author + - authorId + - publishedText + - liveNow + - isUpcoming + - premiereTimestamp + +popular: + title: Popular + url: /api/v1/popular + queryParams: + fields: + type: [] + arrayType: "comma-separated" + default: + - title + - videoId + - videoThumbnails + - lengthSeconds + - viewCount + - author + - authorId + - publishedText + - liveNow + - isUpcoming + - premiereTimestamp + +search: + title: Search + url: /api/v1/search + paginationType: Pages + queryParams: + q: + type: string + sort_by: + type: + - relevance + - rating + - upload_date + - view_count + date: + type: + - hour + - today + - week + - month + - year + duration: + type: + - short + - long + type: + type: + - video + - playlist + - channel + - all + arrayType: comma-separated + default: + - video + - playlist + - channel + features: + type: + - hd + - subtitles + - creative_commons + - 3d + - live + - purchased + - 4k + - 360 + - location + - hdr + arrayType: comma-separated + region: + type: "#ISO3166" + default: GetUserCountryCode + cacheSeconds: 900 # 15 minutes + +# Auth endpoints +auth_feed: + title: Subscriptions + url: /api/v1/auth/feed + authenticated: true + queryParams: + max_results: + type: number + default: 20 + paginationType: Pages + responseHandler: AuthFeedHandler + +auth_playlists: + title: Playlists + url: /api/v1/auth/playlists + authenticated: true + +playlist: + title: Playlist + url: /api/v1/playlists/{plid} + responseHandler: PlaylistHandler + paginationType: Pages + +# video_info, playlist_info and channel_info are used by the +# Bookmarks, so they are cached for longer +video_info: + title: Video + url: /api/v1/videos/{id} + responseHandler: VideoInfoHandler + cacheSeconds: 259200 # 3 days + +playlist_info: + title: Playlist + url: /api/v1/playlists/{plid} + responseHandler: PlaylistInfoHandler + cacheSeconds: 259200 # 3 days + +channel_info: + title: Channel + url: /api/v1/channels/{ucid} + responseHandler: ChannelInfoHandler + cacheSeconds: 259200 # 3 days + +# Channel endpoints +channel_videos: + title: Channel videos + url: /api/v1/channels/{ucid}/videos + responseHandler: ChannelVideosHandler + paginationType: Continuation + queryParams: + sort_by: + # defaults to newest + type: + - newest + - oldest + - popular + +channel_playlists: + title: Channel playlists + url: /api/v1/channels/{ucid}/playlists + responseHandler: ChannelPlaylistsHandler + paginationType: Continuation + queryParams: + sort_by: + required: false + type: + - newest + - oldest + - last + +channel_shorts: + title: Channel shorts + url: /api/v1/channels/{ucid}/shorts + responseHandler: ChannelVideosHandler + paginationType: Continuation + +channel_streams: + title: Channel streams + url: /api/v1/channels/{ucid}/streams + responseHandler: ChannelVideosHandler + paginationType: Continuation + +channel_podcasts: + title: Channel podcasts + url: /api/v1/channels/{ucid}/podcasts + responseHandler: ChannelPlaylistsHandler + paginationType: Continuation + +channel_channels: + title: Related channels + url: /api/v1/channels/{ucid}/channels + responseHandler: ChannelRelatedChannelsHandler + paginationType: Continuation diff --git a/playlet-lib/src/images/icons/star.png b/playlet-lib/src/images/icons/star.png new file mode 100644 index 00000000..1fca5959 Binary files /dev/null and b/playlet-lib/src/images/icons/star.png differ diff --git a/playlet-lib/src/source/utils/ErrorUtils.bs b/playlet-lib/src/source/utils/ErrorUtils.bs index 8c9ff9aa..e6d7731d 100644 --- a/playlet-lib/src/source/utils/ErrorUtils.bs +++ b/playlet-lib/src/source/utils/ErrorUtils.bs @@ -14,7 +14,7 @@ namespace ErrorUtils result = `${error.message} (0x${StrI(error.number, 16)}). backtrace:` for i = error.backtrace.count() - 1 to 0 step -1 backtrace = error.backtrace[i] - result += `\n ${backtrace.function} @ ${backtrace.filename}:${backtrace.line_number}\n` + result += `\n ${backtrace.function} @${backtrace.filename}:${backtrace.line_number}\n` end for return result end if diff --git a/playlet-lib/src/source/utils/Logging.bs b/playlet-lib/src/source/utils/Logging.bs index 2f255386..4e98db12 100644 --- a/playlet-lib/src/source/utils/Logging.bs +++ b/playlet-lib/src/source/utils/Logging.bs @@ -5,13 +5,6 @@ enum LogLevel DEBUG = 3 end enum -function InitializeLogger(logLevel = LogLevel.Info as LogLevel) as void - logger = CreateObject("roSGNode", "Logger") - logger.logLevel = logLevel - m.global.addFields({ logger: logger }) - logger.control = "run" -end function - function LogError(arg1 = invalid as dynamic, arg2 = invalid as dynamic, arg3 = invalid as dynamic, arg4 = invalid as dynamic, arg5 = invalid as dynamic, arg6 = invalid as dynamic, arg7 = invalid as dynamic, arg8 = invalid as dynamic, arg9 = invalid as dynamic, arg10 = invalid as dynamic, arg11 = invalid as dynamic, arg12 = invalid as dynamic, arg13 = invalid as dynamic, arg14 = invalid as dynamic, arg15 = invalid as dynamic, arg16 = invalid as dynamic) as void throw "FATAL: Calling LogError() which is a stub function" end function @@ -45,6 +38,10 @@ function ToString(value as dynamic) as string return "Node(" + value.subType() + ":" + value.id + ")" else if valueType = "roAssociativeArray" return AssocArrayToString(value) + else if valueType = "roArray" + return ArrayToString(value) + else if valueType = "roDateTime" + return value.ToISOString() end if return "<" + valueType + ">" @@ -64,3 +61,18 @@ function AssocArrayToString(dict as object) as string result += "}" return result end function + +function ArrayToString(array as object) as string + result = "[" + count = array.count() + i = 0 + for each item in array + result += ToString(item) + if i < count - 1 + result += ", " + end if + i++ + end for + result += "]" + return result +end function diff --git a/playlet-lib/src/source/utils/RegistryUtils.bs b/playlet-lib/src/source/utils/RegistryUtils.bs index a52b1f75..c0b8cb6b 100644 --- a/playlet-lib/src/source/utils/RegistryUtils.bs +++ b/playlet-lib/src/source/utils/RegistryUtils.bs @@ -6,6 +6,7 @@ namespace RegistryUtils const SEARCH_HISTORY = "search_history" const PLAYLET_LIB_URLS = "playlet_lib_urls" + const BOOKMARKS = "bookmarks" const INVIDIOUS_INSTANCES = "invidious_instances" const INVIDIOUS_TOKEN = "invidious_token" diff --git a/playlet-web/src/App.svelte b/playlet-web/src/App.svelte index aaf6fe27..d7c83052 100644 --- a/playlet-web/src/App.svelte +++ b/playlet-web/src/App.svelte @@ -28,13 +28,8 @@ homeLayoutFileStore.set(value); }); - PlayletApi.getInvidiousVideoApiFile().then((invidiousVideoApiFile) => { - const invidiousVideoApiDefinitions = - invidiousVideoApiFile.endpoints.reduce((acc, endpoint) => { - acc[endpoint.name] = endpoint; - return acc; - }, {}); - invidiousVideoApiStore.set(invidiousVideoApiDefinitions); + PlayletApi.getInvidiousVideoApiFile().then((apiDefinitions) => { + invidiousVideoApiStore.set(apiDefinitions); }); PlayletApi.getPreferencesFile().then((value) => { diff --git a/playlet-web/src/lib/Api/InvidiousApi.ts b/playlet-web/src/lib/Api/InvidiousApi.ts index e4695207..9032878c 100644 --- a/playlet-web/src/lib/Api/InvidiousApi.ts +++ b/playlet-web/src/lib/Api/InvidiousApi.ts @@ -30,12 +30,15 @@ export class InvidiousApi { return await response.json(); } - public async makeRequest(requestData: any) { - if (!requestData || !this.instance || !this.endpoints) { + public async makeRequest(feed: any) { + // TODO:P0 handle multiple feed sources + const feedSource = feed.feedSources[0] + + if (!feedSource || !this.instance || !this.endpoints) { return null; } - let endpoint = this.endpoints[requestData.endpoint]; + let endpoint = this.endpoints[feedSource.endpoint]; if (!endpoint) { return null; } @@ -49,7 +52,7 @@ export class InvidiousApi { if (!this.isLoggedIn) { return null; } - return await PlayletApi.invidiousAuthenticatedRequest(requestData); + return await PlayletApi.invidiousAuthenticatedRequest(feedSource); } if (endpoint.queryParams !== undefined) { @@ -69,13 +72,13 @@ export class InvidiousApi { } } - if (requestData.queryParams !== undefined) { - queryParams = { ...queryParams, ...requestData.queryParams }; + if (feedSource.queryParams !== undefined) { + queryParams = { ...queryParams, ...feedSource.queryParams }; } - if (requestData.pathParams !== undefined) { - for (let param in requestData.pathParams) { - url = url.replace(`{${param}}`, requestData.pathParams[param]); + if (feedSource.pathParams !== undefined) { + for (let param in feedSource.pathParams) { + url = url.replace(`{${param}}`, feedSource.pathParams[param]); } } @@ -86,10 +89,10 @@ export class InvidiousApi { if (!responseHandler) { return null; } - return await responseHandler(requestData, response); + return await responseHandler(feedSource, response); } - private async DefaultHandler(requestData, response) { + private async DefaultHandler(feedSource, response) { const items = await response.json(); return { items }; } diff --git a/playlet-web/src/lib/Api/PlayletApi.ts b/playlet-web/src/lib/Api/PlayletApi.ts index 5d2670b6..2eba3864 100644 --- a/playlet-web/src/lib/Api/PlayletApi.ts +++ b/playlet-web/src/lib/Api/PlayletApi.ts @@ -14,12 +14,12 @@ export class PlayletApi { } static async getHomeLayoutFile() { - const response = await fetch(`${PlayletApi.host()}/config/default_home_layout.json5`); + const response = await fetch(`${PlayletApi.host()}/config/default_home_layout.yaml`); return await response.json(); } static async getInvidiousVideoApiFile() { - const response = await fetch(`${PlayletApi.host()}/config/invidious_video_api.json5`); + const response = await fetch(`${PlayletApi.host()}/config/invidious_video_api.yaml`); return await response.json(); } diff --git a/playlet-web/src/lib/Screens/Home/ScreenHomeRow.svelte b/playlet-web/src/lib/Screens/Home/ScreenHomeRow.svelte index 50f94f35..26639d64 100644 --- a/playlet-web/src/lib/Screens/Home/ScreenHomeRow.svelte +++ b/playlet-web/src/lib/Screens/Home/ScreenHomeRow.svelte @@ -5,7 +5,7 @@ import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte"; import ChannelCell from "./ChannelCell.svelte"; - export let requestData: any = undefined; + export let feed: any = undefined; export let videos = undefined; let itemWidths = []; @@ -40,7 +40,7 @@ }); async function updateRow() { - const result = await invidiousApi.makeRequest(requestData); + const result = await invidiousApi.makeRequest(feed); if (result && result.items) { result.items.forEach((item) => { if (item.videoId) { @@ -89,7 +89,7 @@ {#if videos} - {requestData.title} + {feed.title} - {#each $homeLayoutFileStore as homeLayoutItem} - + {#each $homeLayoutFileStore as feed} + {/each}