Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
add support for bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
SoMuchForSubtlety committed Jun 24, 2021
1 parent 20ff83c commit 9a37f98
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 239 deletions.
10 changes: 6 additions & 4 deletions internal/ui/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package ui

import (
"fmt"
"io"
"log"

"github.com/SoMuchForSubtlety/f1viewer/v2/internal/util"
"github.com/rivo/tview"
)

type tviewLogger struct {
io.Writer
*tview.TextView
}

func (s *UIState) Logger() *tviewLogger {
Expand All @@ -21,15 +21,17 @@ func (l *tviewLogger) Errorf(format string, v ...interface{}) {
}

func (l *tviewLogger) Error(v ...interface{}) {
fmt.Fprintln(l.Writer, fmt.Sprintf("[%s::b]ERROR:[-::-]", util.ColortoHexString(activeTheme.ErrorColor)), fmt.Sprint(v...))
fmt.Fprintln(l.TextView, fmt.Sprintf("[%s::b]ERROR:[-::-]", util.ColortoHexString(activeTheme.ErrorColor)), fmt.Sprint(v...))
log.Println("[ERROR]", fmt.Sprint(v...))
l.ScrollToEnd()
}

func (l *tviewLogger) Infof(format string, v ...interface{}) {
l.Info(fmt.Sprintf(format, v...))
}

func (l *tviewLogger) Info(v ...interface{}) {
fmt.Fprintln(l.Writer, fmt.Sprintf("[%s::b]INFO:[-::-]", util.ColortoHexString(activeTheme.InfoColor)), fmt.Sprint(v...))
fmt.Fprintln(l.TextView, fmt.Sprintf("[%s::b]INFO:[-::-]", util.ColortoHexString(activeTheme.InfoColor)), fmt.Sprint(v...))
log.Println("[INFO]", fmt.Sprint(v...))
l.ScrollToEnd()
}
25 changes: 23 additions & 2 deletions internal/ui/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/SoMuchForSubtlety/f1viewer/v2/internal/cmd"
"github.com/SoMuchForSubtlety/f1viewer/v2/pkg/f1tv/v2"
"github.com/atotto/clipboard"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
Expand Down Expand Up @@ -150,8 +151,9 @@ func (s *UIState) getLiveNode() (bool, *tview.TreeNode, error) {
}
}

func (s *UIState) getHomepageNodes() []*tview.TreeNode {
headings, err := s.v2.GetVideoContainers()
func (s *UIState) getPageNodes(id f1tv.PageID) []*tview.TreeNode {
s.logger.Infof("loading %d", id)
headings, bundles, err := s.v2.GetPageContent(id)
if err != nil {
s.logger.Error(err)
return nil
Expand All @@ -164,6 +166,9 @@ func (s *UIState) getHomepageNodes() []*tview.TreeNode {
if title == "" {
title = h.RetrieveItems.ResultObj.MeetingName
}
if title == "" {
title = "???"
}
metadata := cmd.MetaData{CategoryTitle: title}
headingNode := tview.NewTreeNode(title).
SetColor(activeTheme.CategoryNodeColor).
Expand All @@ -175,6 +180,22 @@ func (s *UIState) getHomepageNodes() []*tview.TreeNode {
}
headingNodes = append(headingNodes, headingNode)
}
for _, b := range bundles {
b := b

metadata := cmd.MetaData{CategoryTitle: b.Title}
headingNode := tview.NewTreeNode(b.Title).
SetColor(activeTheme.FolderNodeColor).
SetReference(&NodeMetadata{nodeType: CategoryNode, metadata: metadata}).
SetExpanded(false)

headingNode.SetSelectedFunc(s.withBlink(headingNode, func() {
headingNode.SetSelectedFunc(nil)
appendNodes(headingNode, s.getPageNodes(b.ID)...)
headingNode.SetExpanded(true)
}, nil))
headingNodes = append(headingNodes, headingNode)
}

return headingNodes
}
Expand Down
31 changes: 30 additions & 1 deletion internal/ui/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,39 @@ func NewUI(cfg config.Config, version string) *UIState {
ui.initUI()
}

appendNodes(root, ui.getHomepageNodes()...)
homepageContent := tview.NewTreeNode("homepage").
SetColor(activeTheme.CategoryNodeColor).
SetReference(&NodeMetadata{nodeType: CategoryNode, metadata: cmd.MetaData{}}).
SetExpanded(true)
homepageContent.SetSelectedFunc(ui.withBlink(homepageContent, func() {
homepageContent.SetSelectedFunc(nil)
appendNodes(homepageContent, ui.getPageNodes(f1tv.PAGE_HOMEPAGE)...)
}, nil))

appendNodes(root,
ui.pageNode(f1tv.PAGE_HOMEPAGE, "Homepage"),
ui.pageNode(f1tv.PAGE_SEASON_20201, "2021 Season"),
ui.pageNode(f1tv.PAGE_ARCHIVE, "archive"),
ui.pageNode(f1tv.PAGE_DOCUMENTARIES, "Documentaries"),
ui.pageNode(f1tv.PAGE_SHOWS, "Shows"),
)

return &ui
}

func (ui *UIState) pageNode(id f1tv.PageID, title string) *tview.TreeNode {
node := tview.NewTreeNode(title).
SetColor(activeTheme.FolderNodeColor).
SetReference(&NodeMetadata{nodeType: CategoryNode, metadata: cmd.MetaData{}}).
SetExpanded(true)
node.SetSelectedFunc(ui.withBlink(node, func() {
node.SetSelectedFunc(nil)
appendNodes(node, ui.getPageNodes(id)...)
}, nil))

return node
}

func (ui *UIState) Stop() {
ui.app.Stop()
}
Expand Down
46 changes: 35 additions & 11 deletions pkg/f1tv/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ const (
MOBILE_DASH StreamType = "MOBILE_DASH"
TABLET_DASH StreamType = "TABLET_DASH"

CATEGORY_LIVE RequestCategory = 395
PAGE_HOMEPAGE PageID = 395
PAGE_ARCHIVE PageID = 493
PAGE_SHOWS PageID = 410
PAGE_DOCUMENTARIES PageID = 413
PAGE_SEASON_20201 PageID = 1510

VIDEO ContentType = "VIDEO"
VIDEO ContentType = "VIDEO"
BUNDLE ContentType = "BUNDLE"

LIVE ContentSubType = "LIVE"
REPLAY ContentSubType = "REPLAY"
Expand All @@ -44,7 +49,7 @@ type ContentSubType string

type StreamType string

type RequestCategory int
type PageID int64

func assembleURL(urlPath string, format StreamType, args ...interface{}) (*url.URL, error) {
args = append([]interface{}{format}, args...)
Expand Down Expand Up @@ -98,7 +103,7 @@ func (f *F1TV) Authenticate(username, password string) error {
return err
}

func (f *F1TV) GetContent(format StreamType, category RequestCategory, v interface{}) error {
func (f *F1TV) GetContent(format StreamType, category PageID, v interface{}) error {
reqURL, err := assembleURL(categoryPagePath, format, category)
if err != nil {
return err
Expand All @@ -115,28 +120,47 @@ func (f *F1TV) GetContent(format StreamType, category RequestCategory, v interfa
return json.NewDecoder(resp.Body).Decode(v)
}

func (f *F1TV) GetVideoContainers() ([]TopContainer, error) {
type RemoteContent struct {
ID PageID
Title string
}

func (f *F1TV) GetPageContent(id PageID) ([]TopContainer, []RemoteContent, error) {
var resp APIResponse
err := f.GetContent(WEB_DASH, CATEGORY_LIVE, &resp)
err := f.GetContent(WEB_DASH, id, &resp)
if err != nil {
return nil, err
return nil, nil, err
}

var nonEmpty []TopContainer
var content []TopContainer
var bundles []RemoteContent
for _, container := range resp.ResultObj.Containers {
var videoContainers []ContentContainer
for _, contentContainer := range container.RetrieveItems.ResultObj.Containers {
if contentContainer.Metadata.ContentType == VIDEO {
videoContainers = append(videoContainers, contentContainer)
} else if contentContainer.Metadata.ContentType == BUNDLE {
if contentContainer.Metadata.EmfAttributes.PageID == id {
// we don't need recusion
continue
}
title := contentContainer.Metadata.Label
if title == "" {
title = contentContainer.Metadata.EmfAttributes.GlobalTitle
}
if title == "" {
title = contentContainer.Metadata.EmfAttributes.GlobalMeetingName
}
bundles = append(bundles, RemoteContent{ID: contentContainer.Metadata.EmfAttributes.PageID, Title: title})
}
}
container.RetrieveItems.ResultObj.Containers = videoContainers
if len(videoContainers) > 0 {
nonEmpty = append(nonEmpty, container)
content = append(content, container)
}
}

return nonEmpty, err
return content, bundles, err
}

func (s AdditionalStream) PrettyName() string {
Expand All @@ -153,7 +177,7 @@ func (s AdditionalStream) PrettyName() string {
}

func (f *F1TV) GetLiveVideoContainers() ([]ContentContainer, error) {
topContainers, err := f.GetVideoContainers()
topContainers, _, err := f.GetPageContent(PAGE_HOMEPAGE)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9a37f98

Please sign in to comment.