]> 127.0.0.1 Git - part/.git/commitdiff
Fix v0.22.9
authorqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 15 Feb 2023 19:03:05 +0000 (03:03 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 15 Feb 2023 19:03:05 +0000 (03:03 +0800)
go.mod
go.sum
websocket/Recoder.go

diff --git a/go.mod b/go.mod
index b85c4ae859850609f5f0948b241e1fa2055ec0ca..1278e3d64355ae92bf4fbb84bc3dad3ba42ce57a 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
 
 require (
        github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
+       github.com/dustin/go-humanize v1.0.1
        github.com/go-ole/go-ole v1.2.5 // indirect
        github.com/stretchr/testify v1.8.1 // indirect
        golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
diff --git a/go.sum b/go.sum
index 9bf370487752d5bb2a70ac362298c7064f14db57..29981c8a9233866d117b4b172a683d7617cd331b 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -5,6 +5,8 @@ github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHG
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
 github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
 github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
 github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
index 34e281792362bea2376dcf10395df6efff3d874e..52c2a2cd55564c2638d1b75b3bdba9f99efa878d 100644 (file)
@@ -4,10 +4,10 @@ import (
        "bytes"
        "errors"
        "fmt"
-       "io"
        "strconv"
        "time"
 
+       "github.com/dustin/go-humanize"
        file "github.com/qydysky/part/file"
        funcCtrl "github.com/qydysky/part/funcCtrl"
        signal "github.com/qydysky/part/signal"
@@ -75,7 +75,7 @@ func (t *Recorder) Stop() {
        t.onlyOnce.UnSet()
 }
 
-func Play(filePath string, perReadSize int, maxReadSize int) (s *Server, close func()) {
+func Play(filePath string) (s *Server, close func()) {
        sg := signal.Init()
 
        s = New_server()
@@ -95,56 +95,66 @@ func Play(filePath string, perReadSize int, maxReadSize int) (s *Server, close f
                timer := time.NewTicker(time.Second)
                defer timer.Stop()
 
-               var (
-                       cu   float64
-                       data []byte
-                       err  error
-               )
-
-               s.Interface().Pull_tag(map[string]func(any) (disable bool){
-                       `recv`: func(a any) (disable bool) {
-                               if d, ok := a.(Uinterface); ok {
-                                       switch string(d.Data) {
-                                       case "%Cpause":
-                                               timer.Stop()
-                                       case "%Cplay":
-                                               timer.Reset(time.Second)
-                                       default:
-                                               cu, _ = strconv.ParseFloat(string(d.Data[2:]), 64)
+               if data, e := f.ReadAll(humanize.KByte, humanize.MByte); e != nil {
+                       panic(e)
+               } else {
+                       var (
+                               cu    float64
+                               index int
+                       )
+
+                       sdata := bytes.Split(data, []byte{'\n'})
+
+                       s.Interface().Pull_tag(map[string]func(any) (disable bool){
+                               `recv`: func(a any) (disable bool) {
+                                       if d, ok := a.(Uinterface); ok {
+                                               switch string(d.Data) {
+                                               case "pause":
+                                                       timer.Stop()
+                                               case "play":
+                                                       timer.Reset(time.Second)
+                                               default:
+                                                       tmp, _ := strconv.ParseFloat(string(d.Data), 64)
+                                                       if tmp < cu {
+                                                               for index > 0 && index < len(sdata) {
+                                                                       tIndex := bytes.Index(sdata[index], []byte{','})
+                                                                       if d, _ := strconv.ParseFloat(string(sdata[index][:tIndex]), 64); d > cu {
+                                                                               index -= 1
+                                                                               continue
+                                                                       } else if d < cu {
+                                                                               break
+                                                                       }
+                                                               }
+                                                       }
+                                                       cu = tmp
+                                               }
                                        }
-                               }
-                               return false
-                       },
-               })
-
-               for sg.Islive() {
-                       <-timer.C
-                       cu += 1
+                                       return false
+                               },
+                       })
 
                        for sg.Islive() {
-                               if data == nil {
-                                       if data, err = f.ReadUntil('\n', perReadSize, maxReadSize); err != nil && !errors.Is(err, io.EOF) {
-                                               panic(err)
-                                       }
-                               }
-                               if len(data) != 0 {
-                                       tIndex := bytes.Index(data, []byte{','})
-                                       if d, _ := strconv.ParseFloat(string(data[:tIndex]), 64); d > cu {
+                               <-timer.C
+                               cu += 1
+
+                               for index > 0 && index < len(sdata) {
+                                       tIndex := bytes.Index(sdata[index], []byte{','})
+                                       if d, _ := strconv.ParseFloat(string(sdata[index][:tIndex]), 64); d > cu+1 {
                                                break
-                                       } else if d-cu > 2 {
+                                       } else if d < cu {
+                                               index += 1
                                                continue
                                        }
-                                       danmuIndex := tIndex + bytes.Index(data[tIndex+2:], []byte{','}) + 3
+                                       index += 1
+
+                                       danmuIndex := tIndex + bytes.Index(sdata[index][tIndex+2:], []byte{','}) + 3
                                        s.Interface().Push_tag(`send`, Uinterface{
                                                Id:   0, //send to all
-                                               Data: data[danmuIndex:],
+                                               Data: sdata[index][danmuIndex:],
                                        })
-                                       data = nil
-                               } else {
-                                       break
                                }
-                       }
 
+                       }
                }
        }()