Skip to content

Commit

Permalink
圣诞更新(直播间优化) (#959)
Browse files Browse the repository at this point in the history
- **加入了当前房间在线人数显示**
  由于b站信息流的特性,现在可以与之前的看过人数轮换显示于粉丝数旁
- **加入全屏/大屏幕模式下的弹幕输入框**
- **支持发送表情,包括可混杂于普通文本中的黄豆表情与单独发送的大表情**
- **直播间加载速度优化,优先加载视频流和弹幕流**
- **解决之前的有新舰长但PivotHeader上的舰长数不更新的问题**
- **一些其他的外观与Typo优化**

fix #949
  • Loading branch information
GD-Slime authored Dec 26, 2024
1 parent ca0a13f commit 8b12aa1
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<Compile Include="Models\Common\Comment\HotReply.cs" />
<Compile Include="Models\Common\Danmaku\BiliDanmakuItem.cs" />
<Compile Include="Models\Common\Dynamic\DynamicUgcSeasonCardModel.cs" />
<Compile Include="Models\Common\Live\LiveRoomEmoticon.cs" />
<Compile Include="Models\Common\MarkdownViewerPagerParameter.cs" />
<Compile Include="Models\Common\Player\RealPlayerType.cs" />
<Compile Include="Models\Common\Player\PlaySpeedMenu.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/BiliLite.UWP/Extensions/TimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public static long GetTimestampS()
}

/// <summary>
/// 生成时间戳/豪秒
/// 生成时间戳/毫秒
/// </summary>
/// <returns></returns>
public static long GetTimestampMS()
public static long GetTimestampMs()
{
return Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 8, 0, 0, 0)).TotalMilliseconds);
}
Expand Down
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Models/Common/Enumerates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ public enum MessageType
/// 直播间等级禁言
/// </summary>
ChatLevelMute,

/// <summary>
/// 直播间观看人数变动
/// </summary>
OnlineCountChange,
}

public enum MessageDelayType {
Expand Down
12 changes: 10 additions & 2 deletions src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public LiveMessageHandleActionsMap()
{ MessageType.OnlineRankChange, OnlineRankChange },
{ MessageType.StopLive, StopLive },
{ MessageType.ChatLevelMute, ChatLevelMute },
{ MessageType.OnlineCountChange, OnlineCountChange }
};
}

Expand Down Expand Up @@ -71,7 +72,12 @@ private void ConnectSuccess(LiveRoomViewModel viewModel, object message)

private void WatchedChange(LiveRoomViewModel viewModel, object message)
{
viewModel.WatchedNum = (string)message;
viewModel.ViewerNumCount = (string)message;
}

private void OnlineCountChange(LiveRoomViewModel viewModel, object message)
{
viewModel.ViewerNumCount = (string)message + "人在看";
}

private void Danmu(LiveRoomViewModel viewModel, object message)
Expand Down Expand Up @@ -251,7 +257,7 @@ private void GuardBuyNew(LiveRoomViewModel viewModel, object message)
if (match.Success) accompanyDays = match.Groups[1].Value.ToInt32();

var text = info.UserName +
(isNewGuard ? "\n新开通了" : "\n续费了") +
(isNewGuard ? "\n开通了" : "\n续费了") +
$"主播的{info.GiftName}" +
(info.Num > 1 ? ${info.Num}{info.Unit}" : "") +
"🎉" +
Expand All @@ -268,6 +274,8 @@ private void GuardBuyNew(LiveRoomViewModel viewModel, object message)

viewModel.Messages.Add(msg);
if (isNewGuard) viewModel.ReloadGuardList().RunWithoutAwait();

if (info.UserID == SettingService.Account.UserID.ToString()) viewModel.GetEmoticons().RunWithoutAwait(); // 自己开通了舰长, 有些表情即可解锁
}

private void RoomChange(LiveRoomViewModel viewModel, object message)
Expand Down
99 changes: 99 additions & 0 deletions src/BiliLite.UWP/Models/Common/Live/LiveRoomEmoticon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace BiliLite.Models.Common.Live
{
public class LiveRoomEmoticonPackage
{
[JsonProperty("pkg_id")]
public int Id { get; set; }

[JsonProperty("pkg_name")]
public string Name { get; set; }

/// <summary>
/// 表情包类型
/// 已知:3为黄豆表情包, 2为房间表情包,5为全站表情包
/// </summary>
[JsonProperty("pkg_type")]
public int Type { get; set; }

/// <summary>
/// 表情包封面图
/// </summary>
[JsonProperty("current_cover")]
public string Cover { get; set; }

[JsonProperty("unlock_identity")]
public int UnlockIdentity { get; set; }

[JsonProperty("unlock_need_gift")]
public int UnlockNeedGift { get; set; }

[JsonProperty("emoticons")]
public ObservableCollection<LiveRoomEmoticon> Emoticons { get; set; }
}

public class LiveRoomEmoticon
{
[JsonProperty("bulge_display")]
public int BulgeDisplay { get; set; }

[JsonProperty("width")]
public int Width { get; set; }

/// <summary>
/// 是否为大表情
/// </summary>
public bool IsBigSticker => Width > 0;

[JsonProperty("emoticon_id")]
public int Id { get; set; }

/// <summary>
/// 表情包ID, 似乎可以唯一标识一个表情
/// </summary>
[JsonProperty("emoticon_unique")]
public string Unique { get; set; }

[JsonProperty("descript")]
public string Descript { get; set; }

[JsonProperty("url")]
public string Url { get; set; }

/// <summary>
/// 表情文本, 用于显示至弹幕
/// </summary>
[JsonProperty("emoji")]
public string Text { get; set; }

/// <summary>
/// 表情文本 + 解锁需要条件(如有)
/// </summary>
public string ShowText => Text + (UnlockShowText.Length > 0 ? "\n[" + UnlockShowText + "]" : "");

/// <summary>
/// 0: 未解锁, 1: 已解锁
/// </summary>
[JsonProperty("perm")]
public int Perm { get; set; }

/// <summary>
/// 显示的图片透明度, 未解锁为0.5
/// </summary>
public double Opacity => Perm == 0 ? 0.5 : 1.0;

/// <summary>
/// 是否显示上锁图标
/// </summary>
public bool LockIconVisibility => Perm == 0;

/// <summary>
/// 解锁需要的条件
/// </summary>
[JsonProperty("unlock_show_text")]
public string UnlockShowText { get; set; }
}
}
53 changes: 50 additions & 3 deletions src/BiliLite.UWP/Models/Requests/Api/Live/LiveRoomAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using BiliLite.Models.Common;
using BiliLite.Models.Common.Live;
using Newtonsoft.Json;

namespace BiliLite.Models.Requests.Api.Live
{
Expand Down Expand Up @@ -156,7 +158,7 @@ public ApiModel SendBagGift(long ruid, int giftId, int num, int bagId, int roomI
body = ApiHelper.MustParameter(AppKey, true) + $"&actionKey=appkey",
need_cookie = true,
};
api.body += $"&biz_code=live&biz_id={roomId}&gift_id={giftId}&gift_num={num}&price=0&bag_id={bagId}&rnd={TimeExtensions.GetTimestampMS()}&ruid={ruid}&uid={SettingService.Account.UserID}";
api.body += $"&biz_code=live&biz_id={roomId}&gift_id={giftId}&gift_num={num}&price=0&bag_id={bagId}&rnd={TimeExtensions.GetTimestampMs()}&ruid={ruid}&uid={SettingService.Account.UserID}";
api.body += ApiHelper.GetSign(api.body, AppKey);
return api;
}
Expand All @@ -174,7 +176,7 @@ public ApiModel SendGift(long ruid, int giftId, string coinType, int num, int ro
body = ApiHelper.MustParameter(AppKey, true) + $"&actionKey=appkey",
need_cookie = true,
};
api.body += $"&biz_code=live&biz_id={roomId}&gift_id={giftId}&gift_num={num}&price={price}&rnd={TimeExtensions.GetTimestampMS()}&ruid={ruid}&uid={SettingService.Account.UserID}";
api.body += $"&biz_code=live&biz_id={roomId}&gift_id={giftId}&gift_num={num}&price={price}&rnd={TimeExtensions.GetTimestampMs()}&ruid={ruid}&uid={SettingService.Account.UserID}";
api.body += ApiHelper.GetSign(api.body, AppKey);

return api;
Expand All @@ -192,7 +194,35 @@ public ApiModel SendDanmu(string text, int roomId)
baseUrl = $"https://api.live.bilibili.com/api/sendmsg",
parameter = ApiHelper.MustParameter(AppKey, true) + $"&actionKey=appkey",
};
api.body = $"cid={roomId}&mid={SettingService.Account.UserID}&msg={Uri.EscapeDataString(text)}&rnd={TimeExtensions.GetTimestampMS()}&mode=1&pool=0&type=json&color=16777215&fontsize=25&playTime=0.0";
api.body = $"cid={roomId}&mid={SettingService.Account.UserID}&msg={Uri.EscapeDataString(text)}&rnd={TimeExtensions.GetTimestampMs()}&mode=1&pool=0&type=json&color=16777215&fontsize=25&playTime=0.0";
api.parameter += ApiHelper.GetSign(api.body, AppKey);
return api;
}

/// <summary>
/// ios端使用的发送弹幕api
/// 更加高级, 可用于发送大表情等
/// </summary>
/// <param name="roomId">直播间号</param>
/// <param name="emoji">表情信息</param>
/// <returns></returns>
public ApiModel SendDanmu(int roomId, LiveRoomEmoticon emoji)
{
var jsonObj = new
{
content = $"{emoji.Text}",
emoticon_unique = $"{emoji.Unique}",
dm_type = 1,
};
var extra = JsonConvert.SerializeObject(jsonObj);

var api = new ApiModel
{
method = HttpMethods.Post,
baseUrl = $"https://api.live.bilibili.com/xlive/app-room/v1/dM/sendmsg",
parameter = ApiHelper.MustParameter(AppKey, true) + $"&actionKey=appkey",
body = $"msg={emoji.Unique}&dm_type=1&extra={extra}&cid={roomId}&mid={SettingService.Account.UserID}&ts={TimeExtensions.GetTimestampS()}&rnd={TimeExtensions.GetTimestampMs()}&mode=1&pool=0&type=json&color=16777215&fontsize=25"
};
api.parameter += ApiHelper.GetSign(api.body, AppKey);
return api;
}
Expand Down Expand Up @@ -400,5 +430,22 @@ public ApiModel JoinRedPocketLottery(long uid, int room_id, long ruid, int lot_i
};
return api;
}

/// <summary>
/// 获取直播间表情
/// </summary>
/// <param name="room_id">房间号</param>
/// <returns></returns>
public ApiModel GetLiveRoomEmoticon(int room_id)
{
var api = new ApiModel()
{
method = HttpMethods.Get,
baseUrl = $"https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons",
parameter = ApiHelper.MustParameter(AppKey, true) + $"&actionKey=appkey&room_id={room_id}",
};
api.parameter += ApiHelper.GetSign(api.parameter, AppKey);
return api;
}
}
}
9 changes: 8 additions & 1 deletion src/BiliLite.UWP/Modules/Live/LiveMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private MessageDelayType ParseMessage(string jsonMessage)
w.UserID = obj["data"]["uid"].ToString();
w.MsgType = obj["data"]["msg_type"].ToInt32();

if (obj["data"]["fans_medal"]["medal_level"].ToInt32() != 0)
if (obj["data"]["fans_medal"].ToString().Length != 0 && obj["data"]["fans_medal"]["medal_level"].ToInt32() != 0)
{
w.MedalName = obj["data"]["fans_medal"]["medal_name"].ToString();
w.MedalLevel = obj["data"]["fans_medal"]["medal_level"].ToInt32();
Expand Down Expand Up @@ -502,6 +502,13 @@ private MessageDelayType ParseMessage(string jsonMessage)
}
return MessageDelayType.SystemMessage;
}
else if (cmd == "ONLINE_RANK_COUNT") // 在线人数变动, 即网页端的"房间观众()括号中的数字"
{
if (obj["data"] != null)
{
NewMessage?.Invoke(MessageType.OnlineCountChange, obj["data"]["online_count_text"].ToString());
}
}
else if (cmd == "ONLINE_RANK_V2")
{
if (obj["data"] != null && obj["data"]["list"] != null)
Expand Down
Loading

0 comments on commit 8b12aa1

Please sign in to comment.