From e7ba85dba3c088462bca397df79f8e2f35bd7dc6 Mon Sep 17 00:00:00 2001 From: immisterio <96652250+immisterio@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:38:57 +0300 Subject: [PATCH] dev --- AppInit.cs | 4 ++- Controllers/ApiController.cs | 36 ++++++++++++++++--------- Controllers/CRON/RutrackerController.cs | 5 ++++ Engine/StatsCron.cs | 3 +-- Engine/Tracks/TracksCron.cs | 3 ++- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/AppInit.cs b/AppInit.cs index 7111c81..b452f15 100644 --- a/AppInit.cs +++ b/AppInit.cs @@ -43,6 +43,8 @@ public static AppInit conf public bool mergeduplicates = true; + public bool mergenumduplicates = true; + public bool openstats = true; public bool opensync = true; @@ -65,7 +67,7 @@ public static AppInit conf public string[] synctrackers = null; - public int maxreadfile = 80; + public int maxreadfile = 200; public bool evercache = false; diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index c0fae0e..29e8380 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -46,7 +46,7 @@ public ActionResult Jackett(string apikey, string query, string title, string ti if (string.IsNullOrWhiteSpace(title) && string.IsNullOrWhiteSpace(title_original) && mNum.Success) { - if (Regex.IsMatch(mNum.Groups[2].Value, "[a-zA-Z]{4}")) + if (Regex.IsMatch(mNum.Groups[2].Value, "[a-zA-Z0-9]{2}")) { rqnum = true; var g = mNum.Groups; @@ -109,7 +109,11 @@ void AddTorrents(TorrentDetails t) string _o = StringConvert.SearchName(title_original); // Быстрая выборка по совпадению ключа в имени - foreach (var val in FileDB.masterDb.Where(i => (_n != null && i.Key.StartsWith($"{_n}:")) || (_o != null && i.Key.EndsWith($":{_o}"))).Take(AppInit.conf.maxreadfile)) + var mdb = FileDB.masterDb.Where(i => (_n != null && i.Key.StartsWith($"{_n}:")) || (_o != null && i.Key.EndsWith($":{_o}"))); + if (!AppInit.conf.evercache) + mdb = mdb.Take(AppInit.conf.maxreadfile); + + foreach (var val in mdb) { foreach (var t in FileDB.OpenRead(val.Key).Values) { @@ -238,7 +242,7 @@ void AddTorrents(TorrentDetails t) } #endregion } - else if (!string.IsNullOrWhiteSpace(query) && query.Length > 3) + else if (!string.IsNullOrWhiteSpace(query) && query.Length > 1) { #region Обычный поиск string _s = StringConvert.SearchName(query); @@ -246,7 +250,11 @@ void AddTorrents(TorrentDetails t) #region torrentsSearch void torrentsSearch(bool exact) { - foreach (var val in FileDB.masterDb.OrderByDescending(i => i.Value).Where(i => i.Key.Contains(_s)).Take(AppInit.conf.maxreadfile)) + var mdb = FileDB.masterDb.OrderByDescending(i => i.Value).Where(i => i.Key.Contains(_s)); + if (!AppInit.conf.evercache) + mdb = mdb.Take(AppInit.conf.maxreadfile); + + foreach (var val in mdb) { foreach (var t in FileDB.OpenRead(val.Key).Values) { @@ -346,11 +354,7 @@ HashSet getCategoryIds(TorrentDetails t, out string categoryDesc) #region Объединить дубликаты var tsort = new List(); - if (!AppInit.conf.mergeduplicates || rqnum) - { - tsort = torrents.Values.ToList(); - } - else + if (AppInit.conf.mergeduplicates || (rqnum && AppInit.conf.mergenumduplicates)) { Dictionary AnnounceUrls)> temp = new Dictionary)>(); @@ -478,6 +482,10 @@ void UpdateTitle() foreach (var item in temp.Select(i => i.Value.torrent)) tsort.Add(item); } + else + { + tsort = torrents.Values.ToList(); + } #endregion #region FFprobe @@ -592,7 +600,7 @@ void AddTorrents(TorrentDetails t) } #endregion - if (string.IsNullOrWhiteSpace(search) || 3 >= search.Length) + if (string.IsNullOrWhiteSpace(search) || search.Length == 1) return Json(torrents); string _s = StringConvert.SearchName(search); @@ -624,9 +632,13 @@ void AddTorrents(TorrentDetails t) else { #region Поиск по совпадению ключа в имени - foreach (var mdb in FileDB.masterDb.OrderByDescending(i => i.Value).Where(i => i.Key.Contains(_s) || (_altsearch != null && i.Key.Contains(_altsearch))).Take(AppInit.conf.maxreadfile)) + var mdb = FileDB.masterDb.OrderByDescending(i => i.Value).Where(i => i.Key.Contains(_s) || (_altsearch != null && i.Key.Contains(_altsearch))); + if (!AppInit.conf.evercache) + mdb = mdb.Take(AppInit.conf.maxreadfile); + + foreach (var val in mdb) { - foreach (var t in FileDB.OpenRead(mdb.Key).Values) + foreach (var t in FileDB.OpenRead(val.Key).Values) { if (t.types == null) continue; diff --git a/Controllers/CRON/RutrackerController.cs b/Controllers/CRON/RutrackerController.cs index 8c1883a..112bccd 100644 --- a/Controllers/CRON/RutrackerController.cs +++ b/Controllers/CRON/RutrackerController.cs @@ -727,6 +727,11 @@ await FileDB.AddOrUpdate(torrents, async (t, db) => var fullNews = await HttpClient.Get(t.url, useproxy: AppInit.conf.Rutracker.useproxy); if (fullNews != null) { + string time = Regex.Match(fullNews, "([^<]+)").Groups[1].Value; + DateTime createTime = tParse.ParseCreateTime(time.Replace("-", " "), "dd.MM.yy HH:mm"); + if (createTime != default) + t.createTime = createTime; + string magnet = Regex.Match(fullNews, "href=\"(magnet:[^\"]+)\" class=\"(med )?magnet-link\"").Groups[1].Value; if (!string.IsNullOrWhiteSpace(magnet)) { diff --git a/Engine/StatsCron.cs b/Engine/StatsCron.cs index ca998ab..18fe13d 100644 --- a/Engine/StatsCron.cs +++ b/Engine/StatsCron.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -50,7 +49,7 @@ async public static Task Run() if (AppInit.conf.tracks && !TracksDB.theBad(t.types)) { - if (!string.IsNullOrEmpty(t.magnet) && t.sid > 0 && t.updateTime > DateTime.Today.AddDays(-20)) + if (!string.IsNullOrEmpty(t.magnet)) { if (TracksDB.Get(t.magnet) != null) s.trkconfirm = s.trkconfirm + 1; diff --git a/Engine/Tracks/TracksCron.cs b/Engine/Tracks/TracksCron.cs index d26ba00..530334e 100644 --- a/Engine/Tracks/TracksCron.cs +++ b/Engine/Tracks/TracksCron.cs @@ -83,7 +83,8 @@ async public static Task Run(int typetask) //if (hex == null) // continue; - torrents.Add((t.trackerName, t.magnet)); + if (typetask == 1 || (t.sid > 0 && t.updateTime > DateTime.Today.AddDays(-20))) + torrents.Add((t.trackerName, t.magnet)); } catch { } }