import "pkg:/source/asyncTask/asyncTask.bs" import "pkg:/source/services/Invidious.bs" import "pkg:/components/Dialog/DialogUtils.bs" import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs" import "pkg:/components/VideoPlayer/MarkVideoWatchedTask.bs" function PlayVideo(videoId as string, args = invalid as object) sender = args?.sender metadata = args?.metadata timestamp = args?.timestamp if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid metadata = args.metadata.getFields() end if if timestamp = invalid timestamp = 0 end if width = 1280 height = 720 translation = [0.0, 0.0] videoContainer = GetVideoContainer() if videoContainer.videoPlayer <> invalid width = videoContainer.videoPlayer.width height = videoContainer.videoPlayer.height translation = videoContainer.videoPlayer.translation end if previousSender = videoContainer.sender CloseVideo(false) if sender <> invalid videoContainer.sender = sender else videoContainer.sender = previousSender end if videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer") videoContainer.insertChild(videoContainer.videoPlayer, 0) videoContainer.videoPlayer.id = "VideoPlayer" videoContainer.videoPlayer.metadata = metadata videoContainer.videoPlayer.timestamp = timestamp videoContainer.videoPlayer.videoId = videoId videoContainer.videoPlayer.width = width videoContainer.videoPlayer.height = height videoContainer.videoPlayer.translation = translation if videoContainer.fullscreen videoContainer.videoPlayer.SetFocus(true) end if StartAsyncTask(MarkVideoWatchedTask, { videoId: videoId }) end function function CloseVideo(setFocus = true as boolean) videoContainer = GetVideoContainer() if videoContainer.videoPlayer <> invalid videoContainer.videoPlayer.control = "stop" videoContainer.RemoveChild(videoContainer.videoPlayer) videoContainer.videoPlayer = invalid end if if setFocus and videoContainer.sender <> invalid if videoContainer.sender.hasField("focus") videoContainer.sender.focus = true else videoContainer.sender.SetFocus(true) end if end if videoContainer.sender = invalid SponsorBlockNotifcationSetVisible(false) end function function ToggleVideoPictureInPicture(sender = invalid as object) as boolean videoContainer = GetVideoContainer() if videoContainer.videoPlayer = invalid return false end if videoContainer.fullscreen = not videoContainer.fullscreen if sender <> invalid videoContainer.sender = sender end if if videoContainer.fullscreen videoContainer.videoPlayer.SetFocus(true) else if videoContainer.sender <> invalid if videoContainer.sender.hasField("focus") videoContainer.sender.focus = true else videoContainer.sender.SetFocus(true) end if end if videoContainer.sender = invalid end if return true end function function GetVideoContainer() as object return m.global.videoContainer end function