From e3dc31cca508f26fd800baf59c9328ae840d21f6 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sun, 5 Mar 2017 17:58:48 -0500 Subject: [PATCH] Try to add year to release titles that have no year (foriegn release groups) (#1028) --- src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 2 +- .../Indexers/Newznab/NewznabRssParser.cs | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 01fa26016..078a8f3de 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Indexers.Newznab public override IParseIndexerResponse GetParser() { - return new NewznabRssParser(); + return new NewznabRssParser(Settings); } public override IEnumerable DefaultDefinitions diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index 521b63fa6..94569101a 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -4,6 +4,7 @@ using System.Xml.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser.Model; +using RestSharp.Extensions; namespace NzbDrone.Core.Indexers.Newznab { @@ -11,9 +12,12 @@ namespace NzbDrone.Core.Indexers.Newznab { public const string ns = "{http://www.newznab.com/DTD/2010/feeds/attributes/}"; - public NewznabRssParser() + private readonly NewznabSettings _settings; + + public NewznabRssParser(NewznabSettings settings) { PreferredEnclosureMimeType = "application/x-nzb"; + _settings = settings; } protected override bool PreProcess(IndexerResponse indexerResponse) @@ -50,6 +54,20 @@ namespace NzbDrone.Core.Indexers.Newznab releaseInfo = base.ProcessItem(item, releaseInfo); releaseInfo.ImdbId = GetImdbId(item); + // Fun, lets try to add year to the releaseTitle for our foriegn friends :) + if (!releaseInfo.Title.Contains(GetImdbTitle(item) + "." + GetImdbYear(item))) + { + if (GetImdbYear(item) != 1900) + { + releaseInfo.Title = releaseInfo.Title.Replace(GetImdbTitle(item), GetImdbTitle(item) + "." + GetImdbYear(item)); + } + } + + //if (_settings.Url == "https://newz-complex.org/www/") + //{ + // releaseInfo.Title = releaseInfo.Title.Replace(GetImdbTitle(item), GetImdbTitle(item) + "." + GetImdbYear(item)); + //} + return releaseInfo; } @@ -125,6 +143,30 @@ namespace NzbDrone.Core.Indexers.Newznab return 0; } + protected virtual string GetImdbTitle(XElement item) + { + var imdbTitle = TryGetNewznabAttribute(item, "imdbtitle"); + if (!imdbTitle.IsNullOrWhiteSpace()) + { + return imdbTitle; + } + + return string.Empty; + } + + protected virtual int GetImdbYear(XElement item) + { + var imdbYearString = TryGetNewznabAttribute(item, "imdbyear"); + int imdbYear; + + if (!imdbYearString.IsNullOrWhiteSpace() && int.TryParse(imdbYearString, out imdbYear)) + { + return imdbYear; + } + + return 1900; + } + protected string TryGetNewznabAttribute(XElement item, string key, string defaultValue = "") { var attr = item.Elements(ns + "attr").FirstOrDefault(e => e.Attribute("name").Value.Equals(key, StringComparison.CurrentCultureIgnoreCase));