Skip to content

Commit

Permalink
15.05.2023
Browse files Browse the repository at this point in the history
  • Loading branch information
immisterio committed May 15, 2023
1 parent dff2cb6 commit d3a7d97
Show file tree
Hide file tree
Showing 107 changed files with 1,392 additions and 715 deletions.
29 changes: 19 additions & 10 deletions DLNA/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,16 @@ async public Task<JsonResult> Show(string path)
#region trackers
string trackers = string.Empty;

foreach (string line in IO.File.ReadLines("cache/trackers.txt"))
if (IO.File.Exists("cache/trackers.txt"))
{
if (string.IsNullOrWhiteSpace(line))
continue;
foreach (string line in IO.File.ReadLines("cache/trackers.txt"))
{
if (string.IsNullOrWhiteSpace(line))
continue;

if (line.StartsWith("http") /*|| line.StartsWith("udp:")*/)
trackers += $"&tr={HttpUtility.HtmlEncode(line)}";
if (line.StartsWith("http") /*|| line.StartsWith("udp:")*/)
trackers += $"&tr={HttpUtility.HtmlEncode(line)}";
}
}
#endregion

Expand Down Expand Up @@ -487,17 +490,22 @@ async public Task<JsonResult> Download(string path, int[] indexs, string thumb)
}
else
{
Directory.CreateDirectory("dlna/");

dynamic tlink = tparse.torrent != null ? Torrent.Load(tparse.torrent) : magnetLink;
manager = AppInit.conf.dlna.mode == "stream" ? await torrentEngine.AddStreamingAsync(tlink, "dlna/") : await torrentEngine.AddAsync(tlink, "dlna/");

#region AddTrackerAsync
foreach (string line in IO.File.ReadLines("cache/trackers.txt"))
if (IO.File.Exists("cache/trackers.txt"))
{
if (string.IsNullOrWhiteSpace(line))
continue;
foreach (string line in IO.File.ReadLines("cache/trackers.txt"))
{
if (string.IsNullOrWhiteSpace(line))
continue;

if (line.StartsWith("http") || line.StartsWith("udp:"))
await manager.TrackerManager.AddTrackerAsync(new Uri(line));
if (line.StartsWith("http") || line.StartsWith("udp:"))
await manager.TrackerManager.AddTrackerAsync(new Uri(line));
}
}
#endregion

Expand Down Expand Up @@ -569,6 +577,7 @@ async public Task<JsonResult> Download(string path, int[] indexs, string thumb)
}
else
{
Directory.CreateDirectory("cache/metadata/");
await IO.File.WriteAllTextAsync($"cache/metadata/{manager.InfoHash.ToHex()}.json", JsonConvert.SerializeObject(indexs));

for (int i = 0; i < manager.Files.Count; i++)
Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/AniLibriaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Caching.Memory;
using Lampac.Engine.Parse;
using Shared;
using Shared.Engine.CORE;

namespace Lampac.Controllers.JAC
{
Expand All @@ -27,7 +28,9 @@ async public Task<ActionResult> parseMagnet(string url, string code)
if (Startup.memoryCache.TryGetValue(key, out byte[] _m))
return File(_m, "application/x-bittorrent");

byte[] _t = await HttpClient.Download($"{AppInit.conf.Anilibria.host}/{url}", referer: $"{AppInit.conf.Anilibria.host}/release/{code}.html", timeoutSeconds: 10, useproxy: AppInit.conf.Anilibria.useproxy);
var proxyManager = new ProxyManager("anilibria", AppInit.conf.Anilibria);

byte[] _t = await HttpClient.Download($"{AppInit.conf.Anilibria.host}/{url}", referer: $"{AppInit.conf.Anilibria.host}/release/{code}.html", timeoutSeconds: 10, proxy: proxyManager.Get());
if (_t != null && BencodeTo.Magnet(_t) != null)
{
await TorrentCache.Write(key, _t);
Expand All @@ -39,6 +42,7 @@ async public Task<ActionResult> parseMagnet(string url, string code)
return File(tcache.torrent, "application/x-bittorrent");
}

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand All @@ -54,12 +58,15 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai
#region Кеш
if (!Startup.memoryCache.TryGetValue(memkey, out List<RootObject> roots))
{
roots = await HttpClient.Get<List<RootObject>>("https://api.anilibria.tv/v2/searchTitles?search=" + HttpUtility.UrlEncode(query), timeoutSeconds: AppInit.conf.jac.timeoutSeconds, useproxy: AppInit.conf.Anilibria.useproxy, IgnoreDeserializeObject: true);
var proxyManager = new ProxyManager("anilibria", AppInit.conf.Anilibria);

roots = await HttpClient.Get<List<RootObject>>("https://api.anilibria.tv/v2/searchTitles?search=" + HttpUtility.UrlEncode(query), timeoutSeconds: AppInit.conf.jac.timeoutSeconds, proxy: proxyManager.Get(), IgnoreDeserializeObject: true);
if (roots == null || roots.Count == 0)
{
if (AppInit.conf.jac.emptycache)
Startup.memoryCache.Set($"{memkey}:error", 0, DateTime.Now.AddMinutes(Math.Max(1, AppInit.conf.jac.htmlCacheToMinutes)));

proxyManager.Refresh();
return false;
}

Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/AnifilmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Lampac.Models.JAC;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Shared.Engine.CORE;

namespace Lampac.Controllers.CRON
{
Expand All @@ -37,7 +38,9 @@ async public Task<ActionResult> parseMagnet(string tid, bool usecache)
return Content("error");
}

_t = await HttpClient.Download($"{AppInit.conf.Anifilm.host}/{tid}", referer: $"{AppInit.conf.Anifilm.host}/", timeoutSeconds: 10, useproxy: AppInit.conf.Anifilm.useproxy);
var proxyManager = new ProxyManager("anifilm", AppInit.conf.Anifilm);

_t = await HttpClient.Download($"{AppInit.conf.Anifilm.host}/{tid}", referer: $"{AppInit.conf.Anifilm.host}/", timeoutSeconds: 10, proxy: proxyManager.Get());
if (_t != null && BencodeTo.Magnet(_t) != null)
{
await TorrentCache.Write(key, _t);
Expand All @@ -50,6 +53,7 @@ async public Task<ActionResult> parseMagnet(string tid, bool usecache)
if (await TorrentCache.Read(key) is var tcache && tcache.cache)
return File(tcache.torrent, "application/x-bittorrent");

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand All @@ -72,7 +76,9 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (!cread.cache)
{
string html = await HttpClient.Get($"{AppInit.conf.Anifilm.host}/releases?title={HttpUtility.UrlEncode(query)}", timeoutSeconds: AppInit.conf.jac.timeoutSeconds, useproxy: AppInit.conf.Anifilm.useproxy);
var proxyManager = new ProxyManager("anifilm", AppInit.conf.Anifilm);

string html = await HttpClient.Get($"{AppInit.conf.Anifilm.host}/releases?title={HttpUtility.UrlEncode(query)}", timeoutSeconds: AppInit.conf.jac.timeoutSeconds, proxy: proxyManager.Get());

if (html != null && html.Contains("id=\"ui-components\""))
{
Expand All @@ -83,6 +89,7 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (cread.html == null)
{
proxyManager.Refresh();
HtmlCache.EmptyCache(cachekey);
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/BitruController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.Caching.Memory;
using Lampac.Models.JAC;
using Shared;
using Shared.Engine.CORE;

namespace Lampac.Controllers.JAC
{
Expand All @@ -37,7 +38,9 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
return Content("error");
}

byte[] _t = await HttpClient.Download($"{AppInit.conf.Bitru.host}/download.php?id={id}", referer: $"{AppInit.conf.Bitru}/details.php?id={id}", useproxy: AppInit.conf.Bitru.useproxy, timeoutSeconds: 10);
var proxyManager = new ProxyManager("bitru", AppInit.conf.Bitru);

byte[] _t = await HttpClient.Download($"{AppInit.conf.Bitru.host}/download.php?id={id}", referer: $"{AppInit.conf.Bitru}/details.php?id={id}", proxy: proxyManager.Get(), timeoutSeconds: 10);
if (_t != null && BencodeTo.Magnet(_t) != null)
{
await TorrentCache.Write(key, _t);
Expand All @@ -50,6 +53,7 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
if (await TorrentCache.Read(key) is var tcache && tcache.cache)
return File(tcache.torrent, "application/x-bittorrent");

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand All @@ -70,7 +74,9 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (!cread.cache)
{
string html = await HttpClient.Get($"{AppInit.conf.Bitru.host}/browse.php?s={HttpUtility.HtmlEncode(query)}&sort=&tmp=&cat=&subcat=&year=&country=&sound=&soundtrack=&subtitles=#content", useproxy: AppInit.conf.Bitru.useproxy, timeoutSeconds: AppInit.conf.jac.timeoutSeconds);
var proxyManager = new ProxyManager("bitru", AppInit.conf.Bitru);

string html = await HttpClient.Get($"{AppInit.conf.Bitru.host}/browse.php?s={HttpUtility.HtmlEncode(query)}&sort=&tmp=&cat=&subcat=&year=&country=&sound=&soundtrack=&subtitles=#content", proxy: proxyManager.Get(), timeoutSeconds: AppInit.conf.jac.timeoutSeconds);

if (html != null && html.Contains("id=\"logo\""))
{
Expand All @@ -81,6 +87,7 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (cread.html == null)
{
proxyManager.Refresh();
HtmlCache.EmptyCache(cachekey);
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/KinozalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Lampac.Models.JAC;
using System.Collections.Generic;
using Shared;
using Shared.Engine.CORE;

namespace Lampac.Controllers.JAC
{
Expand Down Expand Up @@ -134,8 +135,10 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
}
#endregion

var proxyManager = new ProxyManager("kinozal", AppInit.conf.Kinozal);

#region Инфо хеш
string srv_details = await HttpClient.Post($"{AppInit.conf.Kinozal.host}/get_srv_details.php?id={id}&action=2", $"id={id}&action=2", "__cfduid=d476ac2d9b5e18f2b67707b47ebd9b8cd1560164391; uid=20520283; pass=ouV5FJdFCd;", useproxy: AppInit.conf.Kinozal.useproxy, timeoutSeconds: 10);
string srv_details = await HttpClient.Post($"{AppInit.conf.Kinozal.host}/get_srv_details.php?id={id}&action=2", $"id={id}&action=2", "__cfduid=d476ac2d9b5e18f2b67707b47ebd9b8cd1560164391; uid=20520283; pass=ouV5FJdFCd;", proxy: proxyManager.Get(), timeoutSeconds: 10);
if (srv_details != null)
{
string torrentHash = new Regex("<ul><li>Инфо хеш: +([^<]+)</li>").Match(srv_details).Groups[1].Value;
Expand All @@ -160,6 +163,7 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
Redirect(mcache.torrent);
}

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand All @@ -180,7 +184,9 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (!cread.cache)
{
string html = await HttpClient.Get($"{AppInit.conf.Kinozal.host}/browse.php?s={HttpUtility.UrlEncode(query)}&g=0&c=0&v=0&d=0&w=0&t=0&f=0", useproxy: AppInit.conf.Kinozal.useproxy, timeoutSeconds: AppInit.conf.jac.timeoutSeconds);
var proxyManager = new ProxyManager("kinozal", AppInit.conf.Kinozal);

string html = await HttpClient.Get($"{AppInit.conf.Kinozal.host}/browse.php?s={HttpUtility.UrlEncode(query)}&g=0&c=0&v=0&d=0&w=0&t=0&f=0", proxy: proxyManager.Get(), timeoutSeconds: AppInit.conf.jac.timeoutSeconds);

if (html != null && html.Contains("Кинозал.ТВ</title>"))
{
Expand All @@ -194,6 +200,7 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (cread.html == null)
{
proxyManager.Refresh();
HtmlCache.EmptyCache(cachekey);
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/MegapeerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Caching.Memory;
using Shared;
using System.Collections.Generic;
using Shared.Engine.CORE;

namespace Lampac.Controllers.JAC
{
Expand All @@ -39,7 +40,9 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
return Content("error");
}

byte[] _t = await HttpClient.Download($"{AppInit.conf.Megapeer.host}/download/{id}", referer: AppInit.conf.Megapeer.host, timeoutSeconds: 10);
var proxyManager = new ProxyManager("megapeer", AppInit.conf.Megapeer);

byte[] _t = await HttpClient.Download($"{AppInit.conf.Megapeer.host}/download/{id}", referer: AppInit.conf.Megapeer.host, timeoutSeconds: 10, proxy: proxyManager.Get());
if (_t != null && BencodeTo.Magnet(_t) != null)
{
await TorrentCache.Write(key, _t);
Expand All @@ -52,6 +55,7 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
if (await TorrentCache.Read(key) is var tcache && tcache.cache)
return File(tcache.torrent, "application/x-bittorrent");

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand All @@ -71,7 +75,9 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (!cread.cache)
{
string html = await HttpClient.Get($"{AppInit.conf.Megapeer.host}/browse.php?search={HttpUtility.UrlEncode(query, Encoding.GetEncoding(1251))}", encoding: Encoding.GetEncoding(1251), useproxy: AppInit.conf.Megapeer.useproxy, timeoutSeconds: AppInit.conf.jac.timeoutSeconds, addHeaders: new List<(string name, string val)>()
var proxyManager = new ProxyManager("megapeer", AppInit.conf.Megapeer);

string html = await HttpClient.Get($"{AppInit.conf.Megapeer.host}/browse.php?search={HttpUtility.UrlEncode(query, Encoding.GetEncoding(1251))}", encoding: Encoding.GetEncoding(1251), proxy: proxyManager.Get(), timeoutSeconds: AppInit.conf.jac.timeoutSeconds, addHeaders: new List<(string name, string val)>()
{
("dnt", "1"),
("pragma", "no-cache"),
Expand All @@ -92,6 +98,7 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (cread.html == null)
{
proxyManager.Refresh();
HtmlCache.EmptyCache(cachekey);
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions Jackett/Controllers/NNMClubController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Lampac.Models.JAC;
using System.Collections.Generic;
using Shared;
using Shared.Engine.CORE;

namespace Lampac.Controllers.JAC
{
Expand Down Expand Up @@ -124,8 +125,10 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
}
#endregion

var proxyManager = new ProxyManager("nnmclub", AppInit.conf.NNMClub);

#region html
string html = await HttpClient.Get($"{AppInit.conf.NNMClub.host}/forum/viewtopic.php?t=" + id, useproxy: AppInit.conf.NNMClub.useproxy, timeoutSeconds: 10);
string html = await HttpClient.Get($"{AppInit.conf.NNMClub.host}/forum/viewtopic.php?t=" + id, proxy: proxyManager.Get(), timeoutSeconds: 10);
string magnet = new Regex("href=\"(magnet:[^\"]+)\" title=\"Примагнититься\"").Match(html ?? string.Empty).Groups[1].Value;

if (html == null || !html.Contains("NNM-Club</title>") || string.IsNullOrWhiteSpace(magnet))
Expand All @@ -139,6 +142,7 @@ async public Task<ActionResult> parseMagnet(string id, bool usecache)
if (await TorrentCache.ReadMagnet(keymagnet) is var mcache && mcache.cache)
Redirect(mcache.torrent);

proxyManager.Refresh();
return Content("error");
}
#endregion
Expand Down Expand Up @@ -182,8 +186,10 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (!cread.cache)
{
var proxyManager = new ProxyManager("nnmclub", AppInit.conf.NNMClub);

string data = $"prev_sd=0&prev_a=0&prev_my=0&prev_n=0&prev_shc=0&prev_shf=1&prev_sha=1&prev_shs=0&prev_shr=0&prev_sht=0&o=1&s=2&tm=-1&shf=1&sha=1&ta=-1&sns=-1&sds=-1&nm={HttpUtility.UrlEncode(query, Encoding.GetEncoding(1251))}&pn=&submit=%CF%EE%E8%F1%EA";
string html = await HttpClient.Post($"{AppInit.conf.NNMClub.host}/forum/tracker.php", new System.Net.Http.StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded"), encoding: Encoding.GetEncoding(1251), useproxy: AppInit.conf.NNMClub.useproxy, timeoutSeconds: AppInit.conf.jac.timeoutSeconds);
string html = await HttpClient.Post($"{AppInit.conf.NNMClub.host}/forum/tracker.php", new System.Net.Http.StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded"), encoding: Encoding.GetEncoding(1251), proxy: proxyManager.Get(), timeoutSeconds: AppInit.conf.jac.timeoutSeconds);

if (html != null && html.Contains("NNM-Club</title>"))
{
Expand All @@ -197,6 +203,7 @@ async public static Task<bool> parsePage(string host, ConcurrentBag<TorrentDetai

if (cread.html == null)
{
proxyManager.Refresh();
HtmlCache.EmptyCache(cachekey);
return false;
}
Expand Down
Loading

0 comments on commit d3a7d97

Please sign in to comment.