From 587a73f3d6183f338ca54fe7416e009ca8e5a350 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 26 Dec 2022 18:17:50 -0600 Subject: [PATCH] Fixed: (Newznab) Parsing of Ids from non-standard feeds Fixes #1261 --- .../IndexerSearch/NewznabResults.cs | 13 +++++---- .../Definitions/Newznab/NewznabRssParser.cs | 29 +++++++++++-------- src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs | 1 + 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core/IndexerSearch/NewznabResults.cs b/src/NzbDrone.Core/IndexerSearch/NewznabResults.cs index f272559ae..2a076f9c5 100644 --- a/src/NzbDrone.Core/IndexerSearch/NewznabResults.cs +++ b/src/NzbDrone.Core/IndexerSearch/NewznabResults.cs @@ -93,12 +93,13 @@ namespace NzbDrone.Core.IndexerSearch r.Languages == null ? null : from c in r.Languages select GetNabElement("language", c, protocol), r.Subs == null ? null : from c in r.Subs select GetNabElement("subs", c, protocol), r.Genres == null ? null : GetNabElement("genre", string.Join(", ", r.Genres), protocol), - GetNabElement("rageid", r.TvRageId, protocol), - GetNabElement("tvdbid", r.TvdbId, protocol), - GetNabElement("imdb", r.ImdbId.ToString("D7"), protocol), - GetNabElement("tmdbid", r.TmdbId, protocol), - GetNabElement("traktid", r.TraktId, protocol), - GetNabElement("doubanid", r.DoubanId, protocol), + r.TvRageId == 0 ? null : GetNabElement("rageid", r.TvRageId, protocol), + r.TvdbId == 0 ? null : GetNabElement("tvdbid", r.TvdbId, protocol), + r.ImdbId == 0 ? null : GetNabElement("imdb", r.ImdbId.ToString("D7"), protocol), + r.TmdbId == 0 ? null : GetNabElement("tmdbid", r.TmdbId, protocol), + r.TraktId == 0 ? null : GetNabElement("traktid", r.TraktId, protocol), + r.TvMazeId == 0 ? null : GetNabElement("tvmazeid", r.TvMazeId, protocol), + r.DoubanId == 0 ? null : GetNabElement("doubanid", r.DoubanId, protocol), GetNabElement("seeders", t.Seeders, protocol), GetNabElement("files", r.Files, protocol), GetNabElement("grabs", r.Grabs, protocol), diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs index 269b548ab..1efd2ace2 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs @@ -100,12 +100,14 @@ namespace NzbDrone.Core.Indexers.Newznab } releaseInfo = base.ProcessItem(item, releaseInfo); - releaseInfo.ImdbId = GetIntAttribute(item, "imdb"); - releaseInfo.TmdbId = GetIntAttribute(item, "tmdbid"); - releaseInfo.TvdbId = GetIntAttribute(item, "tvdbid"); - releaseInfo.TvRageId = GetIntAttribute(item, "rageid"); - releaseInfo.Grabs = GetIntAttribute(item, "grabs"); - releaseInfo.Files = GetIntAttribute(item, "files"); + releaseInfo.ImdbId = GetIntAttribute(item, new[] { "imdb", "imdbid" }); + releaseInfo.TmdbId = GetIntAttribute(item, new[] { "tmdbid", "tmdb" }); + releaseInfo.TvdbId = GetIntAttribute(item, new[] { "tvdbid", "tvdb" }); + releaseInfo.TvMazeId = GetIntAttribute(item, new[] { "tvmazeid", "tvmaze" }); + releaseInfo.TraktId = GetIntAttribute(item, new[] { "traktid", "trakt" }); + releaseInfo.TvRageId = GetIntAttribute(item, new[] { "rageid" }); + releaseInfo.Grabs = GetIntAttribute(item, new[] { "grabs" }); + releaseInfo.Files = GetIntAttribute(item, new[] { "files" }); releaseInfo.PosterUrl = GetPosterUrl(item); return releaseInfo; @@ -206,14 +208,17 @@ namespace NzbDrone.Core.Indexers.Newznab return url; } - protected virtual int GetIntAttribute(XElement item, string attribute) + protected virtual int GetIntAttribute(XElement item, string[] attributes) { - var idString = TryGetNewznabAttribute(item, attribute); - int idInt; - - if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out idInt)) + foreach (var attr in attributes) { - return idInt; + var idString = TryGetNewznabAttribute(item, attr); + int idInt; + + if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out idInt)) + { + return idInt; + } } return 0; diff --git a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs index f0f66fc1b..511f4f683 100644 --- a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs @@ -34,6 +34,7 @@ namespace NzbDrone.Core.Parser.Model public int ImdbId { get; set; } public int TmdbId { get; set; } public int TraktId { get; set; } + public int TvMazeId { get; set; } public int DoubanId { get; set; } public int Year { get; set; } public string Author { get; set; }