Skip to content

Commit

Permalink
优化订阅循环可能崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Jul 24, 2023
1 parent ca63bd4 commit 400e299
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
4 changes: 3 additions & 1 deletion WkyFast/Service/ChatGptTranslatorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal class ChatGPTTranslatorManager
1.不要添加解释。
2.如果包含多种语言的作品名称,请使用第一个。
3.请避免将字幕组名称及字幕名称等识别为标题。
4.不要对作品名称进行删减或翻译。
5.不要对作品名称中的字符进行转换。
以下为需要提取的内容:

""";
Expand Down Expand Up @@ -55,7 +57,7 @@ public static async Task<string> GetEpisode(string s)
if (!string.IsNullOrEmpty( result.Response))
{
JObject root = JObject.Parse(result.Response);
var title = string.IsNullOrEmpty((string)root["title"]) ? "" : result.Response;
var title = (string)root["title"];
_cache[s] = title;
return title;
}
Expand Down
2 changes: 1 addition & 1 deletion WkyFast/Service/Model/SubscriptionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class SubscriptionModel : BaseNotificationModel


[JsonProperty("EpisodeTitleList")]
public List<string> EpisodeTitleList { get; set; } = new List<string>();
public List<string> EpisodeTitleList { get; set; }

/// <summary>
/// 存储路径
Expand Down
13 changes: 10 additions & 3 deletions WkyFast/Service/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public string GetSubscriptionTitle(string url)
private async void CheckSubscription()
{
EasyLogManager.Logger.Info("检查订阅...");
foreach (var subscription in SubscriptionModel)

var copyList = new List<SubscriptionModel>(SubscriptionModel);

foreach (var subscription in copyList)
{
string url = subscription.Url;

Expand Down Expand Up @@ -381,7 +384,11 @@ private async void CheckSubscription()
var episodeTitle = "";
if (subscription.AutoDir)
{
episodeTitle = subscription.EpisodeTitleList.FirstOrDefault(subject.Contains);
if (subscription.EpisodeTitleList == null)
{
subscription.EpisodeTitleList = new List<string>();
}
episodeTitle = subscription.EpisodeTitleList.FirstOrDefault(a => subject.Contains(a));
if (string.IsNullOrEmpty(episodeTitle) && AppConfig.Instance.ConfigData.OpenAIOpen)
{
EasyLogManager.Logger.Info($"获取剧集名称...");
Expand All @@ -405,7 +412,7 @@ private async void CheckSubscription()

if (!string.IsNullOrEmpty(episodeTitle))
{
savePath = savePath + "/" + episodeTitle;
savePath = savePath + "/" + PathHelper.RemoveInvalidChars(episodeTitle);
}

EasyLogManager.Logger.Info($"添加下载{subject} {link} {savePath}");
Expand Down
25 changes: 25 additions & 0 deletions WkyFast/Utils/PathHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WkyFast.Utils
{
internal class PathHelper
{
public static string RemoveInvalidChars(string input)
{
var invalidFileNameChars = Path.GetInvalidFileNameChars();
var invalidPathChars = Path.GetInvalidPathChars();

foreach (var c in invalidFileNameChars.Union(invalidPathChars).Distinct())
{
input = input.Replace(c.ToString(), "");
}

return input;
}
}
}
2 changes: 1 addition & 1 deletion WkyFast/View/Dialogs/WindowAddSubscription.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
SubscriptionManager.Instance.Add(url, _device, path, regex, regexEnable);
SubscriptionManager.Instance.Add(url, _device, path, regex, regexEnable, autoDir: autoDir);
EasyLogManager.Logger.Info($"订阅已添加:{title} {url}");
Expand Down

0 comments on commit 400e299

Please sign in to comment.