using Microsoft.AspNetCore.Mvc; namespace JacRed.Controllers { [Route("bitru/[action]")] public class BitruController : JacBaseController { #region search public static Task search(string host, ConcurrentBag torrents, string query, string[] cats) { if (!jackett.Bitru.enable || jackett.Bitru.showdown) return Task.FromResult(false); return Joinparse(torrents, () => parsePage(host, query, cats)); } #endregion #region parseMagnet async public Task parseMagnet(string id, bool usecache) { if (!jackett.Bitru.enable) return Content("disable"); var proxyManager = new ProxyManager("bitru", jackett.Bitru); byte[] _t = await Http.Download($"{jackett.Bitru.host}/download.php?id={id}", referer: $"{jackett.Bitru}/details.php?id={id}", proxy: proxyManager.Get()); if (_t != null && BencodeTo.Magnet(_t) != null) return File(_t, "application/x-bittorrent"); proxyManager.Refresh(); return Content("error"); } #endregion #region parsePage async static ValueTask> parsePage(string host, string query, string[] cats) { #region html var proxyManager = new ProxyManager("bitru", jackett.Bitru); string html = await Http.Get($"{jackett.Bitru.host}/browse.php?s={HttpUtility.HtmlEncode(query)}&sort=&tmp=&cat=&subcat=&year=&country=&sound=&soundtrack=&subtitles=#content", proxy: proxyManager.Get(), timeoutSeconds: jackett.timeoutSeconds); if (html == null || !html.Contains("id=\"logo\"")) { consoleErrorLog("bitru"); proxyManager.Refresh(); return null; } #endregion var torrents = new List(); foreach (string row in html.Split("
Аниме")) continue; #region Локальный метод - Match string Match(string pattern, int index = 1) { string res = HttpUtility.HtmlDecode(new Regex(pattern, RegexOptions.IgnoreCase).Match(row).Groups[index].Value.Trim()); res = Regex.Replace(res, "[\n\r\t ]+", " "); return res.Trim(); } #endregion #region Дата создания DateTime createTime = default; if (row.Contains("Сегодня")) { createTime = DateTime.Today; } else if (row.Contains("Вчера")) { createTime = DateTime.Today.AddDays(-1); } else { createTime = tParse.ParseCreateTime(Match("
(]+>)?([0-9]{2} [^ ]+ [0-9]{4}) в [0-9]{2}:[0-9]{2} от ([^<]+)
"); string _sid = Match("([0-9]+)"); string _pir = Match("([0-9]+)"); string sizeName = Match("title=\"Размер\">([^<]+)"); if (string.IsNullOrWhiteSpace(cat) || string.IsNullOrWhiteSpace(newsid) || string.IsNullOrWhiteSpace(title)) continue; if (!title.ToLower().Contains(query.ToLower())) continue; #endregion #region types string[] types = null; switch (cat) { case "movie": types = new string[] { "movie" }; break; case "serial": types = new string[] { "serial" }; break; } if (cats != null) { if (types == null) continue; bool isok = false; foreach (string c in cats) { if (types.Contains(c)) isok = true; } if (!isok) continue; } #endregion int.TryParse(_sid, out int sid); int.TryParse(_pir, out int pir); torrents.Add(new TorrentDetails() { types = types, url = $"{jackett.Bitru.host}/{url}", title = title, sid = sid, pir = pir, sizeName = sizeName, createTime = createTime, parselink = $"{host}/bitru/parsemagnet?id={newsid}" }); } return torrents; } #endregion } }