New: Support for IMDb ID in Plex Watchlist RSS

Closes #6105
This commit is contained in:
Bogdan 2023-10-17 09:52:59 +03:00 committed by GitHub
parent 2fe8f3084c
commit e8a47b4d0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 4 deletions

View File

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