Skip to content

Commit

Permalink
Adding channel to video links
Browse files Browse the repository at this point in the history
Refactoring video display options to use the same approach as the current yet
  • Loading branch information
boggydigital committed Dec 18, 2024
1 parent 095c542 commit 7f1862e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
10 changes: 10 additions & 0 deletions data/video_ended_reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const (
DefaultEndedReason = Completed
)

var videoEndedReasonStrings = map[VideoEndedReason]string{
Completed: "Completed",
Skipped: "Skipped",
SeenEnough: "Seen enough",
}

func ParseVideoEndedReason(s string) VideoEndedReason {
switch s {
case string(Completed):
Expand All @@ -29,3 +35,7 @@ func AllVideoEndedReasons() []VideoEndedReason {
SeenEnough,
}
}

func (ver VideoEndedReason) String() string {
return videoEndedReasonStrings[ver]
}
51 changes: 25 additions & 26 deletions rest/compton_elements/video_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,25 @@ import (
"github.com/boggydigital/compton/consts/size"
"github.com/boggydigital/kevlar"
"github.com/boggydigital/yet/data"
"slices"
"strconv"
"time"
)

//go:embed "styles/*.css"
var videoLinkStyles embed.FS

type VideoDisplayOptions struct {
Duration bool
PublishDate bool
EndedDate bool
Downloaded bool
}
type VideoDisplayOptions int

func DefaultVideoDisplayOptions() *VideoDisplayOptions {
return &VideoDisplayOptions{
Duration: true,
PublishDate: true,
EndedDate: true,
Downloaded: false,
}
}
const (
ShowPublishedDate VideoDisplayOptions = iota
ShowDownloadedDate
ShowEndedDate
ShowDuration
ShowOwnerChannel
)

func VideoLink(r compton.Registrar, videoId string, rdx kevlar.ReadableRedux, opt *VideoDisplayOptions) compton.Element {

if opt == nil {
opt = DefaultVideoDisplayOptions()
}
func VideoLink(r compton.Registrar, videoId string, rdx kevlar.ReadableRedux, options ...VideoDisplayOptions) compton.Element {

r.RegisterStyles(videoLinkStyles, "styles/video-link.css")

Expand All @@ -61,7 +52,7 @@ func VideoLink(r compton.Registrar, videoId string, rdx kevlar.ReadableRedux, op

stack.Append(issaImage)

if opt.Duration {
if slices.Contains(options, ShowDuration) {
if durs, sure := rdx.GetLastVal(data.VideoDurationProperty, videoId); sure && durs != "" {
if duri, err := strconv.ParseInt(durs, 10, 64); err == nil {
durationDiv := compton.DivText(formatSeconds(duri))
Expand All @@ -75,10 +66,18 @@ func VideoLink(r compton.Registrar, videoId string, rdx kevlar.ReadableRedux, op
stack.Append(compton.H2Text(title))
}

if opt.PublishDate {
if slices.Contains(options, ShowOwnerChannel) {
if och, ok := rdx.GetLastVal(data.VideoOwnerChannelNameProperty, videoId); ok && och != "" {
channelFrow := compton.Frow(r).FontSize(size.Small)
channelFrow.PropVal("Channel", och)
stack.Append(channelFrow)
}
}

if slices.Contains(options, ShowPublishedDate) {
var publishedDate string
if pds, ok := rdx.GetLastVal(data.VideoPublishDateProperty, videoId); ok && pds != "" {
publishedDate = parseAndFormat(pds)
publishedDate = parseAndFormatDate(pds)
} else {
if ptts, ok := rdx.GetLastVal(data.VideoPublishTimeTextProperty, videoId); ok && ptts != "" {
publishedDate = ptts
Expand All @@ -92,25 +91,25 @@ func VideoLink(r compton.Registrar, videoId string, rdx kevlar.ReadableRedux, op
}
}

if opt.Downloaded {
if slices.Contains(options, ShowDownloadedDate) {
if dts, ok := rdx.GetLastVal(data.VideoDownloadCompletedProperty, videoId); ok && dts != "" {
downFrow := compton.Frow(r).FontSize(size.Small)
downFrow.PropVal("Downloaded", parseAndFormat(dts))
downFrow.PropVal("Downloaded", parseAndFormatDate(dts))
stack.Append(downFrow)
}
}

if ets, ok := rdx.GetLastVal(data.VideoEndedDateProperty, videoId); ok && ets != "" {
link.AddClass("ended")
if opt.EndedDate {
if slices.Contains(options, ShowEndedDate) {
endedFrow := compton.Frow(r).FontSize(size.Small)
endedFrow.PropVal("Ended", parseAndFormatDate(ets))

endedReason := data.DefaultEndedReason
if er, ok := rdx.GetLastVal(data.VideoEndedReasonProperty, videoId); ok {
endedReason = data.ParseVideoEndedReason(er)
}
endedFrow.PropVal("How", string(endedReason))
endedFrow.PropVal("How", endedReason.String())

stack.Append(endedFrow)
}
Expand Down
6 changes: 5 additions & 1 deletion rest/get_compton.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetCompton(w http.ResponseWriter, r *http.Request) {
"xF8huW3imyk",
"b8I4SsQTqaY",
"KVUHtsxNFyM",
"la0NtENnuf8",
}

pageStack := compton.FlexItems(p, direction.Column)
Expand All @@ -29,7 +30,10 @@ func GetCompton(w http.ResponseWriter, r *http.Request) {
pageStack.Append(gridItems)

for _, videoId := range videoIds {
videoLink := compton_elements.VideoLink(p, videoId, rdx, nil)
videoLink := compton_elements.VideoLink(p, videoId, rdx,
compton_elements.ShowOwnerChannel,
compton_elements.ShowPublishedDate,
compton_elements.ShowEndedDate)
gridItems.Append(videoLink)

}
Expand Down

0 comments on commit 7f1862e

Please sign in to comment.