Feature/channel view content (#150)

* ChannelView feeds

* Fixes for web app

* Add request id to error message
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2023-09-22 17:52:53 -04:00
1 parent e2df0b524a
commit dab6dc5bc4
20 files changed
+414 -133

No files matched your search

@@ -3,12 +3,19 @@ import "pkg:/source/utils/Types.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init()
m.container = m.top.findNode("container")
m.scrollAnimation = m.top.findNode("scrollAnimation")
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
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))
m.authorId = ""
InitializeTabs()
end function
function OnNodeready()
@@ -42,9 +49,28 @@ function OnContentSet() as void
end if
end if
m.rowList.content = content
content@.LoadChannel(m.invidious)
authorId = ValidString(content.authorId)
if authorId <> m.authorId and IsArray(content.tabs)
m.authorId = authorId
m.rowList.contentData = CreateChannelFeeds(m.authorId, content.tabs)
end if
end function
function CreateChannelFeeds(authorId as string, tabs as object) as object
if authorId = ""
return invalid
end if
feeds = []
for i = 0 to tabs.count() - 1
tabName = tabs[i]
if m.tabs.DoesExist(tabName)
feeds.Push(m.tabs[tabName](authorId))
end if
end for
return feeds
end function
function OnkeyEvent(key as string, press as boolean) as boolean
@@ -71,4 +97,47 @@ function OnBannerLoadStatus() as void
aspect = m.banner.bitmapWidth / m.banner.bitmapHeight
m.banner.height = m.banner.width / aspect
m.banner.translation = [0, -m.banner.height]
m.banner.visible = true
startPos = [0, 0]
endPos = [0, m.banner.height]
midPos = [0, m.banner.height / 2]
m.scrollAnimationInterpolator.keyValue = [startPos, midPos, endPos]
m.scrollAnimation.control = "start"
end function
function InitializeTabs()
m.tabs = {
videos: function(authorId as string) as object
return CreateChannelFeed("Latest videos", "channel_videos", authorId)
end function,
shorts: function(authorId as string) as object
return CreateChannelFeed("Shorts", "channel_shorts", authorId)
end function,
streams: function(authorId as string) as object
return CreateChannelFeed("Live", "channel_streams", authorId)
end function,
podcasts: function(authorId as string) as object
return CreateChannelFeed("Podcasts", "channel_podcasts", authorId)
end function,
playlists: function(authorId as string) as object
return CreateChannelFeed("Playlists", "channel_playlists", authorId)
end function,
channels: function(authorId as string) as object
return CreateChannelFeed("Channels", "channel_channels", authorId)
end function
}
end function
function CreateChannelFeed(title as string, endpoint as string, ucid as string) as object
return {
title: title,
apiType: "Invidious",
endpoint: endpoint,
pathParams: {
ucid: ucid
}
}
end function
@@ -11,44 +11,57 @@
color="0x242424">
</Rectangle>
<Poster
id="banner"
translation="[0,0]"
width="1280" />
<Group id="container">
<Poster
id="banner"
width="1280"
visible="false" />
<Poster
translation="[115,180]"
width="104"
height="104"
uri="pkg:/images/circle-mask-500.png">
<Poster
translation="[115,20]"
width="104"
height="104"
uri="pkg:/images/circle-mask-500.png">
<CirclePoster
id="thumbnail"
width="100"
height="100"
translation="[2,2]" />
</Poster>
<CirclePoster
id="thumbnail"
width="100"
height="100"
translation="[2,2]" />
<Label
id="authorLabel"
translation="[228,226]"
font="font:MediumBoldSystemFont" />
<Label
id="authorLabel"
translation="[115,40]"
font="font:MediumBoldSystemFont" />
</Poster>
<VideoRowList
itemComponentName="RowCell"
id="rowList"
focusable="false"
translation="[0,320]"
numRows="1"
rowitemSize="[[350,196]]"
rowItemSpacing="[[25,0]]"
itemSize="[1280,326]"
itemSpacing="[0,65]"
rowLabelOffset="[[115,20]]"
focusXOffset="[115]"
showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true"
focusBitmapUri="pkg:/images/focus_grid.9.png" />
<VideoRowList
itemComponentName="RowCell"
id="rowList"
focusable="false"
translation="[0,160]"
numRows="2"
rowitemSize="[[350,196]]"
rowItemSpacing="[[25,0]]"
itemSize="[1280,326]"
itemSpacing="[0,65]"
rowLabelOffset="[[115,20]]"
focusXOffset="[115]"
showRowLabel="[true]"
rowFocusAnimationStyle="floatingfocus"
variableWidthItems="true"
focusBitmapUri="pkg:/images/focus_grid.9.png" />
<Animation
id="scrollAnimation"
delay="0.3"
duration="0.6">
<Vector2DFieldInterpolator
id="scrollAnimationInterpolator"
key="[ 0.0, 0.5, 1.0 ]"
fieldToInterp="container.translation" />
</Animation>
</Group>
</children>
</component>
@@ -4,7 +4,6 @@ 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
@@ -14,15 +14,8 @@
<field id="videoCountText" type="string" />
<field id="thumbnail" type="string" />
<field id="banner" type="string" />
<field id="latestVideos" type="node" />
<field id="tabs" type="array" />
<field id="HDItemWidth" type="float" value="196" />
</interface>
<children>
<ContentNode id="latestVideos" title="Latest Videos">
</ContentNode>
</children>
</component>
@@ -2,7 +2,8 @@
<interface>
<field id="feed" type="assocarray" />
<field id="loadState" type="string" />
<field id="pagination" type="boolean" />
<field id="paginationType" type="string" />
<field id="page" type="integer" value="0" />
<field id="continuation" type="string" />
</interface>
</component>
@@ -4,6 +4,7 @@ import "pkg:/source/utils/TimeUtils.bs"
import "pkg:/source/utils/CryptoUtils.bs"
import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/components/VideoFeed/PaginationType.bs"
namespace Invidious
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
@@ -48,7 +49,9 @@ namespace Invidious
DefaultHandler: m.DefaultHandler,
AuthFeedHandler: m.AuthFeedHandler,
PlaylistHandler: m.PlaylistHandler,
ChannelHandler: m.ChannelHandler
ChannelVideosHandler: m.ChannelVideosHandler,
ChannelPlaylistsHandler: m.ChannelPlaylistsHandler,
ChannelRelatedChannelsHandler: m.ChannelRelatedChannelsHandler
}
end function
@@ -155,18 +158,26 @@ namespace Invidious
requestData = contentNode.feed
endpoint = m.endpoints[requestData.endpoint]
if endpoint = invalid or endpoint.pagination <> true
if endpoint = invalid or StringUtils.IsNullOrEmpty(endpoint.paginationType)
return
end if
contentNode.pagination = true
contentNode.page += 1
if not requestData.DoesExist("queryParams")
requestData.queryParams = {}
end if
requestData.queryParams.page = contentNode.page
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
if not StringUtils.IsNullOrEmpty(continuation)
requestData.queryParams.continuation = continuation
end if
end if
contentNode.feed = requestData
end function
@@ -254,21 +265,54 @@ namespace Invidious
end function
function DefaultHandler(m as object, requestData as object, response as object) as object
return response.Json()
if response.StatusCode() = 200
json = response.Json()
return {
items: json
}
end if
return invalid
end function
function PlaylistHandler(m as object, requestData as object, response as object) as object
if response.StatusCode() = 200
json = response.Json()
return json.videos
return {
items: json.videos
}
end if
return invalid
end function
function ChannelHandler(m as object, requestData as object, response as object) as object
function ChannelVideosHandler(m as object, requestData as object, response as object) as object
if response.StatusCode() = 200
json = response.Json()
return json.videos
return {
items: json.videos,
continuation: json.continuation
}
end if
return invalid
end function
function ChannelPlaylistsHandler(m as object, requestData as object, response as object) as object
if response.StatusCode() = 200
json = response.Json()
return {
items: json.playlists,
continuation: json.continuation
}
end if
return invalid
end function
function ChannelRelatedChannelsHandler(m as object, requestData as object, response as object) as object
if response.StatusCode() = 200
json = response.Json()
return {
items: json.relatedChannels,
continuation: json.continuation
}
end if
return invalid
end function
@@ -281,7 +325,9 @@ namespace Invidious
videos = []
videos.Append(json.notifications)
videos.Append(json.videos)
return videos
return {
items: videos
}
end if
return invalid
end function
@@ -115,22 +115,7 @@ namespace InvidiousContent
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
SetIfExists(node, "tabs", item, "tabs")
return node
end function
@@ -245,7 +230,7 @@ namespace InvidiousContent
if authorBanners = invalid or authorBanners.Count() = 0
return ""
end if
return authorBanners[authorBanners.Count() - 1].url
return authorBanners[0].url
end function
function GetVideoCountText(item as object) as string
@@ -107,9 +107,9 @@ namespace SponsorBlock
pixelEnd = (segment.segment[1] / videoDuration) * width
color = m.SegmentColor(segment.category)
' highlight's duration is zero, so it is not visble on the bar.
' Add a couple of pixels to see it
' Add a few pixels to see it
if pixelStart = pixelEnd
pixelEnd += 2
pixelEnd += 5
end if
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, height, color)
end for
@@ -0,0 +1,4 @@
enum PaginationType
Pages = "Pages"
Continuation = "Continuation"
end enum
@@ -1,5 +1,6 @@
import "pkg:/source/utils/TimeUtils.bs"
import "pkg:/source/utils/Types.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init()
m.titleLabel = m.top.FindNode("titleLabel")
@@ -23,36 +24,30 @@ function OnContentSet() as void
m.titleLabel.text = content.title
m.authorLabel.text = content.author
if content.isUpcoming = true
m.viewCountDateLabel.text = content.premiereTimestampText
else
publishedText = ValidString(content.publishedText)
viewCountText = ValidString(content.viewCountText)
if publishedText = "" and viewCountText = ""
m.viewCountDateLabel.text = ""
else
m.viewCountDateLabel.text = `${publishedText} • ${viewCountText}`
if not StringUtils.IsNullOrEmpty(content.publishedText)
label = content.publishedText
if not StringUtils.IsNullOrEmpty(content.viewCountText)
label = `${label} • ${content.viewCountText}`
end if
m.viewCountDateLabel.text = label
else if content.isUpcoming = true
m.viewCountDateLabel.text = content.premiereTimestampText
end if
m.thumbnail.uri = content.thumbnail
if content.isUpcoming = true
m.upcomingRect.visible = true
m.liveRect.visible = false
m.durationRect.visible = false
else if content.liveNow
m.upcomingRect.visible = false
m.liveRect.visible = true
m.durationRect.visible = false
m.durationRect.visible = false
m.upcomingRect.visible = false
m.liveRect.visible = false
if ValidInt(content.lengthSeconds) <> 0
SetDurationText(content.lengthText)
m.durationRect.visible = true
else
m.upcomingRect.visible = false
m.liveRect.visible = false
if ValidInt(content.lengthSeconds) <> 0
SetDurationText(content.lengthText)
m.durationRect.visible = true
else
m.durationRect.visible = false
if content.isUpcoming = true
m.upcomingRect.visible = true
else if content.liveNow
m.liveRect.visible = true
end if
end if
end function
@@ -9,6 +9,8 @@ import "pkg:/components/VideoPlayer/VideoUtils.bs"
import "pkg:/components/PlaylistView/PlaylistUtils.bs"
import "pkg:/components/ChannelView/ChannelUtils.bs"
' TODO:P1 add the option to remove a row if it does not have any content
' E.g. NBC News does not return any related chnanels
function Init()
m.pendingLoadTasks = {}
end function
@@ -152,7 +154,7 @@ function GetRowsToLoad() as object
end if
subContentNodes = []
range = m.top.numRows + 2
range = m.top.numRows + 1
for i = -range to range
index = focus + i
if index < 0
@@ -172,6 +174,8 @@ function GetRowsToLoad() as object
end function
function LoadRowContent(contentNode as object)
LogInfo("Loading row content:", contentNode.title)
contentNode.loadState = FeedLoadState.Loading
task = StartAsyncTask(VideoRowListRowContentTask, {
node: m.top,
@@ -43,7 +43,7 @@ function VideoRowListRowContentTask(input as object) as object
instance = service.GetInstance()
itemNodes = []
for each item in response.result
for each item in response.result.items
itemNode = InvidiousContent.ToRowCellContentNode(item, instance)
if itemNode <> invalid
itemNodes.Push(itemNode)
@@ -53,8 +53,20 @@ function VideoRowListRowContentTask(input as object) as object
RemovePlaceHolderItems(contentNode)
contentNode.appendChildren(itemNodes)
if contentNode.pagination = true and response.result.Count() > 0
contentNode.loadState = FeedLoadState.LoadedPage
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
if hasContinuation
contentNode.continuation = response.result.continuation
end if
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