Try to add year to release titles that have no year (foriegn release groups) (#1028)

This commit is contained in:
Devin Buhl 2017-03-05 17:58:48 -05:00 committed by GitHub
parent ddc6ccbf15
commit e3dc31cca5
2 changed files with 44 additions and 2 deletions

View File

@ -32,7 +32,7 @@ namespace NzbDrone.Core.Indexers.Newznab
public override IParseIndexerResponse GetParser()
{
return new NewznabRssParser();
return new NewznabRssParser(Settings);
}
public override IEnumerable<ProviderDefinition> DefaultDefinitions

View File

@ -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));