Skip to content

Commit

Permalink
剧集季的匹配,自动拆分季目录
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed May 20, 2024
1 parent 02fcb13 commit a723c0e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Aria2Fast/Service/Model/SubscriptionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public partial class SubscriptionModel : BaseNotificationModel
[JsonProperty("Name")]
public string Name { get; set; }

[JsonProperty("Season")]
public int Season { get; set; }

[JsonProperty("Filter")]
public string Filter { get; set; }

Expand Down
7 changes: 6 additions & 1 deletion Aria2Fast/Service/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ public void Save()

//存储订阅,读取加载订阅

public bool Add(string url, string path, string keyword = "", bool keywordIsRegex = false, bool autoDir = false)
public bool Add(string url, string path, int season = 0, string title = "", string keyword = "", bool keywordIsRegex = false, bool autoDir = false)
{
if (SubscriptionModel.ToList().Find( a => { return a.Url == url; }) != null)
{
Expand All @@ -715,6 +715,11 @@ public bool Add(string url, string path, string keyword = "", bool keywordIsRege
model.IsFilterRegex = keywordIsRegex;
model.Path = path;
model.AutoDir = autoDir;
model.Season = season;
model.Name = title;
//识别季?


EasyLogManager.Logger.Error($"添加订阅:{model.Url}");

SubscriptionModel.Add(model);
Expand Down
51 changes: 51 additions & 0 deletions Aria2Fast/Utils/MatchUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,56 @@ public static string ExtractEpisodeNumber(string title)

return string.Empty;
}


public static int GetSeasonFromTitle(string title)
{
string pattern = @"第(.{1,2})季";
Regex regex = new Regex(pattern);

if (regex.IsMatch(title))
{
Match match = regex.Match(title);
string seasonStr = match.Groups[1].Value;
// check if the match value is Arabic numeral
if (int.TryParse(seasonStr, out int seasonNum))
{
return seasonNum;
}
// Match Chinese digit
else
{
switch (seasonStr)
{
case "一": return 1;
case "二": return 2;
case "三": return 3;
case "四": return 4;
case "五": return 5;
case "六": return 6;
case "七": return 7;
case "八": return 8;
case "九": return 9;
case "十": return 10;
default: return 0;
}
}
}
return 0;
}


public static string RemoveSeasonFromTitle(string title)
{
string pattern = @"第.{1,2}季";
Regex regex = new Regex(pattern);

if (regex.IsMatch(title))
{
return regex.Replace(title, "").Trim();
}

return title;
}
}
}
16 changes: 16 additions & 0 deletions Aria2Fast/View/AddSubscriptionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@
</Grid>

</Border>

<Border Margin="10,0,10,6" CornerRadius="4">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>
<ComboBox
x:Name="ComboBoxSeasonPath"
Grid.Column="2"
Padding="10,5,10,5"
IsEditable="True" />

</Grid>

</Border>

<Border Margin="10,0,10,10">
<Grid>
<Grid.ColumnDefinitions>
Expand Down
39 changes: 36 additions & 3 deletions Aria2Fast/View/AddSubscriptionView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Aria2Fast.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -35,7 +36,7 @@ public AddSubscriptionView()
InitializeComponent();
LoadDefaultPathSelected();
LoadDefaultFilterList();

LoadSeasons();
}

private void Page_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
Expand All @@ -48,9 +49,32 @@ private void Page_DataContextChanged(object sender, DependencyPropertyChangedEve
UrlTextBox.Text = obj.Item1;
TextBoxRssPath.Text = obj.Item2;
_anime = obj.Item3;

//更新UI
if (_anime != null)
{
ComboBoxSeasonPath.SelectedIndex = MatchUtils.GetSeasonFromTitle(_anime.Name);
}
}
}




private void LoadSeasons()
{
ComboBoxSeasonPath.Items.Add("未知季");
//GetSeasonFromTitle
for (int i = 1; i < 20; i++)
{
string item = $"第{i}季";
ComboBoxSeasonPath.Items.Add(item);
}
ComboBoxSeasonPath.SelectedIndex = 0;

}


private void LoadDefaultFilterList()
{
SubscriptionFilterItemsControl.ItemsSource = AppConfig.Instance.ConfigData.AddSubscriptionFilterList;
Expand All @@ -64,7 +88,7 @@ private void LoadDefaultFilterList()
SubscriptionFilterItemsControl.Visibility = Visibility.Visible;
}
}

private void LoadDefaultPathSelected()
{
try
Expand Down Expand Up @@ -123,6 +147,7 @@ await Task.Run(() => {
bool regexEnable = false;
string path = string.Empty;
bool autoDir = false;
int season = 0;

this.Dispatcher.Invoke(() =>
{
Expand All @@ -131,6 +156,7 @@ await Task.Run(() => {
regexEnable = RegexCheckBox.IsChecked == true ? true : false;
path = PathComboBox.Text;
autoDir = AutoDirSwitch.IsChecked == true ? true : false;
season = ComboBoxSeasonPath.SelectedIndex;
});

try
Expand All @@ -147,6 +173,7 @@ await Task.Run(() => {
this.Dispatcher.Invoke(() =>
{
string title = TextBoxRssPath.Text;
title = MatchUtils.RemoveSeasonFromTitle(title); //移除

if (string.IsNullOrWhiteSpace(title))
{
Expand All @@ -157,7 +184,13 @@ await Task.Run(() => {
path = PathComboBox.Text + (PathComboBox.Text.EndsWith("/") ? "" : "/") + title;
}

SubscriptionManager.Instance.Add(url, path, regex, regexEnable, autoDir: autoDir);

if (season > 0)
{
path = System.IO.Path.Combine(path, $"Season {season}");
}

SubscriptionManager.Instance.Add(url, path, season, title, regex, regexEnable, autoDir: autoDir);
EasyLogManager.Logger.Info($"订阅已添加:{title} {url}");

MainWindow.Instance.ShowSnackbar("添加成功", $"已添加订阅{title}", SymbolRegular.AddCircle24);
Expand Down

0 comments on commit a723c0e

Please sign in to comment.