Skip to content

Commit 530d5ad

Browse files
committed
fix
1 parent 05950ba commit 530d5ad

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

Controllers/ApiController.cs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,43 @@ public JsonResult JacRedConf(string apikey)
3737
[Route("/api/v2.0/indexers/{status}/results")]
3838
public ActionResult Jackett(string apikey, string query, string title, string title_original, int year, Dictionary<string, string> category, int is_serial = -1)
3939
{
40-
bool rqnum = false;
4140
var fastdb = getFastdb();
4241
var torrents = new Dictionary<string, TorrentDetails>();
42+
bool rqnum = !HttpContext.Request.QueryString.Value.Contains("&is_serial=") && HttpContext.Request.Headers.UserAgent.ToString() == "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36";
4343

4444
#region Запрос с NUM
45-
var mNum = Regex.Match(query ?? string.Empty, "^([^a-z-A-Z]+) ([^а-я-А-Я]+) ([0-9]{4})$");
46-
47-
if (string.IsNullOrWhiteSpace(title) && string.IsNullOrWhiteSpace(title_original) &&
48-
mNum.Success)
45+
if (rqnum && query != null)
4946
{
50-
if (Regex.IsMatch(mNum.Groups[2].Value, "[a-zA-Z0-9]{2}"))
47+
var mNum = Regex.Match(query, "^([^a-z-A-Z]+) ([^а-я-А-Я]+) ([0-9]{4})$");
48+
49+
if (mNum.Success)
5150
{
52-
rqnum = true;
53-
var g = mNum.Groups;
51+
if (Regex.IsMatch(mNum.Groups[2].Value, "[a-zA-Z0-9]{2}"))
52+
{
53+
var g = mNum.Groups;
54+
title = g[1].Value;
55+
title_original = g[2].Value;
56+
year = int.Parse(g[3].Value);
57+
}
58+
}
59+
else
60+
{
61+
if (Regex.IsMatch(query, "^([^a-z-A-Z]+) ((19|20)[0-9]{2})$"))
62+
return Json(new RootObject() { Results = new List<Result>() });
5463

55-
title = g[1].Value;
56-
title_original = g[2].Value;
57-
year = int.Parse(g[3].Value);
64+
mNum = Regex.Match(query, "^([^a-z-A-Z]+) ([^а-я-А-Я]+)$");
65+
66+
if (mNum.Success)
67+
{
68+
if (Regex.IsMatch(mNum.Groups[2].Value, "[a-zA-Z0-9]{2}"))
69+
{
70+
var g = mNum.Groups;
71+
title = g[1].Value;
72+
title_original = g[2].Value;
73+
}
74+
}
5875
}
5976
}
60-
61-
if (!rqnum)
62-
rqnum = !HttpContext.Request.QueryString.Value.Contains("&is_serial=") && HttpContext.Request.Headers.UserAgent.ToString() == "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36";
6377
#endregion
6478

6579
#region category
@@ -261,14 +275,14 @@ void updateKeys(string k)
261275
string _s = StringConvert.SearchName(query);
262276

263277
#region torrentsSearch
264-
void torrentsSearch(bool exact)
278+
void torrentsSearch(bool exact, bool exactdb)
265279
{
266280
if (_s == null)
267281
return;
268282

269283
HashSet<string> keys = null;
270284

271-
if (exact)
285+
if (exactdb)
272286
{
273287
if (fastdb.TryGetValue(_s, out List<string> _keys) && _keys.Count > 0)
274288
{
@@ -294,8 +308,7 @@ void torrentsSearch(bool exact)
294308
break;
295309
}
296310

297-
if (keys.Count > 0)
298-
memoryCache.Set(mkey, keys, DateTime.Now.AddHours(1));
311+
memoryCache.Set(mkey, keys, DateTime.Now.AddHours(1));
299312
}
300313
}
301314

@@ -351,12 +364,16 @@ void torrentsSearch(bool exact)
351364
#endregion
352365

353366
if (is_serial == -1)
354-
torrentsSearch(exact: false);
367+
{
368+
torrentsSearch(exact: false, exactdb: true);
369+
if (torrents.Count == 0)
370+
torrentsSearch(exact: false, exactdb: false);
371+
}
355372
else
356373
{
357-
torrentsSearch(exact: true);
374+
torrentsSearch(exact: true, exactdb: true);
358375
if (torrents.Count == 0)
359-
torrentsSearch(exact: false);
376+
torrentsSearch(exact: false, exactdb: false);
360377
}
361378
#endregion
362379
}
@@ -772,11 +789,13 @@ void AddTorrents(TorrentDetails t)
772789

773790

774791
#region getFastdb
775-
Dictionary<string, List<string>> getFastdb()
792+
static Dictionary<string, List<string>> _fastdb = null;
793+
794+
public static Dictionary<string, List<string>> getFastdb(bool update = false)
776795
{
777-
if (!memoryCache.TryGetValue("api:fastdb", out Dictionary<string, List<string>> fastdb))
796+
if (_fastdb == null || update)
778797
{
779-
fastdb = new Dictionary<string, List<string>>();
798+
var fastdb = new Dictionary<string, List<string>>();
780799

781800
foreach (var item in FileDB.masterDb)
782801
{
@@ -787,9 +806,6 @@ Dictionary<string, List<string>> getFastdb()
787806

788807
if (fastdb.TryGetValue(k, out List<string> keys))
789808
{
790-
if (keys == null)
791-
keys = new List<string>();
792-
793809
keys.Add(item.Key);
794810
}
795811
else
@@ -799,10 +815,10 @@ Dictionary<string, List<string>> getFastdb()
799815
}
800816
}
801817

802-
memoryCache.Set("api:fastdb", fastdb, DateTime.Now.AddMinutes(10));
818+
_fastdb = fastdb;
803819
}
804820

805-
return fastdb;
821+
return _fastdb;
806822
}
807823
#endregion
808824
}

Engine/FileDB/staticDB.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ async public static Task CronFast()
248248
{
249249
if (openWriteTask.Count > AppInit.conf.evercache.maxOpenWriteTask)
250250
{
251-
foreach (var i in openWriteTask.OrderBy(i => i.Value.countread).Take(AppInit.conf.evercache.dropCacheTake))
251+
var query = openWriteTask.Where(i => DateTime.Now > i.Value.create.AddMinutes(10));
252+
query = query.OrderBy(i => i.Value.countread).ThenBy(i => i.Value.lastread);
253+
254+
foreach (var i in query.Take(AppInit.conf.evercache.dropCacheTake))
252255
openWriteTask.TryRemove(i.Key, out _);
253256
}
254257
}

Models/WriteTaskModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class WriteTaskModel
99

1010
public DateTime lastread { get; set; }
1111

12+
public DateTime create { get; set; } = DateTime.Now;
13+
1214
public int countread { get; set; }
1315

1416
public int openconnection { get; set; }

Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
using System.Text;
66
using System.Threading;
77
using JacRed.Engine;
8+
using System.Threading.Tasks;
9+
using System;
10+
using JacRed.Controllers;
811

912
namespace JacRed
1013
{
1114
public class Program
1215
{
1316
public static void Main(string[] args)
1417
{
18+
ThreadPool.QueueUserWorkItem(async _ =>
19+
{
20+
await Task.Delay(TimeSpan.FromMinutes(10));
21+
ApiController.getFastdb(update: true);
22+
});
23+
1524
ThreadPool.QueueUserWorkItem(async _ => await SyncCron.Torrents());
1625
ThreadPool.QueueUserWorkItem(async _ => await SyncCron.Spidr());
1726

0 commit comments

Comments
 (0)