Skip to content

Commit

Permalink
#804 支持设置自动跳过OP/ED,默认关闭
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Sep 21, 2024
1 parent 1e41f7f commit d668fe7
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
<Compile Include="Models\Common\Danmaku\BiliDanmakuItem.cs" />
<Compile Include="Models\Common\Dynamic\DynamicUgcSeasonCardModel.cs" />
<Compile Include="Models\Common\Player\PlaySpeedMenu.cs" />
<Compile Include="Models\Common\Season\EpisodeSkip.cs" />
<Compile Include="Models\Common\Player\PlayerSkipItem.cs" />
<Compile Include="Models\Common\Settings\FilterRule.cs" />
<Compile Include="Models\Common\Settings\FilterRuleTypes.cs" />
<Compile Include="Models\Common\UploadFileInfo.cs" />
Expand Down
35 changes: 35 additions & 0 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public BiliPlayUrlQualitesInfo playUrlInfo
set { _playUrlInfo = value; DoPropertyChanged("playUrlInfo"); }
}

private readonly bool m_autoSkipOpEdFlag = false;
private DispatcherTimer m_positionTimer;
DispatcherTimer danmuTimer;
/// <summary>
/// 弹幕信息
Expand Down Expand Up @@ -149,6 +151,12 @@ public PlayerControl()
danmuTimer = new DispatcherTimer();
danmuTimer.Interval = TimeSpan.FromSeconds(1);
danmuTimer.Tick += DanmuTimer_Tick;

m_positionTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
m_positionTimer.Tick += PositionTimer_Tick;
m_autoSkipOpEdFlag = SettingService.GetValue(SettingConstants.Player.AUTO_SKIP_OP_ED,
SettingConstants.Player.DEFAULT_AUTO_SKIP_OP_ED);

this.Loaded += PlayerControl_Loaded;
this.Unloaded += PlayerControl_Unloaded;
m_playerKeyRightAction = (PlayerKeyRightAction)SettingService.GetValue(SettingConstants.Player.PLAYER_KEY_RIGHT_ACTION, (int)PlayerKeyRightAction.ControlProgress);
Expand Down Expand Up @@ -241,6 +249,7 @@ private async void PlayerControl_Loaded(object sender, RoutedEventArgs e)

danmuTimer.Start();
timer_focus.Start();
m_positionTimer.Start();
}

private async void _systemMediaTransportControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
Expand Down Expand Up @@ -814,6 +823,27 @@ private async void DanmuTimer_Tick(object sender, object e)
}
}

private void PositionTimer_Tick(object sender, object e)
{
if (!m_autoSkipOpEdFlag) return;
if (CurrentPlayItem.EpisodeSkip == null) return;
SkipSection(CurrentPlayItem.EpisodeSkip.Op, "SkipOp", "自动跳过OP");
SkipSection(CurrentPlayItem.EpisodeSkip.Ed, "SkipEd", "自动跳过ED");
}

private void SkipSection(PlayerSkipItem section, string toastId, string message)
{
if (section == null) return;
if (!IsSectionValid(section) || (int)Player.Position != section.Start) return;
m_playerToastService.Show(toastId, message);
SetPosition(section.End);
}

private bool IsSectionValid(PlayerSkipItem section)
{
return section.Start != 0 && section.End != 0 && section.Start != section.End;
}

private async Task SetPlayItem(int index)
{
if (PlayInfos == null || PlayInfos.Count == 0)
Expand Down Expand Up @@ -2546,6 +2576,11 @@ public async void Dispose()
danmuTimer.Stop();
danmuTimer = null;
}
if (m_positionTimer != null)
{
m_positionTimer.Stop();
m_positionTimer = null;
}
danmakuPool = null;
if (dispRequest != null)
{
Expand Down
8 changes: 8 additions & 0 deletions src/BiliLite.UWP/Controls/Settings/PlaySettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
<ToggleSwitch x:Name="swAutoPlay"></ToggleSwitch>
</controls:SettingsCard>

<controls:SettingsCard Header="番剧自动跳过OP/ED"
Description="自动跳过片头/片尾">
<controls:SettingsCard.HeaderIcon>
<font:FontAwesome Icon="Solid_Music"></font:FontAwesome>
</controls:SettingsCard.HeaderIcon>
<ToggleSwitch x:Name="SwSkipOpEd"></ToggleSwitch>
</controls:SettingsCard>

<controls:SettingsCard Header="自动跳转至上次观看进度"
Description="自动跳转至上次观看进度">
<controls:SettingsCard.HeaderIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ private void LoadPlayer()
SettingService.SetValue(SettingConstants.Player.AUTO_PLAY, swAutoPlay.IsOn);
});
});
//自动跳过OP/ED
SwSkipOpEd.IsOn = SettingService.GetValue(SettingConstants.Player.AUTO_SKIP_OP_ED, SettingConstants.Player.DEFAULT_AUTO_SKIP_OP_ED);
SwSkipOpEd.Loaded += (sender, e) =>
{
SwSkipOpEd.Toggled += (obj, args) =>
{
SettingService.SetValue(SettingConstants.Player.AUTO_SKIP_OP_ED, SwSkipOpEd.IsOn);
};
};
//自动跳转下一P
swAutoNext.IsOn = SettingService.GetValue<bool>(SettingConstants.Player.AUTO_NEXT, true);
swAutoNext.Loaded += new RoutedEventHandler((sender, e) =>
Expand Down
9 changes: 9 additions & 0 deletions src/BiliLite.UWP/Models/Common/Player/PlayerSkipItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BiliLite.Models.Common.Player
{
public class PlayerSkipItem
{
public long Start { get; set; }

public long End { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/BiliLite.UWP/Models/Common/Season/EpisodeSkip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using BiliLite.Models.Common.Player;

namespace BiliLite.Models.Common.Season
{
public class EpisodeSkip
{
public PlayerSkipItem Op { get; set; }

public PlayerSkipItem Ed { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@ public string LongTitle
public int SectionType { get; set; }

public bool IsPreview => SectionType != 0;

public EpisodeSkip Skip { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/BiliLite.UWP/Models/Common/SettingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@ public class Player

[SettingKey(typeof(string))]
public const string PLAY_SPEED_MENU = "PlaySpeedMenu";

/// <summary>
/// 自动跳过OP/ED
/// </summary>
[SettingKey(typeof(bool))]
public const string AUTO_SKIP_OP_ED = "AutoSkipOpEd";

/// <summary>
/// 默认不自动跳过OP/ED
/// </summary>
[SettingDefaultValue]
public const bool DEFAULT_AUTO_SKIP_OP_ED = false;
}

public class Filter
Expand Down
4 changes: 4 additions & 0 deletions src/BiliLite.UWP/Models/Common/Video/PlayInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

using BiliLite.Models.Common.Season;

namespace BiliLite.Models.Common.Video
{
public class PlayInfo
Expand Down Expand Up @@ -62,5 +64,7 @@ public class PlayInfo
public string TitlePart { get; set; }

public bool ShowTitlePart => TitlePage != null;

public EpisodeSkip EpisodeSkip { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/BiliLite.UWP/Pages/SeasonDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private void UpdatePlayInfoToEpisode(int index)
order = i,
play_mode = VideoPlayType.Season,
title = item.Title + " " + item.LongTitle,
area = m_viewModel.Detail.Title.ParseArea(m_viewModel.Detail.UpInfo?.Mid ?? 0)
area = m_viewModel.Detail.Title.ParseArea(m_viewModel.Detail.UpInfo?.Mid ?? 0),
EpisodeSkip = item.Skip,
});
i++;
}
Expand Down

0 comments on commit d668fe7

Please sign in to comment.