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 @@ protected override ImportListItemInfo ProcessItem(XElement item) 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; + } } }