From a0987d9b500cf8d4819e910dabb1559b6de0ee74 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 10:24:41 -0600 Subject: [PATCH 01/12] Bug fixes for number parsing, fixed ThePirateBay indexer --- src/Jackett/Indexers/AnimeBytes.cs | 27 +++++++------- src/Jackett/Indexers/BitHdtv.cs | 6 ++-- src/Jackett/Indexers/BitMeTV.cs | 6 ++-- src/Jackett/Indexers/Freshon.cs | 6 ++-- src/Jackett/Indexers/IPTorrents.cs | 8 ++--- src/Jackett/Indexers/SceneAccess.cs | 6 ++-- src/Jackett/Indexers/ThePirateBay.cs | 54 +++++++++++++++------------- src/Jackett/Indexers/TorrentDay.cs | 10 +++--- src/Jackett/Indexers/TorrentLeech.cs | 6 ++-- src/Jackett/Indexers/TorrentShack.cs | 8 ++--- src/Jackett/Indexers/Torrentz.cs | 6 ++-- src/Jackett/Jackett.csproj | 9 +++-- src/Jackett/ParseUtil.cs | 28 +++++++++++++++ src/Jackett/SonarApi.cs | 4 +-- src/Jackett/TorznabQuery.cs | 8 ++--- 15 files changed, 115 insertions(+), 77 deletions(-) create mode 100644 src/Jackett/ParseUtil.cs diff --git a/src/Jackett/Indexers/AnimeBytes.cs b/src/Jackett/Indexers/AnimeBytes.cs index e368bb487..36f5de8bc 100644 --- a/src/Jackett/Indexers/AnimeBytes.cs +++ b/src/Jackett/Indexers/AnimeBytes.cs @@ -75,11 +75,11 @@ namespace Jackett.Indexers { var config = new ConfigurationDataBasicLoginAnimeBytes(); config.LoadValuesFromJson(configJson); - - + + // Get the login form as we need the CSRF Token var loginPage = await client.GetAsync(LoginUrl); - CQ loginPageDom = await loginPage.Content.ReadAsStringAsync(); + CQ loginPageDom = await loginPage.Content.ReadAsStringAsync(); var csrfToken = loginPageDom["input[name=\"csrf_token\"]"].Last(); // Build login form @@ -133,7 +133,7 @@ namespace Jackett.Indexers var configSaveData = new JObject(); configSaveData["cookies"] = cookieContainer.ToJson(SiteLink); configSaveData["raws"] = AllowRaws; - + if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -198,9 +198,10 @@ namespace Jackett.Indexers return cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray(); } - var queryUrl = SearchUrl; + var queryUrl = SearchUrl; // Only include the query bit if its required as hopefully the site caches the non query page - if(!string.IsNullOrWhiteSpace(query.SearchTerm)){ + if (!string.IsNullOrWhiteSpace(query.SearchTerm)) + { queryUrl += "&action=advanced&search_type=title&sort=time_added&way=desc&anime%5Btv_series%5D=1&searchstr=" + WebUtility.UrlEncode(query.SearchTerm); } @@ -229,8 +230,8 @@ namespace Jackett.Indexers var yearStr = seriesCq.Find(".group_title strong").First().Text().Trim().Replace("]", "").Trim(); int yearIndex = yearStr.LastIndexOf("["); if (yearIndex > -1) - yearStr = yearStr.Substring(yearIndex+1); - + yearStr = yearStr.Substring(yearIndex + 1); + int year = 0; if (!int.TryParse(yearStr, out year)) year = DateTime.Now.Year; @@ -301,7 +302,7 @@ namespace Jackett.Indexers var downloadLink = links.Get(0); release.Guid = new Uri(BaseUrl + "/" + downloadLink.Attributes.GetAttribute("href") + "&nh=" + Hash(title)); // Sonarr should dedupe on this url - allow a url per name. release.Link = release.Guid;// We dont know this so try to fake based on the release year - release.PublishDate = new DateTime(year,1,1); + release.PublishDate = new DateTime(year, 1, 1); release.PublishDate = release.PublishDate.AddDays(Math.Min(DateTime.Now.DayOfYear, 365) - 1); var infoLink = links.Get(1); @@ -347,15 +348,15 @@ namespace Jackett.Indexers if (size.Count() > 0) { var sizeParts = size.First().Text().Split(' '); - release.Size = ReleaseInfo.GetBytes(sizeParts[1], float.Parse(sizeParts[0])); + release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0])); } // Additional 5 hours per GB release.MinimumSeedTime += (release.Size / 1000000000) * 18000; // Peer info - release.Seeders = int.Parse(rowCq.Find(".torrent_seeders").Text()); - release.Peers = release.Seeders + int.Parse(rowCq.Find(".torrent_leechers").Text()); + release.Seeders = ParseUtil.CoerceInt(rowCq.Find(".torrent_seeders").Text()); + release.Peers = release.Seeders + ParseUtil.CoerceInt(rowCq.Find(".torrent_leechers").Text()); releases.Add(release); } @@ -369,7 +370,7 @@ namespace Jackett.Indexers throw ex; } - + // Add to the cache lock (cache) { diff --git a/src/Jackett/Indexers/BitHdtv.cs b/src/Jackett/Indexers/BitHdtv.cs index a3669d8de..1c394b389 100644 --- a/src/Jackett/Indexers/BitHdtv.cs +++ b/src/Jackett/Indexers/BitHdtv.cs @@ -142,10 +142,10 @@ namespace Jackett.Indexers 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.Size = ReleaseInfo.GetBytes(sizeUnit, ParseUtil.CoerceFloat(sizeVal)); - release.Seeders = int.Parse(qRow.Children().ElementAt(8).Cq().Text().Trim(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Children().ElementAt(9).Cq().Text().Trim(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Trim()); + release.Peers = ParseUtil.CoerceInt(qRow.Children().ElementAt(9).Cq().Text().Trim()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 3df784016..3a15659c6 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -168,12 +168,12 @@ namespace Jackett release.Link = new Uri(BaseUrl + "/" + row.ChildElements.ElementAt(2).Cq().Children("a.index").Attr("href")); var sizeCol = row.ChildElements.ElementAt(6); - var sizeVal = float.Parse(sizeCol.ChildNodes[0].NodeValue); + var sizeVal = ParseUtil.CoerceFloat(sizeCol.ChildNodes[0].NodeValue); var sizeUnit = sizeCol.ChildNodes[2].NodeValue; release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal); - release.Seeders = int.Parse(row.ChildElements.ElementAt(8).Cq().Text(), NumberStyles.AllowThousands); - release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text()); + release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders; //if (!release.Title.ToLower().Contains(title.ToLower())) // continue; diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index be4cbda66..7dc68a11c 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -164,11 +164,11 @@ namespace Jackett 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(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Find("td.table_leechers").Text().Trim(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(qRow.Find("td.table_seeders").Text().Trim()); + release.Peers = ParseUtil.CoerceInt(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 sizeVal = ParseUtil.CoerceFloat(sizeCol.ChildNodes[0].NodeValue.Trim()); var sizeUnit = sizeCol.ChildNodes[2].NodeValue.Trim(); release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal); diff --git a/src/Jackett/Indexers/IPTorrents.cs b/src/Jackett/Indexers/IPTorrents.cs index 450f29e51..53c43de0f 100644 --- a/src/Jackett/Indexers/IPTorrents.cs +++ b/src/Jackett/Indexers/IPTorrents.cs @@ -151,7 +151,7 @@ namespace Jackett.Indexers 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 dateValue = ParseUtil.CoerceFloat(dateString.Split(' ')[0]); var dateUnit = dateString.Split(' ')[1]; if (dateUnit.Contains("minute")) pubDate = DateTime.Now - TimeSpan.FromMinutes(dateValue); @@ -173,12 +173,12 @@ namespace Jackett.Indexers 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 sizeVal = ParseUtil.CoerceFloat(sizeStr.Split(' ')[0]); var sizeUnit = sizeStr.Split(' ')[1]; release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal); - release.Seeders = int.Parse(qRow.Find(".t_seeders").Text().Trim(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Find(".t_leechers").Text().Trim(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(qRow.Find(".t_seeders").Text().Trim()); + release.Peers = ParseUtil.CoerceInt(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/SceneAccess.cs b/src/Jackett/Indexers/SceneAccess.cs index 4f0ecdb63..9de70fc16 100644 --- a/src/Jackett/Indexers/SceneAccess.cs +++ b/src/Jackett/Indexers/SceneAccess.cs @@ -166,7 +166,7 @@ namespace Jackett.Indexers var sizeStr = qRow.Find(".ttr_size").Contents()[0].NodeValue; var sizeParts = sizeStr.Split(' '); - release.Size = ReleaseInfo.GetBytes(sizeParts[1], float.Parse(sizeParts[0], NumberStyles.Float | NumberStyles.AllowThousands)); + release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0])); var timeStr = qRow.Find(".ttr_added").Text(); DateTime time; @@ -175,8 +175,8 @@ namespace Jackett.Indexers release.PublishDate = time; } - release.Seeders = int.Parse(qRow.Find(".ttr_seeders").Text(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Find(".ttr_leechers").Text(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(qRow.Find(".ttr_seeders").Text()); + release.Peers = ParseUtil.CoerceInt(qRow.Find(".ttr_leechers").Text()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/ThePirateBay.cs b/src/Jackett/Indexers/ThePirateBay.cs index 715aef264..1e9328673 100644 --- a/src/Jackett/Indexers/ThePirateBay.cs +++ b/src/Jackett/Indexers/ThePirateBay.cs @@ -28,10 +28,9 @@ namespace Jackett.Indexers public bool IsConfigured { get; private set; } - const string DefaultUrl = "https://thepiratebay.gd"; - const string SearchUrl = "/s/?q=\"{0}\"&category=205&page=0&orderby=99"; - const string SearchUrl2 = "/s/?q=\"{0}\"&category=208&page=0&orderby=99"; - const string SwitchSingleViewUrl = "/switchview.php?view=s"; + const string DefaultUrl = "https://thepiratebay.mn"; + const string SearchUrl = "/search/{0}/0/99/208"; + const string SearchUrl2 = "/search/{0}/0/99/205"; string BaseUrl; @@ -108,25 +107,19 @@ namespace Jackett.Indexers foreach (var episodeSearchUrl in searchUrls) { - var message = new HttpRequestMessage - { - Method = HttpMethod.Get, - RequestUri = new Uri(baseUrl + SwitchSingleViewUrl) - }; - message.Headers.Referrer = new Uri(episodeSearchUrl); string results; if (Program.IsWindows) { - var response = await client.SendAsync(message); - results = await response.Content.ReadAsStringAsync(); + results = await client.GetStringAsync(episodeSearchUrl); } else { - var response = await CurlHelper.GetAsync(baseUrl + SwitchSingleViewUrl, null, episodeSearchUrl); + var response = await CurlHelper.GetAsync(episodeSearchUrl, null, episodeSearchUrl); results = Encoding.UTF8.GetString(response.Content); } + try { CQ dom = results; @@ -136,7 +129,8 @@ namespace Jackett.Indexers { var release = new ReleaseInfo(); - CQ qLink = row.ChildElements.ElementAt(1).Cq().Children("a").First(); + CQ qRow = row.Cq(); + CQ qLink = qRow.Find(".detName > .detLink").First(); release.MinimumRatio = 1; release.MinimumSeedTime = 172800; @@ -145,13 +139,27 @@ namespace Jackett.Indexers release.Comments = new Uri(baseUrl + "/" + qLink.Attr("href").TrimStart('/')); release.Guid = release.Comments; - var timeString = row.ChildElements.ElementAt(2).Cq().Text(); + var downloadCol = row.ChildElements.ElementAt(1).Cq().Children("a"); + release.MagnetUri = new Uri(downloadCol.Attr("href")); + release.InfoHash = release.MagnetUri.ToString().Split(':')[3].Split('&')[0]; + + var descString = qRow.Find(".detDesc").Text().Trim(); + var descParts = descString.Split(','); + + var timeString = descParts[0].Split(' ')[1]; + if (timeString.Contains("mins ago")) - release.PublishDate = (DateTime.Now - TimeSpan.FromMinutes(int.Parse(timeString.Split(' ')[0]))); + { + release.PublishDate = (DateTime.Now - TimeSpan.FromMinutes(ParseUtil.CoerceInt(timeString.Split(' ')[0]))); + } else if (timeString.Contains("Today")) + { release.PublishDate = (DateTime.UtcNow - TimeSpan.FromHours(2) - TimeSpan.Parse(timeString.Split(' ')[1])).ToLocalTime(); + } else if (timeString.Contains("Y-day")) + { release.PublishDate = (DateTime.UtcNow - TimeSpan.FromHours(26) - TimeSpan.Parse(timeString.Split(' ')[1])).ToLocalTime(); + } else if (timeString.Contains(':')) { var utc = DateTime.ParseExact(timeString, "MM-dd HH:mm", CultureInfo.InvariantCulture) - TimeSpan.FromHours(2); @@ -163,17 +171,13 @@ namespace Jackett.Indexers release.PublishDate = DateTime.SpecifyKind(utc, DateTimeKind.Utc).ToLocalTime(); } - var downloadCol = row.ChildElements.ElementAt(3).Cq().Find("a"); - release.MagnetUri = new Uri(downloadCol.Attr("href")); - release.InfoHash = release.MagnetUri.ToString().Split(':')[3].Split('&')[0]; - - var sizeString = row.ChildElements.ElementAt(4).Cq().Text().Split(' '); - var sizeVal = float.Parse(sizeString[0], CultureInfo.InvariantCulture); - var sizeUnit = sizeString[1]; + var sizeParts = descParts[1].Split(new char[] { ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries); + var sizeVal = ParseUtil.CoerceFloat(sizeParts[1]); + var sizeUnit = sizeParts[2]; release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal); - release.Seeders = int.Parse(row.ChildElements.ElementAt(5).Cq().Text()); - release.Peers = int.Parse(row.ChildElements.ElementAt(6).Cq().Text()) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(2).Cq().Text()); + release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(3).Cq().Text()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/TorrentDay.cs b/src/Jackett/Indexers/TorrentDay.cs index d53d79df9..3ebf9a1ff 100644 --- a/src/Jackett/Indexers/TorrentDay.cs +++ b/src/Jackett/Indexers/TorrentDay.cs @@ -150,11 +150,11 @@ namespace Jackett.Indexers var sizeStr = qRow.Find(".sizeInfo").Text().Trim(); var sizeParts = sizeStr.Split(' '); - release.Size = ReleaseInfo.GetBytes(sizeParts[1], float.Parse(sizeParts[0])); + release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0])); - var dateStr = qRow.Find(".ulInfo").Text().Trim(); + var dateStr = qRow.Find(".ulInfo").Text().Split('|').Last().Trim(); var dateParts = dateStr.Split(' '); - var dateValue = int.Parse(dateParts[1]); + var dateValue = ParseUtil.CoerceInt(dateParts[0]); TimeSpan ts = TimeSpan.Zero; if (dateStr.Contains("sec")) ts = TimeSpan.FromSeconds(dateValue); @@ -172,8 +172,8 @@ namespace Jackett.Indexers ts = TimeSpan.FromDays(dateValue * 365); release.PublishDate = DateTime.Now - ts; - release.Seeders = int.Parse(qRow.Find(".seedersInfo").Text(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Find(".leechersInfo").Text(), NumberStyles.AllowThousands) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(qRow.Find(".seedersInfo").Text()); + release.Peers = ParseUtil.CoerceInt(qRow.Find(".leechersInfo").Text()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/TorrentLeech.cs b/src/Jackett/Indexers/TorrentLeech.cs index 2e8610abf..b4a29f160 100644 --- a/src/Jackett/Indexers/TorrentLeech.cs +++ b/src/Jackett/Indexers/TorrentLeech.cs @@ -146,10 +146,10 @@ namespace Jackett.Indexers release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); var sizeStringParts = qRow.Children().ElementAt(4).InnerText.Split(' '); - release.Size = ReleaseInfo.GetBytes(sizeStringParts[1], float.Parse(sizeStringParts[0])); + release.Size = ReleaseInfo.GetBytes(sizeStringParts[1], ParseUtil.CoerceFloat(sizeStringParts[0])); - release.Seeders = int.Parse(qRow.Find(".seeders").Text()); - release.Peers = release.Seeders + int.Parse(qRow.Find(".leechers").Text()); + release.Seeders = ParseUtil.CoerceInt(qRow.Find(".seeders").Text()); + release.Peers = release.Seeders + ParseUtil.CoerceInt(qRow.Find(".leechers").Text()); releases.Add(release); } diff --git a/src/Jackett/Indexers/TorrentShack.cs b/src/Jackett/Indexers/TorrentShack.cs index 74366b36a..7945a77c4 100644 --- a/src/Jackett/Indexers/TorrentShack.cs +++ b/src/Jackett/Indexers/TorrentShack.cs @@ -139,7 +139,7 @@ namespace Jackett.Indexers else { var dateParts = dateStr.Split(' '); - var dateValue = int.Parse(dateParts[0]); + var dateValue = ParseUtil.CoerceInt(dateParts[0]); TimeSpan ts = TimeSpan.Zero; if (dateStr.Contains("sec")) ts = TimeSpan.FromSeconds(dateValue); @@ -160,9 +160,9 @@ namespace Jackett.Indexers var sizeStr = qRow.Find(".size")[0].ChildNodes[0].NodeValue.Trim(); var sizeParts = sizeStr.Split(' '); - release.Size = ReleaseInfo.GetBytes(sizeParts[1], float.Parse(sizeParts[0], NumberStyles.AllowThousands)); - release.Seeders = int.Parse(qRow.Children().ElementAt(6).InnerText.Trim(), NumberStyles.AllowThousands); - release.Peers = int.Parse(qRow.Children().ElementAt(7).InnerText.Trim(), NumberStyles.AllowThousands) + release.Seeders; + release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0])); + release.Seeders = ParseUtil.CoerceInt(qRow.Children().ElementAt(6).InnerText.Trim()); + release.Peers = ParseUtil.CoerceInt(qRow.Children().ElementAt(7).InnerText.Trim()) + release.Seeders; releases.Add(release); } diff --git a/src/Jackett/Indexers/Torrentz.cs b/src/Jackett/Indexers/Torrentz.cs index 78b60edf1..4fcb136fa 100644 --- a/src/Jackett/Indexers/Torrentz.cs +++ b/src/Jackett/Indexers/Torrentz.cs @@ -232,13 +232,13 @@ namespace Jackett.Indexers switch (counter) { case 0: - this.Size = ReleaseInfo.BytesFromMB(long.Parse(val.Substring(0, val.IndexOf(" ") - 1))); + this.Size = ReleaseInfo.BytesFromMB(ParseUtil.CoerceLong(val.Substring(0, val.IndexOf(" ") - 1))); break; case 1: - this.Seeders = int.Parse(val.Contains(",") ? val.Remove(val.IndexOf(","), 1) : val); + this.Seeders = ParseUtil.CoerceInt(val.Contains(",") ? val.Remove(val.IndexOf(","), 1) : val); break; case 2: - this.Peers = int.Parse(val.Contains(",") ? val.Remove(val.IndexOf(","), 1) : val); + this.Peers = ParseUtil.CoerceInt(val.Contains(",") ? val.Remove(val.IndexOf(","), 1) : val); break; case 3: this.hash = val; diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index dd29577c3..d99942c88 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -114,6 +114,7 @@ Main.cs + @@ -163,7 +164,9 @@ PreserveNewest - + + PreserveNewest + PreserveNewest @@ -237,7 +240,9 @@ PreserveNewest - + + PreserveNewest + PreserveNewest diff --git a/src/Jackett/ParseUtil.cs b/src/Jackett/ParseUtil.cs new file mode 100644 index 000000000..7eb7b8fcf --- /dev/null +++ b/src/Jackett/ParseUtil.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jackett +{ + public static class ParseUtil + { + public static float CoerceFloat(string str) + { + return float.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture); + } + + public static int CoerceInt(string str) + { + return int.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture); + } + + public static long CoerceLong(string str) + { + return long.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture); + } + + } +} diff --git a/src/Jackett/SonarApi.cs b/src/Jackett/SonarApi.cs index c5274caaa..6b33622d4 100644 --- a/src/Jackett/SonarApi.cs +++ b/src/Jackett/SonarApi.cs @@ -129,9 +129,9 @@ namespace Jackett { var config = new ConfigurationSonarr(); config.LoadValuesFromJson(configJson); - await ReloadNameMappings(config.Host.Value, int.Parse(config.Port.Value), config.ApiKey.Value); + await ReloadNameMappings(config.Host.Value, ParseUtil.CoerceInt(config.Port.Value), config.ApiKey.Value); Host = "http://" + new Uri(config.Host.Value).Host; - Port = int.Parse(config.Port.Value); + Port = ParseUtil.CoerceInt(config.Port.Value); ApiKey = config.ApiKey.Value; SaveSettings(); } diff --git a/src/Jackett/TorznabQuery.cs b/src/Jackett/TorznabQuery.cs index e2f2a20f9..06a5651d9 100644 --- a/src/Jackett/TorznabQuery.cs +++ b/src/Jackett/TorznabQuery.cs @@ -34,7 +34,7 @@ namespace Jackett else if (string.IsNullOrEmpty(Episode)) episodeString = string.Format("S{0:00}", Season); else - episodeString = string.Format("S{0:00}E{1:00}", Season, int.Parse(Episode)); + episodeString = string.Format("S{0:00}E{1:00}", Season, ParseUtil.CoerceInt(Episode)); return episodeString; } @@ -53,16 +53,16 @@ namespace Jackett if (query["extended"] != null) { - q.Extended = int.Parse(query["extended"]); + q.Extended = ParseUtil.CoerceInt(query["extended"]); } q.ApiKey = query["apikey"]; if (query["limit"] != null) { - q.Limit = int.Parse(query["limit"]); + q.Limit = ParseUtil.CoerceInt(query["limit"]); } if (query["offset"] != null) { - q.Offset = int.Parse(query["offset"]); + q.Offset = ParseUtil.CoerceInt(query["offset"]); } int temp; From 7cbad21e0b5f5e60788e3e0a28c1f34758e650ec Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 10:29:20 -0600 Subject: [PATCH 02/12] Changed app settings location to longer require root on unix --- src/Jackett/Program.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Jackett/Program.cs b/src/Jackett/Program.cs index 52c0d18d5..08bd34a40 100644 --- a/src/Jackett/Program.cs +++ b/src/Jackett/Program.cs @@ -18,7 +18,7 @@ namespace Jackett { class Program { - public static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett"); + public static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett"); public static Server ServerInstance { get; private set; } @@ -36,6 +36,8 @@ namespace Jackett { ExitEvent = new ManualResetEvent(false); + MigrateSettingsDirectory(); + try { if (!Directory.Exists(AppConfigDirectory)) @@ -111,6 +113,22 @@ namespace Jackett Console.WriteLine("Server thread exit"); } + static void MigrateSettingsDirectory() + { + try + { + string oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett"); + if (Directory.Exists(oldDir) && !Directory.Exists(AppConfigDirectory)) + { + Directory.Move(oldDir, AppConfigDirectory); + } + } + catch (Exception ex) + { + Console.WriteLine("ERROR could not migrate settings directory " + ex); + } + } + static void ReadSettingsFile() { var path = Path.Combine(AppConfigDirectory, "config.json"); From 957399758668bfaf58949b7ac0dfd59e84494058 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 10:42:00 -0600 Subject: [PATCH 03/12] Fixed autostart feature --- src/Jackett/Jackett.csproj | 11 +++++++++++ src/Jackett/Main.cs | 34 ++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index d99942c88..9f7154e49 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -274,6 +274,17 @@ false + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Jackett.sln b/src/Jackett.sln index 850174ffe..eae7d18ea 100644 --- a/src/Jackett.sln +++ b/src/Jackett.sln @@ -1,5 +1,6 @@ + Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 +# Visual Studio 2012 VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jackett", "Jackett\Jackett.csproj", "{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}" @@ -12,14 +13,49 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.Build.0 = Release|Any CPU {74420A79-CC16-442C-8B1E-7C1B913844F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74420A79-CC16-442C-8B1E-7C1B913844F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {74420A79-CC16-442C-8B1E-7C1B913844F0}.Release|Any CPU.ActiveCfg = Release|Any CPU {74420A79-CC16-442C-8B1E-7C1B913844F0}.Release|Any CPU.Build.0 = Release|Any CPU + {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.TextStylePolicy = $1 + $1.inheritsSet = VisualStudio + $1.inheritsScope = text/plain + $1.scope = text/x-csharp + $0.CSharpFormattingPolicy = $2 + $2.IndentSwitchBody = True + $2.IndentBlocksInsideExpressions = True + $2.AnonymousMethodBraceStyle = NextLine + $2.PropertyBraceStyle = NextLine + $2.PropertyGetBraceStyle = NextLine + $2.PropertySetBraceStyle = NextLine + $2.EventBraceStyle = NextLine + $2.EventAddBraceStyle = NextLine + $2.EventRemoveBraceStyle = NextLine + $2.StatementBraceStyle = NextLine + $2.ElseNewLinePlacement = NewLine + $2.CatchNewLinePlacement = NewLine + $2.FinallyNewLinePlacement = NewLine + $2.WhileNewLinePlacement = DoNotCare + $2.ArrayInitializerWrapping = DoNotChange + $2.ArrayInitializerBraceStyle = NextLine + $2.BeforeMethodDeclarationParentheses = False + $2.BeforeMethodCallParentheses = False + $2.BeforeConstructorDeclarationParentheses = False + $2.NewLineBeforeConstructorInitializerColon = NewLine + $2.NewLineAfterConstructorInitializerColon = SameLine + $2.BeforeDelegateDeclarationParentheses = False + $2.NewParentheses = False + $2.SpacesBeforeBrackets = False + $2.inheritsSet = Mono + $2.inheritsScope = text/x-csharp + $2.scope = text/x-csharp EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Jackett/CookieContainerExtensions.cs b/src/Jackett/CookieContainerExtensions.cs index 05bcfdc2e..447c3be30 100644 --- a/src/Jackett/CookieContainerExtensions.cs +++ b/src/Jackett/CookieContainerExtensions.cs @@ -5,29 +5,53 @@ using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; +using System.Web; namespace Jackett { - public static class CookieContainerExtensions - { - public static void FillFromJson (this CookieContainer cookies, Uri uri, JArray json) - { - foreach (string cookie in json) { + public static class CookieContainerExtensions + { - var w = cookie.Split ('='); - if (w.Length == 1) - cookies.Add (uri, new Cookie{ Name = cookie.Trim () }); - else - cookies.Add (uri, new Cookie (w [0].Trim (), w [1].Trim ())); - } - } + public static void FillFromJson(this CookieContainer cookies, Uri uri, JToken json) + { + if (json["cookies"] != null) + { + var cookieArray = (JArray)json["cookies"]; + foreach (string cookie in cookieArray) + { + var w = cookie.Split('='); + if (w.Length == 1) + { + cookies.Add(uri, new Cookie { Name = cookie.Trim() }); + } + else + { + cookies.Add(uri, new Cookie(w[0].Trim(), w[1].Trim())); + } + } + } - public static JArray ToJson (this CookieContainer cookies, Uri baseUrl) - { - return new JArray (( - from cookie in cookies.GetCookies (baseUrl).Cast () - select cookie.Name.Trim () + "=" + cookie.Value.Trim () - ).ToArray ()); - } - } + if (json["cookie_header"] != null) + { + var cfh = (string)json["cookie_header"]; + var cookieHeaders = ((string)json["cookie_header"]).Split(';'); + foreach (var c in cookieHeaders) + { + try + { + cookies.SetCookies(uri, c); + } + catch (CookieException ex) + { + Program.LoggerInstance.Info("(Non-critical) Problem loading cookie {0}, {1}, {2}", uri, c, ex.Message); + } + } + } + } + + public static void DumpToJson(this CookieContainer cookies, Uri uri, JToken json) + { + json["cookie_header"] = cookies.GetCookieHeader(uri); + } + } } diff --git a/src/Jackett/Indexers/AlphaRatio.cs b/src/Jackett/Indexers/AlphaRatio.cs index 3ff758bb5..1be0bf14d 100644 --- a/src/Jackett/Indexers/AlphaRatio.cs +++ b/src/Jackett/Indexers/AlphaRatio.cs @@ -75,16 +75,13 @@ namespace Jackett.Indexers public async Task ApplyConfiguration(JToken configJson) { - cookies = new CookieContainer(); - client = new HttpClient(handler); - var configSaveData = new JObject(); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); var config = new ConfigurationDataBasicLogin(); config.LoadValuesFromJson(configJson); - + var pairs = new Dictionary { { "username", config.Username.Value }, { "password", @config.Password.Value }, @@ -95,17 +92,18 @@ namespace Jackett.Indexers var content = new FormUrlEncodedContent(pairs); var message = CreateHttpRequest(new Uri(LoginUrl)); message.Content = content; - - //message.Headers.Referrer = new Uri(LoginUrl); + + //message.Headers.Referrer = new Uri(LoginUrl); string responseContent; - JArray cookieJArray; + + configSaveData = new JObject(); if (Program.IsWindows) { // If Windows use .net http var response = await client.SendAsync(message); responseContent = await response.Content.ReadAsStringAsync(); - cookieJArray = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); } else { @@ -113,7 +111,7 @@ namespace Jackett.Indexers var response = await CurlHelper.PostAsync(LoginUrl, pairs); responseContent = Encoding.UTF8.GetString(response.Content); cookieHeader = response.CookieHeader; - cookieJArray = new JArray(response.CookiesFlat); + configSaveData["cookie_header"] = cookieHeader; } if (!responseContent.Contains("logout.php?")) @@ -126,8 +124,6 @@ namespace Jackett.Indexers } else { - configSaveData = new JObject(); - configSaveData["cookies"] = cookieJArray; if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -146,7 +142,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(SiteLink, (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(SiteLink, jsonConfig); cookieHeader = cookies.GetCookieHeader(SiteLink); IsConfigured = true; } diff --git a/src/Jackett/Indexers/AnimeBytes.cs b/src/Jackett/Indexers/AnimeBytes.cs index 36f5de8bc..f271e28db 100644 --- a/src/Jackett/Indexers/AnimeBytes.cs +++ b/src/Jackett/Indexers/AnimeBytes.cs @@ -131,7 +131,7 @@ namespace Jackett.Indexers { AllowRaws = config.IncludeRaw.Value; var configSaveData = new JObject(); - configSaveData["cookies"] = cookieContainer.ToJson(SiteLink); + cookieContainer.DumpToJson(SiteLink, configSaveData); configSaveData["raws"] = AllowRaws; if (OnSaveConfigurationRequested != null) @@ -143,7 +143,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookieContainer.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookieContainer.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; AllowRaws = jsonConfig["raws"].Value(); } diff --git a/src/Jackett/Indexers/BitHdtv.cs b/src/Jackett/Indexers/BitHdtv.cs index 1c394b389..2e75414b7 100644 --- a/src/Jackett/Indexers/BitHdtv.cs +++ b/src/Jackett/Indexers/BitHdtv.cs @@ -86,7 +86,7 @@ namespace Jackett.Indexers else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -101,7 +101,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 3a15659c6..032142bc6 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -111,7 +111,7 @@ namespace Jackett else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -122,7 +122,7 @@ namespace Jackett public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index 7dc68a11c..37bbde239 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -90,7 +90,7 @@ namespace Jackett else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -101,7 +101,7 @@ namespace Jackett public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/IPTorrents.cs b/src/Jackett/Indexers/IPTorrents.cs index 53c43de0f..a5c0de73f 100644 --- a/src/Jackett/Indexers/IPTorrents.cs +++ b/src/Jackett/Indexers/IPTorrents.cs @@ -89,7 +89,7 @@ namespace Jackett.Indexers else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -110,7 +110,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/MoreThanTV.cs b/src/Jackett/Indexers/MoreThanTV.cs index d9fb0ee13..c4fe43a2a 100644 --- a/src/Jackett/Indexers/MoreThanTV.cs +++ b/src/Jackett/Indexers/MoreThanTV.cs @@ -86,14 +86,16 @@ namespace Jackett.Indexers var content = new FormUrlEncodedContent(pairs); string responseContent; - JArray cookieJArray; + + var configSaveData = new JObject(); if (Program.IsWindows) { // If Windows use .net http var response = await client.PostAsync(LoginUrl, content); responseContent = await response.Content.ReadAsStringAsync(); - cookieJArray = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); + } else { @@ -101,7 +103,7 @@ namespace Jackett.Indexers var response = await CurlHelper.PostAsync(LoginUrl, pairs); responseContent = Encoding.UTF8.GetString(response.Content); cookieHeader = response.CookieHeader; - cookieJArray = new JArray(response.CookiesFlat); + configSaveData["cookie_header"] = cookieHeader; } if (!responseContent.Contains("logout.php?")) @@ -114,9 +116,6 @@ namespace Jackett.Indexers } else { - - var configSaveData = new JObject(); - configSaveData["cookies"] = cookieJArray; if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -126,7 +125,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(SiteLink, (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(SiteLink, jsonConfig); cookieHeader = cookies.GetCookieHeader(SiteLink); IsConfigured = true; } diff --git a/src/Jackett/Indexers/SceneAccess.cs b/src/Jackett/Indexers/SceneAccess.cs index 9de70fc16..d29372658 100644 --- a/src/Jackett/Indexers/SceneAccess.cs +++ b/src/Jackett/Indexers/SceneAccess.cs @@ -80,14 +80,14 @@ namespace Jackett.Indexers var content = new FormUrlEncodedContent(pairs); string responseContent; - JArray cookieJArray; + var configSaveData = new JObject(); if (Program.IsWindows) { // If Windows use .net http var response = await client.PostAsync(LoginUrl, content); responseContent = await response.Content.ReadAsStringAsync(); - cookieJArray = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); } else { @@ -95,7 +95,7 @@ namespace Jackett.Indexers var response = await CurlHelper.PostAsync(LoginUrl, pairs); responseContent = Encoding.UTF8.GetString(response.Content); cookieHeader = response.CookieHeader; - cookieJArray = new JArray(response.CookiesFlat); + configSaveData["cookie_header"] = cookieHeader; } if (!responseContent.Contains("nav_profile")) @@ -107,9 +107,6 @@ namespace Jackett.Indexers } else { - var configSaveData = new JObject(); - configSaveData["cookies"] = cookieJArray; - if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -119,7 +116,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); cookieHeader = cookies.GetCookieHeader(SiteLink); IsConfigured = true; } diff --git a/src/Jackett/Indexers/TorrentDay.cs b/src/Jackett/Indexers/TorrentDay.cs index 3ebf9a1ff..70c2914fc 100644 --- a/src/Jackett/Indexers/TorrentDay.cs +++ b/src/Jackett/Indexers/TorrentDay.cs @@ -107,7 +107,7 @@ namespace Jackett.Indexers else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -118,7 +118,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/TorrentLeech.cs b/src/Jackett/Indexers/TorrentLeech.cs index b4a29f160..c865059a3 100644 --- a/src/Jackett/Indexers/TorrentLeech.cs +++ b/src/Jackett/Indexers/TorrentLeech.cs @@ -90,7 +90,7 @@ namespace Jackett.Indexers else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -101,7 +101,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Indexers/TorrentShack.cs b/src/Jackett/Indexers/TorrentShack.cs index 7945a77c4..b3de5973d 100644 --- a/src/Jackett/Indexers/TorrentShack.cs +++ b/src/Jackett/Indexers/TorrentShack.cs @@ -91,7 +91,7 @@ namespace Jackett.Indexers else { var configSaveData = new JObject(); - configSaveData["cookies"] = cookies.ToJson(SiteLink); + cookies.DumpToJson(SiteLink, configSaveData); if (OnSaveConfigurationRequested != null) OnSaveConfigurationRequested(this, configSaveData); @@ -103,7 +103,7 @@ namespace Jackett.Indexers public void LoadFromSavedConfiguration(JToken jsonConfig) { - cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]); + cookies.FillFromJson(new Uri(BaseUrl), jsonConfig); IsConfigured = true; } diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index 9f7154e49..af603b00d 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -57,11 +57,9 @@ ..\packages\CsQuery.1.3.4\lib\net40\CsQuery.dll - - ..\packages\modernhttpclient.2.3.0\lib\Portable-Net45+WinRT45+WP8+WPA81\ModernHttpClient.dll - - - ..\packages\NLog.3.2.0.0\lib\net45\NLog.dll + + ..\packages\NLog.Windows.Forms.2.0.0.0\lib\net35\NLog.Windows.Forms.dll + True @@ -76,7 +74,10 @@ - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NLog.4.0.1\lib\net45\NLog.dll @@ -293,4 +294,14 @@ --> + + + + + + + + + + \ No newline at end of file diff --git a/src/Jackett/Main.Designer.cs b/src/Jackett/Main.Designer.cs index fff94fc29..d881a2821 100644 --- a/src/Jackett/Main.Designer.cs +++ b/src/Jackett/Main.Designer.cs @@ -1,4 +1,6 @@ -namespace Jackett +#if !__MonoCS__ + +namespace Jackett { partial class Main { @@ -97,4 +99,5 @@ private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemShutdown; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Jackett/Main.cs b/src/Jackett/Main.cs index 129b9224c..250aff2ce 100644 --- a/src/Jackett/Main.cs +++ b/src/Jackett/Main.cs @@ -1,4 +1,5 @@ -using Microsoft.Win32; +#if !__MonoCS__ +using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; @@ -92,3 +93,4 @@ namespace Jackett } } } +#endif \ No newline at end of file diff --git a/src/Jackett/Program.cs b/src/Jackett/Program.cs index 08bd34a40..cc16b2bc1 100644 --- a/src/Jackett/Program.cs +++ b/src/Jackett/Program.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Linq; using NLog; using NLog.Config; using NLog.Targets; +using NLog.Windows.Forms; using System; using System.Collections.Generic; using System.Diagnostics; @@ -70,12 +71,14 @@ namespace Jackett if (Program.IsWindows) { +#if !__MonoCS__ var logAlert = new MessageBoxTarget(); logConfig.AddTarget("alert", logAlert); logAlert.Layout = "${message}"; logAlert.Caption = "Alert"; var logAlertRule = new LoggingRule("*", LogLevel.Fatal, logAlert); logConfig.LoggingRules.Add(logAlertRule); +#endif } var logConsole = new ConsoleTarget(); @@ -98,7 +101,11 @@ namespace Jackett try { if (Program.IsWindows) + { +#if !__MonoCS__ Application.Run(new Main()); +#endif + } } catch (Exception) { diff --git a/src/Jackett/packages.config b/src/Jackett/packages.config index f5186f515..efab650c9 100644 --- a/src/Jackett/packages.config +++ b/src/Jackett/packages.config @@ -1,7 +1,7 @@  - - - + + + \ No newline at end of file From 97e9f86538aa4f25029a39faebcf83b9df110335 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 13:26:57 -0600 Subject: [PATCH 08/12] TorrentShack fix for an unlikely bug --- src/Jackett/Indexers/TorrentShack.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Jackett/Indexers/TorrentShack.cs b/src/Jackett/Indexers/TorrentShack.cs index b3de5973d..d7b88c705 100644 --- a/src/Jackett/Indexers/TorrentShack.cs +++ b/src/Jackett/Indexers/TorrentShack.cs @@ -141,7 +141,9 @@ namespace Jackett.Indexers var dateParts = dateStr.Split(' '); var dateValue = ParseUtil.CoerceInt(dateParts[0]); TimeSpan ts = TimeSpan.Zero; - if (dateStr.Contains("sec")) + if (dateStr.Contains("Just now")) + ts = TimeSpan.Zero; + else if (dateStr.Contains("sec")) ts = TimeSpan.FromSeconds(dateValue); else if (dateStr.Contains("min")) ts = TimeSpan.FromMinutes(dateValue); From e404389254f4dec4d1ec494455bed96d9b0c0bf7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 14:06:13 -0600 Subject: [PATCH 09/12] Timezone publish date fixes for Bit-HDTV, BitMeTv, and MoreThanTV --- src/Jackett/Indexers/BitHdtv.cs | 2 +- src/Jackett/Indexers/BitMeTV.cs | 3 ++- src/Jackett/Indexers/MoreThanTV.cs | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Jackett/Indexers/BitHdtv.cs b/src/Jackett/Indexers/BitHdtv.cs index 2e75414b7..fc16b16f9 100644 --- a/src/Jackett/Indexers/BitHdtv.cs +++ b/src/Jackett/Indexers/BitHdtv.cs @@ -137,7 +137,7 @@ namespace Jackett.Indexers 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; + release.PublishDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Local); var sizeCol = qRow.Children().ElementAt(6); var sizeVal = sizeCol.ChildNodes[0].NodeValue; diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 032142bc6..109ff8c03 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -163,7 +163,8 @@ namespace Jackett var timeParts = new List(timestamp.Replace(" at", "").Replace(",", "").Split(' ')); timeParts[2] = Regex.Replace(timeParts[2], "[^0-9.]", ""); var formattedTimeString = string.Join(" ", timeParts.ToArray()).Trim(); - release.PublishDate = DateTime.ParseExact(formattedTimeString, "dddd MMMM d yyyy hh:mm:ss tt", CultureInfo.InvariantCulture); + 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")); diff --git a/src/Jackett/Indexers/MoreThanTV.cs b/src/Jackett/Indexers/MoreThanTV.cs index c4fe43a2a..a05c7ae9f 100644 --- a/src/Jackett/Indexers/MoreThanTV.cs +++ b/src/Jackett/Indexers/MoreThanTV.cs @@ -170,7 +170,10 @@ namespace Jackett.Indexers DateTime pubDate = DateTime.MinValue; double dateNum; if (double.TryParse((string)r["groupTime"], out dateNum)) + { pubDate = UnixTimestampToDateTime(dateNum); + pubDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Utc).ToLocalTime(); + } var groupName = (string)r["groupName"]; From a651dea5a8c7588f7380d296d3b30d022f9f3728 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 14:23:43 -0600 Subject: [PATCH 10/12] Strip most non alphanumeric characters from show titles before searching --- src/Jackett/SonarApi.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Jackett/SonarApi.cs b/src/Jackett/SonarApi.cs index 6b33622d4..cf7178c91 100644 --- a/src/Jackett/SonarApi.cs +++ b/src/Jackett/SonarApi.cs @@ -86,7 +86,15 @@ namespace Jackett string SanitizeTitle(string title) { - return title.Replace("(", "").Replace(")", ""); + char[] arr = title.ToCharArray(); + + arr = Array.FindAll(arr, c => (char.IsLetterOrDigit(c) + || char.IsWhiteSpace(c) + || c == '-' + || c == '.' + )); + title = new string(arr); + return title; } void LoadSettings() From 658e112a469c0b34d60eb657f61c03305350aed8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Jul 2015 14:30:16 -0600 Subject: [PATCH 11/12] Incremented to app version 0.4.0 --- src/Jackett/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jackett/Properties/AssemblyInfo.cs b/src/Jackett/Properties/AssemblyInfo.cs index 6dcc76d8b..4cd32421c 100644 --- a/src/Jackett/Properties/AssemblyInfo.cs +++ b/src/Jackett/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.3.2.0")] +[assembly: AssemblyVersion("0.4.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] From 42b3e06cdd48c4c84ab13c13b3adc7059d24cfb9 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 11 Jul 2015 14:34:13 -0600 Subject: [PATCH 12/12] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e34c8b61f..e98ec3a2a 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ Download in the [Releases page](https://github.com/zone117x/Jackett/releases) * [RARBG](https://rarbg.com) * [TorrentDay](https://torrentday.eu/) * [TorrentShack](http://torrentshack.me/) - * AlphaRatio - * AnimeBytes - * SceneAccess - * ShowRSS - * Torrentz + * [AlphaRatio](https://alpharatio.cc/) + * [AnimeBytes](https://animebytes.tv/) + * [SceneAccess](https://sceneaccess.eu/login) + * [ShowRSS](https://showrss.info/) + * [Torrentz](https://torrentz.eu/) ### Additional Trackers