From bce7fb59dab55a328d6f50d6d6be12c729ff85b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B1=B3?= Date: Sat, 6 Jul 2024 01:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E6=92=AD=E6=94=BE=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=85=E6=99=B0=E5=BA=A6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Network/Methods/room.cs | 4 +- Core/RuntimeObject/Download/Basics.cs | 37 +++++++++-- Core/RuntimeObject/Download/HLS.cs | 2 +- Desktop/Views/Pages/DataPage.xaml.cs | 1 - Desktop/Views/Windows/VlcPlayWindow.xaml.cs | 70 ++++++++++++++++++--- 5 files changed, 94 insertions(+), 20 deletions(-) diff --git a/Core/Network/Methods/room.cs b/Core/Network/Methods/room.cs index 563bfa889..3c97b2f27 100644 --- a/Core/Network/Methods/room.cs +++ b/Core/Network/Methods/room.cs @@ -25,7 +25,7 @@ public class Room /// /// 清晰度 /// - internal static PlayInfo_Class GetPlayInfo(long RoomId,int Definition) + internal static PlayInfo_Class GetPlayInfo(long RoomId,long Definition) { return _PlayInfo(RoomId,Definition); } @@ -54,7 +54,7 @@ internal static RoomInfo_Class GetRoomInfo(long RoomId) #region Private Method - private static PlayInfo_Class _PlayInfo(long RoomId,int Definition) + private static PlayInfo_Class _PlayInfo(long RoomId,long Definition) { string WebText = Get.GetBody($"{Config.Core_RunConfig._LiveDomainName}/xlive/web-room/v2/index/getRoomPlayInfo?room_id={RoomId}&protocol=0,1&format=0,1,2&codec=0,1&qn={Definition}&platform=web&ptype=8", true); PlayInfo_Class hLSHostClass = new(); diff --git a/Core/RuntimeObject/Download/Basics.cs b/Core/RuntimeObject/Download/Basics.cs index 9b72a9532..9317ec0dc 100644 --- a/Core/RuntimeObject/Download/Basics.cs +++ b/Core/RuntimeObject/Download/Basics.cs @@ -1,4 +1,5 @@ -using ConsoleTableExt; +using AngleSharp.Io; +using ConsoleTableExt; using Core.LiveChat; using Core.LogModule; using Core.Network.Methods; @@ -342,7 +343,7 @@ internal static DlwnloadTaskState CheckAndHandleFile(string File, ref RoomCardCl /// 编码(目前固定avc) /// 清晰度等级 /// - public static HostClass _GetHost(long RoomId, string protocol_name, string format_name, string codec_name, int Definition = 10000) + public static HostClass _GetHost(long RoomId, string protocol_name, string format_name, string codec_name, long Definition = 10000) { HostClass hostClass = new(); PlayInfo_Class playInfo = GetPlayInfo(RoomId, Definition); @@ -373,10 +374,34 @@ public static HostClass _GetHost(long RoomId, string protocol_name, string forma return hostClass; } - //public static string[] GetOptionalClarity(long RoomId) - //{ - - //} + /// + /// 获取可选清晰度列表 + /// + /// 房间号 + /// 类型(http_hls/http_stream) + /// 封装(flv/fmp4) + /// 编码(目前固定avc) + /// + public static List GetOptionalClarity(long RoomId, string protocol_name, string format_name, string codec_name) + { + List Definition = new(); + HostClass hostClass = new(); + PlayInfo_Class playInfo = GetPlayInfo(RoomId, 10000); + if (playInfo == null || playInfo.data.playurl_info == null || playInfo.data.playurl_info.playurl == null) + return Definition; + hostClass.all_special_types = playInfo.data.all_special_types; + PlayInfo_Class.Stream? stream = playInfo.data.playurl_info.playurl.stream.FirstOrDefault(x => x.protocol_name == protocol_name); + if (stream == null) + return Definition; + PlayInfo_Class.Format? format = stream.format.FirstOrDefault(x => x.format_name == format_name); + if (format == null) + return Definition; + PlayInfo_Class.Codec? codec = format.codec.FirstOrDefault(x => x.codec_name == codec_name); + if (codec == null) + return Definition; + Definition = codec.accept_qn; + return Definition; + } diff --git a/Core/RuntimeObject/Download/HLS.cs b/Core/RuntimeObject/Download/HLS.cs index f3c785cce..b97ee507f 100644 --- a/Core/RuntimeObject/Download/HLS.cs +++ b/Core/RuntimeObject/Download/HLS.cs @@ -287,7 +287,7 @@ private static DlwnloadTaskState HandleHlsError(RoomCardClass card, HostClass ho /// /// - public static bool GetHlsAvcUrl(RoomCardClass roomCard,int Definition, out string Url) + public static bool GetHlsAvcUrl(RoomCardClass roomCard,long Definition, out string Url) { Url = ""; if (!RoomInfo.GetLiveStatus(roomCard.RoomId)) diff --git a/Desktop/Views/Pages/DataPage.xaml.cs b/Desktop/Views/Pages/DataPage.xaml.cs index 8ab824364..5eb5b1db0 100644 --- a/Desktop/Views/Pages/DataPage.xaml.cs +++ b/Desktop/Views/Pages/DataPage.xaml.cs @@ -84,7 +84,6 @@ public void Init() /// public void Add_ImportFromFollowList_Menu() { - Task.Run(() => { try diff --git a/Desktop/Views/Windows/VlcPlayWindow.xaml.cs b/Desktop/Views/Windows/VlcPlayWindow.xaml.cs index c46221b6b..bc5b755e2 100644 --- a/Desktop/Views/Windows/VlcPlayWindow.xaml.cs +++ b/Desktop/Views/Windows/VlcPlayWindow.xaml.cs @@ -35,6 +35,7 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; using Key = System.Windows.Input.Key; +using MenuItem = Wpf.Ui.Controls.MenuItem; namespace Desktop.Views.Windows { @@ -73,7 +74,7 @@ public partial class VlcPlayWindow : FluentWindow /// /// 当前窗口的清晰度 /// - public int CurrentWindowClarity = Core_RunConfig._DefaultPlayResolution; + public long CurrentWindowClarity = 10000; public class DanMuOrbitInfo { public string Text { get; set; } @@ -84,7 +85,7 @@ public VlcPlayWindow(long uid) { InitializeComponent(); vlcPlayModels = new(); - CurrentWindowClarity = + CurrentWindowClarity = Core_RunConfig._DefaultPlayResolution; this.DataContext = vlcPlayModels; _Room.GetCardForUID(uid, ref roomCard); @@ -112,11 +113,11 @@ public VlcPlayWindow(long uid) videoView.MediaPlayer.Volume = 30; Task.Run(() => InitVlcPlay(uid)); - + Task.Run(() => SetClarityMenu()); } public void InitVlcPlay(long uid) { - PlaySteam(null, CurrentWindowClarity); + PlaySteam(null); Dispatcher.Invoke(() => { barrageConfig = new BarrageConfig(DanmaCanvas, this.Width); @@ -131,6 +132,55 @@ public void InitVlcPlay(long uid) }); } + private void SetClarityMenu() + { + List DefinitionList = Core.RuntimeObject.Download.Basics.GetOptionalClarity(roomCard.RoomId, "http_hls", "fmp4", "avc"); + + Dictionary clarityMap = new Dictionary + { + {30000, "杜比"}, + {20000, "4K"}, + {10000, "原画"}, + {400, "蓝光"}, + {250, "超清"}, + {150, "高清"}, + {80, "流畅"} + }; + + foreach (var clarity in clarityMap) + { + if (DefinitionList.Contains(clarity.Key)) + { + Dispatcher.Invoke(() => + { + MenuItem childMenuItem = new MenuItem + { + Header = clarity.Value, + Tag = clarity.Key + }; + childMenuItem.Click += ModifyResolutionRightClickMenuEvent_Click; + SwitchPlaybackClarity_Menu.Items.Add(childMenuItem); + }); + } + } + } + + + private void ModifyResolutionRightClickMenuEvent_Click(object sender, RoutedEventArgs e) + { + MenuItem clickedMenuItem = sender as MenuItem; + + Dispatcher.Invoke(() => + { + CurrentWindowClarity = (long)clickedMenuItem.Tag; // 获取被点击的菜单项的索引 + }); + + vlcPlayModels.LoadingVisibility = Visibility.Visible; + vlcPlayModels.OnPropertyChanged("LoadingVisibility"); + + PlaySteam(null); + } + private void MediaPlayer_Playing(object? sender, EventArgs e) { Task.Run(() => @@ -145,7 +195,7 @@ private void MediaPlayer_EndReached(object? sender, EventArgs e) { vlcPlayModels.LoadingVisibility = Visibility.Visible; vlcPlayModels.OnPropertyChanged("LoadingVisibility"); - PlaySteam(null, CurrentWindowClarity); + PlaySteam(null); } private async void SetDanma() @@ -211,7 +261,7 @@ private void LiveChatListener_MessageReceived(object? sender, Core.LiveChat.Mess /// 播放网络路径直播流 /// /// - public async void PlaySteam(string Url = null, int Definition = 10000) + public async void PlaySteam(string Url = null) { Log.Info(nameof(PlaySteam), $"房间号:[{roomCard.RoomId}],播放网络路径直播流"); await Task.Run(() => @@ -235,7 +285,7 @@ await Task.Run(() => } if (string.IsNullOrEmpty(Url)) { - Url = GeUrl(Core_RunConfig._DefaultPlayResolution); + Url = GeUrl(CurrentWindowClarity); } try { @@ -293,7 +343,7 @@ await Task.Run(() => /// /// /// - public string GeUrl(int Definition) + public string GeUrl(long Definition) { string url = ""; if (roomCard != null && (Core.RuntimeObject.Download.HLS.GetHlsAvcUrl(roomCard, Definition, out url))) @@ -488,7 +538,7 @@ private void FluentWindow_KeyDown(object sender, System.Windows.Input.KeyEventAr { vlcPlayModels.LoadingVisibility = Visibility.Visible; vlcPlayModels.OnPropertyChanged("LoadingVisibility"); - PlaySteam(null, CurrentWindowClarity); + PlaySteam(null); } } @@ -518,7 +568,7 @@ private void F5_MenuItem_Click(object sender, RoutedEventArgs e) { vlcPlayModels.LoadingVisibility = Visibility.Visible; vlcPlayModels.OnPropertyChanged("LoadingVisibility"); - PlaySteam(null, CurrentWindowClarity); + PlaySteam(null); } private void MenuItem_Switch_Danma_Send_Click(object sender, RoutedEventArgs e)