]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
直播信息单独界面
authorqydysky <qydysky@foxmail.com>
Sun, 15 Nov 2020 08:11:16 +0000 (16:11 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 15 Nov 2020 08:11:16 +0000 (16:11 +0800)
.gitignore
CV/Var.go
F/api.go
Reply/F.go
Reply/Reply.go
Reply/gtk.go
demo/ui/1.glade
demo/ui/2.glade [new file with mode: 0644]

index 626e18ee0b7e2086bc76fbac4a64c3dba07ab4f4..f32679797482ae0b176fb27706f593bd66f3b804 100644 (file)
@@ -14,3 +14,4 @@ demo/qtbox
 demo/main
 demo/face/*
 demo/demo.run
+demo/ui/*.glade~
index 3c3909ed54e05e56272dd83859fe030d4f274d29..d5842e78cd02660510e5e677d941318bcdbdbce3 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -1,5 +1,9 @@
 package cv
+
+import (
+       "time"
+)
+
 var (
        Live []string//直播链接
        Live_qn string
@@ -7,6 +11,8 @@ var (
        Cookie string
        Title string
        Rev float64//营收
+       Live_Start_Time time.Time//直播开始时间
+       Liveing bool//是否在直播
 )
 
 //from player-loader-2.0.11.min.js
index 43f5812d3a6691d562015bb0f71d7e569d0379b0..aa4008356e7737a5f73ffa1ae15dfba981fc84a0 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -1,6 +1,7 @@
 package F
 
 import (
+       "time"
        "strconv"
        "strings"
 
@@ -147,6 +148,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                if e := r.S(`"durl":[`, `]`, 0, 0).Err;e == nil {
                        if urls := p.Json().GetArrayFrom("[" + r.RS + "]", "url");urls != nil {
                                apilog.W("直播中")
+                               c.Liveing = true
                                o.Live_status = 1
                                for _,v := range urls {
                                        o.Live = append(o.Live, v.(string))
@@ -157,6 +159,9 @@ func (i *api) Get_live(qn ...string) (o *api) {
                if e := r.S(`player-loader-`, `.min`, 0, 0).Err;e == nil {
                        c.VERSION = r.RS
                }
+               if e := r.S(`"live_time":"`, `"`, 0, 0).Err;e == nil {
+                       c.Live_Start_Time,_ = time.Parse("2006-01-02 15:04:05", r.RS)
+               }
                apilog.W("api version", c.VERSION)
        }
 
@@ -201,6 +206,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                                apilog.W("未在直播")
                                return
                        case 1:
+                               c.Liveing = true
                                apilog.W("直播中")
                        default:
                                apilog.W("live_status:", live_status)
@@ -219,7 +225,9 @@ func (i *api) Get_live(qn ...string) (o *api) {
                if i := p.Json().GetValFrom(res, "data.play_url.current_qn"); i != nil {
                        cu_qn = strconv.Itoa(int(i.(float64)))
                }
-
+               if i := p.Json().GetValFrom(res, "data.live_time"); i != nil {
+                       c.Live_Start_Time = time.Unix(int64(i.(float64)),0).In(time.FixedZone("UTC-8", -8*60*60))
+               }
                if len(qn) != 0 && qn[0] != "0" && qn[0] != "" {
                        if _,ok := c.Default_qn[qn[0]];!ok{
                                apilog.W("清晰度未找到", qn[0], ",使用默认")
index c2f571269acda808170fcbf0ea99b6ded440a085..1ef436d6980b1e878ff2c98858647fd3f9180822 100644 (file)
@@ -125,12 +125,12 @@ var (
 func ShowRevf(){
        if!IsOn("ShowRev") {return}
        if ShowRev_start {
-               p.Logf().New().Open("danmu.log").Base(1, "Rev").I("营收 ¥", c.Rev)
+               p.Logf().New().Open("danmu.log").Base(1, "Rev").I(fmt.Sprintf("营收 ¥%.2f",c.Rev))
                return
        }
        ShowRev_start = true
        for {
-               p.Logf().New().Open("danmu.log").Base(1, "Rev").I("营收 ¥", c.Rev)
+               p.Logf().New().Open("danmu.log").Base(1, "Rev").I(fmt.Sprintf("营收 ¥%.2f",c.Rev))
                for c.Rev == ShowRev_old {p.Sys().Timeoutf(60)}
                ShowRev_old = c.Rev
        }
index 6518efd36888265511cb6d4001fd462c409d8ef0..5b31fbd9b06c857a9a64a07ec21b7e782d9151c1 100644 (file)
@@ -2,6 +2,7 @@ package reply
 
 import (
        "fmt"
+       "time"
        "bytes"
        "strconv"
        "compress/zlib"
@@ -359,8 +360,8 @@ func (replyF) preparing(s string) {
                        Obs_R(false)
                        Obsf(false)
                        Saveflv_wait()
-                       c.Rev = 0
                        go ShowRevf()
+                       c.Liveing = false
                }
                if p.Sys().Type(roomid) == "float64" {
                        Gui_show(Itos([]interface{}{"房间", roomid, "下播了"}), "0room")
@@ -385,6 +386,11 @@ func (replyF) live(s string) {
                        Obs_R(true)
                        go Saveflvf()
                }
+               {
+                       c.Rev = 0 //营收
+                       c.Liveing = true //直播i标志
+                       c.Live_Start_Time = time.Now() //开播h时间
+               }
                if p.Sys().Type(roomid) == "float64" {
                        Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}), "0room")
                        msglog.I("房间", int(roomid.(float64)), "开播了")
index 85c635c9575aee545ef8bd1f70cf81d9dc32f99e..0552d165c9564e173de6d7ebe89a8d9142feea8a 100644 (file)
@@ -5,12 +5,14 @@ import (
        "errors"
        "time"
        "log"
+       "fmt"
 
        "github.com/gotk3/gotk3/glib"
        "github.com/gotk3/gotk3/gtk"
        "github.com/gotk3/gotk3/gdk"
        p "github.com/qydysky/part"
        F "github.com/qydysky/bili_danmu/F"
+       c "github.com/qydysky/bili_danmu/CV"
 )
 const (
        max = 50
@@ -58,6 +60,8 @@ func Gtk_danmu() {
        var win *gtk.Window
        var scrolledwindow0 *gtk.ScrolledWindow
        var viewport0 *gtk.Viewport
+       var w2_textView0 *gtk.TextView
+       var w2_textView1 *gtk.TextView
        
        application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
        if err != nil {log.Println(err);return}
@@ -68,13 +72,17 @@ func Gtk_danmu() {
 
                builder, err := gtk.BuilderNewFromFile("ui/1.glade")
                if err != nil {log.Println(err);return}
+               builder2, err := gtk.BuilderNewFromFile("ui/2.glade")
+               if err != nil {log.Println(err);return}
 
                {
                        signals := map[string]interface{}{
                                "on_main_window_destroy": onMainWindowDestroy,
                        }
                        builder.ConnectSignals(signals)
+                       builder2.ConnectSignals(signals)
                }
+
                {
                        obj, err := builder.GetObject("main_window")
                        if err != nil {log.Println(err);return}
@@ -83,6 +91,28 @@ func Gtk_danmu() {
                        application.AddWindow(win)
                        defer win.ShowAll()
                }
+               {
+                       obj, err := builder2.GetObject("main_window")
+                       if err != nil {log.Println(err);return}
+                       win2, err := isWindow(obj)
+                       if err != nil {log.Println(err);return}
+                       application.AddWindow(win2)
+                       defer win2.ShowAll()
+               }
+               {//营收
+                       obj, err := builder2.GetObject("t0")
+                       if err != nil {log.Println(err);return}
+                       if tmp,ok := obj.(*gtk.TextView); ok {
+                               w2_textView0 = tmp
+                       }else{log.Println("cant find #t0 in .glade");return}
+               }
+               {//直播时长
+                       obj, err := builder2.GetObject("t1")
+                       if err != nil {log.Println(err);return}
+                       if tmp,ok := obj.(*gtk.TextView); ok {
+                               w2_textView1 = tmp
+                       }else{log.Println("cant find #t1 in .glade");return}
+               }
                {
                        obj, err := builder.GetObject("scrolledwindow0")
                        if err != nil {log.Println(err);return}
@@ -113,7 +143,7 @@ func Gtk_danmu() {
                        var e error
                        if pro_style,e = gtk.CssProviderNew();e == nil{
                                if e = pro_style.LoadFromPath(`ui/1.css`);e == nil{
-                                       if scr,e := gdk.ScreenGetDefault();e == nil {
+                                       if scr := win.GetScreen();scr != nil {
                                                gtk.AddProviderForScreen(scr,pro_style,gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
                                        }
                                }else{log.Println(e)}
@@ -234,10 +264,30 @@ func Gtk_danmu() {
                                })
                        }
                }()
-               
+
                glib.TimeoutAdd(uint(3000), func()(o bool){
                        o = true
                        //y("sssss",load_face(""))
+                       {//营收
+                               if IsOn("ShowRev") {
+                                       b,e := w2_textView0.GetBuffer()
+                                       if e != nil {log.Println(e);return}
+                                       b.SetText(fmt.Sprintf("¥%.2f",c.Rev))                                 
+                               }
+                       }
+                       {//时长
+                               if c.Liveing {
+                                       b,e := w2_textView1.GetBuffer()
+                                       if e != nil {log.Println(e);return}
+                                       d := time.Since(c.Live_Start_Time).Round(time.Second)
+                                       h := d / time.Hour
+                                       d -= h * time.Hour
+                                       m := d / time.Minute
+                                       d -= m * time.Minute
+                                       s := d / time.Second
+                                       b.SetText(fmt.Sprintf("%02d:%02d:%02d", h, m, s))                                       
+                               }
+                       }
                        if gtkGetList.Len() == 0 {return}
                        el := gtkGetList.Front()
                        if el == nil {return}
index 8e681587638c1f68bfa849d246b34f315eb3b444..e0030abfd300f106ee6ad4f40ca3c71acfd246f2 100644 (file)
@@ -4,6 +4,7 @@
   <requires lib="gtk+" version="3.20"/>
   <object class="GtkWindow" id="main_window">
     <property name="can_focus">False</property>
+    <property name="title" translatable="yes">弹幕</property>
     <property name="window_position">mouse</property>
     <property name="default_width">400</property>
     <property name="default_height">500</property>
diff --git a/demo/ui/2.glade b/demo/ui/2.glade
new file mode 100644 (file)
index 0000000..e2bd81e
--- /dev/null
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkWindow" id="main_window">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">弹幕机信息</property>
+    <property name="window_position">mouse</property>
+    <property name="default_width">400</property>
+    <property name="default_height">500</property>
+    <property name="destroy_with_parent">True</property>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolledwindow0">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hscrollbar_policy">never</property>
+        <child>
+          <object class="GtkViewport" id="viewport0">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkGrid" id="grid0">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="row_spacing">3</property>
+                <property name="column_spacing">2</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">项目</property>
+                    <property name="width_chars">16</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="hexpand">True</property>
+                    <property name="label" translatable="yes">值</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">营收(启动后)</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkTextView" id="t0">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscroll_policy">natural</property>
+                    <property name="editable">False</property>
+                    <property name="justification">right</property>
+                    <property name="cursor_visible">False</property>
+                    <property name="accepts_tab">False</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">直播时长</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkTextView" id="t1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="editable">False</property>
+                    <property name="justification">right</property>
+                    <property name="cursor_visible">False</property>
+                    <property name="accepts_tab">False</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>