cmd/streamdata: display last entry

Useful for catching up with multiple missed entries.

Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
2026-07-04 23:14:52 +09:00
parent 71ff3de617
commit b37ec3cef0
5 changed files with 45 additions and 15 deletions
+18
View File
@@ -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
}
+22 -10
View File
@@ -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",
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+2 -2
View File
@@ -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()
}
}