Skip to content

Commit 2457e97

Browse files
committed
dev
1 parent 12b719b commit 2457e97

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed

Controllers/ApiController.cs

Lines changed: 97 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
{
@@ -793,6 +794,102 @@ void AddTorrents(TorrentDetails t)
793794
}
794795
#endregion
795796

797+
#region Qualitys
798+
[Route("/api/v1.0/qualitys")]
799+
public JsonResult Qualitys(string name, string originalname, string type, int page = 1, int take = 1000)
800+
{
801+
var torrents = new Dictionary<string, Dictionary<int, Models.TorrentQuality>>();
802+
803+
#region AddTorrents
804+
void AddTorrents(TorrentDetails t)
805+
{
806+
if (t?.types == null || t.types.Contains("sport") || t.relased == 0)
807+
return;
808+
809+
if (!string.IsNullOrEmpty(type) && !t.types.Contains(type))
810+
return;
811+
812+
string key = $"{StringConvert.SearchName(t.name)}:{StringConvert.SearchName(t.originalname)}";
813+
814+
var langs = t.languages;
815+
816+
if (t.ffprobe != null || !AppInit.conf.tracks)
817+
langs = TracksDB.Languages(t, t.ffprobe);
818+
else
819+
{
820+
var streams = TracksDB.Get(t.magnet, t.types);
821+
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
822+
}
823+
824+
var model = new Models.TorrentQuality()
825+
{
826+
types = t.types.ToHashSet(),
827+
createTime = t.createTime,
828+
updateTime = t.updateTime,
829+
languages = langs ?? new HashSet<string>(),
830+
qualitys = new HashSet<int>() { t.quality }
831+
};
832+
833+
if (torrents.TryGetValue(key, out Dictionary<int, Models.TorrentQuality> val))
834+
{
835+
if (val.TryGetValue(t.relased, out Models.TorrentQuality _md))
836+
{
837+
if (langs != null)
838+
{
839+
foreach (var item in langs)
840+
_md.languages.Add(item);
841+
}
842+
843+
if (t.types != null)
844+
{
845+
foreach (var item in t.types)
846+
_md.types.Add(item);
847+
}
848+
849+
_md.qualitys.Add(t.quality);
850+
851+
if (_md.createTime > t.createTime)
852+
_md.createTime = t.createTime;
853+
854+
if (t.updateTime > _md.updateTime)
855+
_md.updateTime = t.updateTime;
856+
857+
val[t.relased] = _md;
858+
}
859+
else
860+
{
861+
val.TryAdd(t.relased, model);
862+
}
863+
864+
torrents[key] = val;
865+
}
866+
else
867+
{
868+
torrents.TryAdd(key, new Dictionary<int, Models.TorrentQuality>() { [t.relased] = model });
869+
}
870+
}
871+
#endregion
872+
873+
string _s = StringConvert.SearchName(name);
874+
string _so = StringConvert.SearchName(originalname);
875+
876+
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)));
877+
if (!AppInit.conf.evercache.enable || AppInit.conf.evercache.validHour > 0)
878+
mdb = mdb.Take(AppInit.conf.maxreadfile);
879+
880+
foreach (var val in mdb)
881+
{
882+
foreach (var t in FileDB.OpenRead(val.Key, true).Values)
883+
AddTorrents(t);
884+
}
885+
886+
if (take == -1)
887+
return Json(torrents);
888+
889+
return Json(torrents.Skip((page * take) - take).Take(take));
890+
}
891+
#endregion
892+
796893

797894
#region getFastdb
798895
static Dictionary<string, List<string>> _fastdb = null;

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+
}

0 commit comments

Comments
 (0)