Skip to content

Commit de2017b

Browse files
authored
Merge branch 'master' into feature/docker-container
2 parents 297c0fb + 93c1b7b commit de2017b

File tree

8 files changed

+185
-19
lines changed

8 files changed

+185
-19
lines changed

AppInit.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ public static AppInit conf
7272

7373
public string[] synctrackers = null;
7474

75+
public string[] disable_trackers = new string[] { "hdrezka", "anifilm" };
76+
7577
public bool syncsport = true;
7678

77-
public bool syncspidr = false;
79+
public bool syncspidr = true;
7880

7981
public int maxreadfile = 200;
8082

Controllers/ApiController.cs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using JacRed.Models.Details;
1414
using JacRed.Models.Tracks;
1515
using JacRed.Models.Api;
16+
using Microsoft.AspNetCore.Http;
1617

1718
namespace JacRed.Controllers
1819
{
@@ -24,6 +25,30 @@ public ActionResult Index()
2425
return File(System.IO.File.OpenRead("wwwroot/index.html"), "text/html");
2526
}
2627

28+
[Route("health")]
29+
public IActionResult Health()
30+
{
31+
return Json(new Dictionary<string, string>
32+
{
33+
["status"] = "OK"
34+
});
35+
}
36+
37+
[Route("version")]
38+
public ActionResult Version()
39+
{
40+
return Content("11", contentType: "text/plain; charset=utf-8");
41+
}
42+
43+
[Route("lastupdatedb")]
44+
public ActionResult LastUpdateDB()
45+
{
46+
if (FileDB.masterDb == null || FileDB.masterDb.Count == 0)
47+
return Content("01.01.2000 01:01", contentType: "text/plain; charset=utf-8");
48+
49+
return Content(FileDB.masterDb.OrderByDescending(i => i.Value.updateTime).First().Value.updateTime.ToString("dd.MM.yyyy HH:mm"), contentType: "text/plain; charset=utf-8");
50+
}
51+
2752
[Route("api/v1.0/conf")]
2853
public JsonResult JacRedConf(string apikey)
2954
{
@@ -107,6 +132,9 @@ void AddTorrents(TorrentDetails t)
107132
if (AppInit.conf.synctrackers != null && !AppInit.conf.synctrackers.Contains(t.trackerName))
108133
return;
109134

135+
if (AppInit.conf.disable_trackers != null && AppInit.conf.disable_trackers.Contains(t.trackerName))
136+
return;
137+
110138
if (torrents.TryGetValue(t.url, out TorrentDetails val))
111139
{
112140
if (t.updateTime > val.updateTime)
@@ -665,6 +693,9 @@ void AddTorrents(TorrentDetails t)
665693
if (AppInit.conf.synctrackers != null && !AppInit.conf.synctrackers.Contains(t.trackerName))
666694
return;
667695

696+
if (AppInit.conf.disable_trackers != null && AppInit.conf.disable_trackers.Contains(t.trackerName))
697+
return;
698+
668699
if (torrents.TryGetValue(t.url, out TorrentDetails val))
669700
{
670701
if (t.updateTime > val.updateTime)
@@ -793,6 +824,102 @@ void AddTorrents(TorrentDetails t)
793824
}
794825
#endregion
795826

827+
#region Qualitys
828+
[Route("/api/v1.0/qualitys")]
829+
public JsonResult Qualitys(string name, string originalname, string type, int page = 1, int take = 1000)
830+
{
831+
var torrents = new Dictionary<string, Dictionary<int, Models.TorrentQuality>>();
832+
833+
#region AddTorrents
834+
void AddTorrents(TorrentDetails t)
835+
{
836+
if (t?.types == null || t.types.Contains("sport") || t.relased == 0)
837+
return;
838+
839+
if (!string.IsNullOrEmpty(type) && !t.types.Contains(type))
840+
return;
841+
842+
string key = $"{StringConvert.SearchName(t.name)}:{StringConvert.SearchName(t.originalname)}";
843+
844+
var langs = t.languages;
845+
846+
if (t.ffprobe != null || !AppInit.conf.tracks)
847+
langs = TracksDB.Languages(t, t.ffprobe);
848+
else
849+
{
850+
var streams = TracksDB.Get(t.magnet, t.types);
851+
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
852+
}
853+
854+
var model = new Models.TorrentQuality()
855+
{
856+
types = t.types.ToHashSet(),
857+
createTime = t.createTime,
858+
updateTime = t.updateTime,
859+
languages = langs ?? new HashSet<string>(),
860+
qualitys = new HashSet<int>() { t.quality }
861+
};
862+
863+
if (torrents.TryGetValue(key, out Dictionary<int, Models.TorrentQuality> val))
864+
{
865+
if (val.TryGetValue(t.relased, out Models.TorrentQuality _md))
866+
{
867+
if (langs != null)
868+
{
869+
foreach (var item in langs)
870+
_md.languages.Add(item);
871+
}
872+
873+
if (t.types != null)
874+
{
875+
foreach (var item in t.types)
876+
_md.types.Add(item);
877+
}
878+
879+
_md.qualitys.Add(t.quality);
880+
881+
if (_md.createTime > t.createTime)
882+
_md.createTime = t.createTime;
883+
884+
if (t.updateTime > _md.updateTime)
885+
_md.updateTime = t.updateTime;
886+
887+
val[t.relased] = _md;
888+
}
889+
else
890+
{
891+
val.TryAdd(t.relased, model);
892+
}
893+
894+
torrents[key] = val;
895+
}
896+
else
897+
{
898+
torrents.TryAdd(key, new Dictionary<int, Models.TorrentQuality>() { [t.relased] = model });
899+
}
900+
}
901+
#endregion
902+
903+
string _s = StringConvert.SearchName(name);
904+
string _so = StringConvert.SearchName(originalname);
905+
906+
var mdb = FileDB.masterDb.OrderByDescending(i => i.Value.updateTime).Where(i => (_s == null && _so == null) || (_s != null && i.Key.Contains(_s)) || (_so != null && i.Key.Contains(_so)));
907+
if (!AppInit.conf.evercache.enable || AppInit.conf.evercache.validHour > 0)
908+
mdb = mdb.Take(AppInit.conf.maxreadfile);
909+
910+
foreach (var val in mdb)
911+
{
912+
foreach (var t in FileDB.OpenRead(val.Key, true).Values)
913+
AddTorrents(t);
914+
}
915+
916+
if (take == -1)
917+
return Json(torrents);
918+
919+
return Json(torrents.Skip((page * take) - take).Take(take));
920+
}
921+
#endregion
922+
796923

797924
#region getFastdb
798925
static Dictionary<string, List<string>> _fastdb = null;

Controllers/CRON/MegapeerController.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ async public Task<string> UpdateTasksParse()
8080
continue;
8181

8282
// Максимальное количиство страниц
83-
int.TryParse(Regex.Match(html, ">Всего: ([0-9]+)</td>").Groups[1].Value, out int maxpages);
83+
int.TryParse(Regex.Match(html, ">Всего: ([0-9]+)").Groups[1].Value, out int maxpages);
8484
maxpages = maxpages / 50;
8585

8686
if (maxpages > 0)
8787
{
88+
if (maxpages > 10)
89+
maxpages = 10;
90+
8891
// Загружаем список страниц в список задач
8992
for (int page = 0; page < maxpages; page++)
9093
{
@@ -162,7 +165,7 @@ async Task<bool> parsePage(string cat, int page)
162165

163166
var torrents = new List<MegapeerDetails>();
164167

165-
foreach (string row in html.Split("class=\"tCenter hl-tr\"").Skip(1))
168+
foreach (string row in html.Split("class=\"table_fon\"").Skip(1))
166169
{
167170
#region Локальный метод - Match
168171
string Match(string pattern, int index = 1)
@@ -174,21 +177,24 @@ string Match(string pattern, int index = 1)
174177
#endregion
175178

176179
#region createTime
177-
DateTime createTime = tParse.ParseCreateTime(Match("<span>Добавлен:</span> ([0-9]+ [^ ]+ [0-9]+)"), "dd.MM.yyyy");
180+
DateTime createTime = tParse.ParseCreateTime(Match("<td>([0-9]+ [^ ]+ [0-9]+)</td><td>"), "dd.MM.yy");
178181
if (createTime == default)
179182
continue;
180183
#endregion
181184

182185
#region Данные раздачи
183-
string url = Match("href=\"/(torrent/[0-9]+)\"");
184-
string title = Match("class=\"med tLink hl-tags bold\" [^>]+>([^\n\r]+)</a>");
185-
title = Regex.Replace(title, "<[^>]+>", "");
186+
string url = Match("href=\"/(torrent/[0-9]+)");
187+
string title = Match("class=\"url\">([^<]+)</a></td>");
188+
//title = Regex.Replace(title, "<[^>]+>", "");
186189

187-
string sizeName = Match("href=\"download/[0-9]+\">([\n\r\t ]+)?([^<\n\r]+)<", 2).Trim();
190+
string sizeName = Match("<td align=\"right\">([^<\n\r]+)", 1).Trim();
188191

189192
if (string.IsNullOrWhiteSpace(title))
190193
continue;
191194

195+
string _sid = Match("alt=\"S\"><font [^>]+>([0-9]+)</font>", 1);
196+
string _pir = Match("alt=\"L\"><font [^>]+>([0-9]+)</font>", 1);
197+
192198
url = $"{AppInit.conf.Megapeer.host}/{url}";
193199
#endregion
194200

@@ -382,13 +388,17 @@ string Match(string pattern, int index = 1)
382388
if (string.IsNullOrWhiteSpace(downloadid))
383389
continue;
384390

391+
int.TryParse(_sid, out int sid);
392+
int.TryParse(_pir, out int pir);
393+
385394
torrents.Add(new MegapeerDetails()
386395
{
387396
trackerName = "megapeer",
388397
types = types,
389398
url = url,
390399
title = title,
391-
sid = 1,
400+
sid = sid,
401+
pir = pir,
392402
sizeName = sizeName,
393403
createTime = createTime,
394404
name = name,

JacRed.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</ItemGroup>
3636

3737
<ItemGroup>
38-
<RuntimeHostConfigurationOption Include="System.GC.HeapCount" Value="60" />
38+
<!--<RuntimeHostConfigurationOption Include="System.GC.HeapCount" Value="60" />-->
3939
<!--<RuntimeHostConfigurationOption Include="System.GC.HeapHardLimit" Value="600000000" />-->
4040
</ItemGroup>
4141

Models/TorrentQuality.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace JacRed.Models
5+
{
6+
public class TorrentQuality
7+
{
8+
public HashSet<int> qualitys { get; set; } = new HashSet<int>();
9+
10+
public HashSet<string> types { get; set; } = new HashSet<string>();
11+
12+
public HashSet<string> languages { get; set; } = new HashSet<string>();
13+
14+
15+
public DateTime createTime { get; set; }
16+
17+
public DateTime updateTime { get; set; }
18+
}
19+
}

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ services:
4343

4444
```
4545

46-
# Настройка парсера
46+
* ПО УМОЛЧАНИЯ НАСТРОЕНА СИНХРОНИЗАЦИЯ БАЗЫ С ВНЕШНЕГО СЕРВЕРА
47+
48+
# Источники
49+
Kinozal, Nnmclub, Rutor, Torrentby, Bitru, Rutracker, Megapeer, Selezen, Toloka (UKR), Baibako, LostFilm, Anilibria, Animelayer
50+
51+
# Самостоятельный парсинг источников
4752
1. Настроить init.conf (пример настроек в example.conf)
4853
2. Перенести в crontab "Data/crontab" или указать сервер "syncapi" в init.conf
4954

50-
# Источники
51-
Kinozal, Nnmclub, Rutor, Torrentby, Bitru, Rutracker, Megapeer, Selezen, Toloka (UKR), Rezka, Baibako, LostFilm, Anilibria, Animelayer, Anifilm
52-
5355
# Доступ к доменам .onion
5456
1. Запустить tor на порту 9050
5557
2. В init.conf указать .onion домен в host
@@ -63,11 +65,10 @@ Kinozal, Nnmclub, Rutor, Torrentby, Bitru, Rutracker, Megapeer, Selezen, Toloka
6365
* timeSync - интервал синхронизации с базой syncapi
6466
* maxreadfile - максимальное количество открытых файлов за один поисковый запрос
6567
* evercache - хранить открытые файлы в кеше (рекомендуется для общего доступа с высокой нагрузкой)
66-
* fdbPathLevels - для релиза 25.01.2023 установить в 1
67-
* timeStatsUpdate - интервал обновления статистики в минутах
68+
* timeStatsUpdate - интервал обновления статистики в минутах
6869

6970

70-
# Настройка init.conf
71+
# Пример init.conf
7172
* Список всех параметров, а так же значения по умолчанию смотреть в example.conf
7273
* В init.conf нужно указывать только те параметры, которые хотите изменить
7374

Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ public void Configure(IApplicationBuilder app)
6161

6262
app.UseRouting();
6363
app.UseResponseCompression();
64-
app.UseModHeaders();
6564

6665
if (AppInit.conf.web)
6766
app.UseStaticFiles();
6867

68+
app.UseModHeaders();
69+
6970
app.UseEndpoints(endpoints =>
7071
{
7172
endpoints.MapControllers();

install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ source ~/.bashrc
1515
# Download zip
1616
mkdir $DEST -p && cd $DEST
1717
wget https://github.com/immisterio/jacred-fdb/releases/latest/download/publish.zip
18-
unzip -o publish.zip
18+
unzip -oq publish.zip
1919
rm -f publish.zip
2020

21+
# Download database
22+
wget http://redb.cfhttp.top/latest.zip
23+
echo "Unpacking the database"
24+
unzip -oq latest.zip
25+
rm -f latest.zip
26+
2127
# Create service
2228
echo ""
2329
echo "Install service to /etc/systemd/system/jacred.service ..."

0 commit comments

Comments
 (0)