Git Product home page Git Product logo

acfundanmu's Introduction

acfundanmu

AcFun直播弹幕下载,实现参照 AcFunDanmaku

示例代码

获取弹幕

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// uid为主播的uid
dq := acfundanmu.Start(ctx, uid)
for {
    if danmu := dq.GetDanmu(); danmu != nil {
        for _, d := range danmu {
            // 根据Type处理弹幕
            switch d.Type {
            case acfundanmu.Comment:
                fmt.Printf("%s(%d):%s\n", d.Nickname, d.UserID, d.Comment)
            case acfundanmu.Like:
                fmt.Printf("%s(%d)点赞\n", d.Nickname, d.UserID)
            case acfundanmu.EnterRoom:
                fmt.Printf("%s(%d)进入直播间\n", d.Nickname, d.UserID)
            case acfundanmu.FollowAuthor:
                fmt.Printf("%s(%d)关注了主播\n", d.Nickname, d.UserID)
            case acfundanmu.ThrowBanana:
                fmt.Printf("%s(%d)送出香蕉 * %d\n", d.Nickname, d.UserID, d.BananaCount)
            case acfundanmu.Gift:
                fmt.Printf("%s(%d)送出礼物 %s * %d,连击数:%d\n", d.Nickname, d.UserID, d.Gift.Name, d.Gift.Count, d.Gift.Combo)
            }
        }
    } else {
        fmt.Println("直播结束")
        break
    }
}

获取直播间状态信息

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// uid为主播的uid
dq := acfundanmu.Start(ctx, uid)
go func() {
    for {
        select {
        case <-ctx.Done():
            return
        default:
            // 循环获取info并处理
            time.Sleep(5 * time.Second)
            info := dq.GetInfo()
            fmt.Printf("%+v\n", info)
        }
    }
}()
// 做其他事情

将弹幕转换成ass字幕文件

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// uid为主播的uid
dq := acfundanmu.Start(ctx, uid)
dq.WriteASS(ctx, acfundanmu.SubConfig{
    Title:     "foo",
    PlayResX:  1280, // 直播录播视频的分辨率
    PlayResY:  720,
    FontSize:  40,
    StartTime: time.Now().UnixNano()}, // 这里应该是开始录播的时间
    "foo.ass", true)

acfundanmu's People

Contributors

orzogc avatar

Watchers

James Cloos avatar

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.