cmd/streamdata: resolve un-mirrored asset
Useful for uploading pending videos. Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"cmp"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -228,6 +230,73 @@ func main() {
|
||||
},
|
||||
)
|
||||
|
||||
c.NewCommand(
|
||||
"mirror",
|
||||
"Populate mirror address of the next un-mirrored asset",
|
||||
func([]string) (err error) {
|
||||
if channel == nil {
|
||||
return errors.New("mirror requires a channel selected")
|
||||
}
|
||||
|
||||
idents := slices.Collect(channel.All(&err, false))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
slices.SortFunc(idents, func(a, b *streamdata.Ident) int {
|
||||
return cmp.Compare(a.Serial, b.Serial)
|
||||
})
|
||||
|
||||
unique := errors.New("entry already mirrored")
|
||||
for _, ident := range idents {
|
||||
if err = channel.Edit(ident, func(v *streamdata.VOD) (err error) {
|
||||
if v.Mirror != "" {
|
||||
return unique
|
||||
}
|
||||
|
||||
pathname := path.Join(
|
||||
flagBase,
|
||||
"upload"+streamdata.ChannelVODSuffix,
|
||||
)
|
||||
if err = os.Symlink(path.Join(
|
||||
"vod",
|
||||
ident.String()+streamdata.ChannelVODSuffix,
|
||||
), pathname); err != nil {
|
||||
return
|
||||
}
|
||||
log.Println("pending video at", pathname)
|
||||
defer func() {
|
||||
removeErr := os.Remove(pathname)
|
||||
if err == nil {
|
||||
err = removeErr
|
||||
}
|
||||
}()
|
||||
|
||||
defer toErr(&err)
|
||||
isattyStd()
|
||||
br := bufio.NewReader(os.Stdin)
|
||||
|
||||
retry:
|
||||
fmt.Println(ident)
|
||||
printVOD(v)
|
||||
v.Mirror = require(promptTrimNoEmpty(br, "Mirror : "))
|
||||
if !require(promptBool(br, "Proceed? ", true)) {
|
||||
v.Mirror = ""
|
||||
goto retry
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
if err == unique {
|
||||
err = nil
|
||||
continue
|
||||
}
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
return
|
||||
},
|
||||
)
|
||||
|
||||
c.MustParse(os.Args[1:], func(err error) {
|
||||
if channel != nil {
|
||||
if closeErr := channel.Close(); closeErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user