Skip to content

Commit cf08ffa

Browse files
committed
Merge branch 'main'
2 parents 5a52715 + 1f6f88e commit cf08ffa

25 files changed

+243
-107
lines changed

AppInit.cs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,55 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Threading;
8+
using System.Threading.Tasks;
79

810
namespace JacRed
911
{
1012
public class AppInit
1113
{
1214
#region AppInit
13-
static (AppInit, DateTime) cacheconf = default;
14-
15-
public static AppInit conf
15+
static AppInit()
1616
{
17-
get
17+
void updateConf()
1818
{
19-
if (cacheconf.Item1 == null)
19+
try
2020
{
21-
if (!File.Exists("init.conf"))
22-
return new AppInit();
21+
if (cacheconf.Item1 == null)
22+
{
23+
if (!File.Exists("init.conf"))
24+
{
25+
cacheconf.Item1 = new AppInit();
26+
return;
27+
}
28+
}
29+
30+
var lastWriteTime = File.GetLastWriteTime("init.conf");
31+
32+
if (cacheconf.Item2 != lastWriteTime)
33+
{
34+
cacheconf.Item1 = JsonConvert.DeserializeObject<AppInit>(File.ReadAllText("init.conf"));
35+
cacheconf.Item2 = lastWriteTime;
36+
}
2337
}
38+
catch { }
39+
}
2440

25-
var lastWriteTime = File.GetLastWriteTime("init.conf");
41+
updateConf();
2642

27-
if (cacheconf.Item2 != lastWriteTime)
43+
ThreadPool.QueueUserWorkItem(async _ =>
44+
{
45+
while (true)
2846
{
29-
cacheconf.Item1 = JsonConvert.DeserializeObject<AppInit>(File.ReadAllText("init.conf"));
30-
cacheconf.Item2 = lastWriteTime;
47+
await Task.Delay(TimeSpan.FromSeconds(10));
48+
updateConf();
3149
}
32-
33-
return cacheconf.Item1;
34-
}
50+
});
3551
}
52+
53+
static (AppInit, DateTime) cacheconf = default;
54+
55+
public static AppInit conf => cacheconf.Item1;
3656
#endregion
3757

3858

@@ -72,7 +92,7 @@ public static AppInit conf
7292

7393
public string[] synctrackers = null;
7494

75-
public string[] disable_trackers = new string[] { "hdrezka", "anifilm" };
95+
public string[] disable_trackers = new string[] { "hdrezka", "anifilm", "anilibria" };
7696

7797
public bool syncsport = true;
7898

Controllers/ApiController.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public ActionResult Jackett(string apikey, string query, string title, string ti
6464
{
6565
//Console.WriteLine(HttpContext.Request.Path + HttpContext.Request.QueryString.Value);
6666

67+
string cachekey = $"api:v2.0:indexers:{query}:{title}:{title_original}:{year}:{(category != null && category.Count > 0 ? string.Join(",", category.Select(i => $"{i.Key}={i.Value}")) : "null")}:{is_serial}";
68+
if (memoryCache.TryGetValue(cachekey, out List<Result> _cacheResult))
69+
return Json(new RootObject() { Results = _cacheResult });
70+
6771
var fastdb = getFastdb();
6872
var torrents = new Dictionary<string, TorrentDetails>();
6973
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";
@@ -458,10 +462,10 @@ HashSet<int> getCategoryIds(TorrentDetails t, out string categoryDesc)
458462
{
459463
Dictionary<string, (TorrentDetails torrent, string title, string Name, List<string> AnnounceUrls)> temp = new Dictionary<string, (TorrentDetails, string, string, List<string>)>();
460464

461-
foreach (var torrent in torrents.Values)
465+
foreach (var torrent in torrents.Values.OrderByDescending(i => i.createTime).ThenBy(i => i.trackerName == "selezen"))
462466
{
463467
var magnetLink = MagnetLink.Parse(torrent.magnet);
464-
string hex = magnetLink.InfoHash.ToHex();
468+
string hex = magnetLink.InfoHashes.V1OrV2.ToHex();
465469

466470
if (!temp.TryGetValue(hex, out _))
467471
{
@@ -547,11 +551,14 @@ void UpdateTitle()
547551
}
548552
#endregion
549553

550-
if (torrent.sid > t.torrent.sid)
551-
t.torrent.sid = torrent.sid;
554+
if (torrent.trackerName != "selezen")
555+
{
556+
if (torrent.sid > t.torrent.sid)
557+
t.torrent.sid = torrent.sid;
552558

553-
if (torrent.pir > t.torrent.pir)
554-
t.torrent.pir = torrent.pir;
559+
if (torrent.pir > t.torrent.pir)
560+
t.torrent.pir = torrent.pir;
561+
}
555562

556563
if (torrent.createTime > t.torrent.createTime)
557564
t.torrent.createTime = torrent.createTime;
@@ -601,7 +608,7 @@ List<ffStream> FFprobe(TorrentDetails t, out HashSet<string> langs)
601608
return t.ffprobe;
602609
}
603610

604-
var streams = TracksDB.Get(t.magnet, t.types);
611+
var streams = TracksDB.Get(t.magnet, t.types, onlydb: true);
605612
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
606613
if (streams == null)
607614
return null;
@@ -646,6 +653,9 @@ List<ffStream> FFprobe(TorrentDetails t, out HashSet<string> langs)
646653
});
647654
}
648655

656+
if (AppInit.conf.evercache.enable && AppInit.conf.evercache.validHour == 0)
657+
memoryCache.Set(cachekey, Results, DateTime.Now.AddMinutes(5));
658+
649659
return Json(new RootObject() { Results = Results });
650660
}
651661
#endregion
@@ -847,7 +857,7 @@ void AddTorrents(TorrentDetails t)
847857
langs = TracksDB.Languages(t, t.ffprobe);
848858
else
849859
{
850-
var streams = TracksDB.Get(t.magnet, t.types);
860+
var streams = TracksDB.Get(t.magnet, t.types, onlydb: true);
851861
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
852862
}
853863

@@ -930,7 +940,7 @@ public static Dictionary<string, List<string>> getFastdb(bool update = false)
930940
{
931941
var fastdb = new Dictionary<string, List<string>>();
932942

933-
foreach (var item in FileDB.masterDb)
943+
foreach (var item in FileDB.masterDb.ToArray())
934944
{
935945
foreach (string k in item.Key.Split(":"))
936946
{

Controllers/CRON/AniLibriaController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ async public Task<string> Parse(int limit)
8181
}
8282
}
8383
catch { }
84+
finally
85+
{
86+
workParse = false;
87+
}
8488

85-
workParse = false;
8689
return "ok";
8790
}
8891
}

Controllers/CRON/AnifilmController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ async public Task<string> Parse(bool fullparse)
6464
}
6565
}
6666
catch { }
67+
finally
68+
{
69+
workParse = false;
70+
}
6771

68-
workParse = false;
6972
return string.IsNullOrWhiteSpace(log) ? "ok" : log;
7073
}
7174
#endregion

Controllers/CRON/AnimeLayerController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ async public Task<string> Parse(int maxpage = 1)
114114
}
115115
}
116116
catch { }
117+
finally
118+
{
119+
workParse = false;
120+
}
117121

118-
workParse = false;
119122
return "ok";
120123
}
121124
#endregion

Controllers/CRON/BaibakoController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ async public Task<string> Parse(int maxpage)
113113
}
114114
}
115115
catch { }
116+
finally
117+
{
118+
workParse = false;
119+
}
116120

117-
workParse = false;
118121
return "ok";
119122
}
120123
#endregion

Controllers/CRON/BitruController.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,30 @@ static BitruController()
2727

2828

2929
#region Parse
30+
static bool _workParse = false;
31+
3032
async public Task<string> Parse(int page = 1)
3133
{
34+
if (_workParse)
35+
return "work";
36+
37+
_workParse = true;
3238
string log = "";
3339

34-
// movie - Фильмы | Фильмы
35-
// serial - Сериалы | Сериалы
36-
foreach (string cat in new List<string>() { "movie", "serial" })
40+
try
41+
{
42+
// movie - Фильмы | Фильмы
43+
// serial - Сериалы | Сериалы
44+
foreach (string cat in new List<string>() { "movie", "serial" })
45+
{
46+
await parsePage(cat, page);
47+
log += $"{cat} - {page}\n";
48+
}
49+
}
50+
catch { }
51+
finally
3752
{
38-
await parsePage(cat, page);
39-
log += $"{cat} - {page}\n";
53+
_workParse = false;
4054
}
4155

4256
return string.IsNullOrWhiteSpace(log) ? "ok" : log;

Controllers/CRON/HDRezkaController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ async public Task<string> Parse(int maxpage = 1)
3636
}
3737
}
3838
catch { }
39+
finally
40+
{
41+
workParse = false;
42+
}
3943

40-
workParse = false;
4144
return "ok";
4245
}
4346
#endregion

Controllers/CRON/KinozalController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ async public Task<string> Parse(int page)
131131
}
132132
}
133133
catch { }
134+
finally
135+
{
136+
_workParse = false;
137+
}
134138

135-
_workParse = false;
136139
return string.IsNullOrWhiteSpace(log) ? "ok" : log;
137140
}
138141
#endregion

Controllers/CRON/LostfilmController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ async public Task<string> Parse(int maxpage = 1)
129129
}
130130
}
131131
catch { }
132+
finally
133+
{
134+
_workParse = false;
135+
}
132136

133-
_workParse = false;
134137
return "ok";
135138
}
136139
#endregion

0 commit comments

Comments
 (0)