From 16a59b8abdc20c75b0e0e868698525b6d1cc1659 Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Sat, 4 Apr 2020 22:34:38 +0200 Subject: [PATCH] torrentday: some fixes and code cleanup (#8035) * Add SupportsImdbTVSearch * Code cleanup Tested --- src/Jackett.Common/Indexers/TorrentDay.cs | 89 +++++++++++------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/src/Jackett.Common/Indexers/TorrentDay.cs b/src/Jackett.Common/Indexers/TorrentDay.cs index e68b14faa..cfb8ea695 100644 --- a/src/Jackett.Common/Indexers/TorrentDay.cs +++ b/src/Jackett.Common/Indexers/TorrentDay.cs @@ -45,29 +45,29 @@ namespace Jackett.Common.Indexers "https://td.workisboring.net/", }; - private new ConfigurationDataRecaptchaLogin configData - { - get => (ConfigurationDataRecaptchaLogin)base.configData; - set => base.configData = value; - } + private new ConfigurationDataRecaptchaLogin configData => (ConfigurationDataRecaptchaLogin)base.configData; public TorrentDay(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps) - : base(name: "TorrentDay", - description: "TorrentDay (TD) is a Private site for TV / MOVIES / GENERAL", - link: "https://tday.love/", - caps: TorznabUtil.CreateDefaultTorznabTVCaps(), - configService: configService, - client: wc, - logger: l, - p: ps, - configData: new ConfigurationDataRecaptchaLogin("Make sure you get the cookies from the same torrent day domain as configured above.")) + : base("TorrentDay", + description: "TorrentDay (TD) is a Private site for TV / MOVIES / GENERAL", + link: "https://tday.love/", + caps: new TorznabCapabilities + { + SupportsImdbMovieSearch = true, + SupportsImdbTVSearch = true + }, + configService: configService, + client: wc, + logger: l, + p: ps, + configData: new ConfigurationDataRecaptchaLogin( + "Make sure you get the cookies from the same torrent day domain as configured above.")) { - wc.EmulateBrowser = false; Encoding = Encoding.UTF8; Language = "en-us"; Type = "private"; - TorznabCaps.SupportsImdbMovieSearch = true; + wc.EmulateBrowser = false; AddCategoryMapping(29, TorznabCatType.TVAnime, "Anime"); AddCategoryMapping(28, TorznabCatType.PC, "Appz/Packs"); @@ -181,7 +181,7 @@ namespace Jackett.Common.Indexers errorMessage = dom.TextContent; if (string.IsNullOrWhiteSpace(errorMessage) && result.IsRedirect) - errorMessage = string.Format("Got a redirect to {0}, please adjust your the alternative link", result.RedirectingTo); + errorMessage = $"Got a redirect to {result.RedirectingTo}, please adjust your the alternative link"; throw new ExceptionWithConfigData(errorMessage, configData); }); @@ -191,66 +191,65 @@ namespace Jackett.Common.Indexers protected override async Task> PerformQuery(TorznabQuery query) { var releases = new List(); - var searchString = query.GetQueryString(); - var queryUrl = SearchUrl; var cats = MapTorznabCapsToTrackers(query); if (cats.Count == 0) cats = GetAllTrackerCategories(); - var catStr = string.Join(";", cats); - queryUrl += "?" + catStr; + var searchUrl = SearchUrl + "?" + catStr; - if (!string.IsNullOrWhiteSpace(query.ImdbID)) - queryUrl += ";q=" + query.ImdbID; + if (query.IsImdbQuery) + searchUrl += ";q=" + query.ImdbID; else - queryUrl += ";q=" + WebUtilityHelpers.UrlEncode(searchString, Encoding); + searchUrl += ";q=" + WebUtilityHelpers.UrlEncode(query.GetQueryString(), Encoding); - var results = await RequestStringWithCookiesAndRetry(queryUrl); + var results = await RequestStringWithCookiesAndRetry(searchUrl); // Check for being logged out if (results.IsRedirect) if (results.RedirectingTo.Contains("login.php")) throw new ExceptionWithConfigData("Login failed, please reconfigure the tracker to update the cookies", configData); else - throw new ExceptionWithConfigData(string.Format("Got a redirect to {0}, please adjust your the alternative link", results.RedirectingTo), configData); + throw new ExceptionWithConfigData($"Got a redirect to {results.RedirectingTo}, please adjust your the alternative link", configData); try { - var json = JsonConvert.DeserializeObject(results.Content); + var rows = JsonConvert.DeserializeObject(results.Content); - foreach (var torrent in json) + foreach (var row in rows) { - var title = (string)torrent.name; + var title = (string)row.name; if ((!query.IsImdbQuery || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(title)) continue; - var torrentID = (long)torrent.t; - var comments = new Uri(SiteLink + "details.php?id=" + torrentID); - var seeders = (int)torrent.seeders; - var imdbId = (string)torrent["imdb-id"]; - var downloadMultiplier = (double?)torrent["download-multiplier"]; - var link = new Uri(SiteLink + "download.php/" + torrentID + "/" + torrentID + ".torrent"); - var publishDate = DateTimeUtil.UnixTimestampToDateTime((long)torrent.ctime).ToLocalTime(); + var torrentId = (long)row.t; + var comments = new Uri(SiteLink + "details.php?id=" + torrentId); + var seeders = (int)row.seeders; + var imdbId = (string)row["imdb-id"]; + var downloadMultiplier = (double?)row["download-multiplier"] ?? 1; + var link = new Uri(SiteLink + "download.php/" + torrentId + "/" + torrentId + ".torrent"); + var publishDate = DateTimeUtil.UnixTimestampToDateTime((long)row.ctime).ToLocalTime(); var imdb = ParseUtil.GetImdbID(imdbId); + var release = new ReleaseInfo { Title = title, - MinimumRatio = 1, - MinimumSeedTime = 172800, // 48 hours - Category = MapTrackerCatToNewznab(torrent.c.ToString()), Comments = comments, Guid = comments, Link = link, PublishDate = publishDate, - Size = (long)torrent.size, + Category = MapTrackerCatToNewznab(row.c.ToString()), + Size = (long)row.size, + Files = (long)row.files, + Grabs = (long)row.completed, Seeders = seeders, - Peers = seeders + (int)torrent.leechers, - Files = (long)torrent.files, - Grabs = (long)torrent.completed, + Peers = seeders + (int)row.leechers, Imdb = imdb, - DownloadVolumeFactor = downloadMultiplier ?? 1, - UploadVolumeFactor = 1 + DownloadVolumeFactor = downloadMultiplier, + UploadVolumeFactor = 1, + MinimumRatio = 1, + MinimumSeedTime = 172800 // 48 hours }; + releases.Add(release); } }