diff --git a/src/Jackett.Console/Jackett.Console.csproj b/src/Jackett.Console/Jackett.Console.csproj index 918f669ff..c170cf8f5 100644 --- a/src/Jackett.Console/Jackett.Console.csproj +++ b/src/Jackett.Console/Jackett.Console.csproj @@ -115,6 +115,10 @@ + + {74420a79-cc16-442c-8b1e-7c1b913844f0} + CurlSharp + {e636d5f8-68b4-4903-b4ed-ccfd9c9e899f} Jackett diff --git a/src/Jackett.Service/Jackett.Service.csproj b/src/Jackett.Service/Jackett.Service.csproj index b9614e42a..bf2fb9a88 100644 --- a/src/Jackett.Service/Jackett.Service.csproj +++ b/src/Jackett.Service/Jackett.Service.csproj @@ -121,6 +121,10 @@ + + {74420a79-cc16-442c-8b1e-7c1b913844f0} + CurlSharp + {e636d5f8-68b4-4903-b4ed-ccfd9c9e899f} Jackett diff --git a/src/Jackett.Tray/Main.cs b/src/Jackett.Tray/Main.cs index a1a51b09f..991f72f1a 100644 --- a/src/Jackett.Tray/Main.cs +++ b/src/Jackett.Tray/Main.cs @@ -1,5 +1,4 @@ -#if !__MonoCS__ -using Microsoft.Win32; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; @@ -92,5 +91,4 @@ namespace JackettTray shortcut.Save();*/ } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Jackett/Content/logos/speedcd.png b/src/Jackett/Content/logos/speedcd.png new file mode 100644 index 000000000..7dd781b46 Binary files /dev/null and b/src/Jackett/Content/logos/speedcd.png differ diff --git a/src/Jackett/Controllers/APIController.cs b/src/Jackett/Controllers/APIController.cs index d2ac760f9..18eaad0d0 100644 --- a/src/Jackett/Controllers/APIController.cs +++ b/src/Jackett/Controllers/APIController.cs @@ -57,7 +57,7 @@ namespace Jackett.Controllers continue; var originalLink = release.Link; var encodedLink = HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(originalLink.ToString())) + "/download.torrent"; - var proxyLink = string.Format("{0}api/{1}/download/{2}", severUrl, indexer.DisplayName.ToLowerInvariant(), encodedLink); + var proxyLink = string.Format("{0}api/{1}/download/{2}", severUrl, indexer.DisplayName, encodedLink); release.Link = new Uri(proxyLink); } diff --git a/src/Jackett/Controllers/AdminController.cs b/src/Jackett/Controllers/AdminController.cs index c529fe846..2120bc504 100644 --- a/src/Jackett/Controllers/AdminController.cs +++ b/src/Jackett/Controllers/AdminController.cs @@ -34,7 +34,7 @@ namespace Jackett.Controllers } [Route("get_config_form")] - [HttpGet] + [HttpPost] public async Task GetConfigForm() { var jsonReply = new JObject(); @@ -99,7 +99,7 @@ namespace Jackett.Controllers foreach (var indexer in indexerService.GetAllIndexers()) { var item = new JObject(); - item["id"] = indexer.GetType().Name.ToLowerInvariant(); + item["id"] = indexer.GetType().Name; item["name"] = indexer.DisplayName; item["description"] = indexer.DisplayDescription; item["configured"] = indexer.IsConfigured; @@ -126,6 +126,7 @@ namespace Jackett.Controllers var postData = await ReadPostDataJson(); string indexerString = (string)postData["indexer"]; indexerService.TestIndexer(indexerString); + jsonReply["name"] = indexerService.GetIndexer(indexerString).DisplayName; jsonReply["result"] = "success"; } catch (Exception ex) diff --git a/src/Jackett/Indexers/AlphaRatio.cs b/src/Jackett/Indexers/AlphaRatio.cs index e4883f83d..be2deeae2 100644 --- a/src/Jackett/Indexers/AlphaRatio.cs +++ b/src/Jackett/Indexers/AlphaRatio.cs @@ -12,57 +12,36 @@ using System.Net.Http.Headers; using Jackett.Models; using Jackett.Utils; using NLog; +using Jackett.Services; namespace Jackett.Indexers { - public class AlphaRatio : IIndexer + public class AlphaRatio : BaseIndexer,IIndexer { - public string DisplayName - { - get { return "AlphaRatio"; } - } - - public string DisplayDescription - { - get { return "Legendary"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - - public event Action OnSaveConfigurationRequested; - public event Action OnResultParsingError; - - public bool IsConfigured { get; private set; } - - static string BaseUrl = "https://alpharatio.cc"; - - static string LoginUrl = BaseUrl + "/login.php"; - - static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr="; - - static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id="; - - static string GuidUrl = BaseUrl + "/torrents.php?torrentid="; - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; + private readonly string DownloadUrl = ""; + private readonly string GuidUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; string cookieHeader; - private Logger logger; - public AlphaRatio(Logger l) + public AlphaRatio(IIndexerManagerService i, Logger l): + base(name: "AlphaRatio", + description: "Legendary", + link: new Uri("https://alpharatio.cc"), + rageid: true, + manager:i, + logger:l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/login.php"; + SearchUrl = SiteLink + "/ajax.php?action=browse&searchstr="; + DownloadUrl = SiteLink + "/torrents.php?action=download&id="; + GuidUrl = SiteLink + "/torrents.php?torrentid="; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -83,8 +62,7 @@ namespace Jackett.Indexers public async Task ApplyConfiguration(JToken configJson) { var configSaveData = new JObject(); - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); + SaveConfig(configSaveData); var config = new ConfigurationDataBasicLogin(); config.LoadValuesFromJson(configJson); @@ -131,9 +109,7 @@ namespace Jackett.Indexers } else { - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } @@ -143,7 +119,7 @@ namespace Jackett.Indexers var message = new HttpRequestMessage(); message.Method = HttpMethod.Post; message.RequestUri = uri; - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } @@ -223,8 +199,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/AnimeBytes.cs b/src/Jackett/Indexers/AnimeBytes.cs index c5360a0f8..fe21b802f 100644 --- a/src/Jackett/Indexers/AnimeBytes.cs +++ b/src/Jackett/Indexers/AnimeBytes.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -18,7 +19,7 @@ using System.Web; namespace Jackett.Indexers { - public class AnimeBytes : IIndexer + public class AnimeBytes : BaseIndexer, IIndexer { class ConfigurationDataBasicLoginAnimeBytes : ConfigurationDataBasicLogin { @@ -38,48 +39,27 @@ namespace Jackett.Indexers } } - private static List cache = new List(); - private static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0); + + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; - public event Action OnResultParsingError; - public event Action OnSaveConfigurationRequested; - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; - - public string DisplayName - { - get { return "AnimeBytes"; } - } - - public string DisplayDescription - { - get { return "The web's best Chinese cartoons"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string BaseUrl = "https://animebytes.tv"; - const string LoginUrl = BaseUrl + "/user/login"; - const string SearchUrl = BaseUrl + "/torrents.php?filter_cat[1]=1"; - - public bool IsConfigured { get; private set; } public bool AllowRaws { get; private set; } - - CookieContainer cookieContainer; HttpClientHandler handler; HttpClient client; - Logger logger; - public AnimeBytes(Logger l) + public AnimeBytes(IIndexerManagerService i, Logger l) : + base(name: "AnimeBytes", + description: "The web's best Chinese cartoons", + link: new Uri("https://animebytes.tv"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + + LoginUrl = SiteLink + "/user/login"; + SearchUrl = SiteLink + "/torrents.php?filter_cat[1]=1"; + cookieContainer = new CookieContainer(); handler = new HttpClientHandler { @@ -88,7 +68,7 @@ namespace Jackett.Indexers UseCookies = true, }; client = new HttpClient(handler); - client.DefaultRequestHeaders.Add("User-Agent", chromeUserAgent); + client.DefaultRequestHeaders.Add("User-Agent", BrowserUtil.ChromeUserAgent); } public Task GetConfigurationForSetup() @@ -132,11 +112,11 @@ namespace Jackett.Indexers { foreach (var c in cookies) { - cookieContainer.SetCookies(new Uri(BaseUrl), c.Substring(0, c.LastIndexOf(';'))); + cookieContainer.SetCookies(SiteLink, c.Substring(0, c.LastIndexOf(';'))); } } - foreach (Cookie cookie in cookieContainer.GetCookies(new Uri(BaseUrl))) + foreach (Cookie cookie in cookieContainer.GetCookies(SiteLink)) { if (cookie.Name == "session") { @@ -146,7 +126,7 @@ namespace Jackett.Indexers } // Get the home page now we are logged in as AllowAutoRedirect is false as we needed to get the cookie manually. - response = await client.GetAsync(BaseUrl); + response = await client.GetAsync(SiteLink); responseContent = await response.Content.ReadAsStringAsync(); if (!responseContent.Contains("/user/logout")) @@ -160,16 +140,14 @@ namespace Jackett.Indexers cookieContainer.DumpToJson(SiteLink, configSaveData); configSaveData["raws"] = AllowRaws; - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookieContainer.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookieContainer.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; AllowRaws = jsonConfig["raws"].Value(); } @@ -191,13 +169,7 @@ namespace Jackett.Indexers return sb.ToString(); } - private void CleanCache() - { - foreach (var expired in cache.Where(i => i.Created - DateTime.Now > cacheTime).ToList()) - { - cache.Remove(expired); - } - } + public async Task PerformQuery(TorznabQuery query) @@ -344,9 +316,9 @@ namespace Jackett.Indexers release.PublishDate = release.PublishDate.AddDays(Math.Min(DateTime.Now.DayOfYear, 365) - 1); var infoLink = links.Get(1); - release.Comments = new Uri(BaseUrl + "/" + infoLink.Attributes.GetAttribute("href")); - release.Guid = new Uri(BaseUrl + "/" + infoLink.Attributes.GetAttribute("href") + "&nh=" + Hash(title)); // Sonarr should dedupe on this url - allow a url per name. - release.Link = new Uri(BaseUrl + "/" + downloadLink.Attributes.GetAttribute("href")); + release.Comments = new Uri(SiteLink + "/" + infoLink.Attributes.GetAttribute("href")); + release.Guid = new Uri(SiteLink + "/" + infoLink.Attributes.GetAttribute("href") + "&nh=" + Hash(title)); // Sonarr should dedupe on this url - allow a url per name. + release.Link = new Uri(SiteLink + "/" + downloadLink.Attributes.GetAttribute("href")); // We dont actually have a release name >.> so try to create one var releaseTags = infoLink.InnerText.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); @@ -406,8 +378,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, responseContent, ex); - throw ex; + OnParseError(responseContent, ex); } // Add to the cache diff --git a/src/Jackett/Indexers/BaseIndexer.cs b/src/Jackett/Indexers/BaseIndexer.cs index 1de82fb31..106633a91 100644 --- a/src/Jackett/Indexers/BaseIndexer.cs +++ b/src/Jackett/Indexers/BaseIndexer.cs @@ -6,10 +6,11 @@ using System.Threading.Tasks; using Jackett.Models; using Newtonsoft.Json.Linq; using NLog; +using Jackett.Services; namespace Jackett.Indexers { - public abstract class BaseIndexer: IIndexer + public abstract class BaseIndexer { public string DisplayDescription { get; private set; } public string DisplayName { get; private set; } @@ -17,28 +18,43 @@ namespace Jackett.Indexers public Uri SiteLink { get; private set; } public bool RequiresRageIDLookupDisabled { get; private set; } - public abstract Task ApplyConfiguration(JToken configJson); - public abstract Task Download(Uri link); - public abstract Task GetConfigurationForSetup(); - public abstract void LoadFromSavedConfiguration(JToken jsonConfig); - public abstract Task PerformQuery(TorznabQuery query); + protected Logger logger; + protected IIndexerManagerService indexerService; - private Logger logger; + protected static List cache = new List(); + protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0); - public BaseIndexer(string name, string description, Uri link, Logger logger) + + public BaseIndexer(string name, string description, bool rageid, Uri link, IIndexerManagerService manager, Logger logger) { DisplayName = name; DisplayDescription = description; SiteLink = link; this.logger = logger; + indexerService = manager; + RequiresRageIDLookupDisabled = rageid; } - protected void LogParseError(string results, Exception ex) + protected void SaveConfig(JToken config) + { + indexerService.SaveConfig(this as IIndexer, config); + } + + protected void OnParseError(string results, Exception ex) { var fileName = string.Format("Error on {0} for {1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), DisplayName); var spacing = string.Join("", Enumerable.Repeat(Environment.NewLine, 5)); var fileContents = string.Format("{0}{1}{2}", ex, spacing, results); logger.Error(fileName + fileContents); + throw ex; + } + + protected void CleanCache() + { + foreach (var expired in cache.Where(i => i.Created - DateTime.Now > cacheTime).ToList()) + { + cache.Remove(expired); + } } } } diff --git a/src/Jackett/Indexers/BeyondHD.cs b/src/Jackett/Indexers/BeyondHD.cs index f55a5bdb5..7fca5cb92 100644 --- a/src/Jackett/Indexers/BeyondHD.cs +++ b/src/Jackett/Indexers/BeyondHD.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -14,44 +15,26 @@ using System.Web; namespace Jackett.Indexers { - public class BeyondHD : IIndexer + public class BeyondHD : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "BeyondHD"; } - } - - public string DisplayDescription - { - get { return "Without BeyondHD, your HDTV is just a TV"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string BaseUrl = "https://beyondhd.me"; - const string SearchUrl = BaseUrl + "/browse.php?c40=1&c44=1&c48=1&c89=1&c46=1&c45=1&searchin=title&incldead=0&search={0}"; - const string DownloadUrl = BaseUrl + "/download.php?torrent={0}"; + private readonly string SearchUrl = ""; + private readonly string DownloadUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public BeyondHD(Logger l) + public BeyondHD(IIndexerManagerService i, Logger l) : + base(name: "BeyondHD", + description: "Without BeyondHD, your HDTV is just a TV", + link: new Uri("https://beyondhd.me"), + rageid: true, + manager:i, + logger:l) { - logger = l; - IsConfigured = false; + SearchUrl = SiteLink + "/browse.php?c40=1&c44=1&c48=1&c89=1&c46=1&c45=1&searchin=title&incldead=0&search={0}"; + DownloadUrl = SiteLink + "/download.php?torrent={0}"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -75,9 +58,9 @@ namespace Jackett.Indexers var jsonCookie = new JObject(); jsonCookie["cookie_header"] = config.CookieHeader; - cookies.FillFromJson(new Uri(BaseUrl), jsonCookie, logger); + cookies.FillFromJson(SiteLink, jsonCookie, logger); - var responseContent = await client.GetStringAsync(BaseUrl); + var responseContent = await client.GetStringAsync(SiteLink); if (!responseContent.Contains("logout.php")) { @@ -88,18 +71,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } - } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -124,14 +103,14 @@ namespace Jackett.Indexers var qRow = row.Cq(); var qLink = row.ChildElements.ElementAt(2).FirstChild.Cq(); - release.Link = new Uri(BaseUrl + "/" + qLink.Attr("href")); + release.Link = new Uri(SiteLink + "/" + qLink.Attr("href")); var torrentID = qLink.Attr("href").Split('=').Last(); var descCol = row.ChildElements.ElementAt(3); var qCommentLink = descCol.FirstChild.Cq(); release.Title = qCommentLink.Text(); release.Description = release.Title; - release.Comments = new Uri(BaseUrl + "/" + qCommentLink.Attr("href")); + release.Comments = new Uri(SiteLink + "/" + qCommentLink.Attr("href")); release.Guid = release.Comments; var dateStr = descCol.ChildElements.Last().Cq().Text().Split('|').Last().ToLowerInvariant().Replace("ago.", "").Trim(); @@ -167,11 +146,9 @@ namespace Jackett.Indexers } } - catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/BitHdtv.cs b/src/Jackett/Indexers/BitHdtv.cs index a7319e23c..27ea5cbd5 100644 --- a/src/Jackett/Indexers/BitHdtv.cs +++ b/src/Jackett/Indexers/BitHdtv.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,41 +16,28 @@ using System.Web; namespace Jackett.Indexers { - public class BitHdtv : IIndexer + public class BitHdtv : BaseIndexer, IIndexer { - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "BIT-HDTV"; } - } - - public string DisplayDescription - { - get { return "Home of high definition invites"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - static string BaseUrl = "https://www.bit-hdtv.com"; - static string LoginUrl = BaseUrl + "/takelogin.php"; - static string SearchUrl = BaseUrl + "/torrents.php?cat=0&search="; - static string DownloadUrl = BaseUrl + "/download.php?/{0}/dl.torrent"; + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; + private readonly string DownloadUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger loggger; - public BitHdtv(Logger l) + public BitHdtv(IIndexerManagerService i, Logger l) : + base(name: "BIT-HDTV", + description: "Home of high definition invites", + link: new Uri("https://www.bit-hdtv.com"), + rageid: true, + manager: i, + logger: l) { - loggger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/takelogin.php"; + SearchUrl = SiteLink + "/torrents.php?cat=0&search="; + DownloadUrl = SiteLink + "/download.php?/{0}/dl.torrent"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -94,21 +82,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } - public event Action OnSaveConfigurationRequested; - - public bool IsConfigured { get; private set; } - public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, loggger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -136,7 +117,7 @@ namespace Jackett.Indexers release.MinimumSeedTime = 172800; release.Title = qLink.Attr("title"); release.Description = release.Title; - release.Guid = new Uri(BaseUrl + qLink.Attr("href")); + release.Guid = new Uri(SiteLink + qLink.Attr("href")); release.Comments = release.Guid; release.Link = new Uri(string.Format(DownloadUrl, qLink.Attr("href").Split('=')[1])); @@ -157,8 +138,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); @@ -168,7 +148,5 @@ namespace Jackett.Indexers { return client.GetByteArrayAsync(link); } - - } } diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index fc845d2db..f5f08f209 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -16,7 +17,7 @@ using System.Web; namespace Jackett.Indexers { - public class BitMeTV : IIndexer + public class BitMeTV : BaseIndexer, IIndexer { class BmtvConfig : ConfigurationData { @@ -42,24 +43,28 @@ namespace Jackett.Indexers } } - static string BaseUrl = "http://www.bitmetv.org"; - static string LoginUrl = BaseUrl + "/login.php"; - static string LoginPost = BaseUrl + "/takelogin.php"; - static string CaptchaUrl = BaseUrl + "/visual.php"; - static string SearchUrl = BaseUrl + "/browse.php"; + private readonly string LoginUrl = ""; + private readonly string LoginPost = ""; + private readonly string CaptchaUrl = ""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public event Action OnSaveConfigurationRequested; - public event Action OnResultParsingError; - - public BitMeTV(Logger l) + public BitMeTV(IIndexerManagerService i, Logger l) : + base(name: "BitMeTV", + description: "TV Episode specialty tracker", + link: new Uri("http://www.bitmetv.org"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/login.php"; + LoginPost = SiteLink + "/takelogin.php"; + CaptchaUrl = SiteLink + "/visual.php"; + SearchUrl = SiteLink + "/browse.php"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -70,16 +75,6 @@ namespace Jackett.Indexers client = new HttpClient(handler); } - public string DisplayName { get { return "BitMeTV"; } } - - public string DisplayDescription { get { return "TV Episode specialty tracker"; } } - - public Uri SiteLink { get { return new Uri(BaseUrl); } } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - public async Task GetConfigurationForSetup() { await client.GetAsync(LoginUrl); @@ -119,17 +114,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -155,7 +147,7 @@ namespace Jackett.Indexers release.MinimumRatio = 1; release.MinimumSeedTime = 172800; - release.Comments = new Uri(BaseUrl + "/" + qLink.Attr("href")); + release.Comments = new Uri(SiteLink + "/" + qLink.Attr("href")); release.Guid = release.Comments; release.Title = qLink.Attr("title"); release.Description = release.Title; @@ -169,7 +161,7 @@ namespace Jackett.Indexers var date = DateTime.ParseExact(formattedTimeString, "dddd MMMM d yyyy hh:mm:ss tt", CultureInfo.InvariantCulture); release.PublishDate = DateTime.SpecifyKind(date, DateTimeKind.Utc).ToLocalTime(); - release.Link = new Uri(BaseUrl + "/" + row.ChildElements.ElementAt(2).Cq().Children("a.index").Attr("href")); + release.Link = new Uri(SiteLink + "/" + row.ChildElements.ElementAt(2).Cq().Children("a.index").Attr("href")); var sizeCol = row.ChildElements.ElementAt(6); var sizeVal = ParseUtil.CoerceFloat(sizeCol.ChildNodes[0].NodeValue); @@ -187,8 +179,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/FrenchTorrentDb.cs b/src/Jackett/Indexers/FrenchTorrentDb.cs index d03eecceb..1dead510b 100644 --- a/src/Jackett/Indexers/FrenchTorrentDb.cs +++ b/src/Jackett/Indexers/FrenchTorrentDb.cs @@ -1,7 +1,9 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -12,7 +14,7 @@ using System.Web; namespace Jackett.Indexers { - class FrenchTorrentDb : IIndexer + class FrenchTorrentDb : BaseIndexer, IIndexer { public event Action OnSaveConfigurationRequested; @@ -33,28 +35,9 @@ namespace Jackett.Indexers } } - public string DisplayName - { - get { return "FrenchTorrentDb"; } - } - public string DisplayDescription - { - get { return "One the biggest French Torrent Tracker"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - const string BaseUrl = "http://www.frenchtorrentdb.com/"; - const string MainUrl = BaseUrl + "?section=INDEX"; - const string SearchUrl = BaseUrl + "?section=TORRENTS&exact=1&name={0}&submit=GO"; - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; + private readonly string MainUrl = ""; + private readonly string SearchUrl = ""; string cookie = string.Empty; @@ -62,9 +45,17 @@ namespace Jackett.Indexers HttpClientHandler handler; HttpClient client; - public FrenchTorrentDb() + public FrenchTorrentDb(IIndexerManagerService i, Logger l) : + base(name: "FrenchTorrentDb", + description: "One the biggest French Torrent Tracker", + link: new Uri("http://www.frenchtorrentdb.com/"), + rageid: true, + manager: i, + logger: l) { - IsConfigured = false; + MainUrl = SiteLink + "?section=INDEX"; + SearchUrl = SiteLink + "?section=TORRENTS&exact=1&name={0}&submit=GO"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -73,12 +64,12 @@ namespace Jackett.Indexers UseCookies = true, }; client = new HttpClient(handler); - client.DefaultRequestHeaders.UserAgent.ParseAdd(chromeUserAgent); + client.DefaultRequestHeaders.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); } public Task GetConfigurationForSetup() { - var config = new ConfigurationDataUrl(BaseUrl); + var config = new ConfigurationDataUrl(SiteLink); return Task.FromResult(config); } @@ -86,7 +77,7 @@ namespace Jackett.Indexers { var config = new ConfigurationDataBasicLoginFrenchTorrentDb(); config.LoadValuesFromJson(configJson); - cookies.SetCookies(new Uri(BaseUrl), "WebsiteID=" + config.Cookie.Value); + cookies.SetCookies(SiteLink, "WebsiteID=" + config.Cookie.Value); var mainPage = await client.GetAsync(MainUrl); string responseContent = await mainPage.Content.ReadAsStringAsync(); @@ -109,7 +100,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig) { cookie = (string)jsonConfig["cookie"]; - cookies.SetCookies(new Uri(BaseUrl), "WebsiteID=" + cookie); + cookies.SetCookies(SiteLink, "WebsiteID=" + cookie); IsConfigured = true; } @@ -142,9 +133,9 @@ namespace Jackett.Indexers release.MinimumSeedTime = 172800; release.Title = qLink.Text().Trim(); release.Description = release.Title; - release.Comments = new Uri(BaseUrl + "/" + qLink.Attr("href").TrimStart('/')); + release.Comments = new Uri(SiteLink + "/" + qLink.Attr("href").TrimStart('/')); release.Guid = release.Comments; - release.Link = new Uri(BaseUrl + "/" + qDlLink.Attr("href").TrimStart('/')); + release.Link = new Uri(SiteLink + "/" + qDlLink.Attr("href").TrimStart('/')); release.PublishDate = DateTime.Now; release.Seeders = ParseUtil.CoerceInt(qRow.Find("li.torrents_seeders").Text()); release.Peers = ParseUtil.CoerceInt(qRow.Find("li.torrents_leechers").Text()) + release.Seeders; diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index d5080b10e..41522d2be 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -1,6 +1,7 @@ using CsQuery; using Jackett.Indexers; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -18,38 +19,29 @@ using System.Web.UI.WebControls; namespace Jackett { - public class Freshon : IIndexer + public class Freshon : BaseIndexer, IIndexer { - public event Action OnResultParsingError; - - static string BaseUrl = "https://freshon.tv"; - static string LoginUrl = BaseUrl + "/login.php"; - static string LoginPostUrl = BaseUrl + "/login.php?action=makelogin"; - static string SearchUrl = BaseUrl + "/browse.php"; - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; + private readonly string LoginUrl = ""; + private readonly string LoginPostUrl = ""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public bool IsConfigured { get; private set; } - - public string DisplayName { get { return "FreshOnTV"; } } - - 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 bool RequiresRageIDLookupDisabled { get { return true; } } - - public event Action OnSaveConfigurationRequested; - private Logger logger; - - public Freshon(Logger l) + public Freshon(IIndexerManagerService i, Logger l) : + base(name: "FreshOnTV", + description: "Our goal is to provide the latest stuff in the TV show domain", + link: new Uri("https://www.bit-hdtv.com"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + + LoginUrl = SiteLink + "/login.php"; + LoginPostUrl = SiteLink + "/login.php?action=makelogin"; + SearchUrl = SiteLink + "/browse.php"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -99,17 +91,14 @@ namespace Jackett { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - // if (OnSaveConfigurationRequested != null) - // OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -118,7 +107,7 @@ namespace Jackett var message = new HttpRequestMessage(); message.Method = HttpMethod.Get; message.RequestUri = uri; - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } @@ -156,9 +145,9 @@ namespace Jackett release.MinimumSeedTime = 172800; release.Title = qLink.Attr("title"); release.Description = release.Title; - release.Guid = new Uri(BaseUrl + qLink.Attr("href")); + release.Guid = new Uri(SiteLink + 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(SiteLink + qRow.Find("td.table_links > a").First().Attr("href")); DateTime pubDate; var dateString = qRow.Find("td.table_added").Text().Trim(); @@ -183,8 +172,7 @@ namespace Jackett } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/HDTorrents.cs b/src/Jackett/Indexers/HDTorrents.cs index 9655ec244..63738302e 100644 --- a/src/Jackett/Indexers/HDTorrents.cs +++ b/src/Jackett/Indexers/HDTorrents.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,28 +16,27 @@ using System.Web; namespace Jackett.Indexers { - public class HDTorrents : IIndexer + public class HDTorrents : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - const string DefaultUrl = "http://hdts.ru"; // Of the accessible domains the .ru seems the most reliable. https://hdts.ru | https://hd-torrents.org | https://hd-torrents.net | https://hd-torrents.me - string BaseUrl = DefaultUrl; - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; - private string SearchUrl = DefaultUrl + "/torrents.php?search={0}&active=1&options=0&category%5B%5D=59&category%5B%5D=60&category%5B%5D=30&category%5B%5D=38&page={1}"; - private static string LoginUrl = DefaultUrl + "/login.php"; + private readonly string SearchUrl = ""; + private static string LoginUrl = ""; private const int MAXPAGES = 3; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public HDTorrents(Logger l) + public HDTorrents(IIndexerManagerService i, Logger l) : + base(name: "HD-Torrents", + description: "HD-Torrents is a private torrent website with HD torrents and strict rules on their content.", + link: new Uri("http://hdts.ru"),// Of the accessible domains the .ru seems the most reliable. https://hdts.ru | https://hd-torrents.org | https://hd-torrents.net | https://hd-torrents.me + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + SearchUrl = SiteLink + "/torrents.php?search={0}&active=1&options=0&category%5B%5D=59&category%5B%5D=60&category%5B%5D=30&category%5B%5D=38&page={1}"; + LoginUrl = SiteLink + "/login.php"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -47,29 +47,6 @@ namespace Jackett.Indexers client = new HttpClient(handler); } - public string DisplayName - { - get { return "HD-Torrents"; } - } - - public string DisplayDescription - { - get { return "HD-Torrents is a private torrent website with HD torrents and strict rules on their content."; } - } - - public Uri SiteLink - { - get { return new Uri(DefaultUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured - { - get; - private set; - } - public Task GetConfigurationForSetup() { var config = new ConfigurationDataBasicLogin(); @@ -81,7 +58,7 @@ namespace Jackett.Indexers var message = new HttpRequestMessage(); message.Method = HttpMethod.Get; message.RequestUri = new Uri(url); - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } @@ -118,10 +95,7 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } @@ -132,7 +106,7 @@ namespace Jackett.Indexers IsConfigured = true; } - async Task PerformQuery(TorznabQuery query, string baseUrl) + async Task PerformQuery(TorznabQuery query, Uri baseUrl) { List releases = new List(); List searchurls = new List(); @@ -212,9 +186,9 @@ namespace Jackett.Indexers } release.Size = size; - release.Guid = new Uri(DefaultUrl + "/" + qRow.Find("td.mainblockcontent b a").Attr("href")); - release.Link = new Uri(DefaultUrl + "/" + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href")); - release.Comments = new Uri(DefaultUrl + "/" + qRow.Find("td.mainblockcontent b a").Attr("href") + "#comments"); + release.Guid = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href")); + release.Link = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href")); + release.Comments = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href") + "#comments"); string[] dateSplit = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(','); string dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>')); @@ -225,8 +199,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError( results, ex); } } @@ -236,7 +209,7 @@ namespace Jackett.Indexers public async Task PerformQuery(TorznabQuery query) { - return await PerformQuery(query, BaseUrl); + return await PerformQuery(query, SiteLink); } public Task Download(Uri link) diff --git a/src/Jackett/Indexers/IPTorrents.cs b/src/Jackett/Indexers/IPTorrents.cs index 00ff0ca5a..d26c6ef65 100644 --- a/src/Jackett/Indexers/IPTorrents.cs +++ b/src/Jackett/Indexers/IPTorrents.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,38 +16,22 @@ using System.Web; namespace Jackett.Indexers { - public class IPTorrents : IIndexer + public class IPTorrents : BaseIndexer, IIndexer { - - public event Action OnSaveConfigurationRequested; - public event Action 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 bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; - - static string BaseUrl = "https://iptorrents.com"; - - string SearchUrl = BaseUrl + "/t?q="; - - + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public IPTorrents(Logger l) + public IPTorrents(IIndexerManagerService i, Logger l) : + base(name: "IPTorrents", + description: "Always a step ahead.", + link: new Uri("https://iptorrents.com"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + SearchUrl = SiteLink + "t?q="; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -59,7 +44,7 @@ namespace Jackett.Indexers public async Task GetConfigurationForSetup() { - await client.GetAsync(new Uri(BaseUrl)); + await client.GetAsync(SiteLink); var config = new ConfigurationDataBasicLogin(); return (ConfigurationData)config; } @@ -79,9 +64,9 @@ namespace Jackett.Indexers 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 = SiteLink; + message.Headers.Referrer = SiteLink; + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); var response = await client.SendAsync(message); var responseContent = await response.Content.ReadAsStringAsync(); @@ -97,13 +82,9 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } - } HttpRequestMessage CreateHttpRequest(Uri uri) @@ -111,22 +92,19 @@ namespace Jackett.Indexers var message = new HttpRequestMessage(); message.Method = HttpMethod.Get; message.RequestUri = uri; - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } public async Task PerformQuery(TorznabQuery query) { - - List releases = new List(); - - + var releases = new List(); var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString(); var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString); @@ -148,7 +126,7 @@ namespace Jackett.Indexers 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(SiteLink + qTitleLink.Attr("href")); release.Comments = release.Guid; DateTime pubDate; @@ -174,7 +152,7 @@ namespace Jackett.Indexers release.PublishDate = pubDate; var qLink = row.ChildElements.ElementAt(3).Cq().Children("a"); - release.Link = new Uri(BaseUrl + qLink.Attr("href")); + release.Link = new Uri(SiteLink + qLink.Attr("href")); var sizeStr = row.ChildElements.ElementAt(5).Cq().Text().Trim(); var sizeVal = ParseUtil.CoerceFloat(sizeStr.Split(' ')[0]); @@ -189,12 +167,10 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); - } public async Task Download(Uri link) @@ -204,8 +180,5 @@ namespace Jackett.Indexers var bytes = await response.Content.ReadAsByteArrayAsync(); return bytes; } - - - } } diff --git a/src/Jackett/Indexers/Master.cs b/src/Jackett/Indexers/Master.cs deleted file mode 100644 index b563b69cd..000000000 --- a/src/Jackett/Indexers/Master.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Jackett.Indexers -{ - class Master - { - - - - } -} diff --git a/src/Jackett/Indexers/MoreThanTV.cs b/src/Jackett/Indexers/MoreThanTV.cs index 0c158e524..86136bffd 100644 --- a/src/Jackett/Indexers/MoreThanTV.cs +++ b/src/Jackett/Indexers/MoreThanTV.cs @@ -1,5 +1,7 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; +using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; using System; @@ -14,52 +16,33 @@ using System.Web; namespace Jackett.Indexers { - public class MoreThanTV : IIndexer + public class MoreThanTV : BaseIndexer, IIndexer { - public string DisplayName - { - get { return "MoreThanTV"; } - } - - public string DisplayDescription - { - get { return "ROMANIAN Private Torrent Tracker for TV / MOVIES, and the internal tracker for the release group DRACULA"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public event Action OnSaveConfigurationRequested; - public event Action OnResultParsingError; - - public bool IsConfigured { get; private set; } - - static string BaseUrl = "https://www.morethan.tv"; - - static string LoginUrl = BaseUrl + "/login.php"; - - static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr="; - - static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id="; - - static string GuidUrl = BaseUrl + "/torrents.php?torrentid="; + private readonly string LoginUrl =""; + private readonly string SearchUrl = ""; + private readonly string DownloadUrl = ""; + private readonly string GuidUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - private Logger logger; string cookieHeader; int retries = 3; - public MoreThanTV(Logger l) + public MoreThanTV(IIndexerManagerService i, Logger l) : + base(name: "MoreThanTV", + description: "ROMANIAN Private Torrent Tracker for TV / MOVIES, and the internal tracker for the release group DRACULA.", + link: new Uri("https://www.morethan.tv"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/login.php"; + SearchUrl = SiteLink + "/ajax.php?action=browse&searchstr="; + DownloadUrl = SiteLink + "/torrents.php?action=download&id="; + GuidUrl = SiteLink + "/torrents.php?torrentid="; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -121,9 +104,7 @@ namespace Jackett.Indexers } else { - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } @@ -135,7 +116,7 @@ namespace Jackett.Indexers IsConfigured = true; } - static void FillReleaseInfoFromJson(ReleaseInfo release, JObject r) + private void FillReleaseInfoFromJson(ReleaseInfo release, JObject r) { var id = r["torrentId"]; release.Size = (long)r["size"]; @@ -173,7 +154,7 @@ namespace Jackett.Indexers double dateNum; if (double.TryParse((string)r["groupTime"], out dateNum)) { - pubDate = UnixTimestampToDateTime(dateNum); + pubDate = DateTimeUtil.UnixTimestampToDateTime(dateNum); pubDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Utc).ToLocalTime(); } @@ -205,20 +186,12 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); } - static DateTime UnixTimestampToDateTime(double unixTime) - { - DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); - long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond); - return new DateTime(unixStart.Ticks + unixTimeStampInTicks); - } - public async Task Download(Uri link) { if (Engine.IsWindows) @@ -230,7 +203,6 @@ namespace Jackett.Indexers var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader); return response.Content; } - } } } diff --git a/src/Jackett/Indexers/Rarbg.cs b/src/Jackett/Indexers/Rarbg.cs index 9495d9475..72d16bdfc 100644 --- a/src/Jackett/Indexers/Rarbg.cs +++ b/src/Jackett/Indexers/Rarbg.cs @@ -1,7 +1,9 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Linq; @@ -12,48 +14,27 @@ using System.Threading.Tasks; namespace Jackett.Indexers { - public class Rarbg : IIndexer + public class Rarbg : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "RARBG"; } - } - - public string DisplayDescription - { - get { return DisplayName; } - } - - public Uri SiteLink - { - get { return new Uri("https://rarbg.com"); } - } - - public bool RequiresRageIDLookupDisabled { get { return false; } } - - public bool IsConfigured { get; private set; } - const string DefaultUrl = "http://torrentapi.org"; - const string TokenUrl = "/pubapi.php?get_token=get_token&format=json"; const string SearchTVRageUrl = "/pubapi.php?mode=search&search_tvrage={0}&token={1}&format=json&min_seeders=1"; const string SearchQueryUrl = "/pubapi.php?mode=search&search_string={0}&token={1}&format=json&min_seeders=1"; - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; - - string BaseUrl; + private string BaseUrl; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public Rarbg() + + public Rarbg(IIndexerManagerService i, Logger l) : + base(name: "RARBG", + description: "RARBG", + link: new Uri("https://rarbg.com"), + rageid: true, + manager: i, + logger: l) { - IsConfigured = false; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -85,10 +66,7 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["base_url"] = BaseUrl; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } @@ -103,7 +81,7 @@ namespace Jackett.Indexers var message = new HttpRequestMessage(); message.Method = HttpMethod.Get; message.RequestUri = new Uri(uri); - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } @@ -156,10 +134,9 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); + OnParseError(results, ex); } return releases.ToArray(); - } public Task Download(Uri link) diff --git a/src/Jackett/Indexers/SceneAccess.cs b/src/Jackett/Indexers/SceneAccess.cs index b748423a9..799cfdd6b 100644 --- a/src/Jackett/Indexers/SceneAccess.cs +++ b/src/Jackett/Indexers/SceneAccess.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -13,50 +14,27 @@ using System.Threading.Tasks; namespace Jackett.Indexers { - class SceneAccess : IIndexer + class SceneAccess : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "SceneAccess"; } - } - - public string DisplayDescription - { - get { return "Your gateway to the scene"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string BaseUrl = "https://sceneaccess.eu"; - const string LoginUrl = BaseUrl + "/login"; - const string SearchUrl = BaseUrl + "/{0}?method=1&c{1}=1&search={2}"; - - - public bool IsConfigured - { - get; - private set; - } + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; string cookieHeader; - private Logger logger; - public SceneAccess(Logger l) + public SceneAccess(IIndexerManagerService i, Logger l) : + base(name: "SceneAccess", + description: "Your gateway to the scene", + link: new Uri("https://sceneaccess.eu"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/login"; + SearchUrl = SiteLink + "/{0}?method=1&c{1}=1&search={2}"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -114,16 +92,14 @@ namespace Jackett.Indexers } else { - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); cookieHeader = cookies.GetCookieHeader(SiteLink); IsConfigured = true; } @@ -162,9 +138,9 @@ namespace Jackett.Indexers release.MinimumSeedTime = 129600; release.Title = qRow.Find(".ttr_name > a").Text(); release.Description = release.Title; - release.Guid = new Uri(BaseUrl + "/" + qRow.Find(".ttr_name > a").Attr("href")); + release.Guid = new Uri(SiteLink + "/" + qRow.Find(".ttr_name > a").Attr("href")); release.Comments = release.Guid; - release.Link = new Uri(BaseUrl + "/" + qRow.Find(".td_dl > a").Attr("href")); + release.Link = new Uri(SiteLink + "/" + qRow.Find(".td_dl > a").Attr("href")); var sizeStr = qRow.Find(".ttr_size").Contents()[0].NodeValue; var sizeParts = sizeStr.Split(' '); @@ -185,8 +161,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/SceneTime.cs b/src/Jackett/Indexers/SceneTime.cs index 1ac3fcddb..1e26a6497 100644 --- a/src/Jackett/Indexers/SceneTime.cs +++ b/src/Jackett/Indexers/SceneTime.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,46 +16,28 @@ using System.Web; namespace Jackett.Indexers { - public class SceneTime : IIndexer + public class SceneTime : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "SceneTime"; } - } - - public string DisplayDescription - { - get { return "Always on time"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string BaseUrl = "https://www.scenetime.com"; - const string LoginUrl = BaseUrl + "/takelogin.php"; - const string SearchUrl = BaseUrl + "/browse_API.php"; - const string DownloadUrl = BaseUrl + "/download.php/{0}/download.torrent"; + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; + private readonly string DownloadUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - - public SceneTime(Logger l) + public SceneTime(IIndexerManagerService i, Logger l) : + base(name: "SceneTime", + description: "Always on time", + link: new Uri("https://www.scenetime.com"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/takelogin.php"; + SearchUrl = SiteLink + "/browse_API.php"; + DownloadUrl = SiteLink + "/download.php/{0}/download.torrent"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -96,17 +79,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -146,7 +126,7 @@ namespace Jackett.Indexers var qLink = qDescCol.Find("a"); release.Title = qLink.Text(); release.Description = release.Title; - release.Comments = new Uri(BaseUrl + "/" + qLink.Attr("href")); + release.Comments = new Uri(SiteLink + "/" + qLink.Attr("href")); release.Guid = release.Comments; var torrentId = qLink.Attr("href").Split('=')[1]; release.Link = new Uri(string.Format(DownloadUrl, torrentId)); @@ -169,8 +149,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); } diff --git a/src/Jackett/Indexers/ShowRSS.cs b/src/Jackett/Indexers/ShowRSS.cs index 30d9b7357..c37f271ee 100644 --- a/src/Jackett/Indexers/ShowRSS.cs +++ b/src/Jackett/Indexers/ShowRSS.cs @@ -1,6 +1,8 @@ using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -14,47 +16,25 @@ using System.Xml; namespace Jackett.Indexers { - public class ShowRSS : IIndexer + public class ShowRSS : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "ShowRSS"; } - } - - public string DisplayDescription - { - get { return "showRSS is a service that allows you to keep track of your favorite TV shows"; } - } - - public Uri SiteLink - { - get { return new Uri(DefaultUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string DefaultUrl = "http://showrss.info"; - const string searchAllUrl = DefaultUrl + "/feeds/all.rss"; + private readonly string searchAllUrl = ""; string BaseUrl; - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public bool IsConfigured + public ShowRSS(IIndexerManagerService i, Logger l) : + base(name: "ShowRSS", + description: "showRSS is a service that allows you to keep track of your favorite TV shows", + link: new Uri("http://showrss.info"), + rageid: true, + manager: i, + logger: l) { - get; - private set; - } + searchAllUrl = SiteLink + "/feeds/all.rss"; - public ShowRSS() - { - IsConfigured = false; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -67,13 +47,13 @@ namespace Jackett.Indexers public Task GetConfigurationForSetup() { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); return Task.FromResult(config); } public async Task ApplyConfiguration(Newtonsoft.Json.Linq.JToken configJson) { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); config.LoadValuesFromJson(configJson); var formattedUrl = config.GetFormattedHostUrl(); @@ -85,10 +65,7 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["base_url"] = BaseUrl; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } @@ -112,7 +89,7 @@ namespace Jackett.Indexers { WebClient wc = new WebClient(); WebHeaderCollection headers = new WebHeaderCollection(); - headers.Add("User-Agent", chromeUserAgent); + headers.Add("User-Agent", BrowserUtil.ChromeUserAgent); wc.Headers = headers; return wc; } @@ -166,8 +143,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, xml, ex); - throw ex; + OnParseError(xml, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/SpeedCD.cs b/src/Jackett/Indexers/SpeedCD.cs index 6e43d55e1..97d8a1af6 100644 --- a/src/Jackett/Indexers/SpeedCD.cs +++ b/src/Jackett/Indexers/SpeedCD.cs @@ -1,5 +1,9 @@ using CsQuery; +using Jackett.Models; +using Jackett.Services; +using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -13,36 +17,31 @@ using System.Web; namespace Jackett.Indexers { - public class SpeedCD : IndexerInterface + public class SpeedCD : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName { get { return "Speed.cd"; } } - - public string DisplayDescription { get { return "Your home now!"; } } - - public Uri SiteLink { get { return new Uri(BaseUrl); } } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string BaseUrl = "http://speed.cd"; - const string LoginUrl = BaseUrl + "/take_login.php"; - const string SearchUrl = BaseUrl + "/V3/API/API.php"; - const string SearchFormData = "c53=1&c49=1&c2=1&c52=1&c41=1&c50=1&c30=1&jxt=4&jxw=b"; - const string CommentsUrl = BaseUrl + "/t/{0}"; - const string DownloadUrl = BaseUrl + "/download.php?torrent={0}"; + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; + private readonly string SearchFormData = "c53=1&c49=1&c2=1&c52=1&c41=1&c50=1&c30=1&jxt=4&jxw=b"; + private readonly string CommentsUrl =""; + private readonly string DownloadUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public bool IsConfigured { get; private set; } - - public SpeedCD() + public SpeedCD(IIndexerManagerService i, Logger l) : + base(name: "Speed.cd", + description: "Your home now!", + link: new Uri("http://speed.cd"), + rageid: true, + manager: i, + logger: l) { - IsConfigured = false; + LoginUrl = SiteLink + "/take_login.php"; + SearchUrl = SiteLink + "/V3/API/API.php"; + CommentsUrl = SiteLink + "/t/{0}"; + DownloadUrl = SiteLink + "/download.php?torrent={0}"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -84,17 +83,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -142,7 +138,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); + // OnResultParsingError(this, results, ex); throw ex; } return releases.ToArray(); diff --git a/src/Jackett/Indexers/Strike.cs b/src/Jackett/Indexers/Strike.cs index 594f9c391..c42a7ddff 100644 --- a/src/Jackett/Indexers/Strike.cs +++ b/src/Jackett/Indexers/Strike.cs @@ -1,5 +1,7 @@ using Jackett.Models; +using Jackett.Services; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -12,47 +14,24 @@ using System.Web; namespace Jackett.Indexers { - public class Strike : IIndexer + public class Strike : BaseIndexer, IIndexer { + private readonly string DownloadUrl = "/torrents/api/download/{0}.torrent"; + private readonly string SearchUrl = "/api/v2/torrents/search/?category=TV&phrase={0}"; + private string BaseUrl; - public event Action OnSaveConfigurationRequested; - public event Action OnResultParsingError; + private CookieContainer cookies; + private HttpClientHandler handler; + private HttpClient client; - public string DisplayName + public Strike(IIndexerManagerService i, Logger l) : + base(name: "Strike", + description: "Torrent search engine", + link: new Uri("https://getstrike.net"), + rageid: true, + manager: i, + logger: l) { - get { return "Strike"; } - } - - public string DisplayDescription - { - get { return "Torrent search engine"; } - } - - public Uri SiteLink - { - get { return new Uri(DefaultUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string DefaultUrl = "https://getstrike.net"; - - - //const string DownloadUrl = "/api/v2/torrents/download/?hash={0}"; - const string DownloadUrl = "/torrents/api/download/{0}.torrent"; - - const string SearchUrl = "/api/v2/torrents/search/?category=TV&phrase={0}"; - string BaseUrl; - - CookieContainer cookies; - HttpClientHandler handler; - HttpClient client; - - public Strike() - { - IsConfigured = false; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -65,13 +44,13 @@ namespace Jackett.Indexers public Task GetConfigurationForSetup() { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); return Task.FromResult(config); } public async Task ApplyConfiguration(JToken configJson) { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); config.LoadValuesFromJson(configJson); var formattedUrl = config.GetFormattedHostUrl(); @@ -83,12 +62,8 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["base_url"] = BaseUrl; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; - } public void LoadFromSavedConfiguration(JToken jsonConfig) @@ -138,11 +113,9 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } - return releases.ToArray(); } diff --git a/src/Jackett/Indexers/T411.cs b/src/Jackett/Indexers/T411.cs index 8371acb93..605df001b 100644 --- a/src/Jackett/Indexers/T411.cs +++ b/src/Jackett/Indexers/T411.cs @@ -1,6 +1,8 @@ using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -14,35 +16,9 @@ using System.Web; namespace Jackett.Indexers { - public class T411 : IIndexer + public class T411 : BaseIndexer, IIndexer { - - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "T411"; } - } - - public string DisplayDescription - { - get { return "French Torrent Tracker"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string BaseUrl = "http://www.t411.io"; - const string CommentsUrl = BaseUrl + "/torrents/{0}"; - + private readonly string CommentsUrl = ""; const string ApiUrl = "http://api.t411.io"; const string AuthUrl = ApiUrl + "/auth"; const string SearchUrl = ApiUrl + "/torrents/search/{0}"; @@ -56,8 +32,15 @@ namespace Jackett.Indexers string token = string.Empty; DateTime lastTokenFetch = DateTime.MinValue; - public T411() + public T411(IIndexerManagerService i, Logger l) : + base(name: "T411", + description: "French Torrent Tracker", + link: new Uri("http://www.t411.io"), + rageid: true, + manager: i, + logger: l) { + CommentsUrl = SiteLink + "/torrents/{0}"; IsConfigured = false; handler = new HttpClientHandler { @@ -120,10 +103,7 @@ namespace Jackett.Indexers configSaveData["password"] = password; configSaveData["token"] = token; configSaveData["last_token_fetch"] = lastTokenFetch; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } @@ -182,8 +162,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); } diff --git a/src/Jackett/Indexers/ThePirateBay.cs b/src/Jackett/Indexers/ThePirateBay.cs index c133f55d4..a2b1df7f9 100644 --- a/src/Jackett/Indexers/ThePirateBay.cs +++ b/src/Jackett/Indexers/ThePirateBay.cs @@ -1,7 +1,9 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -15,35 +17,24 @@ using System.Web; namespace Jackett.Indexers { - public class ThePirateBay : IIndexer + public class ThePirateBay : BaseIndexer, IIndexer { - - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName { get { return "The Pirate Bay"; } } - - public string DisplayDescription { get { return "The worlds largest bittorrent indexer"; } } - - public Uri SiteLink { get { return new Uri(DefaultUrl); } } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string DefaultUrl = "https://thepiratebay.mn"; const string SearchUrl = "/search/{0}/0/99/208,205"; - string BaseUrl; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public ThePirateBay() + public ThePirateBay(IIndexerManagerService i, Logger l) : + base(name: "The Pirate Bay", + description: "The worlds largest bittorrent indexer", + link: new Uri("https://thepiratebay.mn"), + rageid: true, + manager: i, + logger: l) { - BaseUrl = DefaultUrl; + BaseUrl = SiteLink.ToString(); IsConfigured = false; cookies = new CookieContainer(); handler = new HttpClientHandler @@ -63,7 +54,7 @@ namespace Jackett.Indexers public async Task ApplyConfiguration(JToken configJson) { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); config.LoadValuesFromJson(configJson); var formattedUrl = config.GetFormattedHostUrl(); @@ -75,10 +66,7 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["base_url"] = BaseUrl; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } diff --git a/src/Jackett/Indexers/TorrentDay.cs b/src/Jackett/Indexers/TorrentDay.cs index 019ac070b..e6bb3b685 100644 --- a/src/Jackett/Indexers/TorrentDay.cs +++ b/src/Jackett/Indexers/TorrentDay.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,47 +16,28 @@ using System.Web; namespace Jackett.Indexers { - public class TorrentDay : IIndexer + public class TorrentDay: BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "TorrentDay"; } - } - - public string DisplayDescription - { - get { return DisplayName; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - public bool IsConfigured { get; private set; } - - const string BaseUrl = "https://torrentday.eu"; - const string StartPageUrl = BaseUrl + "/login.php"; - const string LoginUrl = BaseUrl + "/tak3login.php"; - const string SearchUrl = BaseUrl + "/browse.php?search={0}&cata=yes&c2=1&c7=1&c14=1&c24=1&c26=1&c31=1&c32=1&c33=1"; - - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; + private readonly string StartPageUrl = ""; + private readonly string LoginUrl = ""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public TorrentDay(Logger l) + public TorrentDay(IIndexerManagerService i, Logger l) : + base(name: "TorrentDay", + description: "TorrentDay", + link: new Uri("https://torrentday.eu"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + StartPageUrl = SiteLink + "/login.php"; + LoginUrl = SiteLink + "/tak3login.php"; + SearchUrl = SiteLink + "/browse.php?search={0}&cata=yes&c2=1&c7=1&c14=1&c24=1&c26=1&c31=1&c32=1&c33=1"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -77,7 +59,7 @@ namespace Jackett.Indexers var message = new HttpRequestMessage(); message.Method = HttpMethod.Get; message.RequestUri = new Uri(uri); - message.Headers.UserAgent.ParseAdd(chromeUserAgent); + message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent); return message; } @@ -115,17 +97,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -149,9 +128,9 @@ namespace Jackett.Indexers release.MinimumSeedTime = 172800; release.Title = qRow.Find(".torrentName").Text(); release.Description = release.Title; - release.Guid = new Uri(BaseUrl + "/" + qRow.Find(".torrentName").Attr("href")); + release.Guid = new Uri(SiteLink + "/" + qRow.Find(".torrentName").Attr("href")); release.Comments = release.Guid; - release.Link = new Uri(BaseUrl + "/" + qRow.Find(".dlLinksInfo > a").Attr("href")); + release.Link = new Uri(SiteLink + "/" + qRow.Find(".dlLinksInfo > a").Attr("href")); var sizeStr = qRow.Find(".sizeInfo").Text().Trim(); var sizeParts = sizeStr.Split(' '); @@ -185,8 +164,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); } diff --git a/src/Jackett/Indexers/TorrentLeech.cs b/src/Jackett/Indexers/TorrentLeech.cs index d1ac3218d..cefd16987 100644 --- a/src/Jackett/Indexers/TorrentLeech.cs +++ b/src/Jackett/Indexers/TorrentLeech.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,45 +16,26 @@ using System.Web; namespace Jackett.Indexers { - public class TorrentLeech : IIndexer + public class TorrentLeech : BaseIndexer, IIndexer { - public event Action OnResultParsingError; - - public event Action OnSaveConfigurationRequested; - - public string DisplayName - { - get { return "TorrentLeech"; } - } - - public string DisplayDescription - { - get { return "This is what happens when you seed"; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string BaseUrl = "http://www.torrentleech.org"; - const string LoginUrl = BaseUrl + "/user/account/login/"; - const string SearchUrl = BaseUrl + "/torrents/browse/index/query/{0}/categories/2%2C26%2C27%2C32/orderby/added?"; - - public bool IsConfigured { get; private set; } - + private readonly string LoginUrl =""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public TorrentLeech(Logger l) + public TorrentLeech(IIndexerManagerService i, Logger l) : + base(name: "TorrentLeech", + description: "This is what happens when you seed", + link: new Uri("http://www.torrentleech.org"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/user/account/login/"; + SearchUrl = SiteLink + "/torrents/browse/index/query/{0}/categories/2%2C26%2C27%2C32/orderby/added?"; + cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -98,17 +80,14 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } } public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -137,12 +116,12 @@ namespace Jackett.Indexers release.MinimumSeedTime = 172800; CQ qLink = qRow.Find(".title > a").First(); - release.Guid = new Uri(BaseUrl + qLink.Attr("href")); + release.Guid = new Uri(SiteLink + qLink.Attr("href")); release.Comments = release.Guid; release.Title = qLink.Text(); release.Description = release.Title; - release.Link = new Uri(BaseUrl + qRow.Find(".quickdownload > a").Attr("href")); + release.Link = new Uri(SiteLink + qRow.Find(".quickdownload > a").Attr("href")); var dateString = qRow.Find(".name").First()[0].ChildNodes[4].NodeValue.Replace(" on", "").Trim(); //"2015-04-25 23:38:12" @@ -161,8 +140,7 @@ namespace Jackett.Indexers catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); diff --git a/src/Jackett/Indexers/TorrentShack.cs b/src/Jackett/Indexers/TorrentShack.cs index ec41b0164..8444b7699 100644 --- a/src/Jackett/Indexers/TorrentShack.cs +++ b/src/Jackett/Indexers/TorrentShack.cs @@ -1,5 +1,6 @@ using CsQuery; using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; @@ -15,45 +16,25 @@ using System.Web; namespace Jackett.Indexers { - public class TorrentShack : IIndexer + public class TorrentShack : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "TorrentShack"; } - } - - public string DisplayDescription - { - get { return DisplayName; } - } - - public Uri SiteLink - { - get { return new Uri(BaseUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string BaseUrl = "http://torrentshack.me"; - const string LoginUrl = BaseUrl + "/login.php"; - const string SearchUrl = BaseUrl + "/torrents.php?searchstr={0}&release_type=both&searchtags=&tags_type=0&order_by=s3&order_way=desc&torrent_preset=all&filter_cat%5B600%5D=1&filter_cat%5B620%5D=1&filter_cat%5B700%5D=1&filter_cat%5B981%5D=1&filter_cat%5B980%5D=1"; - + private readonly string LoginUrl =""; + private readonly string SearchUrl = ""; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - Logger logger; - public bool IsConfigured { get; private set; } - - public TorrentShack(Logger l) + public TorrentShack(IIndexerManagerService i, Logger l) : + base(name: "TorrentShack", + description: "TorrentShack", + link: new Uri("http://torrentshack.me"), + rageid: true, + manager: i, + logger: l) { - logger = l; - IsConfigured = false; + LoginUrl = SiteLink + "/login.php"; + SearchUrl = SiteLink + "/torrents.php?searchstr={0}&release_type=both&searchtags=&tags_type=0&order_by=s3&order_way=desc&torrent_preset=all&filter_cat%5B600%5D=1&filter_cat%5B620%5D=1&filter_cat%5B700%5D=1&filter_cat%5B981%5D=1&filter_cat%5B980%5D=1"; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -99,10 +80,7 @@ namespace Jackett.Indexers { var configSaveData = new JObject(); cookies.DumpToJson(SiteLink, configSaveData); - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } @@ -110,7 +88,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, logger); + cookies.FillFromJson(SiteLink, jsonConfig, logger); IsConfigured = true; } @@ -135,9 +113,9 @@ namespace Jackett.Indexers release.MinimumSeedTime = 172800; release.Title = qRow.Find(".torrent_name_link").Text(); release.Description = release.Title; - release.Guid = new Uri(BaseUrl + "/" + qRow.Find(".torrent_name_link").Parent().Attr("href")); + release.Guid = new Uri(SiteLink + "/" + qRow.Find(".torrent_name_link").Parent().Attr("href")); release.Comments = release.Guid; - release.Link = new Uri(BaseUrl + "/" + qRow.Find(".torrent_handle_links > a").First().Attr("href")); + release.Link = new Uri(SiteLink + "/" + qRow.Find(".torrent_handle_links > a").First().Attr("href")); var dateStr = qRow.Find(".time").Text().Trim(); if (dateStr.ToLower().Contains("just now")) @@ -177,8 +155,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, results, ex); - throw ex; + OnParseError(results, ex); } return releases.ToArray(); } diff --git a/src/Jackett/Indexers/Torrentz.cs b/src/Jackett/Indexers/Torrentz.cs index b3991179c..47a968b95 100644 --- a/src/Jackett/Indexers/Torrentz.cs +++ b/src/Jackett/Indexers/Torrentz.cs @@ -1,6 +1,8 @@ using Jackett.Models; +using Jackett.Services; using Jackett.Utils; using Newtonsoft.Json.Linq; +using NLog; using System; using System.Collections.Generic; using System.Globalization; @@ -13,47 +15,25 @@ using System.Xml; namespace Jackett.Indexers { - public class Torrentz : IIndexer + public class Torrentz : BaseIndexer, IIndexer { - public event Action OnSaveConfigurationRequested; - - public event Action OnResultParsingError; - - public string DisplayName - { - get { return "Torrentz"; } - } - - public string DisplayDescription - { - get { return "Torrentz is a meta-search engine and a Multisearch. This means we just search other search engines."; } - } - - public Uri SiteLink - { - get { return new Uri(DefaultUrl); } - } - - public bool RequiresRageIDLookupDisabled { get { return true; } } - - const string DefaultUrl = "https://torrentz.eu"; - const string SearchUrl = DefaultUrl + "/feed_verifiedP?f={0}"; + private readonly string SearchUrl = ""; string BaseUrl; - static string chromeUserAgent = BrowserUtil.ChromeUserAgent; CookieContainer cookies; HttpClientHandler handler; HttpClient client; - public bool IsConfigured + public Torrentz(IIndexerManagerService i, Logger l) : + base(name: "Torrentz", + description: "Torrentz is a meta-search engine and a Multisearch. This means we just search other search engines.", + link: new Uri("https://torrentz.eu"), + rageid: true, + manager: i, + logger: l) { - get; - private set; - } - public Torrentz() - { - IsConfigured = false; + SearchUrl = SiteLink + "/feed_verifiedP?f={0}"; cookies = new CookieContainer(); handler = new HttpClientHandler { @@ -64,18 +44,16 @@ namespace Jackett.Indexers client = new HttpClient(handler); } - - public Task GetConfigurationForSetup() { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); return Task.FromResult(config); } public async Task ApplyConfiguration(JToken configJson) { - var config = new ConfigurationDataUrl(DefaultUrl); + var config = new ConfigurationDataUrl(SiteLink); config.LoadValuesFromJson(configJson); var formattedUrl = config.GetFormattedHostUrl(); @@ -87,10 +65,7 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["base_url"] = BaseUrl; - - if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(this, configSaveData); - + SaveConfig(configSaveData); IsConfigured = true; } @@ -99,7 +74,7 @@ namespace Jackett.Indexers { WebClient wc = new WebClient(); WebHeaderCollection headers = new WebHeaderCollection(); - headers.Add("User-Agent", chromeUserAgent); + headers.Add("User-Agent", BrowserUtil.ChromeUserAgent); wc.Headers = headers; return wc; } @@ -119,7 +94,7 @@ namespace Jackett.Indexers { using (wc) { - xml = wc.DownloadString(episodeSearchUrl); + xml = await wc.DownloadStringTaskAsync(new Uri(episodeSearchUrl)); xmlDoc.LoadXml(xml); } @@ -153,8 +128,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnResultParsingError(this, xml, ex); - throw ex; + OnParseError(xml, ex); } return releases.ToArray(); @@ -176,7 +150,6 @@ namespace Jackett.Indexers { throw new NotImplementedException(); } - } public class TorrentzHelper diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index ca06f9283..e83170226 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -139,6 +139,7 @@ + @@ -153,7 +154,7 @@ - + @@ -164,7 +165,6 @@ - @@ -179,6 +179,7 @@ + @@ -241,6 +242,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index f658d48c8..2b68ce122 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -23,7 +23,7 @@ namespace Jackett .Where(p => typeof(IIndexer).IsAssignableFrom(p) && !p.IsInterface) .ToArray()) { - builder.RegisterType(indexer).Named(indexer.Name.ToLowerInvariant()).SingleInstance(); + builder.RegisterType(indexer).Named(indexer.Name); } } } diff --git a/src/Jackett/Models/ConfigurationData.cs b/src/Jackett/Models/ConfigurationData.cs index 41b6b0055..21344cf9c 100644 --- a/src/Jackett/Models/ConfigurationData.cs +++ b/src/Jackett/Models/ConfigurationData.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Jackett.Utils; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; @@ -57,7 +58,7 @@ namespace Jackett.Models jObject["value"] = ((BoolItem)item).Value; break; case ItemType.DisplayImage: - string dataUri = DataUrl.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg"); + string dataUri = DataUrlUtils.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg"); jObject["value"] = dataUri; break; } diff --git a/src/Jackett/Models/ConfigurationDataUrl.cs b/src/Jackett/Models/ConfigurationDataUrl.cs index 08e80a76a..abf834d58 100644 --- a/src/Jackett/Models/ConfigurationDataUrl.cs +++ b/src/Jackett/Models/ConfigurationDataUrl.cs @@ -10,6 +10,11 @@ namespace Jackett.Models { public StringItem Url { get; private set; } + public ConfigurationDataUrl(Uri defaultUrl) + { + Url = new StringItem { Name = "Url", Value = defaultUrl.ToString() }; + } + public ConfigurationDataUrl(string defaultUrl) { Url = new StringItem { Name = "Url", Value = defaultUrl }; diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 718ea39da..55fd7b9aa 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -27,6 +27,7 @@ namespace Jackett.Services private IContainer container; private IConfigurationService configService; private Logger logger; + private Dictionary indexers = new Dictionary(); public IndexerManagerService(IContainer c, IConfigurationService config, Logger l) { @@ -37,33 +38,35 @@ namespace Jackett.Services public void InitIndexers() { - // Load the existing config for each indexer - foreach (var indexer in GetAllIndexers()) + foreach (var idx in container.Resolve>().OrderBy(_ => _.DisplayName)) { - var configFilePath = GetIndexerConfigFilePath(indexer); + indexers.Add(idx.DisplayName, idx); + var configFilePath = GetIndexerConfigFilePath(idx); if (File.Exists(configFilePath)) { var jsonString = JObject.Parse(File.ReadAllText(configFilePath)); - indexer.LoadFromSavedConfiguration(jsonString); + idx.LoadFromSavedConfiguration(jsonString); } } } public IIndexer GetIndexer(string name) { - var indexer = GetAllIndexers().Where(i => string.Equals(i.DisplayName, name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); - if (indexer == null) + var indexer = indexers.Values.Where(i => string.Equals(i.DisplayName, name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); + if (indexer != null) + { + return indexer; + } + else { logger.Error("Request for unknown indexer: " + name); throw new Exception("Unknown indexer: " + name); } - return indexer; } public IEnumerable GetAllIndexers() { - - return container.Resolve>().OrderBy(_ => _.DisplayName); + return indexers.Values; } public async void TestIndexer(string name) @@ -79,10 +82,9 @@ namespace Jackett.Services public void DeleteIndexer(string name) { var indexer = GetIndexer(name); - var configPath = configService.GetIndexerConfigDir(); + var configPath = GetIndexerConfigFilePath(indexer); File.Delete(configPath); - //Indexers.Remove(name); - //LoadMissingIndexers(); + indexers[name] = container.ResolveNamed(name); } private string GetIndexerConfigFilePath(IIndexer indexer) diff --git a/src/Jackett/DataUrl.cs b/src/Jackett/Utils/DataUrl.cs similarity index 91% rename from src/Jackett/DataUrl.cs rename to src/Jackett/Utils/DataUrl.cs index 3ff22beeb..07b08508b 100644 --- a/src/Jackett/DataUrl.cs +++ b/src/Jackett/Utils/DataUrl.cs @@ -6,9 +6,9 @@ using System.Text; using System.Threading.Tasks; using System.Web; -namespace Jackett +namespace Jackett.Utils { - public class DataUrl + public class DataUrlUtils { public static string ReadFileToDataUrl(string file) { diff --git a/src/Jackett/Utils/DateTimeUtil.cs b/src/Jackett/Utils/DateTimeUtil.cs new file mode 100644 index 000000000..093df7a76 --- /dev/null +++ b/src/Jackett/Utils/DateTimeUtil.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jackett.Utils +{ + public static class DateTimeUtil + { + public static DateTime UnixTimestampToDateTime(double unixTime) + { + DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); + long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond); + return new DateTime(unixStart.Ticks + unixTimeStampInTicks); + } + } +}