parent
2fe8f3084c
commit
e8a47b4d0b
|
@ -1,5 +1,7 @@
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Indexers.Exceptions;
|
using NzbDrone.Core.Indexers.Exceptions;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
@ -8,6 +10,8 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex
|
||||||
{
|
{
|
||||||
public class PlexRssImportParser : RssImportBaseParser
|
public class PlexRssImportParser : RssImportBaseParser
|
||||||
{
|
{
|
||||||
|
private static readonly Regex ImdbIdRegex = new (@"(tt\d{7,8})", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
public PlexRssImportParser(Logger logger)
|
public PlexRssImportParser(Logger logger)
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
|
@ -29,17 +33,37 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex
|
||||||
|
|
||||||
var guid = item.TryGetValue("guid", string.Empty);
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue