From bec3a409e001d425b001a54086e7a2770651a7b2 Mon Sep 17 00:00:00 2001 From: immisterio <96652250+immisterio@users.noreply.github.com> Date: Sat, 17 Jun 2023 17:32:41 +0300 Subject: [PATCH] fix --- AppInit.cs | 2 +- Controllers/CRON/AnimeLayerController.cs | 17 ++++++++++++----- Controllers/CRON/BaibakoController.cs | 19 +++++++++++++------ Controllers/CRON/SelezenController.cs | 14 ++++++++++---- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/AppInit.cs b/AppInit.cs index ce173ff..d167f79 100644 --- a/AppInit.cs +++ b/AppInit.cs @@ -88,7 +88,7 @@ public static AppInit conf public TrackerSettings Anidub = new TrackerSettings("https://tr.anidub.com"); - public TrackerSettings Anifilm = new TrackerSettings("https://anifilm.tv"); + public TrackerSettings Anifilm = new TrackerSettings("https://anifilm.net"); public TrackerSettings Rezka = new TrackerSettings("https://rezka.cc"); diff --git a/Controllers/CRON/AnimeLayerController.cs b/Controllers/CRON/AnimeLayerController.cs index f4fb2ee..0b5d3e1 100644 --- a/Controllers/CRON/AnimeLayerController.cs +++ b/Controllers/CRON/AnimeLayerController.cs @@ -8,6 +8,7 @@ using JacRed.Engine.CORE; using JacRed.Models.Details; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Caching.Memory; namespace JacRed.Controllers.CRON { @@ -15,9 +16,15 @@ namespace JacRed.Controllers.CRON public class AnimeLayerController : BaseController { #region TakeLogin - static string Cookie { get; set; } + static string Cookie(IMemoryCache memoryCache) + { + if (memoryCache.TryGetValue("animelayer:cookie", out string cookie)) + return cookie; + + return null; + } - async public static Task TakeLogin() + async public Task TakeLogin() { try { @@ -63,7 +70,7 @@ async public static Task TakeLogin() if (!string.IsNullOrWhiteSpace(layer_id) && !string.IsNullOrWhiteSpace(layer_hash) && !string.IsNullOrWhiteSpace(PHPSESSID)) { - Cookie = $"layer_id={layer_id}; layer_hash={layer_hash}; PHPSESSID={PHPSESSID};"; + memoryCache.Set("animelayer:cookie", $"layer_id={layer_id}; layer_hash={layer_hash}; PHPSESSID={PHPSESSID};", DateTime.Now.AddDays(1)); return true; } } @@ -84,7 +91,7 @@ async public static Task TakeLogin() async public Task Parse(int maxpage = 1) { #region Авторизация - if (Cookie == null) + if (Cookie(memoryCache) == null) { if (await TakeLogin() == false) return "Не удалось авторизоваться"; @@ -237,7 +244,7 @@ await FileDB.AddOrUpdate(torrents, async (t, db) => if (db.TryGetValue(t.url, out TorrentDetails _tcache) && _tcache.title == t.title) return true; - byte[] torrent = await HttpClient.Download($"{t.url}download/", cookie: Cookie); + byte[] torrent = await HttpClient.Download($"{t.url}download/", cookie: Cookie(memoryCache)); string magnet = BencodeTo.Magnet(torrent); string sizeName = BencodeTo.SizeName(torrent); if (!string.IsNullOrWhiteSpace(magnet) && !string.IsNullOrWhiteSpace(sizeName)) diff --git a/Controllers/CRON/BaibakoController.cs b/Controllers/CRON/BaibakoController.cs index 6ae6e3c..b47a177 100644 --- a/Controllers/CRON/BaibakoController.cs +++ b/Controllers/CRON/BaibakoController.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using JacRed.Engine; using JacRed.Models.Details; +using Microsoft.Extensions.Caching.Memory; namespace JacRed.Controllers.CRON { @@ -16,9 +17,15 @@ namespace JacRed.Controllers.CRON public class BaibakoController : BaseController { #region TakeLogin - static string cookie { get; set; } + static string Cookie(IMemoryCache memoryCache) + { + if (memoryCache.TryGetValue("baibako:cookie", out string cookie)) + return cookie; + + return null; + } - async public static Task TakeLogin() + async public Task TakeLogin() { try { @@ -62,7 +69,7 @@ async public static Task TakeLogin() if (!string.IsNullOrWhiteSpace(sessid) && !string.IsNullOrWhiteSpace(uid) && !string.IsNullOrWhiteSpace(pass)) { - cookie = $"PHPSESSID={sessid}; uid={uid}; pass={pass}"; + memoryCache.Set("baibako:cookie", $"PHPSESSID={sessid}; uid={uid}; pass={pass}", DateTime.Now.AddDays(1)); return true; } } @@ -83,7 +90,7 @@ async public static Task TakeLogin() async public Task Parse(int maxpage) { #region Авторизация - if (cookie == null) + if (Cookie(memoryCache) == null) { if (await TakeLogin() == false) return "Не удалось авторизоваться"; @@ -116,7 +123,7 @@ async public Task Parse(int maxpage) #region parsePage async Task parsePage(int page) { - string html = await HttpClient.Get($"{AppInit.conf.Baibako.host}/browse.php?page={page}", encoding: Encoding.GetEncoding(1251), cookie: cookie); + string html = await HttpClient.Get($"{AppInit.conf.Baibako.host}/browse.php?page={page}", encoding: Encoding.GetEncoding(1251), cookie: Cookie(memoryCache)); if (html == null || !html.Contains("id=\"navtop\"")) return false; @@ -201,7 +208,7 @@ await FileDB.AddOrUpdate(torrents, async (t, db) => if (db.TryGetValue(t.url, out TorrentDetails _tcache) && _tcache.title == t.title) return true; - byte[] torrent = await HttpClient.Download(t.downloadUri, cookie: cookie, referer: $"{AppInit.conf.Baibako.host}/browse.php"); + byte[] torrent = await HttpClient.Download(t.downloadUri, cookie: Cookie(memoryCache), referer: $"{AppInit.conf.Baibako.host}/browse.php"); string magnet = BencodeTo.Magnet(torrent); string sizeName = BencodeTo.SizeName(torrent); diff --git a/Controllers/CRON/SelezenController.cs b/Controllers/CRON/SelezenController.cs index a94e44c..52a0989 100644 --- a/Controllers/CRON/SelezenController.cs +++ b/Controllers/CRON/SelezenController.cs @@ -27,7 +27,13 @@ static SelezenController() } #region Cookie / TakeLogin - static string Cookie; + static string Cookie(IMemoryCache memoryCache) + { + if (memoryCache.TryGetValue("selezen:cookie", out string cookie)) + return cookie; + + return null; + } async Task TakeLogin() { @@ -77,7 +83,7 @@ async Task TakeLogin() if (!string.IsNullOrWhiteSpace(PHPSESSID)) { - Cookie = $"PHPSESSID={PHPSESSID}; _ym_isad=2;"; + memoryCache.Set("selezen:cookie", $"PHPSESSID={PHPSESSID}; _ym_isad=2;", DateTime.Now.AddDays(1)); return true; } } @@ -167,14 +173,14 @@ async public Task ParseAllTask() async Task parsePage(int page) { #region Авторизация - if (Cookie == null && string.IsNullOrEmpty(AppInit.conf.Selezen.cookie)) + if (Cookie(memoryCache) == null && string.IsNullOrEmpty(AppInit.conf.Selezen.cookie)) { if (await TakeLogin() == false) return false; } #endregion - string cookie = AppInit.conf.Selezen.cookie ?? Cookie; + string cookie = AppInit.conf.Selezen.cookie ?? Cookie(memoryCache); string html = await HttpClient.Get(page == 1 ? $"{AppInit.conf.Selezen.host}/relizy-ot-selezen/" : $"{AppInit.conf.Selezen.host}/relizy-ot-selezen/page/{page}/", cookie: cookie, useproxy: AppInit.conf.Selezen.useproxy); if (html == null || !html.Contains("dle_root")) return false;