Skip to content

Commit

Permalink
Merge pull request #453 from ywmoyue/dev
Browse files Browse the repository at this point in the history
4.6.24
  • Loading branch information
ywmoyue authored Dec 24, 2023
2 parents 0d4ea2a + 6dac57a commit b56bc90
Show file tree
Hide file tree
Showing 32 changed files with 697 additions and 178 deletions.
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<ItemGroup>
<Compile Include="Extensions\QrCodeExtensions.cs" />
<Compile Include="Models\Common\Anime\ISeasonItem.cs" />
<Compile Include="Models\Common\Live\DefaultPlayUrlSourceOptions.cs" />
<Compile Include="Models\Common\Live\InteractWordModel.cs" />
<Compile Include="Models\Common\Live\LiveMessageHandleActionsMap.cs" />
<Compile Include="Models\Common\Live\LiveRoomEndRedPocketLotteryInfoModel.cs" />
Expand Down Expand Up @@ -182,7 +183,9 @@
<Compile Include="Models\Common\Live\GiftMsgModel.cs" />
<Compile Include="Models\Common\Live\GuardBuyMsgModel.cs" />
<Compile Include="Models\Common\Live\RoomChangeMsgModel.cs" />
<Compile Include="Models\Common\User\SubmitCollectionItemModel.cs" />
<Compile Include="Models\Common\WbiKey.cs" />
<Compile Include="Models\Exceptions\CustomizedErrorWithDataException.cs" />
<Compile Include="Models\Exceptions\PlayerException.cs" />
<Compile Include="Models\Requests\Api\BaseApi.cs" />
<Compile Include="Player\Controllers\BasePlayerController.cs" />
Expand Down Expand Up @@ -352,6 +355,7 @@
<Compile Include="ViewModels\Season\SeasonDetailUserStatusViewModel.cs" />
<Compile Include="ViewModels\Comment\CommentContentViewModel.cs" />
<Compile Include="ViewModels\Season\SeasonDetailViewModel.cs" />
<Compile Include="ViewModels\User\UserSubmitCollectionViewModel.cs" />
<Compile Include="ViewModels\Video\DanmakuViewModel.cs" />
<Compile Include="ViewModels\Video\VideoDetailReqUserViewModel.cs" />
<Compile Include="ViewModels\Video\VideoDetailRelatesViewModel.cs" />
Expand Down Expand Up @@ -801,6 +805,7 @@
<Content Include="Assets\Live\ic_live_guard_2.png" />
<Content Include="Assets\Live\ic_live_guard_3.png" />
<Content Include="Assets\Live\lottery.png" />
<Content Include="Assets\Live\RedPocket.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Login\ic_22.png" />
<Content Include="Assets\Login\ic_22_hide.png" />
Expand Down
2 changes: 1 addition & 1 deletion src/BiliLite.UWP/Converters/ImageCompressionConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public object Convert(object value, Type targetType, object parameter, string la
return value;
}
if (parameter == null) return value;
return value.ToString() + "@" + parameter.ToString() + ".jpg";
return value.ToString() + "@" + parameter.ToString() + ".png";
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand Down
4 changes: 0 additions & 4 deletions src/BiliLite.UWP/Extensions/QrCodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ public static class QrCodeExtensions
{
public static IServiceCollection AddQrCodeService(this IServiceCollection services)
{
#if ARM64
services.AddTransient<IQrCodeService, QrCoderQrCodeService>();
#else
services.AddTransient<IQrCodeService, ZXingQrCodeService>();
#endif
return services;
}
}
Expand Down
75 changes: 34 additions & 41 deletions src/BiliLite.UWP/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Windows.Security.Cryptography;
using Windows.Storage.Streams;
using System.Threading.Tasks;
using System.Linq;

namespace BiliLite.Extensions
{
Expand Down Expand Up @@ -106,13 +107,13 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote, bool

//生成xaml
var xaml = string.Format(@"<RichTextBlock HorizontalAlignment=""Stretch"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc = ""http://schemas.openxmlformats.org/markup-compatibility/2006"" LineHeight=""{1}"" {2} {3}>
<Paragraph>{0}</Paragraph>
</RichTextBlock>", input,
isLive ? 22 : 20,
color == null ? "" : $"Foreground=\"{color}\"",
$"FontWeight=\"{fontWeight}\"");
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
xmlns:mc = ""http://schemas.openxmlformats.org/markup-compatibility/2006"" LineHeight=""{1}"" {2} {3}>
<Paragraph>{0}</Paragraph>
</RichTextBlock>", input,
isLive ? 22 : 20,
color == null ? "" : $"Foreground=\"{color}\"",
$"FontWeight=\"{fontWeight}\"");
var p = (RichTextBlock)XamlReader.Load(xaml);
return p;
}
Expand All @@ -128,14 +129,13 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote, bool
}
catch (Exception ex)
{
_logger.Error("富文本转换失败", ex);
_logger.Error($"富文本转换失败: {txt}", ex);
var tx = new RichTextBlock();
Paragraph paragraph = new Paragraph();
Run run = new Run() { Text = txt };
paragraph.Inlines.Add(run);
tx.Blocks.Add(paragraph);
return tx;

}
}

Expand Down Expand Up @@ -336,7 +336,7 @@ private static string HandelEmoji(string input, JObject emote)
var emoji = emote[item.Groups[0].Value];
input = input.Replace(item.Groups[0].Value,
string.Format(
@"<InlineUIContainer><Border Margin=""0 -4 4 -4""><Image Source=""{0}"" Width=""{1}"" Height=""{1}"" /></Border></InlineUIContainer>",
@"<InlineUIContainer><Border Margin=""2 0 2 -4""><Image Source=""{0}"" Width=""{1}"" Height=""{1}"" /></Border></InlineUIContainer>",
emoji["url"].ToString(), emoji["meta"]["size"].ToInt32() == 1 ? "20" : "36"));
}

Expand Down Expand Up @@ -373,48 +373,52 @@ private static string HandelVideoID(string input)
{
//处理AV号
List<string> keyword = new List<string>();
List<List<int>> haveHandledOffset = new List<List<int>>();
//如果是链接就不处理了
if (!Regex.IsMatch(input, @"/[aAbBcC][vV]([a-zA-Z0-9]+)"))
{
//处理AV号
MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)");
var offset = 0;
foreach (Match item in av)

//处理BV号
MatchCollection bv = Regex.Matches(input, @"[bB][vV]([a-zA-Z0-9]{8,})");
offset = 0;
foreach (Match item in bv)
{
if (keyword.Contains(item.Groups[0].Value))
if (keyword.Contains(item.Groups[0].Value) || haveHandledOffset.Where(index => (item.Index > index[0] && item.Index < index[1])).ToList().Count > 0)
{
continue;
}

keyword.Add(item.Groups[0].Value);
var data =
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""0 -4 0 -4"" Padding=""0"" " +
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""2 -3 2 -5"" Padding=""0 2 0 0"" " +
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
@" CommandParameter=""{1}"" ><TextBlock>🎞️{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
haveHandledOffset.Add(new List<int> { item.Index + offset, item.Index + offset + data.Length });
offset += data.Length - item.Length;
}

//处理BV号
MatchCollection bv = Regex.Matches(input, @"[bB][vV]([a-zA-Z0-9]{8,})");
offset = 0;
foreach (Match item in bv)
//处理AV号
MatchCollection av = Regex.Matches(input, @"[aA][vV](\d+)");
foreach (Match item in av)
{
if (keyword.Contains(item.Groups[0].Value))
if (keyword.Contains(item.Groups[0].Value) || haveHandledOffset.Where(index => (item.Index > index[0] && item.Index < index[1])).ToList().Count > 0)
{
continue;
}

keyword.Add(item.Groups[0].Value);
var data =
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""0 -4 0 -4"" Padding=""0"" " +
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""2 -3 2 -5"" Padding=""0 2 0 0"" " +
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
@" CommandParameter=""{1}"" ><TextBlock>🎞️{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://video/" + item.Groups[0].Value);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
haveHandledOffset.Add(new List<int> { item.Index + offset, item.Index + offset + data.Length });
offset += data.Length - item.Length;
}

Expand All @@ -423,19 +427,20 @@ private static string HandelVideoID(string input)
offset = 0;
foreach (Match item in cv)
{
if (keyword.Contains(item.Groups[0].Value))
if (keyword.Contains(item.Groups[0].Value) || haveHandledOffset.Where(index => (item.Index > index[0] && item.Index < index[1])).ToList().Count > 0)
{
continue;
}

keyword.Add(item.Groups[0].Value);
var data =
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""0 -4 0 -4"" Padding=""0"" " +
@"<InlineUIContainer><HyperlinkButton Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""2 -3 2 -5"" Padding=""0 2 0 0"" " +
string.Format(
@" CommandParameter=""{1}"" ><TextBlock>{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
@" CommandParameter=""{1}"" ><TextBlock>📝{0}</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value, "bilibili://article/" + item.Groups[1].Value);
input = input.Remove(item.Index + offset, item.Length);
input = input.Insert(item.Index + offset, data);
haveHandledOffset.Add(new List<int> { item.Index + offset, item.Index + offset + data.Length });
offset += data.Length - item.Length;
}
}
Expand All @@ -452,7 +457,6 @@ private static string HandelVideoID(string input)
/// <returns></returns>
private static string HandelUrl(string input)
{
//处理AV号
List<string> keyword = new List<string>();
MatchCollection url = Regex.Matches(input,
@"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
Expand All @@ -465,25 +469,14 @@ private static string HandelUrl(string input)

keyword.Add(item.Groups[0].Value);
var data =
@"<InlineUIContainer><HyperlinkButton x:Name=""btn"" Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""0 -4 0 -4"" Padding=""0"" " +
@"<InlineUIContainer><HyperlinkButton x:Name=""btn"" Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""2 -3 2 -5"" Padding=""0 2 0 0"" " +
string.Format(
@" CommandParameter=""{0}"" ><TextBlock>🔗网页链接</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value);
@"CommandParameter=""{0}"" ><TextBlock>🔗网页链接</TextBlock></HyperlinkButton></InlineUIContainer>",
item.Groups[0].Value.IsUrl() ? item.Groups[0].Value : ApiHelper.NOT_FOUND_URL);
input = input.Replace(item.Groups[0].Value, data);
}


return input;

//MatchCollection url = Regex.Matches(input, @"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
//foreach (Match item in url)
//{
// var data = @"<InlineUIContainer><HyperlinkButton x:Name=""btn"" Command=""{Binding LaunchUrlCommand}"" IsEnabled=""True"" Margin=""0 -4 0 -4"" Padding=""0"" " + string.Format(@" Tag=""{0}"" CommandParameter=""{0}"" >{0}</HyperlinkButton></InlineUIContainer>", item.Groups[0].Value);
// input = input.Replace(item.Groups[0].Value, data);
//}


//return input;
}

#endregion
Expand Down
1 change: 1 addition & 0 deletions src/BiliLite.UWP/Extensions/ViewModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static IServiceCollection AddViewModels(this IServiceCollection services)
services.AddTransient<DownloadDialogViewModel>();
services.AddTransient<CommentControlViewModel>();
services.AddTransient<UserSubmitVideoViewModel>();
services.AddTransient<UserSubmitCollectionViewModel>();
services.AddTransient<RecommendPageViewModel>();
services.AddTransient<DynamicPageViewModel>();
services.AddTransient<AnimePageViewModel>();
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 @@ -395,5 +395,10 @@ public enum MessageType
/// 红包抽奖赢家
/// </summary>
RedPocketLotteryWinner,

/// <summary>
/// 高能榜变动
/// </summary>
OnlineRankChange,
}
}
21 changes: 21 additions & 0 deletions src/BiliLite.UWP/Models/Common/Live/DefaultPlayUrlSourceOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace BiliLite.Models.Common.Live
{
public static class DefaultPlayUrlSourceOptions
{
public static LivePlayUrlSourceOption[] DefaultLivePlayUrlSourceOption = new LivePlayUrlSourceOption[]
{
new LivePlayUrlSourceOption() { Name = "京东云MCDN(PCDN?)", Value = "mcdn" },
new LivePlayUrlSourceOption() { Name = "B站自建地区CDN", Value = "cn-"},
new LivePlayUrlSourceOption() { Name = "备用及第三方CDN", Value = "-gotcha"},
};

public const string DEFAULT_PLAY_URL_SOURCE = "cn-"; //默认使用B站自建CDN
}

public class LivePlayUrlSourceOption
{
public string Name { get; set; }

public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public LiveMessageHandleActionsMap()
{ MessageType.WatchedChange, WatchedChange },
{ MessageType.RedPocketLotteryStart, RedPocketLotteryStart},
{ MessageType.RedPocketLotteryWinner, RedPocketLotteryWinner},
{ MessageType.OnlineRankChange, OnlineRankChange},
};
}

Expand Down Expand Up @@ -140,7 +141,6 @@ private void AnchorLotteryStart(LiveRoomViewModel viewModel, object message)
if (!viewModel.ReceiveLotteryMsg) return;
var info = message.ToString();
viewModel.LotteryViewModel.SetAnchorLotteryInfo(JsonConvert.DeserializeObject<LiveRoomAnchorLotteryInfoModel>(info));

}

private void RedPocketLotteryStart(LiveRoomViewModel viewModel, object message)
Expand Down Expand Up @@ -211,7 +211,7 @@ private void WaringOrCutOff(LiveRoomViewModel viewModel, object message)
{
UserName = info.Command switch
{
"WARNING" => "⛔直播间警告",
"WARNING" => "⚠️直播间警告",
"CUT_OFF" => "⛔直播间切断",
_ => null,
},
Expand All @@ -225,12 +225,17 @@ private void WaringOrCutOff(LiveRoomViewModel viewModel, object message)

private async void StartLive(LiveRoomViewModel viewModel, object room_Id)
{
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(3)); // 挂起三秒再获取, 否则很大可能一直卡加载而不缓冲
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5)); // 挂起五秒再获取, 否则很大可能一直卡加载而不缓冲
viewModel.GetPlayUrls(room_Id.ToInt32(), SettingService.GetValue(SettingConstants.Live.DEFAULT_QUALITY, 10000)).RunWithoutAwait();
viewModel.Messages.Add(new DanmuMsgModel()
{
UserName = $"{room_Id} 直播间开始直播",
});
}

private void OnlineRankChange(LiveRoomViewModel viewModel, object message)
{
viewModel.Ranks.Where(rank => rank.RankType == "contribution-rank").ToList()?[0]?.ReloadData().RunWithoutAwait();
}
}
}
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Models/Common/SettingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ public class Live
/// 隐藏抽奖
/// </summary>
public const string HIDE_LOTTERY = "LiveHideLottery";

/// <summary>
/// 直播流默认源
/// </summary>
public const string DEFAULT_LIVE_PLAY_URL_SOURCE = "DefaultLivePlayUrlSource";
}

public class Player
Expand Down
59 changes: 59 additions & 0 deletions src/BiliLite.UWP/Models/Common/User/SubmitCollectionItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json;

namespace BiliLite.Models.Common.User
{
public class SubmitCollectionItemModel
{
/// <summary>
/// 本合集的视频数量
/// </summary>
public int Count { get; set; }

/// <summary>
/// 本合集的封面
/// </summary>
public string Cover { get; set; }

/// <summary>
/// 跳转格式? 常见值: av
/// </summary>
public string Goto { get; set; }

/// <summary>
/// 可能是收费视频合集?
/// </summary>
[JsonProperty("is_pay")]
public bool IsPay { get; set; }

/// <summary>
/// 合集最后更新时间戳
/// </summary>
[JsonProperty("mtime")]
public int LatestUpdateTime { get; set; }

/// <summary>
/// 未知参数
/// 对于直播回放列表为其纯数字列表id.
/// </summary>
public string Param { get; set; }

/// <summary>
/// 合集标题
/// </summary>
public string Title { get; set; }

/// <summary>
/// 合集类型
/// 目前发现用户自己创建的为season, 直播回放列表为series
/// </summary>
public string Type { get; set; }

/// <summary>
/// 跳转链接
/// 以bilibili://开头.
/// 对于直播回放, 其特别的, 为: bilibili://music/playlist/playpage/{Id}
/// Id可能为合集的纯数字id.
/// </summary>
public string Uri { get; set; }
}
}
Loading

0 comments on commit b56bc90

Please sign in to comment.