Feature/channel view content (#150)
* ChannelView feeds * Fixes for web app * Add request id to error message
This commit is contained in:
1 parent
e2df0b524a
commit
dab6dc5bc4
20 files changed
+414
-133
No files matched your search
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Playlists, streams, podcasts and related channels to Channel UI
|
||||||
|
- Pagination supported
|
||||||
|
- Channels show up in web app (but no UI for channel details yet)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Another bug where the app crashes if an error happens loading channel info
|
- Another bug where the app crashes if an error happens loading channel info
|
||||||
|
|||||||
@@ -3,12 +3,19 @@ import "pkg:/source/utils/Types.bs"
|
|||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
function Init()
|
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.banner = m.top.findNode("banner")
|
||||||
m.thumbnail = m.top.findNode("thumbnail")
|
m.thumbnail = m.top.findNode("thumbnail")
|
||||||
m.authorLabel = m.top.findNode("authorLabel")
|
m.authorLabel = m.top.findNode("authorLabel")
|
||||||
m.rowList = m.top.FindNode("rowList")
|
m.rowList = m.top.FindNode("rowList")
|
||||||
|
|
||||||
m.banner.ObserveField("loadStatus", FuncName(OnBannerLoadStatus))
|
m.banner.ObserveField("loadStatus", FuncName(OnBannerLoadStatus))
|
||||||
|
m.authorId = ""
|
||||||
|
|
||||||
|
InitializeTabs()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeready()
|
function OnNodeready()
|
||||||
@@ -42,9 +49,28 @@ function OnContentSet() as void
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.rowList.content = content
|
|
||||||
|
|
||||||
content@.LoadChannel(m.invidious)
|
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
|
end function
|
||||||
|
|
||||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
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
|
aspect = m.banner.bitmapWidth / m.banner.bitmapHeight
|
||||||
m.banner.height = m.banner.width / aspect
|
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
|
end function
|
||||||
@@ -11,44 +11,57 @@
|
|||||||
color="0x242424">
|
color="0x242424">
|
||||||
</Rectangle>
|
</Rectangle>
|
||||||
|
|
||||||
<Poster
|
<Group id="container">
|
||||||
id="banner"
|
<Poster
|
||||||
translation="[0,0]"
|
id="banner"
|
||||||
width="1280" />
|
width="1280"
|
||||||
|
visible="false" />
|
||||||
|
|
||||||
<Poster
|
<Poster
|
||||||
translation="[115,180]"
|
translation="[115,20]"
|
||||||
width="104"
|
width="104"
|
||||||
height="104"
|
height="104"
|
||||||
uri="pkg:/images/circle-mask-500.png">
|
uri="pkg:/images/circle-mask-500.png">
|
||||||
|
|
||||||
<CirclePoster
|
<CirclePoster
|
||||||
id="thumbnail"
|
id="thumbnail"
|
||||||
width="100"
|
width="100"
|
||||||
height="100"
|
height="100"
|
||||||
translation="[2,2]" />
|
translation="[2,2]" />
|
||||||
</Poster>
|
|
||||||
|
|
||||||
<Label
|
<Label
|
||||||
id="authorLabel"
|
id="authorLabel"
|
||||||
translation="[228,226]"
|
translation="[115,40]"
|
||||||
font="font:MediumBoldSystemFont" />
|
font="font:MediumBoldSystemFont" />
|
||||||
|
</Poster>
|
||||||
|
|
||||||
<VideoRowList
|
<VideoRowList
|
||||||
itemComponentName="RowCell"
|
itemComponentName="RowCell"
|
||||||
id="rowList"
|
id="rowList"
|
||||||
focusable="false"
|
focusable="false"
|
||||||
translation="[0,320]"
|
translation="[0,160]"
|
||||||
numRows="1"
|
numRows="2"
|
||||||
rowitemSize="[[350,196]]"
|
rowitemSize="[[350,196]]"
|
||||||
rowItemSpacing="[[25,0]]"
|
rowItemSpacing="[[25,0]]"
|
||||||
itemSize="[1280,326]"
|
itemSize="[1280,326]"
|
||||||
itemSpacing="[0,65]"
|
itemSpacing="[0,65]"
|
||||||
rowLabelOffset="[[115,20]]"
|
rowLabelOffset="[[115,20]]"
|
||||||
focusXOffset="[115]"
|
focusXOffset="[115]"
|
||||||
showRowLabel="[true]"
|
showRowLabel="[true]"
|
||||||
rowFocusAnimationStyle="floatingfocus"
|
rowFocusAnimationStyle="floatingfocus"
|
||||||
variableWidthItems="true"
|
variableWidthItems="true"
|
||||||
focusBitmapUri="pkg:/images/focus_grid.9.png" />
|
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>
|
</children>
|
||||||
</component>
|
</component>
|
||||||
@@ -4,7 +4,6 @@ import "pkg:/source/utils/ErrorUtils.bs"
|
|||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.top.latestVideos = m.top.findNode("latestVideos")
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function LoadChannel(invidiousNode as object) as void
|
function LoadChannel(invidiousNode as object) as void
|
||||||
|
|||||||
@@ -14,15 +14,8 @@
|
|||||||
<field id="videoCountText" type="string" />
|
<field id="videoCountText" type="string" />
|
||||||
<field id="thumbnail" type="string" />
|
<field id="thumbnail" type="string" />
|
||||||
<field id="banner" type="string" />
|
<field id="banner" type="string" />
|
||||||
|
<field id="tabs" type="array" />
|
||||||
<field id="latestVideos" type="node" />
|
|
||||||
|
|
||||||
<field id="HDItemWidth" type="float" value="196" />
|
<field id="HDItemWidth" type="float" value="196" />
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<children>
|
|
||||||
<ContentNode id="latestVideos" title="Latest Videos">
|
|
||||||
|
|
||||||
</ContentNode>
|
|
||||||
</children>
|
|
||||||
</component>
|
</component>
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
<interface>
|
<interface>
|
||||||
<field id="feed" type="assocarray" />
|
<field id="feed" type="assocarray" />
|
||||||
<field id="loadState" type="string" />
|
<field id="loadState" type="string" />
|
||||||
<field id="pagination" type="boolean" />
|
<field id="paginationType" type="string" />
|
||||||
<field id="page" type="integer" value="0" />
|
<field id="page" type="integer" value="0" />
|
||||||
|
<field id="continuation" type="string" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -4,6 +4,7 @@ import "pkg:/source/utils/TimeUtils.bs"
|
|||||||
import "pkg:/source/utils/CryptoUtils.bs"
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
import "pkg:/source/services/HttpClient.bs"
|
import "pkg:/source/services/HttpClient.bs"
|
||||||
import "pkg:/source/utils/Logging.bs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
import "pkg:/components/VideoFeed/PaginationType.bs"
|
||||||
|
|
||||||
namespace Invidious
|
namespace Invidious
|
||||||
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
||||||
@@ -48,7 +49,9 @@ namespace Invidious
|
|||||||
DefaultHandler: m.DefaultHandler,
|
DefaultHandler: m.DefaultHandler,
|
||||||
AuthFeedHandler: m.AuthFeedHandler,
|
AuthFeedHandler: m.AuthFeedHandler,
|
||||||
PlaylistHandler: m.PlaylistHandler,
|
PlaylistHandler: m.PlaylistHandler,
|
||||||
ChannelHandler: m.ChannelHandler
|
ChannelVideosHandler: m.ChannelVideosHandler,
|
||||||
|
ChannelPlaylistsHandler: m.ChannelPlaylistsHandler,
|
||||||
|
ChannelRelatedChannelsHandler: m.ChannelRelatedChannelsHandler
|
||||||
}
|
}
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -155,18 +158,26 @@ namespace Invidious
|
|||||||
requestData = contentNode.feed
|
requestData = contentNode.feed
|
||||||
|
|
||||||
endpoint = m.endpoints[requestData.endpoint]
|
endpoint = m.endpoints[requestData.endpoint]
|
||||||
if endpoint = invalid or endpoint.pagination <> true
|
if endpoint = invalid or StringUtils.IsNullOrEmpty(endpoint.paginationType)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
contentNode.pagination = true
|
|
||||||
contentNode.page += 1
|
|
||||||
|
|
||||||
if not requestData.DoesExist("queryParams")
|
if not requestData.DoesExist("queryParams")
|
||||||
requestData.queryParams = {}
|
requestData.queryParams = {}
|
||||||
end if
|
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
|
contentNode.feed = requestData
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -254,21 +265,54 @@ namespace Invidious
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function DefaultHandler(m as object, requestData as object, response as object) as object
|
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
|
end function
|
||||||
|
|
||||||
function PlaylistHandler(m as object, requestData as object, response as object) as object
|
function PlaylistHandler(m as object, requestData as object, response as object) as object
|
||||||
if response.StatusCode() = 200
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
json = response.Json()
|
||||||
return json.videos
|
return {
|
||||||
|
items: json.videos
|
||||||
|
}
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
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
|
if response.StatusCode() = 200
|
||||||
json = response.Json()
|
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
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
@@ -281,7 +325,9 @@ namespace Invidious
|
|||||||
videos = []
|
videos = []
|
||||||
videos.Append(json.notifications)
|
videos.Append(json.notifications)
|
||||||
videos.Append(json.videos)
|
videos.Append(json.videos)
|
||||||
return videos
|
return {
|
||||||
|
items: videos
|
||||||
|
}
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -115,22 +115,7 @@ namespace InvidiousContent
|
|||||||
node.videoCountText = GetVideoCountText(item)
|
node.videoCountText = GetVideoCountText(item)
|
||||||
node.thumbnail = GetChannelThumbnail(item.authorThumbnails)
|
node.thumbnail = GetChannelThumbnail(item.authorThumbnails)
|
||||||
node.banner = GetChannelBanner(item.authorBanners)
|
node.banner = GetChannelBanner(item.authorBanners)
|
||||||
|
SetIfExists(node, "tabs", item, "tabs")
|
||||||
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
|
return node
|
||||||
end function
|
end function
|
||||||
@@ -245,7 +230,7 @@ namespace InvidiousContent
|
|||||||
if authorBanners = invalid or authorBanners.Count() = 0
|
if authorBanners = invalid or authorBanners.Count() = 0
|
||||||
return ""
|
return ""
|
||||||
end if
|
end if
|
||||||
return authorBanners[authorBanners.Count() - 1].url
|
return authorBanners[0].url
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetVideoCountText(item as object) as string
|
function GetVideoCountText(item as object) as string
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ namespace SponsorBlock
|
|||||||
pixelEnd = (segment.segment[1] / videoDuration) * width
|
pixelEnd = (segment.segment[1] / videoDuration) * width
|
||||||
color = m.SegmentColor(segment.category)
|
color = m.SegmentColor(segment.category)
|
||||||
' highlight's duration is zero, so it is not visble on the bar.
|
' 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
|
if pixelStart = pixelEnd
|
||||||
pixelEnd += 2
|
pixelEnd += 5
|
||||||
end if
|
end if
|
||||||
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, height, color)
|
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, height, color)
|
||||||
end for
|
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/TimeUtils.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.titleLabel = m.top.FindNode("titleLabel")
|
m.titleLabel = m.top.FindNode("titleLabel")
|
||||||
@@ -23,36 +24,30 @@ function OnContentSet() as void
|
|||||||
m.titleLabel.text = content.title
|
m.titleLabel.text = content.title
|
||||||
m.authorLabel.text = content.author
|
m.authorLabel.text = content.author
|
||||||
|
|
||||||
if content.isUpcoming = true
|
if not StringUtils.IsNullOrEmpty(content.publishedText)
|
||||||
m.viewCountDateLabel.text = content.premiereTimestampText
|
label = content.publishedText
|
||||||
else
|
if not StringUtils.IsNullOrEmpty(content.viewCountText)
|
||||||
publishedText = ValidString(content.publishedText)
|
label = `${label} • ${content.viewCountText}`
|
||||||
viewCountText = ValidString(content.viewCountText)
|
|
||||||
if publishedText = "" and viewCountText = ""
|
|
||||||
m.viewCountDateLabel.text = ""
|
|
||||||
else
|
|
||||||
m.viewCountDateLabel.text = `${publishedText} • ${viewCountText}`
|
|
||||||
end if
|
end if
|
||||||
|
m.viewCountDateLabel.text = label
|
||||||
|
else if content.isUpcoming = true
|
||||||
|
m.viewCountDateLabel.text = content.premiereTimestampText
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.thumbnail.uri = content.thumbnail
|
m.thumbnail.uri = content.thumbnail
|
||||||
|
|
||||||
if content.isUpcoming = true
|
m.durationRect.visible = false
|
||||||
m.upcomingRect.visible = true
|
m.upcomingRect.visible = false
|
||||||
m.liveRect.visible = false
|
m.liveRect.visible = false
|
||||||
m.durationRect.visible = false
|
|
||||||
else if content.liveNow
|
if ValidInt(content.lengthSeconds) <> 0
|
||||||
m.upcomingRect.visible = false
|
SetDurationText(content.lengthText)
|
||||||
m.liveRect.visible = true
|
m.durationRect.visible = true
|
||||||
m.durationRect.visible = false
|
|
||||||
else
|
else
|
||||||
m.upcomingRect.visible = false
|
if content.isUpcoming = true
|
||||||
m.liveRect.visible = false
|
m.upcomingRect.visible = true
|
||||||
if ValidInt(content.lengthSeconds) <> 0
|
else if content.liveNow
|
||||||
SetDurationText(content.lengthText)
|
m.liveRect.visible = true
|
||||||
m.durationRect.visible = true
|
|
||||||
else
|
|
||||||
m.durationRect.visible = false
|
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
|||||||
import "pkg:/components/PlaylistView/PlaylistUtils.bs"
|
import "pkg:/components/PlaylistView/PlaylistUtils.bs"
|
||||||
import "pkg:/components/ChannelView/ChannelUtils.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()
|
function Init()
|
||||||
m.pendingLoadTasks = {}
|
m.pendingLoadTasks = {}
|
||||||
end function
|
end function
|
||||||
@@ -152,7 +154,7 @@ function GetRowsToLoad() as object
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
subContentNodes = []
|
subContentNodes = []
|
||||||
range = m.top.numRows + 2
|
range = m.top.numRows + 1
|
||||||
for i = -range to range
|
for i = -range to range
|
||||||
index = focus + i
|
index = focus + i
|
||||||
if index < 0
|
if index < 0
|
||||||
@@ -172,6 +174,8 @@ function GetRowsToLoad() as object
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function LoadRowContent(contentNode as object)
|
function LoadRowContent(contentNode as object)
|
||||||
|
LogInfo("Loading row content:", contentNode.title)
|
||||||
|
|
||||||
contentNode.loadState = FeedLoadState.Loading
|
contentNode.loadState = FeedLoadState.Loading
|
||||||
task = StartAsyncTask(VideoRowListRowContentTask, {
|
task = StartAsyncTask(VideoRowListRowContentTask, {
|
||||||
node: m.top,
|
node: m.top,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function VideoRowListRowContentTask(input as object) as object
|
|||||||
|
|
||||||
instance = service.GetInstance()
|
instance = service.GetInstance()
|
||||||
itemNodes = []
|
itemNodes = []
|
||||||
for each item in response.result
|
for each item in response.result.items
|
||||||
itemNode = InvidiousContent.ToRowCellContentNode(item, instance)
|
itemNode = InvidiousContent.ToRowCellContentNode(item, instance)
|
||||||
if itemNode <> invalid
|
if itemNode <> invalid
|
||||||
itemNodes.Push(itemNode)
|
itemNodes.Push(itemNode)
|
||||||
@@ -53,8 +53,20 @@ function VideoRowListRowContentTask(input as object) as object
|
|||||||
RemovePlaceHolderItems(contentNode)
|
RemovePlaceHolderItems(contentNode)
|
||||||
contentNode.appendChildren(itemNodes)
|
contentNode.appendChildren(itemNodes)
|
||||||
|
|
||||||
if contentNode.pagination = true and response.result.Count() > 0
|
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
|
||||||
contentNode.loadState = FeedLoadState.LoadedPage
|
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
|
else
|
||||||
contentNode.loadState = FeedLoadState.Loaded
|
contentNode.loadState = FeedLoadState.Loaded
|
||||||
end if
|
end if
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
name: "search",
|
name: "search",
|
||||||
displayName: "Search",
|
displayName: "Search",
|
||||||
url: "/api/v1/search",
|
url: "/api/v1/search",
|
||||||
pagination: true,
|
paginationType: "Pages",
|
||||||
queryParams: {
|
queryParams: {
|
||||||
q: {
|
q: {
|
||||||
required: true,
|
required: true,
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
default: 20,
|
default: 20,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pagination: true,
|
paginationType: "Pages",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "playlists",
|
name: "playlists",
|
||||||
@@ -135,13 +135,14 @@
|
|||||||
displayName: "Playlist",
|
displayName: "Playlist",
|
||||||
url: "/api/v1/playlists/{plid}",
|
url: "/api/v1/playlists/{plid}",
|
||||||
responseHandler: "PlaylistHandler",
|
responseHandler: "PlaylistHandler",
|
||||||
pagination: true,
|
paginationType: "Pages",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "channel",
|
name: "channel_videos",
|
||||||
displayName: "Channel",
|
displayName: "Channel videos",
|
||||||
url: "/api/v1/channels/videos/{ucid}",
|
url: "/api/v1/channels/{ucid}/videos",
|
||||||
responseHandler: "ChannelHandler",
|
responseHandler: "ChannelVideosHandler",
|
||||||
|
paginationType: "Continuation",
|
||||||
queryParams: {
|
queryParams: {
|
||||||
sort_by: {
|
sort_by: {
|
||||||
required: false,
|
required: false,
|
||||||
@@ -149,5 +150,46 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -532,7 +532,7 @@ namespace HttpClient
|
|||||||
else if m.IsCancelled()
|
else if m.IsCancelled()
|
||||||
m._errorMessage = "Request cancelled."
|
m._errorMessage = "Request cancelled."
|
||||||
else if type(m.event) = "roUrlEvent"
|
else if type(m.event) = "roUrlEvent"
|
||||||
m._errorMessage = `Reason :${m.event.GetFailureReason() }\nStatusCode: ${m.StatusCode()}\nBody: ${m.event.GetString()}`
|
m._errorMessage = `Reason :${m.event.GetFailureReason() }\nStatusCode: ${m.StatusCode()}\nRequestId: ${m.event.GetSourceIdentity()}\nBody: ${m.event.GetString()}`
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export class InvidiousApi {
|
|||||||
// Note: handlers for authenticated requests are not needed, since they are handled server side
|
// Note: handlers for authenticated requests are not needed, since they are handled server side
|
||||||
this.responseHandlers = {
|
this.responseHandlers = {
|
||||||
"DefaultHandler": (requestData, response) => this.DefaultHandler(requestData, response),
|
"DefaultHandler": (requestData, response) => this.DefaultHandler(requestData, response),
|
||||||
"PlaylistHandler": (requestData, response) => this.PlaylistHandler(requestData, response),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,12 +90,8 @@ export class InvidiousApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async DefaultHandler(requestData, response) {
|
private async DefaultHandler(requestData, response) {
|
||||||
return await response.json();
|
const items = await response.json();
|
||||||
}
|
return { items };
|
||||||
|
|
||||||
private async PlaylistHandler(requestData, response) {
|
|
||||||
const playlist = await response.json();
|
|
||||||
return playlist.videos
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private makeUrl(url: string, params: any) {
|
private makeUrl(url: string, params: any) {
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||||
|
import { playletStateStore } from "lib/Stores";
|
||||||
|
|
||||||
|
export let author: string | undefined = undefined;
|
||||||
|
export let authorId: string | undefined = undefined;
|
||||||
|
export let authorThumbnails: any[] | undefined = undefined;
|
||||||
|
export let videoCount: number | undefined = undefined;
|
||||||
|
export let subCount: number | undefined = undefined;
|
||||||
|
|
||||||
|
// svelte-ignore unused-export-let
|
||||||
|
export let type: string = undefined;
|
||||||
|
|
||||||
|
let modal;
|
||||||
|
let tvName = "Roku TV";
|
||||||
|
let invidiousInstance;
|
||||||
|
|
||||||
|
playletStateStore.subscribe((value) => {
|
||||||
|
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||||
|
invidiousInstance = value?.invidious?.current_instance;
|
||||||
|
});
|
||||||
|
|
||||||
|
function getThumbnailUrl() {
|
||||||
|
if (!authorThumbnails || authorThumbnails.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const authorThumbnail = authorThumbnails[authorThumbnails.length - 1];
|
||||||
|
let url = authorThumbnail.url;
|
||||||
|
if (url.startsWith("//")) {
|
||||||
|
url = "https:" + url;
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openChannelOnTv() {
|
||||||
|
// TODO:P1 open channel on TV
|
||||||
|
// await PlayletApi.playPlaylist(playlistId, title, videoCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openInvidiousInNewTab() {
|
||||||
|
let url = `${invidiousInstance}/channel/${authorId}`;
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="w-60 p-2" on:click={modal.showModal()}>
|
||||||
|
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||||
|
<figure class="relative">
|
||||||
|
<img
|
||||||
|
class="w-44 rounded-full aspect-square object-cover"
|
||||||
|
loading="lazy"
|
||||||
|
width="176"
|
||||||
|
height="176"
|
||||||
|
src={getThumbnailUrl()}
|
||||||
|
alt={author}
|
||||||
|
/>
|
||||||
|
</figure>
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3>
|
||||||
|
<div>{subCount} subscribers</div>
|
||||||
|
<div>{videoCount} videos</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||||
|
<dialog bind:this={modal} id="modal_{authorId}" class="modal">
|
||||||
|
<form method="dialog" class="modal-box bg-base-100">
|
||||||
|
<h3 class="text-lg m-5">{author}</h3>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<!-- <button class="btn m-2" on:click={openChannelOnTv}
|
||||||
|
>Open on {tvName}</button
|
||||||
|
> -->
|
||||||
|
<button class="btn m-2" on:click={openInvidiousInNewTab}
|
||||||
|
>Open in Invidious</button
|
||||||
|
>
|
||||||
|
<button class="btn m-2">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="dialog" class="modal-backdrop">
|
||||||
|
<button>close</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
@@ -3,20 +3,24 @@
|
|||||||
import { invidiousVideoApiStore, playletStateStore } from "lib/Stores";
|
import { invidiousVideoApiStore, playletStateStore } from "lib/Stores";
|
||||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||||
|
import ChannelCell from "./ChannelCell.svelte";
|
||||||
|
|
||||||
export let requestData: any = undefined;
|
export let requestData: any = undefined;
|
||||||
export let videos = undefined;
|
export let videos = undefined;
|
||||||
|
|
||||||
|
let itemWidths = [];
|
||||||
|
|
||||||
let carouselElement;
|
let carouselElement;
|
||||||
|
|
||||||
let scrollStart = 0;
|
let scrollStart = 0;
|
||||||
let scrollEnd = 0;
|
let scrollEnd = 0;
|
||||||
|
|
||||||
// w-80 p-2: 320px + 16px padding on each side
|
// w-80|w-60 p-2: 320px|240px + 16px padding on each side
|
||||||
const itemWidth = 320 + 16 * 2;
|
const videoItemWidth = 320 + 16 * 2;
|
||||||
|
const channelItemWidth = 240 + 16 * 2;
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (carouselElement && videos && videos.length) {
|
if (carouselElement && itemWidths && itemWidths.length) {
|
||||||
recalculateVisibileCells();
|
recalculateVisibileCells();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,26 +41,49 @@
|
|||||||
|
|
||||||
async function updateRow() {
|
async function updateRow() {
|
||||||
const result = await invidiousApi.makeRequest(requestData);
|
const result = await invidiousApi.makeRequest(requestData);
|
||||||
if (result) {
|
if (result && result.items) {
|
||||||
result.forEach((item) => {
|
result.items.forEach((item) => {
|
||||||
if (item.videoId) {
|
if (item.videoId) {
|
||||||
item.type = "video";
|
item.type = "video";
|
||||||
} else if (item.playlistId) {
|
} else if (item.playlistId) {
|
||||||
item.type = "playlist";
|
item.type = "playlist";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
videos = result.filter(
|
videos = result.items;
|
||||||
(video) => video.type === "video" || video.type === "playlist"
|
itemWidths = videos.map((video) => {
|
||||||
);
|
if (video.type === "channel") {
|
||||||
|
return channelItemWidth;
|
||||||
|
} else {
|
||||||
|
return videoItemWidth;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function recalculateVisibileCells() {
|
function recalculateVisibileCells() {
|
||||||
const scrollLeft = carouselElement.scrollLeft;
|
let scrollLeft = carouselElement.scrollLeft;
|
||||||
const clientWidth = carouselElement.clientWidth || window.innerWidth;
|
const clientWidth = carouselElement.clientWidth || window.innerWidth;
|
||||||
|
|
||||||
scrollStart = Math.floor(scrollLeft / itemWidth) - 1;
|
scrollStart = 0;
|
||||||
scrollEnd = Math.ceil((scrollLeft + clientWidth) / itemWidth) + 1;
|
while (
|
||||||
|
scrollStart < itemWidths.length &&
|
||||||
|
scrollLeft > itemWidths[scrollStart]
|
||||||
|
) {
|
||||||
|
scrollLeft -= itemWidths[scrollStart];
|
||||||
|
scrollStart++;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollEnd = scrollStart;
|
||||||
|
while (
|
||||||
|
scrollEnd < itemWidths.length &&
|
||||||
|
scrollLeft + clientWidth > itemWidths[scrollEnd]
|
||||||
|
) {
|
||||||
|
scrollLeft -= itemWidths[scrollEnd];
|
||||||
|
scrollEnd++;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollStart = Math.max(0, scrollStart - 1);
|
||||||
|
scrollEnd = Math.min(itemWidths.length - 1, scrollEnd + 1);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -70,12 +97,16 @@
|
|||||||
on:scroll={recalculateVisibileCells}
|
on:scroll={recalculateVisibileCells}
|
||||||
>
|
>
|
||||||
{#each videos as video, i}
|
{#each videos as video, i}
|
||||||
<div class="carousel-item w-80 p-2">
|
<div
|
||||||
|
class="carousel-item {video.type === 'channel' ? 'w-60' : 'w-80'} p-2"
|
||||||
|
>
|
||||||
{#if i >= scrollStart && i <= scrollEnd}
|
{#if i >= scrollStart && i <= scrollEnd}
|
||||||
{#if video.type === "video"}
|
{#if video.type === "video"}
|
||||||
<VideoCell {...video} />
|
<VideoCell {...video} />
|
||||||
{:else if video.type === "playlist"}
|
{:else if video.type === "playlist"}
|
||||||
<PlaylistCell {...video} />
|
<PlaylistCell {...video} />
|
||||||
|
{:else if video.type === "channel"}
|
||||||
|
<ChannelCell {...video} />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||||
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
||||||
|
import ChannelCell from "./Home/ChannelCell.svelte";
|
||||||
|
|
||||||
export let visibility: boolean;
|
export let visibility: boolean;
|
||||||
|
|
||||||
@@ -156,6 +157,8 @@
|
|||||||
<VideoCell {...video} />
|
<VideoCell {...video} />
|
||||||
{:else if video.type === "playlist"}
|
{:else if video.type === "playlist"}
|
||||||
<PlaylistCell {...video} />
|
<PlaylistCell {...video} />
|
||||||
|
{:else if video.type === "channel"}
|
||||||
|
<ChannelCell {...video} />
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"isolatedModules": true
|
"isolatedModules": true,
|
||||||
|
"strict": false
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.d.ts",
|
"src/**/*.d.ts",
|
||||||
|
|||||||
Reference in new issue
Block a user