Skip to content

Commit

Permalink
v241008
Browse files Browse the repository at this point in the history
1. Fix a problem caused the program to stop working
  • Loading branch information
tonyhsie committed Oct 7, 2024
1 parent a9583d7 commit 4d9083d
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions qBittorrentBlockXunlei/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ internal class Program
static readonly string sTorrentsTrackers = "/api/v2/torrents/trackers?hash=";
static readonly string sTorrentsProperties = "/api/v2/torrents/properties?hash=";

// responseBody, /api/v2/sync/maindata
static readonly string sFullUpdateText = "\"full_update\":";
static readonly string sTorrentsObjectText = "\"torrents\":{";
static readonly string sNameFieldText = "\"name\":\"";
static readonly string sTotalSizeFieldText = "\"total_size\":";
static readonly string sUpspeedFieldText = "\"upspeed\":";

// propertiesBody, /api/v2/torrents/properties?hash=
static readonly string sPieceSizeFieldText = "\"piece_size\":";

// peersBody, /api/v2/sync/torrentPeers?hash=
static readonly string sTorrentPeersStartText = "{\"full_update\":";
static readonly string sPeersObjectText = "\"peers\":{";
static readonly string sClientFieldText = "\"client\":\"";
static readonly string sCountryCodeFieldText = "\"country_code\":\"";
static readonly string sClientFieldText = "\"client\":";
static readonly string sCountryCodeFieldText = "\"country_code\":";
static readonly string sDownloadedFieldText = "\"downloaded\":";
static readonly string sFlagsFieldText = "\"flags\":\"";
static readonly string sPortFieldText = "\"port\":";
static readonly string sProgressFieldText = "\"progress\":";
static readonly string sUploadedFieldText = "\"uploaded\":";
static readonly string sTotalSizeFieldText = "\"total_size\":";
static readonly string sPieceSizeFieldText = "\"piece_size\":";
static readonly string sNameFieldText = "\"name\":\"";

static readonly List<string> lsLeechClients = new List<string>() { "-XL", "Xunlei", "XunLei", "7.", "aria2", "Xfplay", "dandanplay", "FDM", "go.torrent", "Mozilla", "github.com/anacrolix/torrent (devel) (anacrolix/torrent unknown)", "dt/torrent/", "Taipei-Torrent dev", "trafficConsume", "hp/torrent/", "BitComet 1.92", "BitComet 1.98", "xm/torrent/", "flashget", "FlashGet", "StellarPlayer", "Gopeed", "MediaGet", "aD/", "ADM", "coc_coc_browser", "FileCroc", "filecxx", "Folx", "seanime (devel) (anacrolix/torrent", "HitomiDownloader", "gateway (devel) (anacrolix/torrent", "offline-download (devel) (anacrolix/torrent", "QQDownload" };
static readonly List<string> lsAncientClients = new List<string>() { "TorrentStorm", "Azureus 1.", "Azureus 2.", "Azureus 3.", "Deluge 0.", "Deluge 1.0", "Deluge 1.1", "qBittorrent 0.", "qBittorrent 1.", "qBittorrent 2.", "Transmission 0.", "Transmission 1.", "BitComet 0.", "µTorrent 1.", "uTorrent 1.", "μTorrent 1." };
Expand All @@ -60,7 +64,7 @@ static void CCEHandler(object sender, ConsoleCancelEventArgs args)

static async Task Main(string[] args)
{
Console.Title = "qBittorrentBlockXunlei v241005";
Console.Title = "qBittorrentBlockXunlei v241008";

Console.OutputEncoding = Encoding.UTF8;
Console.CancelKeyPress += new ConsoleCancelEventHandler(CCEHandler);
Expand Down Expand Up @@ -203,13 +207,13 @@ static async Task Main(string[] args)
{
try
{
DateTime dtResetBase = DateTime.Now;
DateTime dtLoopStartTime = DateTime.Now;

TimeSpan ts = dtResetBase - dtLastResetTime;
if (ts.Days >= 1)
TimeSpan tsDuration = dtLoopStartTime - dtLastResetTime;
if (tsDuration.Days >= 1)
{
dtLastResetTime = dtResetBase;
Console.WriteLine(dtLastResetTime + ", Reset banned IPs, reset interval: " + ts.TotalDays + " days");
dtLastResetTime = dtLoopStartTime;
Console.WriteLine(dtLastResetTime + ", Reset banned IPs, reset interval: " + tsDuration.TotalDays + " days");
hsBannedNetworks.Clear();
foreach (string sNetwork in dBannedPeerNetworks.Keys)
dBannedPeerNetworks[sNetwork].Clear();
Expand Down Expand Up @@ -316,12 +320,12 @@ static async Task Main(string[] args)

string sPeer = peersBody.Substring(iPeersStartIndex, iPeersEndIndex - iPeersStartIndex);

iPeersStartIndex = peersBody.IndexOf(sClientFieldText, iPeersEndIndex) + sClientFieldText.Length;
iPeersEndIndex = peersBody.IndexOf('"', iPeersStartIndex);
iPeersStartIndex = peersBody.IndexOf(sClientFieldText, iPeersEndIndex) + sClientFieldText.Length + 1;
iPeersEndIndex = peersBody.IndexOf(',', iPeersStartIndex) - 1;
string sClient = peersBody.Substring(iPeersStartIndex, iPeersEndIndex - iPeersStartIndex);

iPeersStartIndex = peersBody.IndexOf(sCountryCodeFieldText, iPeersEndIndex) + sCountryCodeFieldText.Length;
iPeersEndIndex = peersBody.IndexOf('"', iPeersStartIndex);
iPeersStartIndex = peersBody.IndexOf(sCountryCodeFieldText, iPeersEndIndex) + sCountryCodeFieldText.Length + 1;
iPeersEndIndex = peersBody.IndexOf(',', iPeersStartIndex) - 1;
string sCountryCode = peersBody.Substring(iPeersStartIndex, iPeersEndIndex - iPeersStartIndex);

iPeersStartIndex = peersBody.IndexOf(sDownloadedFieldText, iPeersEndIndex) + sDownloadedFieldText.Length;
Expand Down Expand Up @@ -556,7 +560,7 @@ static async Task Main(string[] args)
{
do
{
Console.WriteLine(ex.Message + "\t" + DateTime.Now.ToString());
Console.WriteLine(ex.Message + "\t" + DateTime.Now);
ex = ex.InnerException;
} while (ex != null);
Thread.Sleep(iPauseBeforeExitMs);
Expand All @@ -579,17 +583,21 @@ static async Task Main(string[] args)
}
hsActiveTorrents.Clear();

DateTime dtNow = DateTime.Now;
ts = dtNow - dtResetBase;
Console.WriteLine(dtNow + ", all/pt/bt: " + iTorrentCount + "/" + (iTorrentCount - iPublicTorrentCount) + "/" + iPublicTorrentCount + ", interval: " + dLoopIntervalSeconds + " sec., cost: " + ts.TotalSeconds + " sec.");
DateTime dtLoopEndTime = DateTime.Now;
tsDuration = dtLoopEndTime - dtLoopStartTime;
Console.WriteLine(dtLoopEndTime + ", all/pt/bt: " + iTorrentCount + "/" + (iTorrentCount - iPublicTorrentCount) + "/" + iPublicTorrentCount + ", interval: " + dLoopIntervalSeconds + " sec., cost: " + tsDuration.TotalSeconds + " sec.");

int iSleepMs = (int)Math.Round(dLoopIntervalMs - ts.TotalMilliseconds);
int iSleepMs = (int)Math.Round(dLoopIntervalMs - tsDuration.TotalMilliseconds);
if (iSleepMs > 0)
Thread.Sleep(iSleepMs);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\t" + DateTime.Now.ToString());
do
{
Console.WriteLine(ex.Message + "\t" + DateTime.Now);
ex = ex.InnerException;
} while (ex != null);
Thread.Sleep(iPauseBeforeExitMs);
}
}
Expand Down

0 comments on commit 4d9083d

Please sign in to comment.