Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
immisterio committed Jan 25, 2023
1 parent d4148c0 commit 2da5c43
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 50 deletions.
4 changes: 2 additions & 2 deletions AppInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static AppInit conf

public bool evercache = false;

public int timeStatsUpdate = 20; // минуты
public int timeStatsUpdate = 20; // минут

public int timeSync = 20; // минуты
public int timeSync = 10; // минут


public TrackerSettings Rutor = new TrackerSettings("http://rutor.info");
Expand Down
99 changes: 65 additions & 34 deletions Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public JsonResult JacRedConf(string apikey)
public ActionResult Jackett(string query, string title, string title_original, int year, int is_serial, Dictionary<string, string> category)
{
bool rqnum = false, setcache = false;
var torrents = new List<TorrentDetails>();
var torrents = new Dictionary<string, TorrentDetails>();

#region Запрос с NUM
var mNum = Regex.Match(query ?? string.Empty, "^([^a-z-A-Z]+) ([^а-я-А-Я]+) ([0-9]{4})$");
Expand Down Expand Up @@ -80,6 +80,21 @@ public ActionResult Jackett(string query, string title, string title_original, i
}
#endregion

#region AddTorrents
void AddTorrents(TorrentDetails t)
{
if (torrents.TryGetValue(t.url, out TorrentDetails val))
{
if (t.updateTime > val.updateTime)
torrents[t.url] = t;
}
else
{
torrents.TryAdd(t.url, t);
}
}
#endregion

string memoryKey = $"{AppInit.conf.mergeduplicates}:{rqnum}:{title}:{title_original}:{year}:{is_serial}";
if (memoryCache.TryGetValue(memoryKey, out string jval))
return Content(jval, "application/json; charset=utf-8");
Expand Down Expand Up @@ -114,11 +129,11 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (year > 0)
{
if (t.relased == year || t.relased == (year - 1) || t.relased == (year + 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}
#endregion
Expand All @@ -131,11 +146,11 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (year > 0)
{
if (t.relased >= (year - 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}
#endregion
Expand All @@ -148,11 +163,11 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (year > 0)
{
if (t.relased >= (year - 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}
#endregion
Expand All @@ -165,11 +180,11 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (year > 0)
{
if (t.relased >= (year - 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}
#endregion
Expand All @@ -182,11 +197,11 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (year > 0)
{
if (t.relased >= (year - 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}
#endregion
Expand All @@ -199,17 +214,17 @@ public ActionResult Jackett(string query, string title, string title_original, i
if (t.types.Contains("movie") || t.types.Contains("multfilm") || t.types.Contains("documovie"))
{
if (t.relased == year || t.relased == (year - 1) || t.relased == (year + 1))
torrents.Add(t);
AddTorrents(t);
}
else
{
if (t.relased >= (year - 1))
torrents.Add(t);
AddTorrents(t);
}
}
else
{
torrents.Add(t);
AddTorrents(t);
}
#endregion
}
Expand Down Expand Up @@ -243,31 +258,31 @@ void torrentsSearch(bool exact)
if (is_serial == 1)
{
if (t.types.Contains("movie") || t.types.Contains("multfilm") || t.types.Contains("anime") || t.types.Contains("documovie"))
torrents.Add(t);
AddTorrents(t);
}
else if (is_serial == 2)
{
if (t.types.Contains("serial") || t.types.Contains("multserial") || t.types.Contains("anime") || t.types.Contains("docuserial") || t.types.Contains("tvshow"))
torrents.Add(t);
AddTorrents(t);
}
else if (is_serial == 3)
{
if (t.types.Contains("tvshow"))
torrents.Add(t);
AddTorrents(t);
}
else if (is_serial == 4)
{
if (t.types.Contains("docuserial") || t.types.Contains("documovie"))
torrents.Add(t);
AddTorrents(t);
}
else if (is_serial == 5)
{
if (t.types.Contains("anime"))
torrents.Add(t);
AddTorrents(t);
}
else
{
torrents.Add(t);
AddTorrents(t);
}
}

Expand Down Expand Up @@ -329,13 +344,13 @@ HashSet<int> getCategoryIds(TorrentDetails t, out string categoryDesc)

if (!AppInit.conf.mergeduplicates || rqnum)
{
tsort = torrents;
tsort = torrents.Values.ToList();
}
else
{
Dictionary<string, (TorrentDetails torrent, string title, string Name, List<string> AnnounceUrls)> temp = new Dictionary<string, (TorrentDetails, string, string, List<string>)>();

foreach (var torrent in torrents)
foreach (var torrent in torrents.Values.ToList())
{
var magnetLink = MagnetLink.Parse(torrent.magnet);
string hex = magnetLink.InfoHash.ToHex();
Expand Down Expand Up @@ -489,8 +504,22 @@ async public Task<JsonResult> Torrents(string search, string altname, bool exact
#endregion

#region Выборка
IEnumerable<TorrentDetails> query = null;
var torrents = new List<TorrentDetails>();
var torrents = new Dictionary<string, TorrentDetails>();

#region AddTorrents
void AddTorrents(TorrentDetails t)
{
if (torrents.TryGetValue(t.url, out TorrentDetails val))
{
if (t.updateTime > val.updateTime)
torrents[t.url] = t;
}
else
{
torrents.TryAdd(t.url, t);
}
}
#endregion

if (string.IsNullOrWhiteSpace(search) || 3 >= search.Length)
return Json(torrents);
Expand All @@ -501,9 +530,9 @@ async public Task<JsonResult> Torrents(string search, string altname, bool exact
if (exact)
{
#region Точный поиск
foreach (var val in FileDB.masterDb.Where(i => i.Key.StartsWith($"{_s}:") || i.Key.EndsWith($":{_s}") || (_altsearch != null && i.Key.Contains(_altsearch))))
foreach (var mdb in FileDB.masterDb.Where(i => i.Key.StartsWith($"{_s}:") || i.Key.EndsWith($":{_s}") || (_altsearch != null && i.Key.Contains(_altsearch))))
{
foreach (var t in FileDB.OpenRead(val.Key).Values)
foreach (var t in FileDB.OpenRead(mdb.Key).Values)
{
if (t.types == null)
continue;
Expand All @@ -514,7 +543,7 @@ async public Task<JsonResult> Torrents(string search, string altname, bool exact
string _o = StringConvert.SearchName(t.originalname);

if (_n == _s || _o == _s || (_altsearch != null && (_n == _altsearch || _o == _altsearch)))
torrents.Add(t);
AddTorrents(t);
}
}

Expand All @@ -524,15 +553,15 @@ async public Task<JsonResult> Torrents(string search, string altname, bool exact
else
{
#region Поиск по совпадению ключа в имени
foreach (var val in FileDB.masterDb.OrderByDescending(i => i.Value).Where(i => i.Key.Contains(_s) || (_altsearch != null && i.Key.Contains(_altsearch))).Take(AppInit.conf.maxreadfile))
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))
{
foreach (var t in FileDB.OpenRead(val.Key).Values)
foreach (var t in FileDB.OpenRead(mdb.Key).Values)
{
if (t.types == null)
continue;

if (string.IsNullOrWhiteSpace(type) || t.types.Contains(type))
torrents.Add(t);
AddTorrents(t);
}

}
Expand All @@ -542,20 +571,22 @@ async public Task<JsonResult> Torrents(string search, string altname, bool exact
if (torrents.Count == 0)
return Json(torrents);

IEnumerable<TorrentDetails> query = torrents.Values;

#region sort
switch (sort ?? string.Empty)
{
case "sid":
query = torrents.OrderByDescending(i => i.sid);
query = query.OrderByDescending(i => i.sid);
break;
case "pir":
query = torrents.OrderByDescending(i => i.pir);
query = query.OrderByDescending(i => i.pir);
break;
case "size":
query = torrents.OrderByDescending(i => i.size);
query = query.OrderByDescending(i => i.size);
break;
default:
query = torrents.OrderByDescending(i => i.createTime);
query = query.OrderByDescending(i => i.createTime);
break;
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/AnifilmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async public Task<string> Parse(bool fullparse)
{
foreach (string cat in new List<string>() { "serials", "ova", "ona", "movies" })
{
await parsePage(cat, 1, DateTime.Now);
await parsePage(cat, 1, DateTime.UtcNow);
log += $"{cat} - 1\n";
}
}
Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/BitruController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ string Match(string pattern, int index = 1)

if (row.Contains("<span>Сегодня"))
{
createTime = DateTime.Today;
createTime = DateTime.UtcNow;
}
else if (row.Contains("<span>Вчера"))
{
Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/HDRezkaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ string Match(string pattern, int index = 1)
if (page != 1)
continue;

createTime = DateTime.Now;
createTime = DateTime.UtcNow;
}
#endregion

Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/KinozalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ string Match(string pattern, int index = 1)

if (row.Contains("<td class='s'>сегодня"))
{
createTime = DateTime.Today;
createTime = DateTime.UtcNow;
}
else if (row.Contains("<td class='s'>вчера"))
{
Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/LostfilmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ string Match(string pattern, int index = 1)
if (page != 1)
continue;

createTime = DateTime.Now;
createTime = DateTime.UtcNow;
}
#endregion

Expand Down
2 changes: 1 addition & 1 deletion Controllers/CRON/TorrentByController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ string Match(string pattern, int index = 1)

if (row.Contains(">Сегодня</td>"))
{
createTime = DateTime.Today;
createTime = DateTime.UtcNow;
}
else if (row.Contains(">Вчера</td>"))
{
Expand Down
23 changes: 18 additions & 5 deletions Controllers/SyncController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,33 @@ public JsonResult Torrents(long time)
if (!AppInit.conf.opensync || time == 0)
return Json(new List<string>());

int take = 2_000;
int take = 5_000;
DateTime lastsync = time == -1 ? default : DateTime.FromFileTimeUtc(time);

var torrents = new Dictionary<string, TorrentDetails>();
foreach (var item in FileDB.masterDb.OrderBy(i => i.Value).Where(i => i.Value > lastsync))
{
foreach (var torrent in FileDB.OpenRead(item.Key).OrderBy(i => i.Value.updateTime).Where(i => i.Value.updateTime > lastsync))
torrents.Add(torrent.Key, torrent.Value);
foreach (var torrent in FileDB.OpenRead(item.Key))
{
if (torrents.TryGetValue(torrent.Key, out TorrentDetails val))
{
if (torrent.Value.updateTime > val.updateTime)
torrents[torrent.Key] = torrent.Value;
}
else
{
torrents.TryAdd(torrent.Key, torrent.Value);
}
}

if (torrents.Count >= take)
if (torrents.Count > take)
{
take = torrents.Count;
break;
}
}

return Json(new { take, torrents = torrents.Take(take) });
return Json(new { take, torrents = torrents.OrderBy(i => i.Value.updateTime) });
}
}
}
1 change: 1 addition & 0 deletions Engine/FileDB/FileDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public void AddOrUpdate(TorrentBaseDetails torrent)
magnet = torrent.magnet
};

updateTime = default;
updateFullDetails(t);
db.TryAdd(t.url, t);
AddOrUpdateMasterDb(t);
Expand Down
4 changes: 2 additions & 2 deletions Engine/FileDB/staticDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public static void SaveChangesToFile()
if (!File.Exists($"Data/masterDb_{DateTime.Today:dd-MM-yyyy}.bz"))
File.Copy("Data/masterDb.bz", $"Data/masterDb_{DateTime.Today:dd-MM-yyyy}.bz");

if (File.Exists($"Data/masterDb_{DateTime.Today.AddDays(-2):dd-MM-yyyy}.bz"))
File.Delete($"Data/masterDb_{DateTime.Today.AddDays(-2):dd-MM-yyyy}.bz");
if (File.Exists($"Data/masterDb_{DateTime.Today.AddDays(-3):dd-MM-yyyy}.bz"))
File.Delete($"Data/masterDb_{DateTime.Today.AddDays(-3):dd-MM-yyyy}.bz");
}
catch { }
}
Expand Down
Loading

0 comments on commit 2da5c43

Please sign in to comment.