### Get User Info and Live Info in Go Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches basic user information and current live stream details for a specified user ID. Requires a device ID. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { deviceID, _ := acfundanmu.GetDeviceID() uid := int64(12345678) // 获取用户基本信息(无需登录) userInfo, err := acfundanmu.GetUserInfo(uid, deviceID) if err != nil { log.Fatalf("获取用户信息失败: %v", err) } log.Printf("========== 用户信息 ==========") log.Printf("用户ID: %d", userInfo.UserID) log.Printf("昵称: %s", userInfo.Nickname) log.Printf("头像: %s", userInfo.Avatar) log.Printf("签名: %s", userInfo.Signature) log.Printf("关注数: %s", userInfo.FollowingCount) log.Printf("粉丝数: %s", userInfo.FansCount) log.Printf("投稿数: %s", userInfo.ContributeCount) log.Printf("认证信息: %s", userInfo.VerifiedText) // 获取用户直播信息 liveInfo, err := acfundanmu.GetUserLiveInfo(uid, deviceID) if err != nil { log.Fatalf("获取用户直播信息失败: %v", err) } if liveInfo.LiveID != "" { log.Printf("\n========== 直播信息 ==========") log.Printf("直播ID: %s", liveInfo.LiveID) log.Printf("直播标题: %s", liveInfo.Title) log.Printf("直播分类: %s - %s", liveInfo.LiveType.CategoryName, liveInfo.LiveType.Name) log.Printf("在线人数: %d", liveInfo.OnlineCount) log.Printf("点赞数: %d", liveInfo.LikeCount) log.Printf("是否手机直播: %v", liveInfo.Portrait) log.Printf("是否全景直播: %v", liveInfo.Panoramic) } else { log.Println("\n用户当前未直播") } } ``` -------------------------------- ### Get Live Room Status (Non-Event Mode) in Go Source: https://github.com/orzogc/acfundanmu/blob/master/README.md This example shows how to periodically fetch live room status information without relying on event callbacks. It uses a select statement with a context for graceful shutdown and a fixed delay for polling. ```go // uid 为主播的 uid ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Panicln(err) } ctx, cancel := context.WithCancel(context.Background()) defuncel cancel() ch := ac.StartDanmu(ctx, false) for { select { case <-ctx.Done(): return default: // 循环获取 info 并处理 time.Sleep(5 * time.Second) info := ac.GetLiveInfo() log.Printf("%+v\n", info) } } if err = <-ch; err != nil { log.Panicln(err) } else { log.Println("直播结束") } ``` -------------------------------- ### Get Summary - Retrieve Live Stream Summary Information Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches post-live stream summary data, including duration, likes, viewership, and revenue. Requires the live ID and an initialized AcFunLive client. ```go package main import ( "log" "time" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } liveID := ac.GetLiveID() summary, err := ac.GetSummary(liveID) if err != nil { log.Fatalf("获取直播总结失败: %v", err) } duration := time.Duration(summary.Duration) * time.Millisecond log.Printf("========== 直播总结 ==========") log.Printf("直播时长: %v", duration) log.Printf("点赞总数: %s", summary.LikeCount) log.Printf("观看人数: %s", summary.WatchCount) log.Printf("付费礼物数量: %d", summary.GiftCount) log.Printf("收到钻石: %d (约%.2f AC币)", summary.DiamondCount, float64(summary.DiamondCount)/100) log.Printf("收到香蕉: %d", summary.BananaCount) } ``` -------------------------------- ### Get Wallet Balance in Go (Requires Login) Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches the logged-in user's ACoin and banana balance. This operation requires successful login using account credentials to obtain cookies. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { // 先登录获取 cookies cookies, err := acfundanmu.Login("your_account@email.com", "your_password") if err != nil { log.Fatalf("登录失败: %v", err) } ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetCookies(cookies)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } accoins, bananas, err := ac.GetWalletBalance() if err != nil { log.Fatalf("获取钱包余额失败: %v", err) } log.Printf("========== 钱包余额 ==========") log.Printf("AC币: %d", accoins) log.Printf("香蕉: %d", bananas) } ``` -------------------------------- ### Get Playback - Fetch Live Stream Replay Information Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves details about a live stream's replay, such as the playback URL, duration, and resolution. Requires a specific live ID and an initialized AcFunLive client. The `Distinguish` method helps separate Alibaba Cloud and Tencent Cloud URLs. ```go package main import ( "log" "time" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 需要知道具体的 liveID liveID := "your_live_id" playback, err := ac.GetPlayback(liveID) if err != nil { log.Fatalf("获取直播回放失败: %v", err) } duration := time.Duration(playback.Duration) * time.Millisecond log.Printf("========== 直播回放 ==========") log.Printf("回放时长: %v", duration) log.Printf("分辨率: %dx%d", playback.Width, playback.Height) log.Printf("回放链接: %s", playback.URL) log.Printf("备用链接: %s", playback.BackupURL) // 区分阿里云和腾讯云链接 aliURL, txURL := playback.Distinguish() if aliURL != "" { log.Printf("阿里云链接(下载较快): %s", aliURL) } if txURL != "" { log.Printf("腾讯云链接: %s", txURL) } } ``` -------------------------------- ### Write ASS - Convert Danmaku to ASS Subtitles Source: https://context7.com/orzogc/acfundanmu/llms.txt Converts live danmaku (bullet comments) into an ASS subtitle file in real-time, useful for adding subtitles to recorded videos. Requires context, configuration for subtitle appearance (resolution, font size, start time), and a file path for output. The `newFile` parameter determines if a new file with headers is created or if data is appended. ```go package main import ( "context" "log" "time" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() ch := ac.StartDanmu(ctx, false) // 字幕配置 subConfig := acfundanmu.SubConfig{ Title: "直播弹幕字幕", PlayResX: 1920, // 视频分辨率宽度 PlayResY: 1080, // 视频分辨率高度 FontSize: 36, // 弹幕字体大小 StartTime: time.Now().UnixNano(), // 录播开始时间 } // 在后台写入弹幕字幕 // newFile 为 true 时创建新文件(包含完整的 ASS 头部) // newFile 为 false 时追加写入(只写入弹幕行) go ac.WriteASS(ctx, subConfig, "danmu.ass", true) log.Println("开始录制弹幕字幕到 danmu.ass") // 等待弹幕获取结束 if err := <-ch; err != nil { log.Printf("出错: %v", err) } else { log.Println("直播结束,弹幕字幕录制完成") } } ``` -------------------------------- ### Get Gift Lists - Fetch All and Live-Specific Gifts Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches all available gifts or gifts for a specific live stream. Initializes the client and then calls either GetAllGiftList or GetGiftList with the live ID. Note that GetGiftList requires a valid live ID obtained from the client. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 获取全部礼物列表 allGifts, err := ac.GetAllGiftList() if err != nil { log.Fatalf("获取全部礼物列表失败: %v", err) } log.Printf("全部礼物列表 (共%d个):", len(allGifts)) for giftID, gift := range allGifts { payType := "免费" if gift.PayWalletType == 1 { payType = "付费" } log.Printf(" [%d] %s - %d AC币 (%s) - %s", giftID, gift.GiftName, gift.Price, payType, gift.Description) } // 获取指定直播间的礼物列表 liveID := ac.GetLiveID() if liveID != "" { gifts, err := ac.GetGiftList(liveID) if err != nil { log.Fatalf("获取直播间礼物列表失败: %v", err) } log.Printf("\n直播间礼物列表 (共%d个):", len(gifts)) for giftID, gift := range gifts { log.Printf(" [%d] %s - %d AC币", giftID, gift.GiftName, gift.Price) } } } ``` -------------------------------- ### Use Event-Driven Danmaku Handling in Go Source: https://github.com/orzogc/acfundanmu/blob/master/README.md This approach uses callback functions to handle different danmaku events as they occur. It's suitable for real-time processing and requires starting the danmaku stream with the event mode enabled. ```go // uid 为主播的 uid ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Panicln(err) } ac.OnDanmuStop(func(ac *acfundanmu.AcFunLive, err error) { if err != nil { log.Println(err) } else { log.Println("直播结束") } }) ac.OnComment(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Comment) { log.Printf("%s(%d):%s\n", d.Nickname, d.UserID, d.Content) }) ac.OnLike(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Like) { log.Printf("%s(%d)点赞\n", d.Nickname, d.UserID) }) ac.OnEnterRoom(func(ac *acfundanmu.AcFunLive, d *acfundanmu.EnterRoom) { log.Printf("%s(%d)进入直播间\n", d.Nickname, d.UserID) }) ac.OnFollowAuthor(func(ac *acfundanmu.AcFunLive, d *acfundanmu.FollowAuthor) { log.Printf("%s(%d)关注了主播\n", d.Nickname, d.UserID) }) ac.OnThrowBanana(func(ac *acfundanmu.AcFunLive, d *acfundanmu.ThrowBanana) { log.Printf("%s(%d)送出香蕉 * %d\n", d.Nickname, d.UserID, d.BananaCount) }) ac.OnGift(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Gift) { log.Printf("%s(%d)送出礼物 %s * %d,连击数:%d\n", d.Nickname, d.UserID, d.GiftName, d.Count, d.Combo) }) ac.OnJoinClub(func(ac *acfundanmu.AcFunLive, d *acfundanmu.JoinClub) { log.Printf("%s(%d)加入主播%s(%d)的守护团", d.FansInfo.Nickname, d.FansInfo.UserID, d.UperInfo.Nickname, d.UperInfo.UserID) }) ac.OnShareLive(func(ac *acfundanmu.AcFunLive, d *acfundanmu.ShareLive) { log.Printf("%s(%d)分享直播间到 %d %s", d.Nickname, d.UserID, d.SharePlatform, d.SharePlatformIcon) }) ctx, cancel := context.WithCancel(context.Background()) defuncel cancel() _ = ac.StartDanmu(ctx, true) // 做其他事情 ``` -------------------------------- ### GetLiveInfo - Get Live Room Status Information Source: https://context7.com/orzogc/acfundanmu/llms.txt This API retrieves the real-time status information of a live room, including the number of viewers, likes, bananas, and the top three gift-givers. ```APIDOC ## GET /api/live/info ### Description Retrieves the real-time status information of a live room, including online viewers, likes, bananas, and top gift contributors. ### Method GET ### Endpoint `/api/live/info` (This is a conceptual endpoint based on the function name. The actual implementation might not expose a direct HTTP endpoint but rather a method within the SDK.) ### Parameters N/A (Parameters are typically set during client initialization or implicitly handled by the SDK). ### Request Example ```go // In Go SDK: ac.GetLiveInfo() ``` ### Response #### Success Response (200) - **WatchingCount** (string) - Current number of online viewers. - **LikeCount** (string) - Total number of likes. - **AllBananaCount** (string) - Total number of bananas. - **TopUsers** (array of TopUser) - List of top gift-givers. - **Nickname** (string) - Nickname of the user. - **DisplaySendAmount** (string) - Displayed amount of gifts sent. - **RedpackList** (array of Redpack) - List of active red packets. - **Nickname** (string) - Nickname of the user who sent the red packet. - **RedpackAmount** (int) - Amount of AC coins in the red packet. #### Response Example ```json { "WatchingCount": "1500", "LikeCount": "100000", "AllBananaCount": "50000", "TopUsers": [ { "Nickname": "UserA", "DisplaySendAmount": "1000" }, { "Nickname": "UserB", "DisplaySendAmount": "800" }, { "Nickname": "UserC", "DisplaySendAmount": "600" } ], "RedpackList": [ { "Nickname": "RedpackSender", "RedpackAmount": 100 } ] } ``` ``` -------------------------------- ### Get Live Stream Statistics (Go) Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves statistical data for a streamer's recent live streams, including duration, viewership, danmaku count, and revenue. Requires the streamer's account to be logged in. ```Go package main import ( "log" "time" "github.com/orzogc/acfundanmu" ) func main() { // 需要登录主播账号 cookies, err := acfundanmu.Login("streamer@email.com", "password") if err != nil { log.Fatalf("登录失败: %v", err) } ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetCookies(cookies)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 获取最近7天的直播数据 data, err := ac.GetLiveData(7) if err != nil { log.Fatalf("获取直播数据失败: %v", err) } log.Printf("========== 直播统计 (%s ~ %s) ==========", data.BeginDate, data.EndDate) log.Printf("总直播时长: %v", time.Duration(data.Overview.Duration)*time.Millisecond) log.Printf("总观看人数: %d", data.Overview.WatchCount) log.Printf("总弹幕数: %d", data.Overview.CommentCount) log.Printf("总收到钻石: %d (约%.2f AC币)", data.Overview.DiamondCount, float64(data.Overview.DiamondCount)/100) log.Printf("总收到香蕉: %d", data.Overview.BananaCount) log.Printf("\n每日统计:") for _, daily := range data.DailyData { log.Printf(" %s: 直播%d次, 时长%v, 观看%d人, 钻石%d, 香蕉%d", daily.Date, daily.LiveTimes, time.Duration(daily.Duration)*time.Millisecond, daily.WatchCount, daily.DiamondCount, daily.BananaCount) } } ``` -------------------------------- ### Get Live Stream Lists in Go Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches paginated and all currently live stream room lists. Requires a device ID. The `GetLiveList` function returns a boolean indicating if the current page is the last page. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { deviceID, _ := acfundanmu.GetDeviceID() // 分页获取正在直播的列表 liveList, lastPage, err := acfundanmu.GetLiveList(10, 0, deviceID) if err != nil { log.Fatalf("获取直播列表失败: %v", err) } log.Printf("正在直播的直播间 (第1页, 共%d个):", len(liveList)) for i, live := range liveList { log.Printf("%d. [%s] %s - %s (%d人在线)", i+1, live.Profile.Nickname, live.Title, live.LiveType.Name, live.OnlineCount) } log.Printf("是否最后一页: %v", lastPage) // 获取全部正在直播的列表 allList, err := acfundanmu.GetAllLiveList(deviceID) if err != nil { log.Fatalf("获取全部直播列表失败: %v", err) } log.Printf("\n当前共有 %d 个直播间正在直播", len(allList)) } ``` -------------------------------- ### GetWatchingList - Get Online Audience List Source: https://context7.com/orzogc/acfundanmu/llms.txt This API retrieves a list of the top 50 online audience members in the live room, including their user information and gift contributions. ```APIDOC ## GET /api/live/watchinglist ### Description Retrieves a list of the top 50 online audience members in the live room, including user information and gift contributions. ### Method GET ### Endpoint `/api/live/watchinglist` (This is a conceptual endpoint based on the function name. The actual implementation might not expose a direct HTTP endpoint but rather a method within the SDK.) ### Parameters #### Path Parameters - **liveID** (string) - Required - The ID of the live room. ### Request Example ```go // In Go SDK: watchingList, err := ac.GetWatchingList(liveID) ``` ### Response #### Success Response (200) - **watchingList** (array of WatchingUser) - List of online users. - **Nickname** (string) - Nickname of the user. - **UserID** (int64) - User ID. - **DisplaySendAmount** (string) - Displayed amount of gifts contributed. - **AnonymousUser** (bool) - Indicates if the user is anonymous. - **ManagerType** (string) - Type of manager role (e.g., NormalManager). #### Response Example ```json [ { "Nickname": "Viewer1", "UserID": 98765, "DisplaySendAmount": "500", "AnonymousUser": false, "ManagerType": "NormalManager" }, { "Nickname": "Viewer2", "UserID": 12345, "DisplaySendAmount": "300", "AnonymousUser": true, "ManagerType": "None" } ] ``` ``` -------------------------------- ### Retrieve Live Room Status Source: https://context7.com/orzogc/acfundanmu/llms.txt Polls the live room for real-time statistics like viewer count, likes, and top contributors. Requires starting the danmu client with event mode disabled. ```go package main import ( "context" "log" "time" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() ch := ac.StartDanmu(ctx, false) go func() { for { select { case <-ctx.Done(): return default: time.Sleep(5 * time.Second) info := ac.GetLiveInfo() log.Printf("========== 直播间状态 ==========") log.Printf("在线人数: %s", info.WatchingCount) log.Printf("点赞总数: %s", info.LikeCount) log.Printf("香蕉总数: %s", info.AllBananaCount) log.Printf("礼物榜前三:") for i, user := range info.TopUsers { log.Printf(" %d. %s - %s", i+1, user.Nickname, user.DisplaySendAmount) } if len(info.RedpackList) > 0 { log.Printf("红包列表:") for _, rp := range info.RedpackList { log.Printf(" %s: %d AC币", rp.Nickname, rp.RedpackAmount) } } } } }() // 等待弹幕获取结束 if err := <-ch; err != nil { log.Printf("出错: %v", err) } } ``` -------------------------------- ### Get Top 50 Online Viewers for Live Room Source: https://github.com/orzogc/acfundanmu/blob/master/README.md Retrieves a list of the top 50 online viewers for a given live room. Requires the anchor's UID to initialize. The viewer list is fetched periodically in a goroutine. ```go // uid 为主播的 uid ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Panicln(err) } ctx, cancel := context.WithCancel(context.Background()) deferr cancel() liveID := ac.GetLiveID() go func() { for { select { case <-ctx.Done(): return default: // 循环获取 watchingList 并处理 watchingList, err := ac.GetWatchingList(liveID) if err != nil { log.Panicln(err) } log.Printf("%+v\n", *watchingList) time.Sleep(30 * time.Second) } } }() // 做其他事情 ``` -------------------------------- ### Get Guardian Rank List in Go Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves the guardian ranking list for a specified anchor, showing the top 50 users by guardian badge intimacy. Requires a device ID. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { deviceID, _ := acfundanmu.GetDeviceID() uid := int64(12345678) rankList, err := acfundanmu.GetMedalRankList(uid, deviceID) if err != nil { log.Fatalf("获取守护榜失败: %v", err) } log.Printf("========== 守护榜 ==========") log.Printf("守护徽章名称: %s", rankList.ClubName) log.Printf("是否有守护团: %v", rankList.HasFansClub) log.Printf("守护团人数: %d", rankList.MedalCount) log.Printf("\n守护榜前50名:") for i, user := range rankList.RankList { log.Printf("%d. %s - 等级%d - 亲密度%d", i+1, user.Nickname, user.Level, user.FriendshipDegree) } } ``` -------------------------------- ### Get Danmaku (Non-Event Mode) in Go Source: https://github.com/orzogc/acfundanmu/blob/master/README.md Use this method to poll for danmaku messages without setting up event handlers. Ensure proper context management and error handling for the stream. ```go // uid 为主播的 uid ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Panicln(err) } ctx, cancel := context.WithCancel(context.Background()) defuncel cancel() ch := ac.StartDanmu(ctx, false) for { if danmu := ac.GetDanmu(); danmu != nil { for _, d := range danmu { switch d := d.(type) { case *acfundanmu.Comment: log.Printf("%s(%d):%s\n", d.Nickname, d.UserID, d.Content) case *acfundanmu.Like: log.Printf("%s(%d)点赞\n", d.Nickname, d.UserID) case *acfundanmu.EnterRoom: log.Printf("%s(%d)进入直播间\n", d.Nickname, d.UserID) case *acfundanmu.FollowAuthor: log.Printf("%s(%d)关注了主播\n", d.Nickname, d.UserID) case *acfundanmu.ThrowBanana: log.Printf("%s(%d)送出香蕉 * %d\n", d.Nickname, d.UserID, d.BananaCount) case *acfundanmu.Gift: log.Printf("%s(%d)送出礼物 %s * %d,连击数:%d\n", d.Nickname, d.UserID, d.GiftName, d.Count, d.Combo) case *acfundanmu.RichText: for _, r := range d.Segments { switch r := r.(type) { case *acfundanmu.RichTextUserInfo: log.Printf("富文本用户信息:%+v\n", *r) case *acfundanmu.RichTextPlain: log.Printf("富文本文字:%s,颜色:%s\n", r.Text, r.Color) case *acfundanmu.RichTextImage: for _, image := range r.Pictures { log.Printf("富文本图片:%s\n", image) } log.Printf("富文本图片另外的文字:%s,颜色:%s\n", r.AlternativeText, r.AlternativeColor) } } case *acfundanmu.JoinClub: log.Printf("%s(%d)加入主播%s(%d)的守护团", d.FansInfo.Nickname, d.FansInfo.UserID, d.UperInfo.Nickname, d.UperInfo.UserID) } case *acfundanmu.ShareLive: log.Printf("%s(%d)分享直播间到 %d %s", d.Nickname, d.UserID, d.SharePlatform, d.SharePlatformIcon) } } else { if err = <-ch; err != nil { log.Panicln(err) } else { log.Println("直播结束") } break } } ``` -------------------------------- ### Get Guardian Medal List and Details (Go) Source: https://context7.com/orzogc/acfundanmu/llms.txt Fetches the list of guardian medals owned by a logged-in account and retrieves detailed information for a specific streamer's guardian medal. Requires user login credentials. ```Go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { cookies, err := acfundanmu.Login("your_account@email.com", "your_password") if err != nil { log.Fatalf("登录失败: %v", err) } ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetCookies(cookies)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 获取守护徽章列表 medalList, err := ac.GetMedalList() if err != nil { log.Fatalf("获取守护徽章列表失败: %v", err) } log.Printf("========== 我的守护徽章 (共%d个) ==========", len(medalList)) for i, medal := range medalList { wearStatus := "" if medal.WearMedal { wearStatus = " [佩戴中]" } log.Printf("%d. [%s] %s - 等级%d - 亲密度%d/%d%s", i+1, medal.ClubName, medal.UperName, medal.Level, medal.FriendshipDegree, medal.CurrentDegreeLimit, wearStatus) } // 获取指定主播的守护徽章详细信息 if len(medalList) > 0 { uperID := medalList[0].UperID detail, err := ac.GetMedalDetail(uperID) if err != nil { log.Fatalf("获取守护徽章详情失败: %v", err) } log.Printf("\n========== 守护徽章详情 ==========") log.Printf("主播: %s", detail.Medal.UperName) log.Printf("徽章名: %s", detail.Medal.ClubName) log.Printf("等级: %d", detail.Medal.Level) log.Printf("亲密度: %d/%d", detail.Medal.FriendshipDegree, detail.Medal.CurrentDegreeLimit) log.Printf("排名: %s", detail.UserRank) log.Printf("今日亲密度获取:") log.Printf(" 礼物: %d/%d", detail.MedalDegree.GiftDegree, detail.MedalDegree.GiftDegreeLimit) log.Printf(" 投桃: %d/%d", detail.MedalDegree.PeachDegree, detail.MedalDegree.PeachDegreeLimit) log.Printf(" 看播: %d/%d", detail.MedalDegree.LiveWatchDegree, detail.MedalDegree.LiveWatchDegreeLimit) log.Printf(" 投蕉: %d/%d", detail.MedalDegree.BananaDegree, detail.MedalDegree.BananaDegreeLimit) } } ``` -------------------------------- ### Get Billboard - Fetch Top 50 Gift Contributors Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves the top 50 viewers by gift contribution in the last seven days for a given streamer. Requires initializing the AcFunLive client with the streamer's UID. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } billboard, err := ac.GetBillboard(uid) if err != nil { log.Fatalf("获取礼物贡献榜失败: %v", err) } log.Printf("最近7日礼物贡献榜 (前50名):") for i, user := range billboard { log.Printf("%d. %s(%d) - 贡献: %s AC币", i+1, user.Nickname, user.UserID, user.DisplaySendAmount) } } ``` -------------------------------- ### Create AcFunLive Client Source: https://context7.com/orzogc/acfundanmu/llms.txt Initializes a new client instance for a specific streamer UID. Use options to configure authentication cookies or default to guest mode. ```go package main import ( "context" "log" "github.com/orzogc/acfundanmu" ) func main() { // 游客模式创建客户端,uid 为主播的 uid uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 获取直播源信息 streamInfo := ac.GetStreamInfo() log.Printf("直播标题: %s", streamInfo.Title) log.Printf("直播ID: %s", streamInfo.LiveID) for _, stream := range streamInfo.StreamList { log.Printf("直播源: %s (%s) - %s", stream.QualityName, stream.QualityType, stream.URL) } } ``` -------------------------------- ### NewAcFunLive - Create Live Client Source: https://context7.com/orzogc/acfundanmu/llms.txt Creates a new AcFunLive instance to connect to a specified streamer's live room. Options can be set using functional options to configure streamer UID, login cookies, and token information. If cookies are not provided, it operates in guest mode. ```APIDOC ## NewAcFunLive - Create Live Client ### Description Creates a new AcFunLive instance to connect to a specified streamer's live room. Options can be set using functional options to configure streamer UID, login cookies, and token information. If cookies are not provided, it operates in guest mode. ### Method Constructor ### Endpoint N/A (Library function) ### Parameters #### Functional Options - **SetLiverUID(uid int64)**: Sets the unique identifier of the streamer. - **SetCookies(cookies []*http.Cookie)**: Sets the cookies for authenticated access. - **SetToken(token string)**: Sets the authentication token. ### Request Example ```go package main import ( "context" "log" "github.com/orzogc/acfundanmu" ) func main() { // Guest mode client creation, uid is the streamer's uid uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("Failed to create client: %v", err) } // Get live stream information streamInfo := ac.GetStreamInfo() log.Printf("Live Title: %s", streamInfo.Title) log.Printf("Live ID: %s", streamInfo.LiveID) for _, stream := range streamInfo.StreamList { log.Printf("Stream Source: %s (%s) - %s", stream.QualityName, stream.QualityType, stream.URL) } } ``` ### Response #### Success Response (Client Instance) - **acfundanmu.AcFunLive**: An instance of the AcFunLive client. - **error**: An error if the client creation fails. ``` -------------------------------- ### Convert Danmaku to ASS Subtitle File Source: https://github.com/orzogc/acfundanmu/blob/master/README.md Converts danmaku from a live stream into an ASS subtitle file. Requires the anchor's UID to initialize. You need to specify subtitle configuration such as resolution and font size. The process runs in a goroutine and signals completion via a channel. ```go // uid 为主播的 uid ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Panicln(err) } ctx, cancel := context.WithCancel(context.Background()) deferr cancel() ch := ac.StartDanmu(ctx, false) ac.WriteASS(ctx, acfundanmu.SubConfig{ Title: "foo", PlayResX: 1280, // 直播录播视频的分辨率 PlayResY: 720, FontSize: 40, StartTime: time.Now().UnixNano()}, // 这里应该是开始录播的时间 "foo.ass", true) if err = <-ch; err != nil { log.Panicln(err) } else { log.Println("直播结束") } ``` -------------------------------- ### Fetch Online Viewer List Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves the top 50 viewers in the current live room. Requires a valid live ID obtained from the client instance. ```go package main import ( "log" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } liveID := ac.GetLiveID() watchingList, err := ac.GetWatchingList(liveID) if err != nil { log.Fatalf("获取在线观众列表失败: %v", err) } log.Printf("在线观众列表 (前50名):") for i, user := range watchingList { log.Printf("%d. %s(%d) - 贡献: %s, 匿名: %v, 房管: %v", i+1, user.Nickname, user.UserID, user.DisplaySendAmount, user.AnonymousUser, user.ManagerType == acfundanmu.NormalManager) } } ``` -------------------------------- ### Handle Live Events with Callbacks Source: https://context7.com/orzogc/acfundanmu/llms.txt Registers event handlers for various live stream activities such as comments, gifts, and room status updates. Use this pattern for asynchronous processing of incoming data. ```go package main import ( "context" "log" "time" "github.com/orzogc/acfundanmu" ) func main() { uid := int64(12345678) ac, err := acfundanmu.NewAcFunLive(acfundanmu.SetLiverUID(uid)) if err != nil { log.Fatalf("创建客户端失败: %v", err) } // 注册弹幕结束事件 ac.OnDanmuStop(func(ac *acfundanmu.AcFunLive, err error) { if err != nil { log.Printf("弹幕获取出错: %v", err) } else { log.Println("直播已结束") } }) // 注册评论事件 ac.OnComment(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Comment) { log.Printf("[评论] %s: %s", d.Nickname, d.Content) }) // 注册点赞事件 ac.OnLike(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Like) { log.Printf("[点赞] %s 点赞了", d.Nickname) }) // 注册进场事件 ac.OnEnterRoom(func(ac *acfundanmu.AcFunLive, d *acfundanmu.EnterRoom) { log.Printf("[进场] %s 进入直播间", d.Nickname) }) // 注册关注事件 ac.OnFollowAuthor(func(ac *acfundanmu.AcFunLive, d *acfundanmu.FollowAuthor) { log.Printf("[关注] %s 关注了主播", d.Nickname) }) // 注册礼物事件 ac.OnGift(func(ac *acfundanmu.AcFunLive, d *acfundanmu.Gift) { log.Printf("[礼物] %s 送出 %s x%d", d.Nickname, d.GiftName, d.Count*d.Combo) }) // 注册加入守护团事件 ac.OnJoinClub(func(ac *acfundanmu.AcFunLive, d *acfundanmu.JoinClub) { log.Printf("[守护] %s 加入了守护团", d.FansInfo.Nickname) }) // 注册分享直播间事件 ac.OnShareLive(func(ac *acfundanmu.AcFunLive, d *acfundanmu.ShareLive) { log.Printf("[分享] %s 分享了直播间", d.Nickname) }) // 注册直播间数据更新事件 ac.OnDisplayInfo(func(ac *acfundanmu.AcFunLive, d *acfundanmu.DisplayInfo) { log.Printf("[状态] 在线: %s, 点赞: %s", d.WatchingCount, d.LikeCount) }) // 注册礼物榜前三更新事件 ac.OnTopUsers(func(ac *acfundanmu.AcFunLive, users []acfundanmu.TopUser) { for i, user := range users { log.Printf("[榜单] 第%d名: %s - %s", i+1, user.Nickname, user.DisplaySendAmount) } }) // 注册红包列表事件 ac.OnRedpackList(func(ac *acfundanmu.AcFunLive, redpacks []acfundanmu.Redpack) { for _, rp := range redpacks { log.Printf("[红包] %s 发了 %d AC币红包", rp.Nickname, rp.RedpackAmount) } }) // 注册被踢出直播间事件 ac.OnKickedOut(func(ac *acfundanmu.AcFunLive, reason string) { log.Printf("[踢出] 被踢出直播间: %s", reason) }) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() // event 参数为 true 时使用事件响应模式 _ = ac.StartDanmu(ctx, true) // 在这里可以做其他事情,弹幕会通过回调函数异步处理 <-ctx.Done() } ``` -------------------------------- ### GetSummary - 获取直播总结信息 Source: https://context7.com/orzogc/acfundanmu/llms.txt Retrieves summary information for a completed live stream, including duration, likes, viewers, and revenue. ```APIDOC ## GetSummary /api/summary/{liveID} ### Description Retrieves summary information for a completed live stream. ### Method GET ### Endpoint /api/summary/{liveID} ### Parameters #### Path Parameters - **liveID** (string) - Required - The unique identifier of the live stream. ### Response #### Success Response (200) - **summary** (object) - An object containing the live stream summary. - **Duration** (integer) - The duration of the live stream in milliseconds. - **LikeCount** (string) - The total number of likes received. - **WatchCount** (string) - The total number of unique viewers. - **GiftCount** (integer) - The total number of gifts received. - **DiamondCount** (integer) - The total number of diamonds received. - **BananaCount** (integer) - The total number of bananas received. ### Response Example { "summary": { "Duration": 7200000, "LikeCount": "10000", "WatchCount": "5000", "GiftCount": 150, "DiamondCount": 15000, "BananaCount": 300 } } ```