From e8a47b4d0b3d8289b29448a7da1004b000446e72 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 17 Oct 2023 09:52:59 +0300 Subject: [PATCH] New: Support for IMDb ID in Plex Watchlist RSS Closes #6105 --- .../Rss/Plex/PlexRssImportParser.cs | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs index cad233559..efd26708e 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs @@ -1,5 +1,7 @@ +using System.Text.RegularExpressions; using System.Xml.Linq; using NLog; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser.Model; @@ -8,6 +10,8 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex { public class PlexRssImportParser : RssImportBaseParser { + private static readonly Regex ImdbIdRegex = new (@"(tt\d{7,8})", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public PlexRssImportParser(Logger logger) : base(logger) { @@ -29,17 +33,37 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex var guid = item.TryGetValue("guid", string.Empty); - if (int.TryParse(guid.Replace("tvdb://", ""), out var tvdbId)) + if (guid.IsNotNullOrWhiteSpace()) { - info.TvdbId = tvdbId; + if (guid.StartsWith("imdb://")) + { + info.ImdbId = ParseImdbId(guid.Replace("imdb://", "")); + } + + if (int.TryParse(guid.Replace("tvdb://", ""), out var tvdbId)) + { + info.TvdbId = tvdbId; + } } - if (info.TvdbId == 0) + if (info.ImdbId.IsNullOrWhiteSpace() && info.TvdbId == 0) { - throw new UnsupportedFeedException("Each item in the RSS feed must have a guid element with a TVDB ID"); + throw new UnsupportedFeedException("Each item in the RSS feed must have a guid element with a IMDB ID or TVDB ID"); } return info; } + + private static string ParseImdbId(string value) + { + if (value.IsNullOrWhiteSpace()) + { + return null; + } + + var match = ImdbIdRegex.Match(value); + + return match.Success ? match.Groups[1].Value : null; + } } }