diff --git a/CHANGELOG.md b/CHANGELOG.md
index f7f95ae4..f81592a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A field to indicate when a playlist was last updated
- Voice search in search page
+- Basic support for channels (open channel, see latest videos)
### Changed
diff --git a/playlet-lib/src/components/ChannelView/ChannelUtils.bs b/playlet-lib/src/components/ChannelView/ChannelUtils.bs
new file mode 100644
index 00000000..d794da97
--- /dev/null
+++ b/playlet-lib/src/components/ChannelView/ChannelUtils.bs
@@ -0,0 +1,8 @@
+namespace ChannelUtils
+ function Open(contentNode as object)
+ channelView = CreateObject("roSGNode", "ChannelView")
+ m.appController@.PushScreen(channelView)
+ channelView@.BindNode(invalid)
+ channelView.content = contentNode
+ end function
+end namespace
diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs
new file mode 100644
index 00000000..68241a66
--- /dev/null
+++ b/playlet-lib/src/components/ChannelView/ChannelView.bs
@@ -0,0 +1,77 @@
+import "pkg:/source/roku_modules/log/LogMixin.brs"
+import "pkg:/source/utils/FocusManagement.bs"
+import "pkg:/source/utils/Types.bs"
+import "pkg:/source/utils/StringUtils.bs"
+
+function Init()
+ m.log = new log.Logger("ChannelView")
+
+ m.banner = m.top.findNode("banner")
+ m.thumbnail = m.top.findNode("thumbnail")
+ m.authorLabel = m.top.findNode("authorLabel")
+ m.rowList = m.top.FindNode("rowList")
+
+ m.banner.ObserveField("loadStatus", FuncName(OnBannerLoadStatus))
+end function
+
+function OnNodeready()
+ m.rowList@.BindNode(invalid)
+end function
+
+function OnFocusChange() as void
+ if not m.top.focus
+ return
+ end if
+
+ NodeSetFocus(m.rowList, true)
+end function
+
+function OnContentSet() as void
+ content = m.top.content
+ if content = invalid
+ return
+ end if
+
+ ' 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 = ""
+ else
+ if m.thumbnail.uri <> content.thumbnail or m.thumbnail.loadStatus = "failed"
+ m.thumbnail.loadingBitmapUri = m.thumbnail.uri
+ m.thumbnail.uri = content.thumbnail
+ end if
+ end if
+
+ m.rowList.content = content
+
+ content@.LoadChannel(m.invidious)
+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.appController@.PopScreen(invalid)
+end function
+
+function OnBannerLoadStatus() as void
+ status = m.banner.loadStatus
+ if status <> "ready"
+ return
+ end if
+
+ aspect = m.banner.bitmapWidth / m.banner.bitmapHeight
+ m.banner.height = m.banner.width / aspect
+end function
diff --git a/playlet-lib/src/components/ChannelView/ChannelView.xml b/playlet-lib/src/components/ChannelView/ChannelView.xml
new file mode 100644
index 00000000..02f293df
--- /dev/null
+++ b/playlet-lib/src/components/ChannelView/ChannelView.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/components/ContentNode/ChannelContentNode.bs b/playlet-lib/src/components/ContentNode/ChannelContentNode.bs
new file mode 100644
index 00000000..804d17d2
--- /dev/null
+++ b/playlet-lib/src/components/ContentNode/ChannelContentNode.bs
@@ -0,0 +1,48 @@
+import "pkg:/source/asyncTask/asyncTask.bs"
+import "pkg:/components/ContentNode/ChannelContentTask.bs"
+import "pkg:/source/utils/ErrorUtils.bs"
+import "pkg:/components/Dialog/DialogUtils.bs"
+
+function Init()
+ m.top.latestVideos = m.top.findNode("latestVideos")
+end function
+
+function LoadChannel(invidiousNode as object) as void
+ if m.contentTask <> invalid
+ m.contentTask.cancel = true
+ end if
+
+ loadState = m.top.loadState
+ if loadState = FeedLoadState.Loading or loadState = FeedLoadState.Loaded
+ return
+ end if
+
+ m.top.loadState = FeedLoadState.Loading
+ m.contentTask = StartAsyncTask(ChannelContentTask, {
+ content: m.top,
+ invidious: invidiousNode
+ }, OnChannelContentTaskResult)
+end function
+
+function OnChannelContentTaskResult(output as object) as void
+ m.contentTask = invalid
+
+ if output.cancelled
+ 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)
+ m.log.error(error)
+ playlistId = output.task.input.content.playlistId
+ message = `Failed to load playlist ${playlistId}\n${error}`
+ DialogUtils.ShowDialog(message, "Playlist load fail", true)
+ return
+ end if
+end function
diff --git a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml
index 72a8eeea..876751f8 100644
--- a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml
+++ b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml
@@ -1,7 +1,28 @@
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/components/ContentNode/ChannelContentTask.bs b/playlet-lib/src/components/ContentNode/ChannelContentTask.bs
new file mode 100644
index 00000000..5b5b903c
--- /dev/null
+++ b/playlet-lib/src/components/ContentNode/ChannelContentTask.bs
@@ -0,0 +1,40 @@
+import "pkg:/components/Services/Invidious/InvidiousService.bs"
+import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
+
+@asynctask
+function ChannelContentTask(input as object) as object
+ contentNode = input.content
+ invidiousNode = input.invidious
+
+ if m.top.cancel
+ contentNode.loadState = FeedLoadState.None
+ return invalid
+ end if
+
+ service = new Invidious.InvidiousService(invidiousNode)
+ response = service.GetChannel(contentNode.authorId, m.top.cancellation)
+
+ if m.top.cancel
+ contentNode.loadState = FeedLoadState.None
+ return invalid
+ end if
+
+ metadata = response.Json()
+
+ if not response.IsSuccess() or metadata = invalid
+ contentNode.loadState = FeedLoadState.Error
+ return {
+ success: false,
+ error: response.ErrorMessage()
+ }
+ end if
+
+ instance = service.GetInstance()
+ InvidiousContent.ToChannelContentNode(contentNode, metadata, instance)
+
+ contentNode.loadState = FeedLoadState.Loaded
+
+ return {
+ success: true
+ }
+end function
diff --git a/playlet-lib/src/components/PlaylistView/PlaylistView.bs b/playlet-lib/src/components/PlaylistView/PlaylistView.bs
index c3522eb0..b2d8fcec 100644
--- a/playlet-lib/src/components/PlaylistView/PlaylistView.bs
+++ b/playlet-lib/src/components/PlaylistView/PlaylistView.bs
@@ -9,7 +9,6 @@ import "pkg:/components/VideoFeed/FeedLoadState.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/components/Dialog/DialogUtils.bs"
-' TODO:P2 use already loaded thumbnail, and crossfade to highres version (using same Poster)
function Init()
m.log = new log.Logger("PlaylistView")
@@ -47,7 +46,8 @@ function OnContentSet() as void
m.updatedLabel.text = content.updatedText
m.descriptionLabel.text = content.description
- ' TODO:P2 cross fade
+ ' We use two Posters to cross fade from the low res thumbnail to the high res thumbnail.
+ ' We can't use a single Poster because we're using the blendColor. There's no loadingBitmapBlendColor.
m.backgroundSmall.uri = content.thumbnail
m.background.uri = content.thumbnailBackground
diff --git a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml
index b6e81d26..ffd6caea 100644
--- a/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml
+++ b/playlet-lib/src/components/Screens/HomeScreen/HomeScreen.xml
@@ -20,6 +20,7 @@
focusXOffset="[115]"
showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus"
+ variableWidthItems="true"
focusBitmapUri="pkg:/images/focus_grid.9.png"
/>
diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
index 2958276e..4fc5cfa8 100644
--- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
+++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
@@ -16,6 +16,7 @@ namespace Invidious
const VIDEOS_ENDPOINT = "/api/v1/videos"
const PLAYLISTS_ENDPOINT = "/api/v1/playlists"
+ const CHANNELS_ENDPOINT = "/api/v1/channels"
const HISTORY_ENDPOINT = "/api/v1/auth/history"
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
@@ -136,6 +137,17 @@ namespace Invidious
return request.Await()
end function
+ function GetChannel(authorId as string, cancellation = invalid as object) as object
+ instance = m.GetInstance()
+ url = `${instance}${Invidious.CHANNELS_ENDPOINT}/${authorId}`
+
+ request = HttpClient.Get(url)
+ request.QueryParams(m.DefaultQueryParams())
+ request.Cancellation(cancellation)
+
+ return request.Await()
+ end function
+
function GetVideoStreamUrl(videoId as string) as string
instance = m.GetInstance()
return `${instance}/latest_version?id=${videoId}`
diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
index 39ba3615..011965a8 100644
--- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
+++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
@@ -21,8 +21,7 @@ namespace InvidiousContent
else if item.type = "playlist"
return ToPlaylistContentNode(invalid, item, instance)
else if item.type = "channel"
- return invalid
- ' return ToChannelContentNode(item, instance)
+ return ToChannelContentNode(invalid, item, instance)
else
return invalid
end if
@@ -67,7 +66,7 @@ namespace InvidiousContent
SetIfExists(node, "playlistId", item, "playlistId")
SetIfExists(node, "title", item, "title")
SetIfExists(node, "videoCount", item, "videoCount")
- node.videoCountText = PlaylistGetVideoCountText(item)
+ node.videoCountText = GetVideoCountText(item)
SetIfExists(node, "viewCount", item, "viewCount")
node.viewCountText = PlaylistGetViewCountText(item)
SetIfExists(node, "updated", item, "updated")
@@ -99,10 +98,40 @@ namespace InvidiousContent
return node
end function
- function ToChannelContentNode(item as object, instance as dynamic) as object
- node = CreateObject("roSGNode", "ChannelContentNode")
+ function ToChannelContentNode(node as object, item as object, instance as dynamic) as object
+ if node = invalid
+ node = CreateObject("roSGNode", "ChannelContentNode")
+ node.loadState = FeedLoadState.None
+ end if
node.type = "channel"
+ ' 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, "subCount", item, "subCount")
+ node.subCountText = GetChannelSubCountText(item)
+ SetIfExists(node, "videoCount", item, "videoCount")
+ node.videoCountText = GetVideoCountText(item)
+ node.thumbnail = GetChannelThumbnail(item.authorThumbnails)
+ node.banner = GetChannelBanner(item.authorBanners)
+
+ if item.latestVideos <> invalid
+ newNodes = []
+
+ for each video in item.latestVideos
+ video.type = "video"
+ videoNode = ToVideoContentNode(invalid, video, instance)
+ if videoNode <> invalid
+ newNodes.push(videoNode)
+ end if
+ end for
+
+ if newNodes.Count() > 0
+ node.latestVideos.appendChildren(newNodes)
+ end if
+ end if
+
return node
end function
@@ -201,11 +230,34 @@ namespace InvidiousContent
node[nodeField] = thumbnail
end function
- function PlaylistGetVideoCountText(playlistItem as object) as string
- videoCount = ValidInt(playlistItem.videoCount)
+ function GetChannelThumbnail(authorThumbnails as object) as string
+ if authorThumbnails = invalid or authorThumbnails.Count() = 0
+ return ""
+ end if
+ url = authorThumbnails[authorThumbnails.Count() - 1].url
+ if url.startsWith("//")
+ url = "https:" + url
+ end if
+ return url
+ end function
+
+ function GetChannelBanner(authorBanners as object) as string
+ if authorBanners = invalid or authorBanners.Count() = 0
+ return ""
+ end if
+ return authorBanners[authorBanners.Count() - 1].url
+ end function
+
+ function GetVideoCountText(item as object) as string
+ videoCount = ValidInt(item.videoCount)
return videoCount = 1 ? "1 video" : `${videoCount} videos`
end function
+ function GetChannelSubCountText(channel as object) as string
+ subCount = ValidInt(channel.subCount)
+ return subCount = 1 ? "1 subscriber" : `${subCount} subscribers`
+ end function
+
function PlaylistGetViewCountText(playlistItem as object) as string
return VideoGetViewCountText(playlistItem)
end function
diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.bs b/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.bs
index f2c0ce93..9cb4ec74 100644
--- a/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.bs
+++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.bs
@@ -13,44 +13,9 @@ function OnContentSet() as void
return
end if
- m.authorLabel.text = content.author
- SetSubCount(content.subCount)
-
- m.thumbnail.uri = GetThumbnailUrl(content.authorThumbnails)
-
- SetVideoCount(content.videoCount)
-end function
-
-function SetSubCount(subCount as integer)
- subCountText = ""
- if subCount = 1
- subCountText = "1 subscriber"
- else
- subCountText = `${subCount} subscribers`
- end if
-
- m.subCountLabel.text = subCountText
-end function
-
-
-function SetVideoCount(videoCount as integer)
- videoCountText = ""
- if videoCount = 1
- videoCountText = "1 video"
- else
- videoCountText = `${videoCount} videos`
- end if
-
- m.videoCountLabel.text = videoCountText
-end function
-
-function GetThumbnailUrl(videoThumbnails as object) as string
- if videoThumbnails = invalid or videoThumbnails.Count() = 0
- return ""
- end if
- url = videoThumbnails[videoThumbnails.Count() - 1].url
- if url.startsWith("//")
- url = "https:" + url
- end if
- return url
+ ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
+ m.authorLabel.text = content._author
+ m.subCountLabel.text = content.subCountText
+ m.videoCountLabel.text = content.videoCountText
+ m.thumbnail.uri = content.thumbnail
end function
diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.xml b/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.xml
index 3b9b1418..20c272c0 100644
--- a/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.xml
+++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/ChannelRowCell.xml
@@ -8,27 +8,29 @@
-
-
+
+
+
diff --git a/playlet-lib/src/components/VideoFeed/VideoRowList.bs b/playlet-lib/src/components/VideoFeed/VideoRowList.bs
index e2b0e916..ed071c27 100644
--- a/playlet-lib/src/components/VideoFeed/VideoRowList.bs
+++ b/playlet-lib/src/components/VideoFeed/VideoRowList.bs
@@ -7,6 +7,7 @@ import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/VideoPlayer/VideoUtils.bs"
import "pkg:/components/PlaylistView/PlaylistUtils.bs"
+import "pkg:/components/ChannelView/ChannelUtils.bs"
function Init()
m.pendingLoadTasks = {}
@@ -78,6 +79,7 @@ function OnRowItemSelected(event as object)
else if rowItem.type = "channel"
authorId = rowItem.authorId
m.log.info("Open channel: " + authorId)
+ ChannelUtils.Open(rowItem)
else if rowItem.type = "action"
if rowItem.action = "LoginDialog"
dialog = CreateObject("roSGNode", "LoginDialog")
diff --git a/playlet-lib/src/config/invidious_video_api.json5 b/playlet-lib/src/config/invidious_video_api.json5
index 09526c64..573e5c55 100644
--- a/playlet-lib/src/config/invidious_video_api.json5
+++ b/playlet-lib/src/config/invidious_video_api.json5
@@ -84,7 +84,7 @@
required: false,
type: ["video", "playlist", "channel", "all"],
arrayType: "comma-separated",
- default: ["video", "playlist"],
+ default: ["video", "playlist", "channel"],
},
features: {
required: false,
diff --git a/playlet-lib/src/images/circle-mask-500.png b/playlet-lib/src/images/circle-mask-500.png
new file mode 100644
index 00000000..f5c4fb3e
Binary files /dev/null and b/playlet-lib/src/images/circle-mask-500.png differ