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]
|
||||
|
||||
### 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
|
||||
|
||||
- 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"
|
||||
|
||||
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
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
name: "search",
|
||||
displayName: "Search",
|
||||
url: "/api/v1/search",
|
||||
pagination: true,
|
||||
paginationType: "Pages",
|
||||
queryParams: {
|
||||
q: {
|
||||
required: true,
|
||||
@@ -122,7 +122,7 @@
|
||||
default: 20,
|
||||
},
|
||||
},
|
||||
pagination: true,
|
||||
paginationType: "Pages",
|
||||
},
|
||||
{
|
||||
name: "playlists",
|
||||
@@ -135,13 +135,14 @@
|
||||
displayName: "Playlist",
|
||||
url: "/api/v1/playlists/{plid}",
|
||||
responseHandler: "PlaylistHandler",
|
||||
pagination: true,
|
||||
paginationType: "Pages",
|
||||
},
|
||||
{
|
||||
name: "channel",
|
||||
displayName: "Channel",
|
||||
url: "/api/v1/channels/videos/{ucid}",
|
||||
responseHandler: "ChannelHandler",
|
||||
name: "channel_videos",
|
||||
displayName: "Channel videos",
|
||||
url: "/api/v1/channels/{ucid}/videos",
|
||||
responseHandler: "ChannelVideosHandler",
|
||||
paginationType: "Continuation",
|
||||
queryParams: {
|
||||
sort_by: {
|
||||
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()
|
||||
m._errorMessage = "Request cancelled."
|
||||
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
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ export class InvidiousApi {
|
||||
// Note: handlers for authenticated requests are not needed, since they are handled server side
|
||||
this.responseHandlers = {
|
||||
"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) {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
private async PlaylistHandler(requestData, response) {
|
||||
const playlist = await response.json();
|
||||
return playlist.videos
|
||||
const items = await response.json();
|
||||
return { items };
|
||||
}
|
||||
|
||||
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 VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import ChannelCell from "./ChannelCell.svelte";
|
||||
|
||||
export let requestData: any = undefined;
|
||||
export let videos = undefined;
|
||||
|
||||
let itemWidths = [];
|
||||
|
||||
let carouselElement;
|
||||
|
||||
let scrollStart = 0;
|
||||
let scrollEnd = 0;
|
||||
|
||||
// w-80 p-2: 320px + 16px padding on each side
|
||||
const itemWidth = 320 + 16 * 2;
|
||||
// w-80|w-60 p-2: 320px|240px + 16px padding on each side
|
||||
const videoItemWidth = 320 + 16 * 2;
|
||||
const channelItemWidth = 240 + 16 * 2;
|
||||
|
||||
$: {
|
||||
if (carouselElement && videos && videos.length) {
|
||||
if (carouselElement && itemWidths && itemWidths.length) {
|
||||
recalculateVisibileCells();
|
||||
}
|
||||
}
|
||||
@@ -37,26 +41,49 @@
|
||||
|
||||
async function updateRow() {
|
||||
const result = await invidiousApi.makeRequest(requestData);
|
||||
if (result) {
|
||||
result.forEach((item) => {
|
||||
if (result && result.items) {
|
||||
result.items.forEach((item) => {
|
||||
if (item.videoId) {
|
||||
item.type = "video";
|
||||
} else if (item.playlistId) {
|
||||
item.type = "playlist";
|
||||
}
|
||||
});
|
||||
videos = result.filter(
|
||||
(video) => video.type === "video" || video.type === "playlist"
|
||||
);
|
||||
videos = result.items;
|
||||
itemWidths = videos.map((video) => {
|
||||
if (video.type === "channel") {
|
||||
return channelItemWidth;
|
||||
} else {
|
||||
return videoItemWidth;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function recalculateVisibileCells() {
|
||||
const scrollLeft = carouselElement.scrollLeft;
|
||||
let scrollLeft = carouselElement.scrollLeft;
|
||||
const clientWidth = carouselElement.clientWidth || window.innerWidth;
|
||||
|
||||
scrollStart = Math.floor(scrollLeft / itemWidth) - 1;
|
||||
scrollEnd = Math.ceil((scrollLeft + clientWidth) / itemWidth) + 1;
|
||||
scrollStart = 0;
|
||||
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>
|
||||
|
||||
@@ -70,12 +97,16 @@
|
||||
on:scroll={recalculateVisibileCells}
|
||||
>
|
||||
{#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 video.type === "video"}
|
||||
<VideoCell {...video} />
|
||||
{:else if video.type === "playlist"}
|
||||
<PlaylistCell {...video} />
|
||||
{:else if video.type === "channel"}
|
||||
<ChannelCell {...video} />
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
||||
import ChannelCell from "./Home/ChannelCell.svelte";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -156,6 +157,8 @@
|
||||
<VideoCell {...video} />
|
||||
{:else if video.type === "playlist"}
|
||||
<PlaylistCell {...video} />
|
||||
{:else if video.type === "channel"}
|
||||
<ChannelCell {...video} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
*/
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"isolatedModules": true
|
||||
"isolatedModules": true,
|
||||
"strict": false
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.d.ts",
|
||||
|
||||
Reference in new issue
Block a user