From 8ad468758b402a46d6fe57070e50ae495a1da85d Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:26:54 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BB=A5=E5=8F=8A=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=B5=81=E9=80=89=E6=8B=A9=20(#430)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复天选时刻错误的展示发送弹幕按钮和中奖名单的问题 - 修复新一轮天选时刻/人气红包开始时倒计时展示的问题 - 修复人气红包图片没有正确的被加入csproj的问题 - 更改了一下金银瓜子的显示位置 - 新增默认直播流选择 --- src/BiliLite.UWP/BiliLite.UWP.csproj | 2 + .../Live/DefaultPlayUrlSourceOptions.cs | 21 +++++++++++ .../Live/LiveMessageHandleActionsMap.cs | 3 +- .../Models/Common/SettingConstants.cs | 5 +++ src/BiliLite.UWP/Pages/LiveDetailPage.xaml | 36 ++++++++++++------ src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs | 37 ++++++++++++++++--- .../Live/LiveDetailPageViewModel.cs | 2 + .../Live/LiveRoomLotteryViewModel.cs | 3 ++ 8 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 src/BiliLite.UWP/Models/Common/Live/DefaultPlayUrlSourceOptions.cs diff --git a/src/BiliLite.UWP/BiliLite.UWP.csproj b/src/BiliLite.UWP/BiliLite.UWP.csproj index 3034457ae..0620f5554 100644 --- a/src/BiliLite.UWP/BiliLite.UWP.csproj +++ b/src/BiliLite.UWP/BiliLite.UWP.csproj @@ -138,6 +138,7 @@ + @@ -801,6 +802,7 @@ + diff --git a/src/BiliLite.UWP/Models/Common/Live/DefaultPlayUrlSourceOptions.cs b/src/BiliLite.UWP/Models/Common/Live/DefaultPlayUrlSourceOptions.cs new file mode 100644 index 000000000..e6a08b139 --- /dev/null +++ b/src/BiliLite.UWP/Models/Common/Live/DefaultPlayUrlSourceOptions.cs @@ -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; } + } +} diff --git a/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs b/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs index b765667dc..35d274c09 100644 --- a/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs +++ b/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs @@ -140,7 +140,6 @@ private void AnchorLotteryStart(LiveRoomViewModel viewModel, object message) if (!viewModel.ReceiveLotteryMsg) return; var info = message.ToString(); viewModel.LotteryViewModel.SetAnchorLotteryInfo(JsonConvert.DeserializeObject(info)); - } private void RedPocketLotteryStart(LiveRoomViewModel viewModel, object message) @@ -225,7 +224,7 @@ 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() { diff --git a/src/BiliLite.UWP/Models/Common/SettingConstants.cs b/src/BiliLite.UWP/Models/Common/SettingConstants.cs index d94eab02f..236d41560 100644 --- a/src/BiliLite.UWP/Models/Common/SettingConstants.cs +++ b/src/BiliLite.UWP/Models/Common/SettingConstants.cs @@ -343,6 +343,11 @@ public class Live /// 隐藏抽奖 /// public const string HIDE_LOTTERY = "LiveHideLottery"; + + /// + /// 直播流默认源 + /// + public const string DEFAULT_LIVE_PLAY_URL_SOURCE = "DefaultLivePlayUrlSource"; } public class Player diff --git a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml index c0edd2ab5..b36e9b849 100644 --- a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml +++ b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml @@ -433,14 +433,28 @@ - 播放器默认模式 - - + + 播放器默认模式 + + + + + 直播流默认来源 + + + @@ -750,7 +764,7 @@ 弹幕口令: 赠送礼物:x 限制条件:--> - + @@ -848,7 +862,7 @@ - + @@ -856,7 +870,7 @@ - + diff --git a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs index 4b6e26dcf..304a14720 100644 --- a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs @@ -132,10 +132,7 @@ private void Timer_focus_Tick(object sender, object e) private void LiveRoomViewModelAnchorLotteryStart(object sender, LiveRoomAnchorLotteryInfoModel e) { AnchorLotteryWinnerList.Content = e.WinnerList; - if (e.WinnerList.Children.Count != 0) - { - m_liveRoomViewModel.ShowAnchorLotteryWinnerList = true; - } + m_liveRoomViewModel.ShowAnchorLotteryWinnerList = e.AwardUsers.Count > 0; } private void LiveRoomViewModelAnchorLotteryEnd(object sender, LiveRoomEndAnchorLotteryInfoModel e) @@ -373,8 +370,24 @@ private void LiveRoomViewModelChangedPlayUrl(object sender, EventArgs e) m_realPlayInfo.PlayUrls.HlsUrls = m_liveRoomViewModel.HlsUrls; m_realPlayInfo.PlayUrls.FlvUrls = m_liveRoomViewModel.FlvUrls; - BottomCBLine.ItemsSource = m_liveRoomViewModel.HlsUrls ?? m_liveRoomViewModel.FlvUrls; - BottomCBLine.SelectedIndex = 0; + var urls = m_liveRoomViewModel.HlsUrls ?? m_liveRoomViewModel.FlvUrls; + BottomCBLine.ItemsSource = urls; + + var flag = false; + for (var i = 0; i < urls.Count; i++) + { + var domain = new Uri(urls[i].Url).Host; + + if (domain.Contains(m_viewModel.LivePlayUrlSource) && !flag) { + BottomCBLine.SelectedIndex = i; + flag = true; + } + } + if (!flag) + { + BottomCBLine.SelectedIndex = 0; + } + BottomCBQuality.SelectedItem = m_liveRoomViewModel.CurrentQn; changePlayUrlFlag = false; } @@ -511,6 +524,11 @@ private void PreLoadSetting() SettingConstants.Player.DEFAULT_LIVE_PLAYER_MODE, (int)DefaultPlayerModeOptions.DEFAULT_LIVE_PLAYER_MODE); m_playerConfig.PlayMode = m_viewModel.LivePlayerMode; + + // 直播流默认源 + m_viewModel.LivePlayUrlSource = SettingService.GetValue( + SettingConstants.Live.DEFAULT_LIVE_PLAY_URL_SOURCE, + DefaultPlayUrlSourceOptions.DEFAULT_PLAY_URL_SOURCE); } private void LoadSetting() @@ -1205,5 +1223,12 @@ private async void PlayerModeComboBox_OnSelectionChanged(object sender, Selectio m_playerConfig.PlayMode = m_viewModel.LivePlayerMode; await LoadPlayer(); } + + private async void PlayUrlSourceComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + SettingService.SetValue(SettingConstants.Live.DEFAULT_LIVE_PLAY_URL_SOURCE, m_viewModel.LivePlayUrlSource); + LiveRoomViewModelChangedPlayUrl(null, null); + await LoadPlayer(); + } } } diff --git a/src/BiliLite.UWP/ViewModels/Live/LiveDetailPageViewModel.cs b/src/BiliLite.UWP/ViewModels/Live/LiveDetailPageViewModel.cs index 53403f424..632aec9bc 100644 --- a/src/BiliLite.UWP/ViewModels/Live/LiveDetailPageViewModel.cs +++ b/src/BiliLite.UWP/ViewModels/Live/LiveDetailPageViewModel.cs @@ -78,5 +78,7 @@ public string LoadText : new Thickness(0); public LivePlayerMode LivePlayerMode { get; set; } + + public string LivePlayUrlSource { get; set; } } } diff --git a/src/BiliLite.UWP/ViewModels/Live/LiveRoomLotteryViewModel.cs b/src/BiliLite.UWP/ViewModels/Live/LiveRoomLotteryViewModel.cs index 0d3e9150e..641b00dd7 100644 --- a/src/BiliLite.UWP/ViewModels/Live/LiveRoomLotteryViewModel.cs +++ b/src/BiliLite.UWP/ViewModels/Live/LiveRoomLotteryViewModel.cs @@ -83,6 +83,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch AnchorLotteryTimer.Stop(); AnchorLotteryShow = false; AnchorLotteryInfo = null; + AnchorLotteryDownTime = "--:--"; return; } @@ -116,6 +117,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch RedPocketLotteryInfo = null; RedPocketLotteryTimer.Stop(); RedPocketLotteryShow = false; + RedPocketLotteryDownTime = "--:--"; return; } @@ -175,6 +177,7 @@ public async Task LoadLotteryInfo(int roomId) public void SetAnchorLotteryInfo(LiveRoomAnchorLotteryInfoModel info) { AnchorLotteryInfo = info; + AnchorLotteryStart?.Invoke(this, AnchorLotteryInfo); AnchorLotteryShow = true; AnchorLotteryTimer.Start(); } From 81536ef7dbf9dbaeba13b16933ad7d80620d409d Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sat, 16 Dec 2023 15:30:17 +0800 Subject: [PATCH 02/11] =?UTF-8?q?x64=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=94=B9=E7=94=A8QrCoder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Extensions/QrCodeExtensions.cs | 4 ---- src/BiliLite.UWP/Services/QrCoderQrCodeService.cs | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BiliLite.UWP/Extensions/QrCodeExtensions.cs b/src/BiliLite.UWP/Extensions/QrCodeExtensions.cs index dab41dd3b..bd927f86e 100644 --- a/src/BiliLite.UWP/Extensions/QrCodeExtensions.cs +++ b/src/BiliLite.UWP/Extensions/QrCodeExtensions.cs @@ -8,11 +8,7 @@ public static class QrCodeExtensions { public static IServiceCollection AddQrCodeService(this IServiceCollection services) { -#if ARM64 services.AddTransient(); -#else - services.AddTransient(); -#endif return services; } } diff --git a/src/BiliLite.UWP/Services/QrCoderQrCodeService.cs b/src/BiliLite.UWP/Services/QrCoderQrCodeService.cs index 57c0ea371..d3e0c739b 100644 --- a/src/BiliLite.UWP/Services/QrCoderQrCodeService.cs +++ b/src/BiliLite.UWP/Services/QrCoderQrCodeService.cs @@ -10,8 +10,12 @@ namespace BiliLite.Services { public class QrCoderQrCodeService : IQrCodeService { + private static readonly ILogger _logger = GlobalLogger.FromCurrentType(); + public async Task GenerateQrCode(string content, int size = 200) { + size /= 10; + _logger.Info($"[QrCoder]生成二维码:{content}"); var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); From 2949f93f0c4dec32ed9ff6d1e259ca1b16d24ab8 Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:20:56 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E4=B8=8D=E6=98=BE=E7=A4=BA=E6=97=A0=E7=B2=89=E4=B8=9D?= =?UTF-8?q?=E5=8B=8B=E7=AB=A0=E7=9A=84=E5=BC=B9=E5=B9=95=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#435)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Modules/Live/LiveMessage.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BiliLite.UWP/Modules/Live/LiveMessage.cs b/src/BiliLite.UWP/Modules/Live/LiveMessage.cs index afe98119d..450a5c1b6 100644 --- a/src/BiliLite.UWP/Modules/Live/LiveMessage.cs +++ b/src/BiliLite.UWP/Modules/Live/LiveMessage.cs @@ -220,7 +220,8 @@ private void ParseMessage(string jsonMessage) } // 是否为舰长 - if (obj["info"][3][10] != null && Convert.ToInt32(obj["info"][3][10].ToString()) != 0) + if (obj["info"][3] != null && obj["info"][3].ToArray().Length != 0 && + obj["info"][3][10] != null && Convert.ToInt32(obj["info"][3][10].ToString()) != 0) { switch (Convert.ToInt32(obj["info"][3][10].ToString())) { From e90ffd1851fbbdfbb58c3397e2af4cd5b2c097f7 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Tue, 19 Dec 2023 20:23:31 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=9A=84=E6=8A=BD?= =?UTF-8?q?=E5=A5=96=E9=A1=B5=E9=9D=A2=E6=94=B9=E7=94=A8webView2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Pages/WebPage.xaml.cs | 4 +-- .../UserDynamic/UserDynamicViewModel.cs | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/BiliLite.UWP/Pages/WebPage.xaml.cs b/src/BiliLite.UWP/Pages/WebPage.xaml.cs index b7d004906..ec3538fbf 100644 --- a/src/BiliLite.UWP/Pages/WebPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/WebPage.xaml.cs @@ -90,7 +90,6 @@ protected override async void OnNavigatedTo(NavigationEventArgs e) } } webView.Source=new Uri(uri); - } private async Task InitWebView2() @@ -141,7 +140,8 @@ private async void btnOpenBrowser_Click(object sender, RoutedEventArgs e) await Windows.System.Launcher.LaunchUriAsync(webView.Source); } - private async void webView_UnsupportedUriSchemeIdentified(WebView sender, WebViewUnsupportedUriSchemeIdentifiedEventArgs args) + // webview2中没找到代替的api,暂时不用 + private async void webView_UnsupportedUriSchemeIdentified(object sender, WebViewUnsupportedUriSchemeIdentifiedEventArgs args) { if (args.Uri.AbsoluteUri.Contains("article")) { diff --git a/src/BiliLite.UWP/ViewModels/UserDynamic/UserDynamicViewModel.cs b/src/BiliLite.UWP/ViewModels/UserDynamic/UserDynamicViewModel.cs index adc65c9d9..60ab54e38 100644 --- a/src/BiliLite.UWP/ViewModels/UserDynamic/UserDynamicViewModel.cs +++ b/src/BiliLite.UWP/ViewModels/UserDynamic/UserDynamicViewModel.cs @@ -9,7 +9,6 @@ using Windows.UI.Xaml.Controls; using AutoMapper; using Bilibili.App.Dynamic.V2; -using BiliLite.Controls.Dynamic; using BiliLite.Dialogs; using BiliLite.Extensions; using BiliLite.Models; @@ -27,9 +26,9 @@ using BiliLite.Services; using BiliLite.ViewModels.Common; using Microsoft.Extensions.DependencyInjection; +using Microsoft.UI.Xaml.Controls; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using static BiliLite.Models.Requests.Api.User.DynamicAPI; using DynamicItemDataTemplateSelector = BiliLite.Controls.DataTemplateSelectors.DynamicItemDataTemplateSelector; using DynamicType = BiliLite.Models.Common.DynamicType; @@ -45,6 +44,7 @@ public class UserDynamicViewModel : BaseViewModel private static readonly ILogger _logger = GlobalLogger.FromCurrentType(); private readonly IMapper m_mapper; private readonly GrpcService m_grpcService; + private readonly CookieService m_cookieService; #endregion @@ -54,6 +54,7 @@ public UserDynamicViewModel() { m_mapper = App.ServiceProvider.GetRequiredService(); m_grpcService = App.ServiceProvider.GetService(); + m_cookieService = App.ServiceProvider.GetRequiredService(); m_dynamicApi = new DynamicAPI(); m_watchLaterVm = new WatchLaterVM(); m_dynamicItemDataTemplateSelector = new DynamicItemDataTemplateSelector(); @@ -181,16 +182,28 @@ private async void OpenLottery(object id) Title = "抽奖", PrimaryButtonText = "关闭" }; - contentDialog.PrimaryButtonClick += new TypedEventHandler((sender, e) => - { - contentDialog.Hide(); - }); - contentDialog.Content = new WebView() + contentDialog.PrimaryButtonClick += + (sender, e) => + { + contentDialog.Hide(); + }; + var webView = new WebView2() { Width = 500, Height = 500, - Source = new Uri($"https://t.bilibili.com/lottery/h5/index/#/result?business_id={id.ToString()}&business_type=1&isWeb=1"), + Source = new Uri( + $"https://t.bilibili.com/lottery/h5/index/#/result?business_id={id.ToString()}&business_type=1&isWeb=1"), }; + await webView.EnsureCoreWebView2Async(); + foreach (var cookie in m_cookieService.Cookies) + { + var webCookie = + webView.CoreWebView2.CookieManager.CreateCookie(cookie.Name, cookie.Value, Constants.BILIBILI_HOST, + "/"); + webView.CoreWebView2.CookieManager.AddOrUpdateCookie(webCookie); + } + + contentDialog.Content = webView; await contentDialog.ShowAsync(); } From 45d2b9afd3ba741b26310016e730391a1b36d7fd Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Thu, 21 Dec 2023 22:31:50 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98=20(#441)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复部分视频打开评论区后卡死 - 修复评论区的黄豆表情错位现象 --- .../Extensions/StringExtensions.cs | 75 +++++++++---------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/src/BiliLite.UWP/Extensions/StringExtensions.cs b/src/BiliLite.UWP/Extensions/StringExtensions.cs index c16da0ede..93e7ee390 100644 --- a/src/BiliLite.UWP/Extensions/StringExtensions.cs +++ b/src/BiliLite.UWP/Extensions/StringExtensions.cs @@ -15,6 +15,7 @@ using Windows.Security.Cryptography; using Windows.Storage.Streams; using System.Threading.Tasks; +using System.Linq; namespace BiliLite.Extensions { @@ -106,13 +107,13 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote, bool //生成xaml var xaml = string.Format(@" - {0} - ", 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}> + {0} + ", input, + isLive ? 22 : 20, + color == null ? "" : $"Foreground=\"{color}\"", + $"FontWeight=\"{fontWeight}\""); var p = (RichTextBlock)XamlReader.Load(xaml); return p; } @@ -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; - } } @@ -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( - @"", + @"", emoji["url"].ToString(), emoji["meta"]["size"].ToInt32() == 1 ? "20" : "36")); } @@ -373,48 +373,52 @@ private static string HandelVideoID(string input) { //处理AV号 List keyword = new List(); + List> haveHandledOffset = new List>(); //如果是链接就不处理了 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 = - @"{0}", + @" CommandParameter=""{1}"" >🎞️{0}", 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 { 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 = - @"{0}", + @" CommandParameter=""{1}"" >🎞️{0}", 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 { item.Index + offset, item.Index + offset + data.Length }); offset += data.Length - item.Length; } @@ -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 = - @"{0}", + @" CommandParameter=""{1}"" >📝{0}", 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 { item.Index + offset, item.Index + offset + data.Length }); offset += data.Length - item.Length; } } @@ -452,7 +457,6 @@ private static string HandelVideoID(string input) /// private static string HandelUrl(string input) { - //处理AV号 List keyword = new List(); MatchCollection url = Regex.Matches(input, @"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"); @@ -465,25 +469,14 @@ private static string HandelUrl(string input) keyword.Add(item.Groups[0].Value); var data = - @"🔗网页链接", - item.Groups[0].Value); + @"CommandParameter=""{0}"" >🔗网页链接", + 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 = @"{0}", item.Groups[0].Value); - // input = input.Replace(item.Groups[0].Value, data); - //} - - - //return input; } #endregion From a8ca495a2aa8bbd68931990ab5f9ec3975924d9a Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Thu, 21 Dec 2023 23:04:09 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E4=B8=BA=E4=B8=AA=E4=BA=BA=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=90=88=E9=9B=86=E9=80=89?= =?UTF-8?q?=E9=A1=B9.=20(#445)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 个人空间添加合集页面 --- src/BiliLite.UWP/BiliLite.UWP.csproj | 2 + .../Extensions/ViewModelExtensions.cs | 1 + .../Common/User/SubmitCollectionItemModel.cs | 59 ++++++ .../Models/Requests/Api/User/UserDetailAPI.cs | 13 ++ .../Modules/User/UserDetail/UserDetailVM.cs | 3 + src/BiliLite.UWP/Pages/UserInfoPage.xaml | 87 ++++++++- src/BiliLite.UWP/Pages/UserInfoPage.xaml.cs | 26 ++- src/BiliLite.UWP/Services/MessageCenter.cs | 16 ++ .../User/UserSubmitCollectionViewModel.cs | 172 ++++++++++++++++++ 9 files changed, 368 insertions(+), 11 deletions(-) create mode 100644 src/BiliLite.UWP/Models/Common/User/SubmitCollectionItemModel.cs create mode 100644 src/BiliLite.UWP/ViewModels/User/UserSubmitCollectionViewModel.cs diff --git a/src/BiliLite.UWP/BiliLite.UWP.csproj b/src/BiliLite.UWP/BiliLite.UWP.csproj index 0620f5554..343bbb670 100644 --- a/src/BiliLite.UWP/BiliLite.UWP.csproj +++ b/src/BiliLite.UWP/BiliLite.UWP.csproj @@ -183,6 +183,7 @@ + @@ -353,6 +354,7 @@ + diff --git a/src/BiliLite.UWP/Extensions/ViewModelExtensions.cs b/src/BiliLite.UWP/Extensions/ViewModelExtensions.cs index dde653872..e3d04945e 100644 --- a/src/BiliLite.UWP/Extensions/ViewModelExtensions.cs +++ b/src/BiliLite.UWP/Extensions/ViewModelExtensions.cs @@ -14,6 +14,7 @@ public static IServiceCollection AddViewModels(this IServiceCollection services) services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/BiliLite.UWP/Models/Common/User/SubmitCollectionItemModel.cs b/src/BiliLite.UWP/Models/Common/User/SubmitCollectionItemModel.cs new file mode 100644 index 000000000..2638f9d6d --- /dev/null +++ b/src/BiliLite.UWP/Models/Common/User/SubmitCollectionItemModel.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; + +namespace BiliLite.Models.Common.User +{ + public class SubmitCollectionItemModel + { + /// + /// 本合集的视频数量 + /// + public int Count { get; set; } + + /// + /// 本合集的封面 + /// + public string Cover { get; set; } + + /// + /// 跳转格式? 常见值: av + /// + public string Goto { get; set; } + + /// + /// 可能是收费视频合集? + /// + [JsonProperty("is_pay")] + public bool IsPay { get; set; } + + /// + /// 合集最后更新时间戳 + /// + [JsonProperty("mtime")] + public int LatestUpdateTime { get; set; } + + /// + /// 未知参数 + /// 对于直播回放列表为其纯数字列表id. + /// + public string Param { get; set; } + + /// + /// 合集标题 + /// + public string Title { get; set; } + + /// + /// 合集类型 + /// 目前发现用户自己创建的为season, 直播回放列表为series + /// + public string Type { get; set; } + + /// + /// 跳转链接 + /// 以bilibili://开头. + /// 对于直播回放, 其特别的, 为: bilibili://music/playlist/playpage/{Id} + /// Id可能为合集的纯数字id. + /// + public string Uri { get; set; } + } +} diff --git a/src/BiliLite.UWP/Models/Requests/Api/User/UserDetailAPI.cs b/src/BiliLite.UWP/Models/Requests/Api/User/UserDetailAPI.cs index ec4f2fef4..80488fc0b 100644 --- a/src/BiliLite.UWP/Models/Requests/Api/User/UserDetailAPI.cs +++ b/src/BiliLite.UWP/Models/Requests/Api/User/UserDetailAPI.cs @@ -104,6 +104,19 @@ public ApiModel SubmitArticles(string mid, int page = 1, int pagesize = 30, Subm }; return api; } + + public ApiModel SubmitCollections(string mid, int pageNum) + { + var api = new ApiModel() + { + method = RestSharp.Method.Get, + baseUrl = $"https://app.bilibili.com/x/polymer/space/seasons_series_list_mobile", + parameter = $"{ApiHelper.MustParameter(AppKey, true)}&mid={mid}&page_num={pageNum}&page_size=20", + }; + api.parameter += ApiHelper.GetSign(api.parameter, AppKey); + return api; + } + /// /// 关注的分组 /// diff --git a/src/BiliLite.UWP/Modules/User/UserDetail/UserDetailVM.cs b/src/BiliLite.UWP/Modules/User/UserDetail/UserDetailVM.cs index aa1778820..231af0e76 100644 --- a/src/BiliLite.UWP/Modules/User/UserDetail/UserDetailVM.cs +++ b/src/BiliLite.UWP/Modules/User/UserDetail/UserDetailVM.cs @@ -120,6 +120,7 @@ public async Task GetSpeceStat() stat.favourite_count = (data.data["favourite2"]?["count"] ?? 0).ToInt32(); stat.follower = data.data["card"]["fans"].ToInt32(); stat.following = data.data["card"]["attention"].ToInt32(); + stat.CollectionCount = (data.data?["ugc_season"]?["count"] ?? 0).ToInt32() + (data.data?["series"]?["item"].ToArray().Length ?? 0); return stat; } else @@ -304,6 +305,8 @@ public string favourite } } + public int CollectionCount { get; set; } + public string Collection { get => CollectionCount > 0 ? " " + CollectionCount.ToCountString() : ""; } } public class UserCenterInfoModel : IModules { diff --git a/src/BiliLite.UWP/Pages/UserInfoPage.xaml b/src/BiliLite.UWP/Pages/UserInfoPage.xaml index b0f09d3f3..5322301f4 100644 --- a/src/BiliLite.UWP/Pages/UserInfoPage.xaml +++ b/src/BiliLite.UWP/Pages/UserInfoPage.xaml @@ -230,12 +230,12 @@ - + - + @@ -389,11 +389,88 @@ - + + + + + + + + + + + + + + + + + + 🎞️ + + + + + + + + + + + + + + + + + + + + + + + 最后更新: + + + + + + + + + + + 加载更多 + + + + + + + + + + + + 收藏 diff --git a/src/BiliLite.UWP/Pages/UserInfoPage.xaml.cs b/src/BiliLite.UWP/Pages/UserInfoPage.xaml.cs index df2db895f..d6cf0156a 100644 --- a/src/BiliLite.UWP/Pages/UserInfoPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/UserInfoPage.xaml.cs @@ -22,9 +22,10 @@ public enum UserTab SubmitVideo = 0, Dynamic = 1, Article = 2, - Favorite = 3, - Attention = 4, - Fans = 5, + Collection = 3, + Favorite = 4, + Attention = 5, + Fans = 6, } public class UserInfoParameter { @@ -39,6 +40,7 @@ public sealed partial class UserInfoPage : BasePage readonly UserDynamicViewModel m_userDynamicViewModel; UserDetailVM userDetailVM; UserSubmitVideoViewModel m_userSubmitVideoViewModel; + UserSubmitCollectionViewModel m_userSubmitCollectionViewModel; UserSubmitArticleVM userSubmitArticleVM; UserFavlistVM userFavlistVM; UserFollowVM fansVM; @@ -51,6 +53,7 @@ public UserInfoPage() Title = "用户中心"; userDetailVM = new Modules.User.UserDetailVM(); m_userSubmitVideoViewModel = App.ServiceProvider.GetService(); + m_userSubmitCollectionViewModel = App.ServiceProvider.GetService(); userSubmitArticleVM = new UserSubmitArticleVM(); userFavlistVM = new UserFavlistVM(); m_userDynamicViewModel = new UserDynamicViewModel(); @@ -133,6 +136,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) } userDetailVM.mid = mid; m_userSubmitVideoViewModel.Mid = mid; + m_userSubmitCollectionViewModel.Mid = mid; userSubmitArticleVM.mid = mid; userFavlistVM.mid = mid; fansVM.mid = mid; @@ -293,11 +297,15 @@ private async void pivot_SelectionChanged(object sender, SelectionChangedEventAr { await userSubmitArticleVM.GetSubmitArticle(); } - if (pivot.SelectedIndex == 3 && userFavlistVM.Items == null) + if (pivot.SelectedIndex == 3 && m_userSubmitCollectionViewModel.SubmitCollectionItems == null) + { + await m_userSubmitCollectionViewModel.GetSubmitCollection(); + } + if (pivot.SelectedIndex == 4 && userFavlistVM.Items == null) { await userFavlistVM.Get(); } - if (pivot.SelectedIndex == 4 && followVM.Items == null) + if (pivot.SelectedIndex == 5 && followVM.Items == null) { if (isSelf) { @@ -306,7 +314,7 @@ private async void pivot_SelectionChanged(object sender, SelectionChangedEventAr await followVM.Get(); } - if (pivot.SelectedIndex == 5 && fansVM.Items == null) + if (pivot.SelectedIndex == 6 && fansVM.Items == null) { await fansVM.Get(); } @@ -324,6 +332,12 @@ private void SubmitArticle_ItemClick(object sender, ItemClickEventArgs e) }); } + private async void SubmitCollection_ItemClick(object sender, ItemClickEventArgs e) + { + if (!(e.ClickedItem is SubmitCollectionItemModel data)) return; + await MessageCenter.HandelUrl(data.Uri); + } + private void comArticleOrder_SelectionChanged(object sender, SelectionChangedEventArgs e) { userSubmitArticleVM?.Refresh(); diff --git a/src/BiliLite.UWP/Services/MessageCenter.cs b/src/BiliLite.UWP/Services/MessageCenter.cs index 95b7e046a..ba2fb431f 100644 --- a/src/BiliLite.UWP/Services/MessageCenter.cs +++ b/src/BiliLite.UWP/Services/MessageCenter.cs @@ -113,6 +113,7 @@ public static async Task HandelUrl(string url, bool dontGoTo = false) * bilibili://?av=4284663 * https://m.bilibili.com/playlist/pl733016988?avid=68818070 * bilibili://story/722919541 + * bilibili://music/playlist/playpage/2484684 */ var video = ""; @@ -172,6 +173,21 @@ public static async Task HandelUrl(string url, bool dontGoTo = false) return true; } + // 目前无法将此类型播放列表的所有视频正确加载进视频页面 + video = StringExtensions.RegexMatch(url, @"bilibili://music/playlist/playpage/(\d+)"); + if (video != "") + { + NavigateToPage(null, new NavigationInfo() + { + icon = Symbol.Play, + page = typeof(WebPage), + title = "视频加载中...", + parameters = $"https://www.bilibili.com/list/1?sid={video}", + dontGoTo = dontGoTo, + }); + return true; + } + /* * 视频BV号 * https://www.bilibili.com/video/BV1EE411w75R diff --git a/src/BiliLite.UWP/ViewModels/User/UserSubmitCollectionViewModel.cs b/src/BiliLite.UWP/ViewModels/User/UserSubmitCollectionViewModel.cs new file mode 100644 index 000000000..83e7eb2e8 --- /dev/null +++ b/src/BiliLite.UWP/ViewModels/User/UserSubmitCollectionViewModel.cs @@ -0,0 +1,172 @@ +using AutoMapper; +using BiliLite.Extensions; +using BiliLite.Models.Common.User; +using BiliLite.Models.Exceptions; +using BiliLite.Models.Requests.Api.User; +using BiliLite.Modules; +using BiliLite.Services; +using BiliLite.ViewModels.Common; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace BiliLite.ViewModels.User +{ + /// + /// 合集投稿 + /// + public class UserSubmitCollectionViewModel : BaseViewModel + { + #region Fields + + private static readonly ILogger _logger = GlobalLogger.FromCurrentType(); + private readonly UserDetailAPI m_userDetailApi; + + #endregion + + #region Constructors + + public UserSubmitCollectionViewModel() + { + RefreshSubmitCollectionCommand = new RelayCommand(Refresh); + LoadMoreSubmitCollectionCommand = new RelayCommand(LoadMore); + m_userDetailApi = new UserDetailAPI(); + } + + #endregion + + #region Properties + + public ICommand RefreshSubmitCollectionCommand { get; private set; } + + public ICommand LoadMoreSubmitCollectionCommand { get; private set; } + + public string Mid { get; set; } + + public bool LoadingSubmitCollection { get; set; } = true; + + public bool SubmitCollectionCanLoadMore { get; set; } + + public ObservableCollection SubmitCollectionItems { get; set; } + + public bool Nothing { get; set; } + + public int SubmitCollectionPage { get; set; } = 1; + + #endregion + + #region Private Methods + + private void GetSubmitCollectionCore(JObject data) + { + var items = JsonConvert.DeserializeObject>(data["data"]["items"].ToString()); + SubmitCollectionPage = data["data"]["page"]["page_num"].ToInt32(); + var count = data["data"]["page"]["total"].ToInt32(); + AttachSubmitCollectionItems(items, count); + } + + private void AttachSubmitCollectionItems(List submitCollectionItems, int count) + { + if (SubmitCollectionItems == null) + { + var observableSubmitCollectionItems = new ObservableCollection(submitCollectionItems); + SubmitCollectionItems = observableSubmitCollectionItems; + } + else + { + foreach (var item in submitCollectionItems) + { + SubmitCollectionItems.Add(item); + } + } + + if (SubmitCollectionPage == 1 && SubmitCollectionItems == null) + { + Nothing = true; + } + if (SubmitCollectionItems.Count >= count) + { + SubmitCollectionCanLoadMore = false; + } + else + { + SubmitCollectionCanLoadMore = true; + SubmitCollectionPage++; + } + } + + #endregion + + #region Public Methods + + public async Task GetSubmitCollection() + { + try + { + Nothing = false; + SubmitCollectionCanLoadMore = false; + LoadingSubmitCollection = true; + + var api = m_userDetailApi.SubmitCollections(Mid, SubmitCollectionPage); + var results = await api.Request(); + if (!results.status) + { + throw new CustomizedErrorException(results.message); + } + + var data = results.GetJObject(); + if (data["code"].ToInt32() != 0) + { + throw new CustomizedErrorException(data["message"].ToString()); + } + + GetSubmitCollectionCore(data); + } + catch (CustomizedErrorException ex) + { + Notify.ShowMessageToast(ex.Message); + _logger.Error("获取用户合集失败", ex); + } + catch (Exception ex) + { + var handel = HandelError(ex); + Notify.ShowMessageToast(handel.message); + _logger.Error("获取用户合集失败", ex); + } + finally + { + LoadingSubmitCollection = false; + } + } + + public async void Refresh() + { + if (LoadingSubmitCollection) + { + return; + } + SubmitCollectionItems = null; + SubmitCollectionPage = 1; + await GetSubmitCollection(); + } + + public async void LoadMore() + { + if (LoadingSubmitCollection) + { + return; + } + if (SubmitCollectionItems == null) + { + return; + } + await GetSubmitCollection(); + } + + #endregion + } +} From 63998a0b25f27e380a971b3830b1d8fe6de92ec8 Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:58:17 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E9=97=AE=E9=A2=98=20(#447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复二维码登录后没有直播分区选项 - 修复直播分区娱乐分区闪退 --- .../Converters/ImageCompressionConvert.cs | 2 +- src/BiliLite.UWP/Models/Requests/Api/Home/LiveAPI.cs | 1 + src/BiliLite.UWP/Modules/Home/LiveVM.cs | 3 --- src/BiliLite.UWP/Pages/Home/LivePage.xaml | 7 ++++++- src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml | 11 ++++++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/BiliLite.UWP/Converters/ImageCompressionConvert.cs b/src/BiliLite.UWP/Converters/ImageCompressionConvert.cs index 69aa60805..5c5099170 100644 --- a/src/BiliLite.UWP/Converters/ImageCompressionConvert.cs +++ b/src/BiliLite.UWP/Converters/ImageCompressionConvert.cs @@ -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) diff --git a/src/BiliLite.UWP/Models/Requests/Api/Home/LiveAPI.cs b/src/BiliLite.UWP/Models/Requests/Api/Home/LiveAPI.cs index d890c6f97..365a55e08 100644 --- a/src/BiliLite.UWP/Models/Requests/Api/Home/LiveAPI.cs +++ b/src/BiliLite.UWP/Models/Requests/Api/Home/LiveAPI.cs @@ -12,6 +12,7 @@ public ApiModel LiveHome() baseUrl = "https://api.live.bilibili.com/xlive/app-interface/v2/index/getAllList", parameter = ApiHelper.MustParameter(AppKey, true) + "&device=android&rec_page=1&relation_page=1&scale=xxhdpi", }; + api.parameter = api.parameter.Replace("mobi_app=iphone", "mobi_app=android"); //只有mobi_app=android才能拿到area_entrance_v2 api.parameter += ApiHelper.GetSign(api.parameter, AppKey); return api; } diff --git a/src/BiliLite.UWP/Modules/Home/LiveVM.cs b/src/BiliLite.UWP/Modules/Home/LiveVM.cs index 587900d37..011a3e19e 100644 --- a/src/BiliLite.UWP/Modules/Home/LiveVM.cs +++ b/src/BiliLite.UWP/Modules/Home/LiveVM.cs @@ -230,9 +230,6 @@ public class LiveHomeAreaModel public string link { get; set; } } - - - public class LivePendentItemModel { public string bg_pic { get; set; } diff --git a/src/BiliLite.UWP/Pages/Home/LivePage.xaml b/src/BiliLite.UWP/Pages/Home/LivePage.xaml index c5860d815..39459adc2 100644 --- a/src/BiliLite.UWP/Pages/Home/LivePage.xaml +++ b/src/BiliLite.UWP/Pages/Home/LivePage.xaml @@ -39,7 +39,12 @@ - + diff --git a/src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml b/src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml index eab5448ce..700ab05fa 100644 --- a/src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml +++ b/src/BiliLite.UWP/Pages/Live/LiveAreaPage.xaml @@ -5,7 +5,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:BiliLite.Pages.Live" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:modules="using:BiliLite.Modules.Live" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:modules="using:BiliLite.Modules.Live" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" mc:Ignorable="d" Background="Transparent"> @@ -36,9 +36,14 @@ - + - + From 64a815255d711a576370a916763ce01fc6c5fc3a Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Sat, 23 Dec 2023 19:00:14 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E7=9A=84=E4=B8=80=E4=B8=AA=E7=BA=BF=E8=B7=AF=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=97=AE=E9=A2=98=20(#448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs | 1 + src/BiliLite.UWP/Player/SubPlayers/LiveHlsPlayer.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs index 304a14720..1533c6640 100644 --- a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs @@ -682,6 +682,7 @@ private async Task LoadPlayer() } catch (Exception ex) { + logger.Log("播放失败", LogType.Error, ex); Notify.ShowMessageToast("播放失败" + ex.Message); } } diff --git a/src/BiliLite.UWP/Player/SubPlayers/LiveHlsPlayer.cs b/src/BiliLite.UWP/Player/SubPlayers/LiveHlsPlayer.cs index 10ee2fb24..485f0ebe0 100644 --- a/src/BiliLite.UWP/Player/SubPlayers/LiveHlsPlayer.cs +++ b/src/BiliLite.UWP/Player/SubPlayers/LiveHlsPlayer.cs @@ -151,11 +151,11 @@ public override async Task Load() if (defaultPlayerMode == LivePlayerMode.Hls) { - url = urls.HlsUrls != null ? urls.HlsUrls[selectRouteLine].Url : urls.FlvUrls[selectRouteLine].Url; + url = (urls.HlsUrls != null && selectRouteLine < urls.HlsUrls.Count) ? urls.HlsUrls[selectRouteLine].Url : urls.FlvUrls[selectRouteLine].Url; } else { - url = urls.FlvUrls != null ? urls.FlvUrls[selectRouteLine].Url : urls.HlsUrls[selectRouteLine].Url; + url = (urls.FlvUrls != null && selectRouteLine < urls.FlvUrls.Count) ? urls.FlvUrls[selectRouteLine].Url : urls.HlsUrls[selectRouteLine].Url; } m_url = url; From 475918c39c3717034043bcbfbc632fa1f424a7b1 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sun, 24 Dec 2023 11:16:46 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/BiliLite.UWP.csproj | 1 + .../CustomizedErrorWithDataException.cs | 17 ++ src/BiliLite.UWP/Modules/User/LoginVM.cs | 182 ++++++++++-------- 3 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 src/BiliLite.UWP/Models/Exceptions/CustomizedErrorWithDataException.cs diff --git a/src/BiliLite.UWP/BiliLite.UWP.csproj b/src/BiliLite.UWP/BiliLite.UWP.csproj index 0620f5554..c19fc7ed0 100644 --- a/src/BiliLite.UWP/BiliLite.UWP.csproj +++ b/src/BiliLite.UWP/BiliLite.UWP.csproj @@ -184,6 +184,7 @@ + diff --git a/src/BiliLite.UWP/Models/Exceptions/CustomizedErrorWithDataException.cs b/src/BiliLite.UWP/Models/Exceptions/CustomizedErrorWithDataException.cs new file mode 100644 index 000000000..83e0f8b77 --- /dev/null +++ b/src/BiliLite.UWP/Models/Exceptions/CustomizedErrorWithDataException.cs @@ -0,0 +1,17 @@ +using System; +using Newtonsoft.Json; + +namespace BiliLite.Models.Exceptions +{ + public class CustomizedErrorWithDataException:Exception + { + private readonly object m_data; + + public string DataText => JsonConvert.SerializeObject(m_data); + + public CustomizedErrorWithDataException(string msg, object data) : base(msg) + { + m_data = data; + } + } +} diff --git a/src/BiliLite.UWP/Modules/User/LoginVM.cs b/src/BiliLite.UWP/Modules/User/LoginVM.cs index 005909c1e..ef7352e5c 100644 --- a/src/BiliLite.UWP/Modules/User/LoginVM.cs +++ b/src/BiliLite.UWP/Modules/User/LoginVM.cs @@ -15,12 +15,13 @@ using BiliLite.Services; using BiliLite.Services.Interfaces; using Microsoft.Extensions.DependencyInjection; +using BiliLite.Models.Exceptions; namespace BiliLite.Modules.User { public class LoginVM : IModules { - private static readonly ILogger logger = GlobalLogger.FromCurrentType(); + private static readonly ILogger _logger = GlobalLogger.FromCurrentType(); public Account account; Timer smsTimer; @@ -170,7 +171,7 @@ public async void ValidateLogin(JObject jObject) } catch (Exception ex) { - logger.Log("登录二次验证失败", LogType.Error, ex); + _logger.Log("登录二次验证失败", LogType.Error, ex); } } @@ -237,21 +238,26 @@ public async Task LoadCountry() } else { - Notify.ShowMessageToast(data.message); + throw new CustomizedErrorWithDataException(data.message, data); } } else { - Notify.ShowMessageToast(results.message); + throw new CustomizedErrorWithDataException(results.message, results); } } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); + } catch (Exception ex) { var handel = HandelError(ex); Notify.ShowMessageToast(handel.message); } - } + private async void SmsTimer_Elapsed(object sender, ElapsedEventArgs e) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => @@ -287,83 +293,91 @@ public async void SendSMSCode() var appKey = SettingConstants.Account.DefaultLoginAppKeySecret; sessionId = Guid.NewGuid().ToString().Replace("-", ""); var results = await accountApi.SendSMS(CurrentCountry.country_code, Phone, sessionId, appKey).Request(); - if (results.status) + if (!results.status) { - var data = await results.GetJson>(); - if (data.success) - { - if (data.data.recaptcha_url != null && data.data.recaptcha_url.Length > 0) - { - var uri = new Uri(data.data.recaptcha_url); - SetWebViewVisibility?.Invoke(this, true); - OpenWebView?.Invoke(this, new Uri("ms-appx-web:///Assets/GeeTest/bili_gt.html" + uri.Query + "&app=uwp")); - } - else - { - captchaKey = data.data.captcha_key; - EnableSendSMS = false; - //验证码发送成功,倒计时 - SMSCountDown = 60; - smsTimer.Start(); - } - } - else - { - Notify.ShowMessageToast(data.message); - } + throw new CustomizedErrorWithDataException(results.message, results); + } + + var data = await results.GetJson>(); + if (!data.success) + { + throw new CustomizedErrorWithDataException(data.message, data); + } + + if (!string.IsNullOrEmpty(data.data.recaptcha_url)) + { + var uri = new Uri(data.data.recaptcha_url); + SetWebViewVisibility?.Invoke(this, true); + OpenWebView?.Invoke(this, + new Uri("ms-appx-web:///Assets/GeeTest/bili_gt.html" + uri.Query + "&app=uwp")); } else { - Notify.ShowMessageToast(results.message); + captchaKey = data.data.captcha_key; + EnableSendSMS = false; + //验证码发送成功,倒计时 + SMSCountDown = 60; + smsTimer.Start(); } } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); + EnableSendSMS = true; + } catch (Exception ex) { + _logger.Error($"{ex.Message}", ex); Notify.ShowMessageToast(ex.Message); EnableSendSMS = true; } } + public async void SendSMSCodeWithCaptcha(string seccode = "", string validate = "", string challenge = "", string recaptcha_token = "") { try { var appKey = SettingConstants.Account.DefaultLoginAppKeySecret; - var results = await accountApi.SendSMSWithCaptcha(CurrentCountry.country_code, Phone, sessionId, seccode, validate, challenge, recaptcha_token, appKey).Request(); - if (results.status) + var results = await accountApi.SendSMSWithCaptcha(CurrentCountry.country_code, Phone, sessionId, + seccode, validate, challenge, recaptcha_token, appKey).Request(); + if (!results.status) { - var data = await results.GetJson>(); - if (data.success) - { - if (data.data.recaptcha_url != null && data.data.recaptcha_url.Length > 0) - { - var uri = new Uri(data.data.recaptcha_url); - SetWebViewVisibility?.Invoke(this, true); - OpenWebView?.Invoke(this, new Uri("ms-appx-web:///Assets/GeeTest/bili_gt.html" + uri.Query + "&app=uwp")); + throw new CustomizedErrorWithDataException(results.message, results); + } - } - else - { - captchaKey = data.data.captcha_key; - //验证码发送成功,倒计时 - EnableSendSMS = false; - SMSCountDown = 60; - smsTimer.Start(); - } - } - else - { - Notify.ShowMessageToast(data.message); - } + var data = await results.GetJson>(); + if (!data.success) + { + throw new CustomizedErrorWithDataException(data.message, data); + } + + if (!string.IsNullOrEmpty(data.data.recaptcha_url)) + { + var uri = new Uri(data.data.recaptcha_url); + SetWebViewVisibility?.Invoke(this, true); + OpenWebView?.Invoke(this, + new Uri("ms-appx-web:///Assets/GeeTest/bili_gt.html" + uri.Query + "&app=uwp")); } else { - Notify.ShowMessageToast(results.message); + captchaKey = data.data.captcha_key; + //验证码发送成功,倒计时 + EnableSendSMS = false; + SMSCountDown = 60; + smsTimer.Start(); } - + } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"SMS登录错误:{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); + EnableSendSMS = true; } catch (Exception ex) { + _logger.Error($"SMS登录错误:{ex.Message}", ex); Notify.ShowMessageToast(ex.Message); EnableSendSMS = true; } @@ -399,12 +413,19 @@ private async void DoSMSLogin() } else { - Notify.ShowMessageToast(results.message); + throw new CustomizedErrorWithDataException(results.message, results); } } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"SMS登录错误:{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); + EnableSendSMS = true; + } catch (Exception ex) { + _logger.Error($"SMS登录错误:{ex.Message}", ex); Notify.ShowMessageToast(ex.Message); EnableSendSMS = true; } @@ -459,13 +480,18 @@ private async void DoPasswordLogin() } else { - Notify.ShowMessageToast(results.message); + throw new CustomizedErrorWithDataException(results.message, results); } } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"密码登录错误:{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); + } catch (Exception ex) { + _logger.Error($"密码登录错误:{ex.Message}", ex); Notify.ShowMessageToast(ex.Message); - } finally { @@ -484,30 +510,30 @@ private async void CompletePasswordLoginCheck() try { var req = await accountApi.SubmitPwdLoginSMSCheck(Code, gee_tmp_token, gee_request_id, captchaKey).Request(); - if (req.status) + if (!req.status) { - var obj = req.GetJObject(); - if (obj["code"].ToInt32() == 0) - { - var code = obj["data"]["code"].ToString(); - var result = await PasswordLoginFetchCookie(code); - HnadelResult(result); - } - else - { - Notify.ShowMessageToast(obj["message"].ToString()); - return; - } + throw new CustomizedErrorWithDataException(req.message, req); } - else + + var obj = req.GetJObject(); + if (obj["code"].ToInt32() != 0) { - Notify.ShowMessageToast(req.message); + throw new CustomizedErrorWithDataException(obj["message"].ToString(), req); } + + var code = obj["data"]["code"].ToString(); + var result = await PasswordLoginFetchCookie(code); + HnadelResult(result); + } + catch (CustomizedErrorWithDataException ex) + { + _logger.Error($"{ex.Message}|{ex.DataText}", ex); + Notify.ShowMessageToast(ex.Message); } catch (Exception ex) { + _logger.Error($"{ex.Message}", ex); Notify.ShowMessageToast(ex.Message); - } finally { @@ -620,7 +646,7 @@ private async void GetQRAuthInfo() } catch (Exception ex) { - logger.Log("读取和加载登录二维码失败", LogType.Error, ex); + _logger.Log("读取和加载登录二维码失败", LogType.Error, ex); Notify.ShowMessageToast("加载二维码失败"); } finally @@ -718,7 +744,7 @@ private async void FetchHideTelNumber() } catch (Exception ex) { - logger.Log("获取验证手机号失败", LogType.Error, ex); + _logger.Log("获取验证手机号失败", LogType.Error, ex); } } @@ -751,7 +777,7 @@ private async void SendPwdLoginVerifySMS() } catch (Exception ex) { - logger.Log("发送短信验证码失败", LogType.Error, ex); + _logger.Log("发送短信验证码失败", LogType.Error, ex); } } @@ -852,7 +878,7 @@ private async Task StartGeetestCaptcha() } catch (Exception ex) { - logger.Log("读取极验验证码失败", LogType.Error, ex); + _logger.Log("读取极验验证码失败", LogType.Error, ex); return null; } } From f95a78903e52d5ed4052f7eb228c968f6816aa81 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sun, 24 Dec 2023 11:21:07 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8A=95=E7=A8=BF=E4=B8=AD=E7=9A=84=E6=9C=80=E5=A4=9A=E6=94=B6?= =?UTF-8?q?=E8=97=8F=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Pages/UserInfoPage.xaml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BiliLite.UWP/Pages/UserInfoPage.xaml b/src/BiliLite.UWP/Pages/UserInfoPage.xaml index 5322301f4..40e42e5d5 100644 --- a/src/BiliLite.UWP/Pages/UserInfoPage.xaml +++ b/src/BiliLite.UWP/Pages/UserInfoPage.xaml @@ -210,7 +210,6 @@ 最新发布 最多播放 - 最多收藏 From 6dac57a43899605ff85d6d9b076f0b9f5b040028 Mon Sep 17 00:00:00 2001 From: GD-Slime <82302542+GD-Slime@users.noreply.github.com> Date: Sun, 24 Dec 2023 13:22:24 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=B5=81=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20(#449)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了高能榜变动消息,每五次触发后会刷新高能用户贡献榜(大约三分钟) 修复了一个打开直播间时获取主播抽奖信息的bug 其他外观更改 --- src/BiliLite.UWP/Models/Common/Enumerates.cs | 5 +++++ .../Common/Live/LiveMessageHandleActionsMap.cs | 8 +++++++- src/BiliLite.UWP/Modules/Live/LiveMessage.cs | 9 ++++++++- src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs | 2 +- .../ViewModels/Live/LiveRoomRankViewModel.cs | 16 +++++++++++++++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/BiliLite.UWP/Models/Common/Enumerates.cs b/src/BiliLite.UWP/Models/Common/Enumerates.cs index 1a5abb626..8fa093ce3 100644 --- a/src/BiliLite.UWP/Models/Common/Enumerates.cs +++ b/src/BiliLite.UWP/Models/Common/Enumerates.cs @@ -395,5 +395,10 @@ public enum MessageType /// 红包抽奖赢家 /// RedPocketLotteryWinner, + + /// + /// 高能榜变动 + /// + OnlineRankChange, } } \ No newline at end of file diff --git a/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs b/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs index 35d274c09..b4d580f2e 100644 --- a/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs +++ b/src/BiliLite.UWP/Models/Common/Live/LiveMessageHandleActionsMap.cs @@ -33,6 +33,7 @@ public LiveMessageHandleActionsMap() { MessageType.WatchedChange, WatchedChange }, { MessageType.RedPocketLotteryStart, RedPocketLotteryStart}, { MessageType.RedPocketLotteryWinner, RedPocketLotteryWinner}, + { MessageType.OnlineRankChange, OnlineRankChange}, }; } @@ -210,7 +211,7 @@ private void WaringOrCutOff(LiveRoomViewModel viewModel, object message) { UserName = info.Command switch { - "WARNING" => "⛔直播间警告", + "WARNING" => "⚠️直播间警告", "CUT_OFF" => "⛔直播间切断", _ => null, }, @@ -231,5 +232,10 @@ private async void StartLive(LiveRoomViewModel viewModel, object room_Id) UserName = $"{room_Id} 直播间开始直播", }); } + + private void OnlineRankChange(LiveRoomViewModel viewModel, object message) + { + viewModel.Ranks.Where(rank => rank.RankType == "contribution-rank").ToList()?[0]?.ReloadData().RunWithoutAwait(); + } } } diff --git a/src/BiliLite.UWP/Modules/Live/LiveMessage.cs b/src/BiliLite.UWP/Modules/Live/LiveMessage.cs index 450a5c1b6..48329c8c2 100644 --- a/src/BiliLite.UWP/Modules/Live/LiveMessage.cs +++ b/src/BiliLite.UWP/Modules/Live/LiveMessage.cs @@ -444,12 +444,19 @@ private void ParseMessage(string jsonMessage) NewMessage?.Invoke(MessageType.WatchedChange, obj["data"]["text_large"].ToString()); } } + else if (cmd == "ONLINE_RANK_V2") + { + if (obj["data"] != null) + { + NewMessage?.Invoke(MessageType.OnlineRankChange, obj["data"]["list"].ToString()); + } + } } catch (Exception ex) { if (ex is JsonReaderException) { - logger.Error("直播解析JSON包出错", ex); + logger.Log("直播解析JSON包出错", LogType.Error ,ex); } } } diff --git a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs index 1533c6640..35eb97d26 100644 --- a/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/LiveDetailPage.xaml.cs @@ -132,7 +132,7 @@ private void Timer_focus_Tick(object sender, object e) private void LiveRoomViewModelAnchorLotteryStart(object sender, LiveRoomAnchorLotteryInfoModel e) { AnchorLotteryWinnerList.Content = e.WinnerList; - m_liveRoomViewModel.ShowAnchorLotteryWinnerList = e.AwardUsers.Count > 0; + m_liveRoomViewModel.ShowAnchorLotteryWinnerList = e.AwardUsers != null && e.AwardUsers.Count > 0; } private void LiveRoomViewModelAnchorLotteryEnd(object sender, LiveRoomEndAnchorLotteryInfoModel e) diff --git a/src/BiliLite.UWP/ViewModels/Live/LiveRoomRankViewModel.cs b/src/BiliLite.UWP/ViewModels/Live/LiveRoomRankViewModel.cs index c8a58dbc3..11224ecfa 100644 --- a/src/BiliLite.UWP/ViewModels/Live/LiveRoomRankViewModel.cs +++ b/src/BiliLite.UWP/ViewModels/Live/LiveRoomRankViewModel.cs @@ -60,7 +60,7 @@ public LiveRoomRankViewModel(int roomId, long uid, string title, string type) public bool CanLoadMore { get; set; } - public int Next { get; set; } = 0; + public int ReloadFlag { get; set; } = 0; #endregion @@ -137,6 +137,20 @@ public async Task LoadData() } } + public async Task ReloadData() + { + if (ReloadFlag > 5) // 大约三分钟刷新一次 + { + Items.Clear(); + Page = 1; + await LoadData(); + ReloadFlag = 0; + } else + { + ReloadFlag++; + } + } + #endregion } } \ No newline at end of file