Skip to content

Commit 88fa9d2

Browse files
committed
trackers.txt
1 parent c96086b commit 88fa9d2

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

Engine/TrackersCron.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Net.Sockets;
5+
using System.Text;
6+
using System.Text.RegularExpressions;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using System.Web;
10+
11+
namespace JacRed.Engine
12+
{
13+
public static class TrackersCron
14+
{
15+
async public static Task Run()
16+
{
17+
await Task.Delay(20_000);
18+
19+
while (true)
20+
{
21+
if (!AppInit.conf.evercache.enable || AppInit.conf.evercache.validHour > 0)
22+
{
23+
await Task.Delay(TimeSpan.FromMinutes(1));
24+
continue;
25+
}
26+
27+
await Task.Delay(TimeSpan.FromHours(1));
28+
29+
try
30+
{
31+
HashSet<string> trackers = new HashSet<string>();
32+
33+
foreach (var item in FileDB.masterDb.ToArray())
34+
{
35+
foreach (var t in FileDB.OpenRead(item.Key/*, cache: false*/).Values)
36+
{
37+
if (string.IsNullOrEmpty(t.magnet))
38+
continue;
39+
40+
try
41+
{
42+
if (t.magnet.Contains("&"))
43+
{
44+
foreach (Match tr in Regex.Matches(t.magnet, "tr=([^&]+)"))
45+
{
46+
string tracker = HttpUtility.UrlDecode(tr.Groups[1].Value.Split("?")[0]).Trim().ToLower();
47+
if (string.IsNullOrWhiteSpace(tracker) || tracker.Contains("[") || !tracker.Replace("://", "").Contains(":") || tracker.Contains(" ") || tracker.Contains("torrentsmd.eu"))
48+
continue;
49+
50+
if (Regex.IsMatch(tracker, "[^/]+/[^/]+/announce"))
51+
continue;
52+
53+
if (await ckeck(tracker))
54+
trackers.Add(tracker);
55+
}
56+
}
57+
}
58+
catch { }
59+
}
60+
}
61+
62+
File.WriteAllLines("wwwroot/trackers.txt", trackers);
63+
}
64+
catch { }
65+
}
66+
}
67+
68+
69+
async static ValueTask<bool> ckeck(string tracker)
70+
{
71+
if (string.IsNullOrWhiteSpace(tracker) || tracker.Contains("["))
72+
return false;
73+
74+
if (tracker.StartsWith("http"))
75+
{
76+
try
77+
{
78+
var handler = new System.Net.Http.HttpClientHandler();
79+
handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
80+
81+
using (var client = new System.Net.Http.HttpClient(handler))
82+
{
83+
client.Timeout = TimeSpan.FromSeconds(7);
84+
await client.GetAsync(tracker, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
85+
return true;
86+
}
87+
}
88+
catch { }
89+
}
90+
else if (tracker.StartsWith("udp:"))
91+
{
92+
try
93+
{
94+
tracker = tracker.Replace("udp://", "");
95+
96+
string host = tracker.Split(':')[0].Split('/')[0];
97+
int port = tracker.Contains(":") ? int.Parse(tracker.Split(':')[1].Split('/')[0]) : 6969;
98+
99+
using (UdpClient client = new UdpClient(host, port))
100+
{
101+
CancellationTokenSource cts = new CancellationTokenSource();
102+
cts.CancelAfter(7000);
103+
104+
string uri = Regex.Match(tracker, "^[^/]/(.*)").Groups[1].Value;
105+
await client.SendAsync(Encoding.UTF8.GetBytes($"GET /{uri} HTTP/1.1\r\nHost: {host}\r\n\r\n"), cts.Token);
106+
return true;
107+
}
108+
}
109+
catch { }
110+
}
111+
112+
return false;
113+
}
114+
}
115+
}

Engine/Tracks/TracksCron.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class TracksCron
1313
/// 2 - месяц
1414
/// 3 - год
1515
/// 4 - остальное
16+
/// 5 - обновления
1617
/// </param>
1718
async public static Task Run(int typetask)
1819
{
@@ -70,6 +71,11 @@ async public static Task Run(int typetask)
7071
isok = true;
7172
break;
7273
}
74+
case 5:
75+
{
76+
isok = t.updateTime >= DateTime.UtcNow.AddMonths(-1);
77+
break;
78+
}
7379
default:
7480
break;
7581
}
@@ -104,7 +110,7 @@ async public static Task Run(int typetask)
104110
if ((typetask == 3 || typetask == 4) && DateTime.Now > starttime.AddMonths(2))
105111
break;
106112

107-
if ((typetask == 3 || typetask == 4) && t.ffprobe_tryingdata >= 3)
113+
if ((typetask == 3 || typetask == 4 || typetask == 5) && t.ffprobe_tryingdata >= 3)
108114
continue;
109115

110116
if (TracksDB.Get(t.magnet) == null)

Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Main(string[] args)
2626

2727
ThreadPool.QueueUserWorkItem(async _ => await SyncCron.Torrents());
2828
ThreadPool.QueueUserWorkItem(async _ => await SyncCron.Spidr());
29-
29+
ThreadPool.QueueUserWorkItem(async _ => await TrackersCron.Run());
3030
ThreadPool.QueueUserWorkItem(async _ => await StatsCron.Run());
3131

3232
ThreadPool.QueueUserWorkItem(async _ => await FileDB.Cron());
@@ -36,6 +36,7 @@ public static void Main(string[] args)
3636
ThreadPool.QueueUserWorkItem(async _ => await TracksCron.Run(2));
3737
ThreadPool.QueueUserWorkItem(async _ => await TracksCron.Run(3));
3838
ThreadPool.QueueUserWorkItem(async _ => await TracksCron.Run(4));
39+
ThreadPool.QueueUserWorkItem(async _ => await TracksCron.Run(5));
3940

4041
CultureInfo.CurrentCulture = new CultureInfo("ru-RU");
4142
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

0 commit comments

Comments
 (0)