From 2a992f6c2b3e6ca7d4b8a5d81f319abb676e9ae0 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 1 Sep 2018 23:37:55 -0400 Subject: [PATCH] Fixed: Remove MediaBrowser metadata and pushalot --- .../Migration/020_remove_pushalot.cs | 16 +++ .../MediaBrowser/MediaBrowserMetadata.cs | 125 ------------------ .../MediaBrowserMetadataSettings.cs | 31 ----- .../Notifications/Pushalot/Pushalot.cs | 43 ------ .../Pushalot/PushalotPriority.cs | 9 -- .../Notifications/Pushalot/PushalotProxy.cs | 106 --------------- .../Pushalot/PushalotResponse.cs | 9 -- .../Pushalot/PushalotSettings.cs | 41 ------ src/NzbDrone.Core/NzbDrone.Core.csproj | 8 +- 9 files changed, 17 insertions(+), 371 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/020_remove_pushalot.cs delete mode 100644 src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadata.cs delete mode 100644 src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadataSettings.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs delete mode 100644 src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/020_remove_pushalot.cs b/src/NzbDrone.Core/Datastore/Migration/020_remove_pushalot.cs new file mode 100644 index 000000000..e7339afb9 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/020_remove_pushalot.cs @@ -0,0 +1,16 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(20)] + public class remove_pushalot : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Delete.FromTable("Notifications").Row(new { Implementation = "Pushalot" }); + Delete.FromTable("Metadata").Row(new { Implementation = "MediaBrowserMetadata" }); + Delete.FromTable("MetadataFiles").Row(new { Consumer = "MediaBrowserMetadata" }); + } + } +} diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadata.cs deleted file mode 100644 index 84874371f..000000000 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadata.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml; -using System.Xml.Linq; -using NLog; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Extras.Metadata.Files; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Music; - -namespace NzbDrone.Core.Extras.Metadata.Consumers.MediaBrowser -{ - public class MediaBrowserMetadata : MetadataBase - { - private readonly Logger _logger; - - public MediaBrowserMetadata( - Logger logger) - { - _logger = logger; - } - - public override string Name => "Emby (Legacy)"; - - public override MetadataFile FindMetadataFile(Artist artist, string path) - { - var filename = Path.GetFileName(path); - - if (filename == null) return null; - - var metadata = new MetadataFile - { - ArtistId = artist.Id, - Consumer = GetType().Name, - RelativePath = artist.Path.GetRelativePath(path) - }; - - if (filename.Equals("artist.xml", StringComparison.InvariantCultureIgnoreCase)) - { - metadata.Type = MetadataType.ArtistMetadata; - return metadata; - } - - return null; - } - - public override MetadataFileResult ArtistMetadata(Artist artist) - { - if (!Settings.ArtistMetadata) - { - return null; - } - - _logger.Debug("Generating artist.xml for: {0}", artist.Name); - var sb = new StringBuilder(); - var xws = new XmlWriterSettings(); - xws.OmitXmlDeclaration = true; - xws.Indent = false; - - using (var xw = XmlWriter.Create(sb, xws)) - { - var artistElement = new XElement("Artist"); - - artistElement.Add(new XElement("id", artist.ForeignArtistId)); - artistElement.Add(new XElement("Status", artist.Status)); - - artistElement.Add(new XElement("Added", artist.Added.ToString("MM/dd/yyyy HH:mm:ss tt"))); - artistElement.Add(new XElement("LockData", "false")); - artistElement.Add(new XElement("Overview", artist.Overview)); - artistElement.Add(new XElement("LocalTitle", artist.Name)); - - artistElement.Add(new XElement("Rating", artist.Ratings.Value)); - - var persons = new XElement("Persons"); - - foreach (var person in artist.Members) - { - persons.Add(new XElement("Person", - new XElement("Name", person.Name), - new XElement("Type", "Actor"), - new XElement("Role", person.Instrument) - )); - } - - artistElement.Add(persons); - - - var doc = new XDocument(artistElement); - doc.Save(xw); - - _logger.Debug("Saving artist.xml for {0}", artist.Name); - - return new MetadataFileResult("artist.xml", doc.ToString()); - } - } - - public override MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath) - { - return null; - } - - public override MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile) - { - return null; - } - - public override List ArtistImages(Artist artist) - { - return new List(); - } - - public override List AlbumImages(Artist artist, Album album, string albumFolder) - { - return new List(); - } - - public override List TrackImages(Artist artist, TrackFile trackFile) - { - return new List(); - } - } -} diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadataSettings.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadataSettings.cs deleted file mode 100644 index bf2f3c3ae..000000000 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/MediaBrowser/MediaBrowserMetadataSettings.cs +++ /dev/null @@ -1,31 +0,0 @@ -using FluentValidation; -using NzbDrone.Core.Annotations; -using NzbDrone.Core.ThingiProvider; -using NzbDrone.Core.Validation; - -namespace NzbDrone.Core.Extras.Metadata.Consumers.MediaBrowser -{ - public class MediaBrowserSettingsValidator : AbstractValidator - { - } - - public class MediaBrowserMetadataSettings : IProviderConfig - { - private static readonly MediaBrowserSettingsValidator Validator = new MediaBrowserSettingsValidator(); - - public MediaBrowserMetadataSettings() - { - ArtistMetadata = true; - } - - [FieldDefinition(0, Label = "Artist Metadata", Type = FieldType.Checkbox, HelpText = "artist.xml")] - public bool ArtistMetadata { get; set; } - - public bool IsValid => true; - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs b/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs deleted file mode 100644 index 2929d465b..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/Pushalot.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using FluentValidation.Results; -using NzbDrone.Common.Extensions; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class Pushalot : NotificationBase - { - private readonly IPushalotProxy _proxy; - - public Pushalot(IPushalotProxy proxy) - { - _proxy = proxy; - } - - public override string Name => "Pushalot"; - public override string Link => "https://pushalot.com/"; - - public override void OnGrab(GrabMessage grabMessage) - { - _proxy.SendNotification(ALBUM_GRABBED_TITLE, grabMessage.Message, Settings); - } - - public override void OnDownload(TrackDownloadMessage message) - { - _proxy.SendNotification(TRACK_DOWNLOADED_TITLE, message.Message, Settings); - } - - public override void OnAlbumDownload(AlbumDownloadMessage message) - { - _proxy.SendNotification(ALBUM_DOWNLOADED_TITLE, message.Message, Settings); - } - - public override ValidationResult Test() - { - var failures = new List(); - - failures.AddIfNotNull(_proxy.Test(Settings)); - - return new ValidationResult(failures); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs deleted file mode 100644 index 58effba2f..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotPriority.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace NzbDrone.Core.Notifications.Pushalot -{ - public enum PushalotPriority - { - Silent = -1, - Normal = 0, - Important = 1 - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs deleted file mode 100644 index 7c306cad3..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotProxy.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Net; -using FluentValidation.Results; -using NLog; -using NzbDrone.Common.Serializer; -using NzbDrone.Core.Rest; -using RestSharp; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public interface IPushalotProxy - { - void SendNotification(string title, string message, PushalotSettings settings); - ValidationFailure Test(PushalotSettings settings); - } - - public class PushalotProxy : IPushalotProxy - { - private readonly Logger _logger; - private const string URL = "https://pushalot.com/api/sendmessage"; - - public PushalotProxy(Logger logger) - { - _logger = logger; - } - - public void SendNotification(string title, string message, PushalotSettings settings) - { - var client = RestClientFactory.BuildClient(URL); - var request = BuildRequest(); - - request.AddParameter("Source", "Lidarr"); - - if (settings.Image) - { - request.AddParameter("Image", "https://raw.githubusercontent.com/Lidarr/Lidarr/develop/Logo/128.png"); - } - - request.AddParameter("Title", title); - request.AddParameter("Body", message); - request.AddParameter("AuthorizationToken", settings.AuthToken); - - if ((PushalotPriority)settings.Priority == PushalotPriority.Important) - { - request.AddParameter("IsImportant", true); - } - - if ((PushalotPriority)settings.Priority == PushalotPriority.Silent) - { - request.AddParameter("IsSilent", true); - } - - client.ExecuteAndValidate(request); - } - - public RestRequest BuildRequest() - { - var request = new RestRequest(Method.POST); - - return request; - } - - public ValidationFailure Test(PushalotSettings settings) - { - try - { - const string title = "Test Notification"; - const string body = "This is a test message from Lidarr"; - - SendNotification(title, body, settings); - } - catch (RestException ex) - { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) - { - _logger.Error(ex, "Authentication Token is invalid"); - return new ValidationFailure("AuthToken", "Authentication Token is invalid"); - } - - if (ex.Response.StatusCode == HttpStatusCode.NotAcceptable) - { - _logger.Error(ex, "Message limit reached"); - return new ValidationFailure("AuthToken", "Message limit reached"); - } - - if (ex.Response.StatusCode == HttpStatusCode.Gone) - { - _logger.Error(ex, "Authorization Token is no longer valid"); - return new ValidationFailure("AuthToken", "Authorization Token is no longer valid, please use a new one."); - } - - var response = Json.Deserialize(ex.Response.Content); - - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("AuthToken", response.Description); - } - catch (Exception ex) - { - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("", "Unable to send test message"); - } - - return null; - } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs deleted file mode 100644 index 860be65c6..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class PushalotResponse - { - public bool Success { get; set; } - public int Status { get; set; } - public string Description { get; set; } - } -} diff --git a/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs b/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs deleted file mode 100644 index 008503e84..000000000 --- a/src/NzbDrone.Core/Notifications/Pushalot/PushalotSettings.cs +++ /dev/null @@ -1,41 +0,0 @@ -using FluentValidation; -using NzbDrone.Core.Annotations; -using NzbDrone.Core.ThingiProvider; -using NzbDrone.Core.Validation; - -namespace NzbDrone.Core.Notifications.Pushalot -{ - public class PushalotSettingsValidator : AbstractValidator - { - public PushalotSettingsValidator() - { - RuleFor(c => c.AuthToken).NotEmpty(); - } - } - - public class PushalotSettings : IProviderConfig - { - public PushalotSettings() - { - Image = true; - } - - private static readonly PushalotSettingsValidator Validator = new PushalotSettingsValidator(); - - [FieldDefinition(0, Label = "Authorization Token", HelpLink = "https://pushalot.com/manager/authorizations")] - public string AuthToken { get; set; } - - [FieldDefinition(1, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushalotPriority))] - public int Priority { get; set; } - - [FieldDefinition(2, Label = "Image", Type = FieldType.Checkbox, HelpText = "Include Lidarr logo with notifications")] - public bool Image { get; set; } - - public bool IsValid => !string.IsNullOrWhiteSpace(AuthToken); - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index e312d692e..f5dcc1b87 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -188,6 +188,7 @@ + @@ -795,8 +796,6 @@ - - @@ -1019,11 +1018,6 @@ Code - - - - -