From b37ec3cef04250d85fabc2f5d55ab55a31a7c3f8 Mon Sep 17 00:00:00 2001 From: Yonah Date: Sat, 4 Jul 2026 23:14:52 +0900 Subject: [PATCH] cmd/streamdata: display last entry Useful for catching up with multiple missed entries. Signed-off-by: Yonah --- cmd/streamdata/format.go | 18 ++++++++++++++++++ cmd/streamdata/main.go | 32 ++++++++++++++++++++++---------- go.mod | 2 +- go.sum | 4 ++-- ident.go | 4 ++-- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/cmd/streamdata/format.go b/cmd/streamdata/format.go index 9917152..8196f33 100644 --- a/cmd/streamdata/format.go +++ b/cmd/streamdata/format.go @@ -1,7 +1,10 @@ package main import ( + "errors" "fmt" + "os" + "syscall" "git.gensokyo.uk/yonah/streamdata" ) @@ -22,3 +25,18 @@ func printVOD(v *streamdata.VOD) { fmt.Println("Mirror :", v.Mirror) } } + +// printVODIdent calls printVOD for a VOD identifier. +func printVODIdent(channel *streamdata.Channel, ident *streamdata.Ident) error { + v, err := channel.Load(ident) + if err != nil { + if !errors.Is(err, os.ErrNotExist) { + return err + } + return syscall.ENOENT + } + + printVOD(v) + fmt.Println("Path :", channel.Path(ident)) + return nil +} diff --git a/cmd/streamdata/main.go b/cmd/streamdata/main.go index aa3a2df..fca8441 100644 --- a/cmd/streamdata/main.go +++ b/cmd/streamdata/main.go @@ -203,16 +203,7 @@ func main() { return err } - if v, err := channel.Load(&ident); err != nil { - if !errors.Is(err, os.ErrNotExist) { - return err - } - return syscall.ENOENT - } else { - printVOD(v) - fmt.Println("Path :", channel.Path(&ident)) - return nil - } + return printVODIdent(channel, &ident) }, ) @@ -231,6 +222,27 @@ func main() { }, ) + c.NewCommand( + "last", + "Display metadata of final VOD entry", + func([]string) (err error) { + if channel == nil { + return errors.New("last requires a channel selected") + } + + var ident *streamdata.Ident + for ident = range channel.All(&err, true) { + } + if err != nil { + return + } + if ident == nil { + return errors.New("no entries available") + } + return printVODIdent(channel, ident) + }, + ) + c.NewCommand( "mirror", "Populate mirror address of the next un-mirrored asset", diff --git a/go.mod b/go.mod index 06781e3..fdcfe5c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module git.gensokyo.uk/yonah/streamdata go 1.26 -require hakurei.app v0.3.8-0.20260317115839-6cdb6a652b63 +require hakurei.app v0.4.5 diff --git a/go.sum b/go.sum index 5de2cc6..9d8233e 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -hakurei.app v0.3.8-0.20260317115839-6cdb6a652b63 h1:Nx5eaHEbWUx6pwA4A+EdmHXvCvO3Xbw7PPcT1QbsVcA= -hakurei.app v0.3.8-0.20260317115839-6cdb6a652b63/go.mod h1:rIWpoHYiZtIPue49bQLkROpQHYh/j2VjJGFrzNrvixU= +hakurei.app v0.4.5 h1:u/aEG1K9E0sRORGaaTKkvL3UdaTrw7q6t/Y0pnlTVvs= +hakurei.app v0.4.5/go.mod h1:rIWpoHYiZtIPue49bQLkROpQHYh/j2VjJGFrzNrvixU= diff --git a/ident.go b/ident.go index 0277497..faf6b44 100644 --- a/ident.go +++ b/ident.go @@ -86,8 +86,8 @@ func atoi(data []byte) (v uint64, err error) { 10, 64, ) if err != nil { - var numError *strconv.NumError - if errors.As(err, &numError) && numError != nil { + numError, ok := errors.AsType[*strconv.NumError](err) + if ok && numError != nil { err = numError.Unwrap() } }