Skip to content

Commit

Permalink
移除 P2P 相关设置 (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Dec 29, 2023
1 parent 424f8d7 commit 83cce89
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 64 deletions.
3 changes: 0 additions & 3 deletions src/App/Controls/Settings/PlayerModeSettingSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@
</labs:SettingsCard.Header>
<ToggleSwitch IsOn="{x:Bind ViewModel.IsAutoCloseWindowWhenEnded, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard Description="{ext:Locale Name=DisableP2PCdnDescription}" Header="{ext:Locale Name=DisableP2PCdn}">
<ToggleSwitch IsOn="{x:Bind ViewModel.DisableP2PCdn, Mode=TwoWay}" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
</local:SettingSection>
1 change: 0 additions & 1 deletion src/Models/Models.Constants/App/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public enum SettingNames
PlaybackRate,
DanmakuArea,
DanmakuSpeed,
DisableP2PCdn,
IsContinuePlay,
IgnoreVersion,
IsOnlyShowIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Bili.Copilot.Libs.Provider;
using Bili.Copilot.Libs.Toolkit;
Expand Down Expand Up @@ -83,7 +82,6 @@ private async Task InitializeVideoMediaInformationAsync()
{
var view = _viewData as VideoPlayerView;
_mediaInformation = await PlayerProvider.GetVideoMediaInformationAsync(view.Information.Identifier.Id, _currentPart.Id);
CheckVideoP2PUrls();
}

private async Task InitializeOriginalVideoSourceAsync()
Expand Down Expand Up @@ -173,57 +171,6 @@ private async Task SelectVideoFormatAsync(FormatInformation format)
}
}

private void CheckVideoP2PUrls()
{
if (!SettingsToolkit.ReadLocalSetting(SettingNames.DisableP2PCdn, false))
{
return;
}

// 剔除 P2P CDN URL
if (_mediaInformation.AudioSegments != null)
{
var cdnUrl = _mediaInformation.AudioSegments.Select(p => p.BaseUrl)
.Concat(_mediaInformation.AudioSegments.SelectMany(p => p.BackupUrls))
.FirstOrDefault(p => Regex.IsMatch(p, "up[\\w-]+\\.bilivideo\\.com"));
var cdn = string.IsNullOrEmpty(cdnUrl) ? "upos-sz-mirrorcoso1.bilivideo.com" : new Uri(cdnUrl).Host;

for (var i = 0; i < _mediaInformation.AudioSegments.Count(); i++)
{
var seg = _mediaInformation.AudioSegments[i];
var url = new Uri(seg.BaseUrl);
if (url.Host.Contains(".mcdn.bilivideo.cn"))
{
var replacedUrl = seg.BaseUrl.Replace(url.Host, cdn)
.Replace($":{url.Port}", ":443");

seg.BaseUrl = replacedUrl;
}
}
}

if (_mediaInformation.VideoSegments != null)
{
var cdnUrl = _mediaInformation.VideoSegments.Select(p => p.BaseUrl)
.Concat(_mediaInformation.VideoSegments.SelectMany(p => p.BackupUrls))
.FirstOrDefault(p => Regex.IsMatch(p, "up[\\w-]+\\.bilivideo\\.com"));
var cdn = string.IsNullOrEmpty(cdnUrl) ? "upos-sz-mirrorcoso1.bilivideo.com" : new Uri(cdnUrl).Host;

for (var i = 0; i < _mediaInformation.VideoSegments.Count(); i++)
{
var seg = _mediaInformation.VideoSegments[i];
var url = new Uri(seg.BaseUrl);
if (url.Host.Contains(".mcdn.bilivideo.cn"))
{
var replacedUrl = seg.BaseUrl.Replace(url.Host, cdn)
.Replace($":{url.Port}", ":443");

seg.BaseUrl = replacedUrl;
}
}
}
}

[RelayCommand]
private void SelectInteractionChoice(InteractionInformation info)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public sealed partial class SettingsPageViewModel
[ObservableProperty]
private PlayerDisplayMode _defaultPlayerDisplayMode;

[ObservableProperty]
private bool _disableP2PCdn;

[ObservableProperty]
private bool _isContinuePlay;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void InitializeSettings()
CheckTheme();
IsAutoPlayWhenLoaded = ReadSetting(SettingNames.IsAutoPlayWhenLoaded, true);
IsAutoPlayNextRelatedVideo = ReadSetting(SettingNames.IsAutoPlayNextRelatedVideo, false);
DisableP2PCdn = ReadSetting(SettingNames.DisableP2PCdn, false);
IsContinuePlay = ReadSetting(SettingNames.IsContinuePlay, true);
IsAutoCloseWindowWhenEnded = ReadSetting(SettingNames.IsAutoCloseWindowWhenEnded, false);
SingleFastForwardAndRewindSpan = ReadSetting(SettingNames.SingleFastForwardAndRewindSpan, 30d);
Expand Down Expand Up @@ -83,9 +82,6 @@ private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
case nameof(DefaultPlayerDisplayMode):
WriteSetting(SettingNames.DefaultPlayerDisplayMode, DefaultPlayerDisplayMode);
break;
case nameof(DisableP2PCdn):
WriteSetting(SettingNames.DisableP2PCdn, DisableP2PCdn);
break;
case nameof(IsContinuePlay):
WriteSetting(SettingNames.IsContinuePlay, IsContinuePlay);
break;
Expand Down

0 comments on commit 83cce89

Please sign in to comment.