Code Monkey home page Code Monkey logo

Comments (12)

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb 代码不完整,建议补全

from danmu.

littleweb avatar littleweb commented on May 26, 2024
# -*- coding: UTF-8 -*-
import time, sys, requests

from danmu import DanMuClient

star_url = "http://www.douyu.com/wt55kai"


def pp(msg):
    print(msg.encode(sys.stdin.encoding, 'ignore').
        decode(sys.stdin.encoding))
    sys.stdout.flush()

dmc = DanMuClient(star_url)
if not dmc.isValid(): print('Url not valid')

@dmc.danmu
def danmu_fn(msg):
    payload = {
            "star_id": "star_id",
            "text": msg['Content'],
            "type": "danmu",
            "plat": "plat"
        }
    print payload

@dmc.gift
def gift_fn(msg):
    pp('[%s] sent a gift!' % content['NickName'])
    payload = {
            "star_id": "star_id",
            "text": msg['Content'],
            "type": "danmu",
            "plat": "plat"
        }
    print payload

@dmc.other
def other_fn(msg):
    pp('Other message received')

dmc.start(blockThread = True)

from danmu.

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb
我这里获取正常没有问题。
另,gift的Content键是没有内容的。

from danmu.

littleweb avatar littleweb commented on May 26, 2024

我把代码精简了下,还是只能打印出danmu,gift打印不出呢。

import time, sys, requests

from danmu import DanMuClient

star_url = "http://www.douyu.com/wt55kai"

dmc = DanMuClient(star_url)
if not dmc.isValid(): print('Url not valid')

@dmc.danmu
def danmu_fn(msg):
    print "danmu";

@dmc.gift
def gift_fn(msg):
    print "gift";

@dmc.other
def other_fn(msg):
    print('Other message received')

dmc.start(blockThread=True)

from danmu.

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb

  • 你的danmu包版本是多少?
  • 我这里能够获取说明协议没有问题
  • 弹幕能获取说明通信与启动没有问题
  • 建议抓个包看一下是否收到了弹幕的相关消息

from danmu.

littleweb avatar littleweb commented on May 26, 2024

OK了,应该是语法问题,多谢
礼物的数量有没有办法截获到呢

from danmu.

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb
哪段代码的语法问题?我没有看出来
不同平台数量的算法不一样的,你可以获取整个消息体研究一下。

from danmu.

littleweb avatar littleweb commented on May 26, 2024
payload = {
            "star_id": "star_id",
            "text": msg['Content'],
            "type": "danmu",
            "plat": "plat"
        }
    print payload

我把这块封装了一下就好了

from danmu.

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb
为什么封装一下就好了?
另,不是精简的代码也同样打不出来吗?

from danmu.

littleweb avatar littleweb commented on May 26, 2024

有可能调试的时候正好没有礼物吧

from danmu.

littlecodersh avatar littlecodersh commented on May 26, 2024

@littleweb
好的,那封装是指?

from danmu.

littleweb avatar littleweb commented on May 26, 2024
def save(type,text):
    payload = {
            "star_id": star_id,
            "text": text,
            "type": type,
            "plat": plat
        }
    r = requests.get("http://localhost:9203/save", params=payload)

dmc = DanMuClient(star_url)
if not dmc.isValid(): print('Url not valid')

@dmc.danmu
def danmu_fn(msg):
    save("danmu",msg['Content'])
    pp('danmu')

@dmc.gift
def gift_fn(msg):
    save("gift","")
    pp('gift')

@dmc.other
def other_fn(msg):
    pp('Other message received')

dmc.start(blockThread = True)

这样就可以了,很奇怪

from danmu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.