88 lines
2.6 KiB
Plaintext
88 lines
2.6 KiB
Plaintext
import "pkg:/components/Services/Innertube/InnertubeService.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
|
|
|
@job("VideoContentDevJob")
|
|
function ExecuteJob() as void
|
|
input = JobGetInput()
|
|
|
|
titleLabel = input.titleLabel
|
|
secondaryTitleLabel = input.secondaryTitleLabel
|
|
backgroundPoster = input.backgroundPoster
|
|
contentNode = input.content
|
|
invidiousNode = input.invidious
|
|
preferencesNode = input.preferences
|
|
|
|
titleLabel.text = contentNode.title
|
|
secondaryTitleLabel.text = contentNode.secondaryTitle
|
|
|
|
videoId = contentNode.videoId
|
|
|
|
if StringUtils.IsNullOrEmpty(videoId)
|
|
JobError("Can't load video information: videoId is missing")
|
|
return
|
|
end if
|
|
|
|
service = new Invidious.InvidiousService(invidiousNode)
|
|
instance = service.GetInstance()
|
|
|
|
backgroundPoster.uri = `${instance}/vi/${videoId}/maxresdefault.jpg`
|
|
|
|
cancellation = JobGetCancellation()
|
|
backend = preferencesNode["backend.selected"]
|
|
if backend = "playlet"
|
|
metadata = InnertubeService.GetVideoMetadata(videoId, { cancellation: cancellation })
|
|
else
|
|
metadata = service.GetVideoMetadata(videoId, { cancellation: cancellation })
|
|
end if
|
|
|
|
if JobIsCancelled()
|
|
JobCancel()
|
|
return
|
|
end if
|
|
|
|
if metadata.error <> invalid
|
|
JobError(metadata.error)
|
|
return
|
|
end if
|
|
|
|
contentNode.title = metadata.title
|
|
titleLabel.text = metadata.title
|
|
|
|
secondaryTitle = `${metadata.author}`
|
|
viewCount = InvidiousContent.VideoGetViewCountText(metadata)
|
|
if not StringUtils.IsNullOrEmpty(viewCount)
|
|
secondaryTitle = `${secondaryTitle} • ${viewCount}`
|
|
end if
|
|
pubslishedText = InvidiousContent.VideoGetPublishedText(metadata)
|
|
if not StringUtils.IsNullOrEmpty(pubslishedText)
|
|
secondaryTitle = `${secondaryTitle} • ${pubslishedText}`
|
|
end if
|
|
|
|
contentNode.secondaryTitle = secondaryTitle
|
|
secondaryTitleLabel.text = secondaryTitle
|
|
contentNode.live = metadata.liveNow
|
|
|
|
streamUrls = CreateStreamUrls(metadata)
|
|
contentNode.url = streamUrls[0]
|
|
|
|
contentNode.addFields({
|
|
metadata: metadata
|
|
' StreamUrls is taken
|
|
playletStreamUrls: streamUrls
|
|
playletStreamUrlIndex: 0
|
|
})
|
|
end function
|
|
|
|
function CreateStreamUrls(metadata as object) as object
|
|
streamUrls = []
|
|
|
|
if metadata.hlsUrl <> invalid
|
|
streamUrls.push(metadata.hlsUrl)
|
|
else
|
|
streamUrls.push(`http://127.0.0.1:8888/api/dash?v=${metadata.videoId}`)
|
|
end if
|
|
|
|
return streamUrls
|
|
end function
|