From 477bfb7835b3e4394c0a294299bb52ef6d4ffe45 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 8 May 2023 23:39:03 +0300 Subject: [PATCH] Minor cleanup in RssImport --- .../ImportLists/Rss/Plex/PlexRssImport.cs | 8 +++---- .../Rss/Plex/PlexRssImportParser.cs | 14 ++++++------ .../Rss/Plex/PlexRssImportSettings.cs | 4 ++-- .../ImportLists/Rss/RssImportBase.cs | 10 ++++----- .../ImportLists/Rss/RssImportBaseParser.cs | 22 +++++++++---------- .../ImportLists/Rss/RssImportBaseSettings.cs | 2 +- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImport.cs b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImport.cs index 2a02de133..91a379c54 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImport.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImport.cs @@ -8,6 +8,10 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex { public class PlexRssImport : RssImportBase { + public override string Name => "Plex Watchlist RSS"; + public override ImportListType ListType => ImportListType.Plex; + public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); + public PlexRssImport(IHttpClient httpClient, IImportListStatusService importListStatusService, IConfigService configService, @@ -17,10 +21,6 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex { } - public override ImportListType ListType => ImportListType.Plex; - public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); - public override string Name => "Plex Watchlist RSS"; - public override IParseImportListResponse GetParser() { return new PlexRssImportParser(_logger); diff --git a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs index 9efdf196a..cad233559 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportParser.cs @@ -8,18 +8,13 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex { public class PlexRssImportParser : RssImportBaseParser { - private readonly Logger _logger; - public PlexRssImportParser(Logger logger) - : base(logger) + : base(logger) { - _logger = logger; } protected override ImportListItemInfo ProcessItem(XElement item) { - var info = new ImportListItemInfo(); - var guid = item.TryGetValue("guid", string.Empty); var category = item.TryGetValue("category"); if (category != "show") @@ -27,7 +22,12 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex return null; } - info.Title = item.TryGetValue("title", "Unknown"); + var info = new ImportListItemInfo + { + Title = item.TryGetValue("title", "Unknown") + }; + + var guid = item.TryGetValue("guid", string.Empty); if (int.TryParse(guid.Replace("tvdb://", ""), out var tvdbId)) { diff --git a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportSettings.cs b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportSettings.cs index 58e16f93a..941b90a4a 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/Plex/PlexRssImportSettings.cs @@ -12,9 +12,9 @@ namespace NzbDrone.Core.ImportLists.Rss.Plex } } - public class PlexRssImportSettings : RssImportBaseSettings, IImportListSettings + public class PlexRssImportSettings : RssImportBaseSettings { - private PlexRssImportSettingsValidator Validator => new PlexRssImportSettingsValidator(); + private PlexRssImportSettingsValidator Validator => new (); [FieldDefinition(0, Label = "Url", Type = FieldType.Textbox, HelpLink = "https://app.plex.tv/desktop/#!/settings/watchlist")] public override string Url { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/Rss/RssImportBase.cs b/src/NzbDrone.Core/ImportLists/Rss/RssImportBase.cs index dba32e022..de3846687 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/RssImportBase.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/RssImportBase.cs @@ -11,6 +11,10 @@ namespace NzbDrone.Core.ImportLists.Rss public class RssImportBase : HttpImportListBase where TSettings : RssImportBaseSettings, new() { + public override string Name => "RSS List Base"; + public override ImportListType ListType => ImportListType.Advanced; + public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); + public RssImportBase(IHttpClient httpClient, IImportListStatusService importListStatusService, IConfigService configService, @@ -20,10 +24,6 @@ namespace NzbDrone.Core.ImportLists.Rss { } - public override ImportListType ListType => ImportListType.Advanced; - public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); - public override string Name => "RSS List Base"; - public override IList Fetch() { return FetchItems(g => g.GetListItems()); @@ -36,7 +36,7 @@ namespace NzbDrone.Core.ImportLists.Rss public override IImportListRequestGenerator GetRequestGenerator() { - return new RssImportRequestGenerator() + return new RssImportRequestGenerator { Settings = Settings }; diff --git a/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseParser.cs b/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseParser.cs index 9f17e1c7d..d067322e3 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseParser.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseParser.cs @@ -83,10 +83,9 @@ namespace NzbDrone.Core.ImportLists.Rss var content = XmlCleaner.ReplaceEntities(importListResponse.Content); content = XmlCleaner.ReplaceUnicode(content); - using (var xmlTextReader = XmlReader.Create(new StringReader(content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) - { - return XDocument.Load(xmlTextReader); - } + using var xmlTextReader = XmlReader.Create(new StringReader(content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }); + + return XDocument.Load(xmlTextReader); } catch (XmlException ex) { @@ -120,19 +119,18 @@ namespace NzbDrone.Core.ImportLists.Rss protected virtual ImportListItemInfo ProcessItem(XElement item) { - var info = new ImportListItemInfo(); + var info = new ImportListItemInfo + { + Title = item.TryGetValue("title", "Unknown") + }; + var guid = item.TryGetValue("guid"); - if (guid != null) + if (guid != null && int.TryParse(guid, out var tvdbId)) { - if (int.TryParse(guid, out var tvdbId)) - { - info.TvdbId = tvdbId; - } + info.TvdbId = tvdbId; } - info.Title = item.TryGetValue("title", "Unknown"); - if (info.TvdbId == 0) { throw new UnsupportedFeedException("Each item in the RSS feed must have a guid element with a TVDB ID"); diff --git a/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseSettings.cs b/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseSettings.cs index 19f18c7ce..32f631676 100644 --- a/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Rss/RssImportBaseSettings.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.ImportLists.Rss public class RssImportBaseSettings : IImportListSettings { - private RssImportSettingsValidator Validator => new RssImportSettingsValidator(); + private RssImportSettingsValidator Validator => new (); public string BaseUrl { get; set; }