Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
immisterio committed Jul 28, 2024
1 parent 12b719b commit 2457e97
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
97 changes: 97 additions & 0 deletions Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using JacRed.Models.Details;
using JacRed.Models.Tracks;
using JacRed.Models.Api;
using Microsoft.AspNetCore.Http;

namespace JacRed.Controllers
{
Expand Down Expand Up @@ -793,6 +794,102 @@ void AddTorrents(TorrentDetails t)
}
#endregion

#region Qualitys
[Route("/api/v1.0/qualitys")]
public JsonResult Qualitys(string name, string originalname, string type, int page = 1, int take = 1000)
{
var torrents = new Dictionary<string, Dictionary<int, Models.TorrentQuality>>();

#region AddTorrents
void AddTorrents(TorrentDetails t)
{
if (t?.types == null || t.types.Contains("sport") || t.relased == 0)
return;

if (!string.IsNullOrEmpty(type) && !t.types.Contains(type))
return;

string key = $"{StringConvert.SearchName(t.name)}:{StringConvert.SearchName(t.originalname)}";

var langs = t.languages;

if (t.ffprobe != null || !AppInit.conf.tracks)
langs = TracksDB.Languages(t, t.ffprobe);
else
{
var streams = TracksDB.Get(t.magnet, t.types);
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
}

var model = new Models.TorrentQuality()
{
types = t.types.ToHashSet(),
createTime = t.createTime,
updateTime = t.updateTime,
languages = langs ?? new HashSet<string>(),
qualitys = new HashSet<int>() { t.quality }
};

if (torrents.TryGetValue(key, out Dictionary<int, Models.TorrentQuality> val))
{
if (val.TryGetValue(t.relased, out Models.TorrentQuality _md))
{
if (langs != null)
{
foreach (var item in langs)
_md.languages.Add(item);
}

if (t.types != null)
{
foreach (var item in t.types)
_md.types.Add(item);
}

_md.qualitys.Add(t.quality);

if (_md.createTime > t.createTime)
_md.createTime = t.createTime;

if (t.updateTime > _md.updateTime)
_md.updateTime = t.updateTime;

val[t.relased] = _md;
}
else
{
val.TryAdd(t.relased, model);
}

torrents[key] = val;
}
else
{
torrents.TryAdd(key, new Dictionary<int, Models.TorrentQuality>() { [t.relased] = model });
}
}
#endregion

string _s = StringConvert.SearchName(name);
string _so = StringConvert.SearchName(originalname);

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)));
if (!AppInit.conf.evercache.enable || AppInit.conf.evercache.validHour > 0)
mdb = mdb.Take(AppInit.conf.maxreadfile);

foreach (var val in mdb)
{
foreach (var t in FileDB.OpenRead(val.Key, true).Values)
AddTorrents(t);
}

if (take == -1)
return Json(torrents);

return Json(torrents.Skip((page * take) - take).Take(take));
}
#endregion


#region getFastdb
static Dictionary<string, List<string>> _fastdb = null;
Expand Down
2 changes: 1 addition & 1 deletion JacRed.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.GC.HeapCount" Value="60" />
<!--<RuntimeHostConfigurationOption Include="System.GC.HeapCount" Value="60" />-->
<!--<RuntimeHostConfigurationOption Include="System.GC.HeapHardLimit" Value="600000000" />-->
</ItemGroup>

Expand Down
19 changes: 19 additions & 0 deletions Models/TorrentQuality.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace JacRed.Models
{
public class TorrentQuality
{
public HashSet<int> qualitys { get; set; } = new HashSet<int>();

public HashSet<string> types { get; set; } = new HashSet<string>();

public HashSet<string> languages { get; set; } = new HashSet<string>();


public DateTime createTime { get; set; }

public DateTime updateTime { get; set; }
}
}

0 comments on commit 2457e97

Please sign in to comment.