|
13 | 13 | using JacRed.Models.Details; |
14 | 14 | using JacRed.Models.Tracks; |
15 | 15 | using JacRed.Models.Api; |
| 16 | +using Microsoft.AspNetCore.Http; |
16 | 17 |
|
17 | 18 | namespace JacRed.Controllers |
18 | 19 | { |
@@ -793,6 +794,102 @@ void AddTorrents(TorrentDetails t) |
793 | 794 | } |
794 | 795 | #endregion |
795 | 796 |
|
| 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 | + |
796 | 893 |
|
797 | 894 | #region getFastdb |
798 | 895 | static Dictionary<string, List<string>> _fastdb = null; |
|
0 commit comments