]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
弹幕格式化发送
authorqydysky <qydysky@foxmail.com>
Fri, 20 Nov 2020 07:43:25 +0000 (15:43 +0800)
committerqydysky <qydysky@foxmail.com>
Fri, 20 Nov 2020 07:43:25 +0000 (15:43 +0800)
CV/Var.go
README.md
Reply/gtk.go
Send/Send.go
bili_danmu.go
demo/ui/2.glade

index fbc51914280c8d0b5f50b7451fd1ca4a3b484551..67de52224659535d7446a0df5abf741f1303e765 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -18,6 +18,10 @@ var (
 )
 
 //消息队列
+type Danmu_Main_mq_item struct {
+       Class string
+       Data interface{}
+}
 var Danmu_Main_mq = mq.New()
 
 //from player-loader-2.0.11.min.js
index 6b3fb0eaf5696d4c6f382c61638de7d1cde57123..21e66a56a908ec5c49943b7272b1effe8fafedd6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -86,7 +86,7 @@ var AllF = map[string]bool{
 弹幕重连
 直播流开播自动下载
 直播流下载重连
-gtk弹幕窗自定义人/事件消息停留
+gtk弹幕窗自定义人/事件消息停留/房间切换/弹幕格式化发送
 营收统计
 ...
 ```
@@ -149,6 +149,17 @@ SC:  吹舞火 ¥ 30
 私の隣の一万は幻ですか?
 ====
 ```
+```
+//gtk的弹幕格式化发送
+2020/11/20 15:39:57 弹幕格式已设置为 [{D}]
+INFO: 2020/11/20 15:40:05 [弹幕发送] [发送 [就是这样] 至 394988]
+[就是这样]
+INFO: 2020/11/20 15:40:15 [弹幕发送] [发送 [你知道么] 至 394988]
+[你知道么]
+2020/11/20 15:42:38 弹幕长度大于20,不做格式处理
+INFO: 2020/11/20 15:42:38 [弹幕发送] [发送 11111111111111111111 至 394988]
+11111111111111111111
+```
 ctrl+c退出,会同时追加记录到文件danmu.log中(文件记录完整信息,不会减少附加功能作用的弹幕)
 - 流保存以及弹幕ass
 ```
index 65341d2d5bf7decb321ecf624f8054d00c030aae..f44c0cdb40440c124e177c72f8942c7de17417a7 100644 (file)
@@ -7,6 +7,7 @@ import (
        "errors"
        "strconv"
        "time"
+       "strings"
        "log"
        "fmt"
 
@@ -91,7 +92,7 @@ func Gtk_danmu() {
        var w2_textView1 *gtk.TextView
        var w2_Entry0 *gtk.Entry
        var w2_Entry0_editting bool
-       
+
        application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
        if err != nil {log.Println(err);return}
 
@@ -142,6 +143,40 @@ func Gtk_danmu() {
                                w2_textView1 = tmp
                        }else{log.Println("cant find #t1 in .glade");return}
                }
+               {//发送弹幕
+                       var danmu_send_form string
+                       {//发送弹幕格式
+                               obj, err := builder2.GetObject("send_danmu_form")
+                               if err != nil {log.Println(err);return}
+                               if tmp,ok := obj.(*gtk.Entry); ok {
+                                       tmp.Connect("focus-out-event", func() {
+                                               if t,e := tmp.GetText();e == nil && t != ``{
+                                                       danmu_send_form = t
+                                                       log.Println("弹幕格式已设置为",danmu_send_form)
+                                               }
+                                       })
+                               }else{log.Println("cant find #send_danmu in .glade");return}
+                       }
+                       obj, err := builder2.GetObject("send_danmu")
+                       if err != nil {log.Println(err);return}
+                       if tmp,ok := obj.(*gtk.Entry); ok {
+                               tmp.Connect("key-release-event", func(entry *gtk.Entry, event *gdk.Event) {
+                                       eventKey := gdk.EventKeyNewFromEvent(event)
+                                       if eventKey.KeyVal() == gdk.KEY_Return {
+                                               if t,e := entry.GetText();e == nil && t != ``{
+                                                       danmu_want_send := t
+                                                       if danmu_send_form != `` {danmu_want_send = strings.ReplaceAll(danmu_send_form, "{D}", t)}
+                                                       if len([]rune(danmu_want_send)) > 20 {
+                                                               log.Println(`弹幕长度大于20,不做格式处理`)
+                                                               danmu_want_send = t
+                                                       } 
+                                                       Msg_senddanmu(danmu_want_send)
+                                                       entry.SetText(``)
+                                               }
+                                       }
+                               })
+                       }else{log.Println("cant find #send_danmu in .glade");return}
+               }
                {//房间id
                        obj, err := builder2.GetObject("want_room_id")
                        if err != nil {log.Println(err);return}
@@ -167,7 +202,9 @@ func Gtk_danmu() {
                                                        y(`输入错误`,load_face("0room"))
                                                } else {
                                                        c.Roomid =  i
-                                                       c.Danmu_Main_mq.Push(`change_room`)
+                                                       c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{
+                                                               Class:`change_room`,
+                                                       })
                                                }
                                        } else {
                                                y(`房间号输入为空`,load_face("0room"))
index 9e768157259e5822dde2a0775ac1d64a0da6cca7..45342f0689b9396dcb82526afe3d38656828bcd5 100644 (file)
@@ -50,8 +50,7 @@ func Danmu_s(msg,Cookie string, roomid int) {
                }
        }
 
-       PostStr := `color=16777215&fontsize=25&mode=1&msg=` + msg + `&rnd=` + strconv.Itoa(int(p.Sys().GetMTime())) + `&roomid=` + strconv.Itoa(roomid) + `&bubble=0&csrf_token=` + csrf + `&csrf=` + csrf
-
+       PostStr := `color=16777215&fontsize=25&mode=1&msg=` + msg + `&rnd=` + strconv.Itoa(int(p.Sys().GetSTime())) + `&roomid=` + strconv.Itoa(roomid) + `&bubble=0&csrf_token=` + csrf + `&csrf=` + csrf
        l.I("发送", msg, "至", roomid)
        r := p.Req()
        err := r.Reqf(p.Rval{
@@ -59,6 +58,16 @@ func Danmu_s(msg,Cookie string, roomid int) {
                PostStr:PostStr,
                Timeout:5,
                Header:map[string]string{
+                       `Host`: `api.live.bilibili.com`,
+                       `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
+                       `Accept`: `application/json, text/javascript, */*; q=0.01`,
+                       `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
+                       `Accept-Encoding`: `gzip, deflate, br`,
+                       `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`,
+                       `Origin`: `https://live.bilibili.com`,
+                       `Connection`: `keep-alive`,
+                       `Pragma`: `no-cache`,
+                       `Cache-Control`: `no-cache`,
                        `Referer`:"https://live.bilibili.com/" + strconv.Itoa(roomid),
                        `Cookie`:Cookie,
                },
index 3d2b6de3309e946a78f8674cb8cbf8d163a270cb..b4d41c52aff06f58c1d5fc5f11df9d612751ad1f 100644 (file)
@@ -59,7 +59,8 @@ func Demo(roomid ...int) {
                        )
                        for {
                                data,sig = c.Danmu_Main_mq.Pull(sig)
-                               if data.(string) != `change_room` {continue}
+                               if d,ok := data.(c.Danmu_Main_mq_item);!ok || d.Class != `change_room` {continue}
+                               c.Rev = 0 //营收
                                change_room_chan <- true
                        }
                }()
index c59ee50c2ff38a133964bfa37ac2107193097859..a3d8610347760830180bdd17ced592b915e2fc20 100644 (file)
               <object class="GtkGrid" id="grid0">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="margin_left">2</property>
+                <property name="margin_right">2</property>
                 <property name="margin_top">2</property>
                 <property name="margin_bottom">2</property>
                 <property name="orientation">vertical</property>
-                <property name="row_spacing">3</property>
+                <property name="row_spacing">4</property>
                 <property name="column_spacing">2</property>
                 <child>
                   <object class="GtkExpander">
@@ -38,7 +40,7 @@
                     <property name="margin_left">2</property>
                     <property name="margin_right">2</property>
                     <property name="hexpand">True</property>
-                    <property name="vexpand">False</property>
+                    <property name="vexpand">True</property>
                     <property name="expanded">True</property>
                     <child>
                       <object class="GtkGrid">
@@ -47,7 +49,7 @@
                         <property name="hexpand">True</property>
                         <property name="vexpand">True</property>
                         <property name="row_spacing">3</property>
-                        <property name="column_spacing">2</property>
+                        <property name="column_spacing">3</property>
                         <child>
                           <object class="GtkLabel">
                             <property name="visible">True</property>
                   <object class="GtkSeparator">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="margin_left">2</property>
+                    <property name="margin_right">2</property>
                     <property name="margin_top">2</property>
                   </object>
                   <packing>
                     <property name="top_attach">1</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkExpander">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="expanded">True</property>
+                    <child>
+                      <object class="GtkGrid">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkEntry" id="send_danmu">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="margin_top">3</property>
+                            <property name="hexpand">True</property>
+                            <property name="max_length">20</property>
+                            <property name="activates_default">True</property>
+                            <property name="truncate_multiline">True</property>
+                            <property name="placeholder_text" 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>
+                            <property name="width_chars">6</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="label" translatable="yes">格式</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkEntry" id="send_danmu_form">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="margin_bottom">3</property>
+                            <property name="placeholder_text" translatable="yes">{D}由内容替换后发送,本项可为空</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">发送弹幕</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">3</property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>