import "pkg:/source/services/Invidious.bs" @asynctask function SearchTask(input as object) as object q = input.q rootChildren = [] response = Invidious.Search(q, { type: "video" }) rowContent = GetCategoryContent(`Search - ${q}`, response) if rowContent <> invalid rootChildren.Push(rowContent) end if return { q: q, rootChildren: rootChildren } end function function GetCategoryContent(category as string, json as object) as object if json <> invalid and json.Count() > 0 row = {} row.title = category row.children = [] for each item in json ' parse items and push them to row itemData = GetItemData(item) if itemData <> invalid row.children.Push(itemData) end if end for return row end if return invalid end function function GetItemData(video as object) as object ' TODO: handle playlists and channels if video.videoId = invalid return invalid end if return video end function