mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Added parsing error logging
This commit is contained in:
@@ -14,6 +14,8 @@ namespace Jackett
|
||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
string DisplayName { get; }
|
||||
string DisplayDescription { get; }
|
||||
Uri SiteLink { get; }
|
||||
|
@@ -43,6 +43,7 @@ namespace Jackett
|
||||
|
||||
IndexerInterface newIndexer = (IndexerInterface)Activator.CreateInstance(indexerType);
|
||||
newIndexer.OnSaveConfigurationRequested += newIndexer_OnSaveConfigurationRequested;
|
||||
newIndexer.OnResultParsingError += newIndexer_OnResultParsingError;
|
||||
|
||||
var configFilePath = GetIndexerConfigFilePath(newIndexer);
|
||||
if (File.Exists(configFilePath))
|
||||
@@ -54,6 +55,14 @@ namespace Jackett
|
||||
Indexers.Add(name, newIndexer);
|
||||
}
|
||||
|
||||
void newIndexer_OnResultParsingError(IndexerInterface indexer, string results, Exception ex)
|
||||
{
|
||||
var fileName = string.Format("Error on {0} for {1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), indexer.DisplayName);
|
||||
var spacing = string.Join("", Enumerable.Repeat(Environment.NewLine, 5));
|
||||
var fileContents = string.Format("{0}{1}{2}", ex, spacing, results);
|
||||
File.WriteAllText(Path.Combine(Program.AppConfigDirectory, fileName), fileContents);
|
||||
}
|
||||
|
||||
string GetIndexerConfigFilePath(IndexerInterface indexer)
|
||||
{
|
||||
return Path.Combine(IndexerConfigDirectory, indexer.GetType().Name.ToLower() + ".json");
|
||||
|
@@ -14,16 +14,21 @@ namespace Jackett.Indexers
|
||||
{
|
||||
public class BitHdtv : IndexerInterface
|
||||
{
|
||||
public string DisplayName {
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get { return "BIT-HDTV"; }
|
||||
}
|
||||
|
||||
public string DisplayDescription {
|
||||
public string DisplayDescription
|
||||
{
|
||||
get { return "Home of high definition invites"; }
|
||||
}
|
||||
|
||||
public Uri SiteLink {
|
||||
get { return new Uri (BaseUrl); }
|
||||
public Uri SiteLink
|
||||
{
|
||||
get { return new Uri(BaseUrl); }
|
||||
}
|
||||
|
||||
static string BaseUrl = "https://www.bit-hdtv.com";
|
||||
@@ -35,52 +40,56 @@ namespace Jackett.Indexers
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public BitHdtv ()
|
||||
public BitHdtv()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer ();
|
||||
handler = new HttpClientHandler {
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient (handler);
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup ()
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
return Task.FromResult<ConfigurationData> (config);
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return Task.FromResult<ConfigurationData>(config);
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration (JToken configJson)
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
config.LoadValuesFromJson (configJson);
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent (pairs);
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
|
||||
var response = await client.PostAsync (LoginUrl, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync ();
|
||||
var response = await client.PostAsync(LoginUrl, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains ("logout.php")) {
|
||||
if (!responseContent.Contains("logout.php"))
|
||||
{
|
||||
CQ dom = responseContent;
|
||||
var messageEl = dom ["table.detail td.text"].Last ();
|
||||
messageEl.Children ("a").Remove ();
|
||||
messageEl.Children ("style").Remove ();
|
||||
var errorMessage = messageEl.Text ().Trim ();
|
||||
throw new ExceptionWithConfigData (errorMessage, (ConfigurationData)config);
|
||||
} else {
|
||||
var configSaveData = new JObject ();
|
||||
configSaveData ["cookies"] = cookies.ToJson (SiteLink);
|
||||
var messageEl = dom["table.detail td.text"].Last();
|
||||
messageEl.Children("a").Remove();
|
||||
messageEl.Children("style").Remove();
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookies.ToJson(SiteLink);
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested (this, configSaveData);
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
@@ -90,61 +99,73 @@ namespace Jackett.Indexers
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
public void LoadFromSavedConfiguration (JToken jsonConfig)
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson (new Uri (BaseUrl), (JArray)jsonConfig ["cookies"]);
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery (TorznabQuery query)
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo> ();
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty }) {
|
||||
var searchString = title + " " + query.GetEpisodeSearchString ();
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode (searchString);
|
||||
var results = await client.GetStringAsync (episodeSearchUrl);
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
dom ["#needseed"].Remove ();
|
||||
var rows = dom ["table[width='750'] > tbody"].Children ();
|
||||
foreach (var row in rows.Skip(1)) {
|
||||
dom["#needseed"].Remove();
|
||||
var rows = dom["table[width='750'] > tbody"].Children();
|
||||
foreach (var row in rows.Skip(1))
|
||||
{
|
||||
|
||||
var release = new ReleaseInfo ();
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
var qRow = row.Cq ();
|
||||
var qLink = qRow.Children ().ElementAt (2).Cq ().Children ("a").First ();
|
||||
var qRow = row.Cq();
|
||||
var qLink = qRow.Children().ElementAt(2).Cq().Children("a").First();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
release.Title = qLink.Attr ("title");
|
||||
release.Title = qLink.Attr("title");
|
||||
release.Description = release.Title;
|
||||
release.Guid = new Uri (BaseUrl + qLink.Attr ("href"));
|
||||
release.Guid = new Uri(BaseUrl + qLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
release.Link = new Uri (string.Format (DownloadUrl, qLink.Attr ("href").Split ('=') [1]));
|
||||
release.Link = new Uri(string.Format(DownloadUrl, qLink.Attr("href").Split('=')[1]));
|
||||
|
||||
var dateString = qRow.Children ().ElementAt (5).Cq ().Text ().Trim ();
|
||||
var pubDate = DateTime.ParseExact (dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
var dateString = qRow.Children().ElementAt(5).Cq().Text().Trim();
|
||||
var pubDate = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
release.PublishDate = pubDate;
|
||||
|
||||
var sizeCol = qRow.Children ().ElementAt (6);
|
||||
var sizeVal = sizeCol.ChildNodes [0].NodeValue;
|
||||
var sizeUnit = sizeCol.ChildNodes [2].NodeValue;
|
||||
release.Size = ReleaseInfo.GetBytes (sizeUnit, float.Parse (sizeVal));
|
||||
var sizeCol = qRow.Children().ElementAt(6);
|
||||
var sizeVal = sizeCol.ChildNodes[0].NodeValue;
|
||||
var sizeUnit = sizeCol.ChildNodes[2].NodeValue;
|
||||
release.Size = ReleaseInfo.GetBytes(sizeUnit, float.Parse(sizeVal));
|
||||
|
||||
release.Seeders = int.Parse (qRow.Children ().ElementAt (8).Cq ().Text ().Trim ());
|
||||
release.Peers = int.Parse (qRow.Children ().ElementAt (9).Cq ().Text ().Trim ()) + release.Seeders;
|
||||
release.Seeders = int.Parse(qRow.Children().ElementAt(8).Cq().Text().Trim());
|
||||
release.Peers = int.Parse(qRow.Children().ElementAt(9).Cq().Text().Trim()) + release.Seeders;
|
||||
|
||||
releases.Add (release);
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray ();
|
||||
}
|
||||
|
||||
public Task<byte[]> Download (Uri link)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return client.GetByteArrayAsync (link);
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
{
|
||||
return client.GetByteArrayAsync(link);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ namespace Jackett
|
||||
HttpClient client;
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public BitMeTV()
|
||||
{
|
||||
@@ -136,6 +137,8 @@ namespace Jackett
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
|
||||
var table = dom["tbody > tr > .latest"].Parent().Parent();
|
||||
@@ -178,6 +181,12 @@ namespace Jackett
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
|
||||
@@ -187,5 +196,6 @@ namespace Jackett
|
||||
{
|
||||
return client.GetByteArrayAsync(link);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ namespace Jackett
|
||||
{
|
||||
public class Freshon : IndexerInterface
|
||||
{
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
static string BaseUrl = "https://freshon.tv";
|
||||
static string LoginUrl = BaseUrl + "/login.php";
|
||||
@@ -34,147 +35,161 @@ namespace Jackett
|
||||
|
||||
public string DisplayDescription { get { return "Our goal is to provide the latest stuff in the TV show domain"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri (BaseUrl); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public Freshon ()
|
||||
public Freshon()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer ();
|
||||
handler = new HttpClientHandler {
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient (handler);
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup ()
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var request = CreateHttpRequest (new Uri (LoginUrl));
|
||||
var response = await client.SendAsync (request);
|
||||
await response.Content.ReadAsStreamAsync ();
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
var request = CreateHttpRequest(new Uri(LoginUrl));
|
||||
var response = await client.SendAsync(request);
|
||||
await response.Content.ReadAsStreamAsync();
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return config;
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration (JToken configJson)
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
config.LoadValuesFromJson (configJson);
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent (pairs);
|
||||
var message = CreateHttpRequest (new Uri (LoginPostUrl));
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
var message = CreateHttpRequest(new Uri(LoginPostUrl));
|
||||
message.Method = HttpMethod.Post;
|
||||
message.Content = content;
|
||||
message.Headers.Referrer = new Uri (LoginUrl);
|
||||
message.Headers.Referrer = new Uri(LoginUrl);
|
||||
|
||||
var response = await client.SendAsync (message);
|
||||
var responseContent = await response.Content.ReadAsStringAsync ();
|
||||
var response = await client.SendAsync(message);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains ("/logout.php")) {
|
||||
if (!responseContent.Contains("/logout.php"))
|
||||
{
|
||||
CQ dom = responseContent;
|
||||
var messageEl = dom [".error_text"];
|
||||
var errorMessage = messageEl.Text ().Trim ();
|
||||
throw new ExceptionWithConfigData (errorMessage, (ConfigurationData)config);
|
||||
} else {
|
||||
var configSaveData = new JObject ();
|
||||
configSaveData ["cookies"] = cookies.ToJson (SiteLink);
|
||||
var messageEl = dom[".error_text"];
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookies.ToJson(SiteLink);
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested (this, configSaveData);
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration (JToken jsonConfig)
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson (new Uri (BaseUrl), (JArray)jsonConfig ["cookies"]);
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
HttpRequestMessage CreateHttpRequest (Uri uri)
|
||||
HttpRequestMessage CreateHttpRequest(Uri uri)
|
||||
{
|
||||
var message = new HttpRequestMessage ();
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = uri;
|
||||
message.Headers.UserAgent.ParseAdd (chromeUserAgent);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
return message;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery (TorznabQuery query)
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo> ();
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty }) {
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
string episodeSearchUrl;
|
||||
|
||||
if (string.IsNullOrEmpty (title))
|
||||
if (string.IsNullOrEmpty(title))
|
||||
episodeSearchUrl = SearchUrl;
|
||||
else {
|
||||
var searchString = title + " " + query.GetEpisodeSearchString ();
|
||||
episodeSearchUrl = string.Format ("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode (searchString));
|
||||
else
|
||||
{
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
}
|
||||
|
||||
var request = CreateHttpRequest (new Uri (episodeSearchUrl));
|
||||
var response = await client.SendAsync (request);
|
||||
var results = await response.Content.ReadAsStringAsync ();
|
||||
|
||||
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
|
||||
var response = await client.SendAsync(request);
|
||||
var results = await response.Content.ReadAsStringAsync();
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
|
||||
var rows = dom ["#highlight > tbody > tr"];
|
||||
var rows = dom["#highlight > tbody > tr"];
|
||||
|
||||
foreach (var row in rows.Skip(1)) {
|
||||
var release = new ReleaseInfo ();
|
||||
foreach (var row in rows.Skip(1))
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
var qRow = row.Cq ();
|
||||
var qLink = qRow.Find ("a.torrent_name_link").First ();
|
||||
var qRow = row.Cq();
|
||||
var qLink = qRow.Find("a.torrent_name_link").First();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
release.Title = qLink.Attr ("title");
|
||||
release.Title = qLink.Attr("title");
|
||||
release.Description = release.Title;
|
||||
release.Guid = new Uri (BaseUrl + qLink.Attr ("href"));
|
||||
release.Guid = new Uri(BaseUrl + qLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
release.Link = new Uri (BaseUrl + qRow.Find ("td.table_links > a").First ().Attr ("href"));
|
||||
release.Link = new Uri(BaseUrl + qRow.Find("td.table_links > a").First().Attr("href"));
|
||||
|
||||
DateTime pubDate;
|
||||
var dateString = qRow.Find ("td.table_added").Text ().Trim ();
|
||||
if (dateString.StartsWith ("Today "))
|
||||
pubDate = (DateTime.UtcNow + TimeSpan.Parse (dateString.Split (' ') [1])).ToLocalTime ();
|
||||
else if (dateString.StartsWith ("Yesterday "))
|
||||
pubDate = (DateTime.UtcNow + TimeSpan.Parse (dateString.Split (' ') [1]) - TimeSpan.FromDays (1)).ToLocalTime ();
|
||||
var dateString = qRow.Find("td.table_added").Text().Trim();
|
||||
if (dateString.StartsWith("Today "))
|
||||
pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1])).ToLocalTime();
|
||||
else if (dateString.StartsWith("Yesterday "))
|
||||
pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1)).ToLocalTime();
|
||||
else
|
||||
pubDate = DateTime.ParseExact (dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime ();
|
||||
pubDate = DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||
release.PublishDate = pubDate;
|
||||
|
||||
release.Seeders = int.Parse (qRow.Find ("td.table_seeders").Text ().Trim ());
|
||||
release.Peers = int.Parse (qRow.Find ("td.table_leechers").Text ().Trim ()) + release.Seeders;
|
||||
release.Seeders = int.Parse(qRow.Find("td.table_seeders").Text().Trim());
|
||||
release.Peers = int.Parse(qRow.Find("td.table_leechers").Text().Trim()) + release.Seeders;
|
||||
|
||||
var sizeCol = qRow.Find ("td.table_size") [0];
|
||||
var sizeVal = float.Parse (sizeCol.ChildNodes [0].NodeValue.Trim ());
|
||||
var sizeUnit = sizeCol.ChildNodes [2].NodeValue.Trim ();
|
||||
release.Size = ReleaseInfo.GetBytes (sizeUnit, sizeVal);
|
||||
var sizeCol = qRow.Find("td.table_size")[0];
|
||||
var sizeVal = float.Parse(sizeCol.ChildNodes[0].NodeValue.Trim());
|
||||
var sizeUnit = sizeCol.ChildNodes[2].NodeValue.Trim();
|
||||
release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);
|
||||
|
||||
releases.Add (release);
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray ();
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download (Uri link)
|
||||
catch (Exception ex)
|
||||
{
|
||||
var request = CreateHttpRequest (link);
|
||||
var response = await client.SendAsync (request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync ();
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
var request = CreateHttpRequest(link);
|
||||
var response = await client.SendAsync(request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
@@ -14,13 +14,14 @@ namespace Jackett.Indexers
|
||||
public class IPTorrents : IndexerInterface
|
||||
{
|
||||
|
||||
public event Action<IndexerInterface, Newtonsoft.Json.Linq.JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public string DisplayName { get { return "IPTorrents"; } }
|
||||
|
||||
public string DisplayDescription { get { return "Always a step ahead"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri (BaseUrl); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
@@ -36,156 +37,173 @@ namespace Jackett.Indexers
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public IPTorrents ()
|
||||
public IPTorrents()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer ();
|
||||
handler = new HttpClientHandler {
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient (handler);
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup ()
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
await client.GetAsync (new Uri (BaseUrl));
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
await client.GetAsync(new Uri(BaseUrl));
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return (ConfigurationData)config;
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration (JToken configJson)
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
|
||||
var config = new ConfigurationDataBasicLogin ();
|
||||
config.LoadValuesFromJson (configJson);
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent (pairs);
|
||||
var message = new HttpRequestMessage ();
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Post;
|
||||
message.Content = content;
|
||||
message.RequestUri = new Uri (BaseUrl);
|
||||
message.Headers.Referrer = new Uri (BaseUrl);
|
||||
message.Headers.UserAgent.ParseAdd (chromeUserAgent);
|
||||
message.RequestUri = new Uri(BaseUrl);
|
||||
message.Headers.Referrer = new Uri(BaseUrl);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
|
||||
var response = await client.SendAsync (message);
|
||||
var responseContent = await response.Content.ReadAsStringAsync ();
|
||||
var response = await client.SendAsync(message);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains ("/my.php")) {
|
||||
if (!responseContent.Contains("/my.php"))
|
||||
{
|
||||
CQ dom = responseContent;
|
||||
var messageEl = dom ["body > div"].First ();
|
||||
var errorMessage = messageEl.Text ().Trim ();
|
||||
throw new ExceptionWithConfigData (errorMessage, (ConfigurationData)config);
|
||||
} else {
|
||||
var configSaveData = new JObject ();
|
||||
configSaveData ["cookies"] = cookies.ToJson (SiteLink);
|
||||
var messageEl = dom["body > div"].First();
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookies.ToJson(SiteLink);
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested (this, configSaveData);
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HttpRequestMessage CreateHttpRequest (Uri uri)
|
||||
HttpRequestMessage CreateHttpRequest(Uri uri)
|
||||
{
|
||||
var message = new HttpRequestMessage ();
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = uri;
|
||||
message.Headers.UserAgent.ParseAdd (chromeUserAgent);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
return message;
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration (Newtonsoft.Json.Linq.JToken jsonConfig)
|
||||
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson (new Uri (BaseUrl), (JArray)jsonConfig ["cookies"]);
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery (TorznabQuery query)
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo> ();
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty }) {
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
|
||||
var searchString = title + " " + query.GetEpisodeSearchString ();
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode (searchString);
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||
|
||||
var request = CreateHttpRequest (new Uri (episodeSearchUrl));
|
||||
var response = await client.SendAsync (request);
|
||||
var results = await response.Content.ReadAsStringAsync ();
|
||||
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
|
||||
var response = await client.SendAsync(request);
|
||||
var results = await response.Content.ReadAsStringAsync();
|
||||
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
|
||||
var rows = dom ["table.torrents > tbody > tr"];
|
||||
foreach (var row in rows.Skip(1)) {
|
||||
var release = new ReleaseInfo ();
|
||||
var rows = dom["table.torrents > tbody > tr"];
|
||||
foreach (var row in rows.Skip(1))
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
var qRow = row.Cq ();
|
||||
var qRow = row.Cq();
|
||||
|
||||
var qTitleLink = qRow.Find ("a.t_title").First ();
|
||||
release.Title = qTitleLink.Text ().Trim ();
|
||||
var qTitleLink = qRow.Find("a.t_title").First();
|
||||
release.Title = qTitleLink.Text().Trim();
|
||||
release.Description = release.Title;
|
||||
release.Guid = new Uri (BaseUrl + qTitleLink.Attr ("href"));
|
||||
release.Guid = new Uri(BaseUrl + qTitleLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
|
||||
DateTime pubDate;
|
||||
var descString = qRow.Find (".t_ctime").Text ();
|
||||
var dateString = descString.Split ('|').Last ().Trim ();
|
||||
dateString = dateString.Split (new string[] { " by " }, StringSplitOptions.None) [0];
|
||||
var dateValue = float.Parse (dateString.Split (' ') [0]);
|
||||
var dateUnit = dateString.Split (' ') [1];
|
||||
if (dateUnit.Contains ("minute"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromMinutes (dateValue);
|
||||
else if (dateUnit.Contains ("hour"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromHours (dateValue);
|
||||
else if (dateUnit.Contains ("day"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays (dateValue);
|
||||
else if (dateUnit.Contains ("week"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays (7 * dateValue);
|
||||
else if (dateUnit.Contains ("month"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays (30 * dateValue);
|
||||
else if (dateUnit.Contains ("year"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays (365 * dateValue);
|
||||
var descString = qRow.Find(".t_ctime").Text();
|
||||
var dateString = descString.Split('|').Last().Trim();
|
||||
dateString = dateString.Split(new string[] { " by " }, StringSplitOptions.None)[0];
|
||||
var dateValue = float.Parse(dateString.Split(' ')[0]);
|
||||
var dateUnit = dateString.Split(' ')[1];
|
||||
if (dateUnit.Contains("minute"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromMinutes(dateValue);
|
||||
else if (dateUnit.Contains("hour"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromHours(dateValue);
|
||||
else if (dateUnit.Contains("day"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(dateValue);
|
||||
else if (dateUnit.Contains("week"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(7 * dateValue);
|
||||
else if (dateUnit.Contains("month"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(30 * dateValue);
|
||||
else if (dateUnit.Contains("year"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(365 * dateValue);
|
||||
else
|
||||
pubDate = DateTime.MinValue;
|
||||
release.PublishDate = pubDate;
|
||||
|
||||
var qLink = row.ChildElements.ElementAt (3).Cq ().Children ("a");
|
||||
release.Link = new Uri (BaseUrl + qLink.Attr ("href"));
|
||||
var qLink = row.ChildElements.ElementAt(3).Cq().Children("a");
|
||||
release.Link = new Uri(BaseUrl + qLink.Attr("href"));
|
||||
|
||||
var sizeStr = row.ChildElements.ElementAt (5).Cq ().Text ().Trim ();
|
||||
var sizeVal = float.Parse (sizeStr.Split (' ') [0]);
|
||||
var sizeUnit = sizeStr.Split (' ') [1];
|
||||
release.Size = ReleaseInfo.GetBytes (sizeUnit, sizeVal);
|
||||
var sizeStr = row.ChildElements.ElementAt(5).Cq().Text().Trim();
|
||||
var sizeVal = float.Parse(sizeStr.Split(' ')[0]);
|
||||
var sizeUnit = sizeStr.Split(' ')[1];
|
||||
release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);
|
||||
|
||||
release.Seeders = int.Parse (qRow.Find (".t_seeders").Text ().Trim ());
|
||||
release.Peers = int.Parse (qRow.Find (".t_leechers").Text ().Trim ()) + release.Seeders;
|
||||
release.Seeders = int.Parse(qRow.Find(".t_seeders").Text().Trim());
|
||||
release.Peers = int.Parse(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders;
|
||||
|
||||
releases.Add (release);
|
||||
releases.Add(release);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return releases.ToArray ();
|
||||
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download (Uri link)
|
||||
catch (Exception ex)
|
||||
{
|
||||
var request = CreateHttpRequest (link);
|
||||
var response = await client.SendAsync (request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync ();
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
var request = CreateHttpRequest(link);
|
||||
var response = await client.SendAsync(request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ namespace Jackett.Indexers
|
||||
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
@@ -159,6 +160,8 @@ namespace Jackett.Indexers
|
||||
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader);
|
||||
results = Encoding.UTF8.GetString(response.Content);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
var json = JObject.Parse(results);
|
||||
foreach (JObject r in json["response"]["results"])
|
||||
@@ -191,6 +194,12 @@ namespace Jackett.Indexers
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
@@ -215,5 +224,6 @@ namespace Jackett.Indexers
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ namespace Jackett.Indexers
|
||||
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
@@ -116,6 +117,8 @@ namespace Jackett.Indexers
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = baseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode(searchString.Trim()));
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
try
|
||||
{
|
||||
var jResults = JObject.Parse(results);
|
||||
foreach (JObject result in (JArray)jResults["torrents"])
|
||||
{
|
||||
@@ -144,6 +147,12 @@ namespace Jackett.Indexers
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
@@ -157,5 +166,7 @@ namespace Jackett.Indexers
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,9 @@ namespace Jackett.Indexers
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<IndexerInterface, Newtonsoft.Json.Linq.JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public string DisplayName { get { return "The Pirate Bay"; } }
|
||||
|
||||
@@ -133,7 +135,8 @@ namespace Jackett.Indexers
|
||||
var response = await CurlHelper.GetAsync(baseUrl + SwitchSingleViewUrl, null, episodeSearchUrl);
|
||||
results = Encoding.UTF8.GetString(response.Content);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
|
||||
var rows = dom["#searchResult > tbody > tr"];
|
||||
@@ -183,6 +186,12 @@ namespace Jackett.Indexers
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return releases.ToArray();
|
||||
|
||||
}
|
||||
@@ -192,5 +201,7 @@ namespace Jackett.Indexers
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ namespace Jackett.Indexers
|
||||
{
|
||||
public class TorrentLeech : IndexerInterface
|
||||
{
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
@@ -114,6 +115,8 @@ namespace Jackett.Indexers
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
|
||||
CQ qRows = dom["#torrenttable > tbody > tr"];
|
||||
@@ -150,9 +153,17 @@ namespace Jackett.Indexers
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, results, ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
|
||||
@@ -160,5 +171,8 @@ namespace Jackett.Indexers
|
||||
{
|
||||
return client.GetByteArrayAsync(link);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user