From ec4237d51a54a746be358ed1f1c90a86532a44d8 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 24 Aug 2019 22:43:33 +0200 Subject: [PATCH] Added BuildInfo.AppName to centralize 'Lidarr' --- .../EnvironmentInfo/BuildInfo.cs | 2 ++ src/NzbDrone.Common/Http/HttpProvider.cs | 2 +- src/NzbDrone.Common/Http/UserAgentBuilder.cs | 6 ++--- .../Indexers/Rarbg/RarbgRequestGenerator.cs | 3 ++- .../Notifications/Boxcar/BoxcarProxy.cs | 5 ++-- .../Notifications/Plex/PlexTv/PlexTvProxy.cs | 5 ++-- .../Plex/PlexTv/PlexTvService.cs | 24 ++++++++++--------- .../Plex/Server/PlexServerProxy.cs | 4 ++-- .../Notifications/Prowl/ProwlService.cs | 5 ++-- src/NzbDrone.Core/Rest/RestClientFactory.cs | 2 +- src/NzbDrone.Host/Owin/OwinServiceProvider.cs | 5 ++-- 11 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs index fb75ad41e..15dc9ae98 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs @@ -26,6 +26,8 @@ namespace NzbDrone.Common.EnvironmentInfo Release = $"{Version}-{Branch}"; } + public static string AppName { get; } = "Lidarr"; + public static Version Version { get; } public static String Branch { get; } public static string Release { get; } diff --git a/src/NzbDrone.Common/Http/HttpProvider.cs b/src/NzbDrone.Common/Http/HttpProvider.cs index 4a8f8c54a..a61ac8a14 100644 --- a/src/NzbDrone.Common/Http/HttpProvider.cs +++ b/src/NzbDrone.Common/Http/HttpProvider.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Common.Http public HttpProvider(Logger logger) { _logger = logger; - _userAgent = string.Format("Lidarr {0}", BuildInfo.Version); + _userAgent = $"{BuildInfo.AppName}/{BuildInfo.Version.ToString(2)}"; ServicePointManager.Expect100Continue = false; } diff --git a/src/NzbDrone.Common/Http/UserAgentBuilder.cs b/src/NzbDrone.Common/Http/UserAgentBuilder.cs index afe13ecce..525b8ee0b 100644 --- a/src/NzbDrone.Common/Http/UserAgentBuilder.cs +++ b/src/NzbDrone.Common/Http/UserAgentBuilder.cs @@ -1,4 +1,4 @@ -using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Common.Http { @@ -33,8 +33,8 @@ namespace NzbDrone.Common.Http var osVersion = osInfo.Version?.ToLower(); - _userAgent = $"Lidarr/{BuildInfo.Version} ({osName} {osVersion})"; - _userAgentSimplified = $"Lidarr/{BuildInfo.Version.ToString(2)}"; + _userAgent = $"{BuildInfo.AppName}/{BuildInfo.Version} ({osName} {osVersion})"; + _userAgentSimplified = $"{BuildInfo.AppName}/{BuildInfo.Version.ToString(2)}"; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs index b5b14ea59..a1fae523c 100644 --- a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; @@ -76,7 +77,7 @@ namespace NzbDrone.Core.Indexers.Rarbg requestBuilder.AddQueryParam("limit", "100"); requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings)); requestBuilder.AddQueryParam("format", "json_extended"); - requestBuilder.AddQueryParam("app_id", "Lidarr"); + requestBuilder.AddQueryParam("app_id", BuildInfo.AppName); yield return new IndexerRequest(requestBuilder.Build()); } diff --git a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs b/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs index 17b87cb05..75b70c415 100644 --- a/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs +++ b/src/NzbDrone.Core/Notifications/Boxcar/BoxcarProxy.cs @@ -4,6 +4,7 @@ using FluentValidation.Results; using NLog; using RestSharp; using NzbDrone.Core.Rest; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Core.Notifications.Boxcar { @@ -75,8 +76,8 @@ namespace NzbDrone.Core.Notifications.Boxcar request.AddParameter("user_credentials", settings.Token); request.AddParameter("notification[title]", title); request.AddParameter("notification[long_message]", message); - request.AddParameter("notification[source_name]", "Lidarr"); - request.AddParameter("notification[icon_url]", "https://raw.githubusercontent.com/Lidarr/Lidarr/7818f0c59b787312f0bcbc5c0eafc3c9dd7e5451/Logo/64.png"); + request.AddParameter("notification[source_name]", BuildInfo.AppName); + request.AddParameter("notification[icon_url]", "https://github.com/lidarr/Lidarr/raw/develop/Logo/64.png"); client.ExecuteAndValidate(request); } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvProxy.cs b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvProxy.cs index cac6a529a..c4fafe006 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvProxy.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvProxy.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv { string GetAuthToken(string clientIdentifier, int pinId); } + public class PlexTvProxy : IPlexTvProxy { private readonly IHttpClient _httpClient; @@ -42,10 +43,10 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv var requestBuilder = new HttpRequestBuilder("https://plex.tv") .Accept(HttpAccept.Json) .AddQueryParam("X-Plex-Client-Identifier", clientIdentifier) - .AddQueryParam("X-Plex-Product", "Lidarr") + .AddQueryParam("X-Plex-Product", BuildInfo.AppName) .AddQueryParam("X-Plex-Platform", "Windows") .AddQueryParam("X-Plex-Platform-Version", "7") - .AddQueryParam("X-Plex-Device-Name", "Lidarr") + .AddQueryParam("X-Plex-Device-Name", BuildInfo.AppName) .AddQueryParam("X-Plex-Version", BuildInfo.Version.ToString()); return requestBuilder; diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs index 1f5089a84..8866775c6 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs @@ -31,10 +31,10 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv var requestBuilder = new HttpRequestBuilder("https://plex.tv/api/v2/pins") .Accept(HttpAccept.Json) .AddQueryParam("X-Plex-Client-Identifier", clientIdentifier) - .AddQueryParam("X-Plex-Product", "Lidarr") + .AddQueryParam("X-Plex-Product", BuildInfo.AppName) .AddQueryParam("X-Plex-Platform", "Windows") .AddQueryParam("X-Plex-Platform-Version", "7") - .AddQueryParam("X-Plex-Device-Name", "Lidarr") + .AddQueryParam("X-Plex-Device-Name", BuildInfo.AppName) .AddQueryParam("X-Plex-Version", BuildInfo.Version.ToString()) .AddQueryParam("strong", true); @@ -43,10 +43,10 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv var request = requestBuilder.Build(); return new PlexTvPinUrlResponse - { - Url = request.Url.ToString(), - Headers = request.Headers.ToDictionary(h => h.Key, h => h.Value) - }; + { + Url = request.Url.ToString(), + Headers = request.Headers.ToDictionary(h => h.Key, h => h.Value) + }; } public PlexTvSignInUrlResponse GetSignInUrl(string callbackUrl, int pinId, string pinCode) @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv .AddQueryParam("clientID", clientIdentifier) .AddQueryParam("forwardUrl", callbackUrl) .AddQueryParam("code", pinCode) - .AddQueryParam("context[device][product]", "Lidarr") + .AddQueryParam("context[device][product]", BuildInfo.AppName) .AddQueryParam("context[device][platform]", "Windows") .AddQueryParam("context[device][platformVersion]", "7") .AddQueryParam("context[device][version]", BuildInfo.Version.ToString()); @@ -68,14 +68,16 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv var request = requestBuilder.Build(); return new PlexTvSignInUrlResponse - { - OauthUrl = request.Url.ToString(), - PinId = pinId - }; + { + OauthUrl = request.Url.ToString(), + PinId = pinId + }; } + public string GetAuthToken(int pinId) { var authToken = _proxy.GetAuthToken(_configService.PlexClientIdentifier, pinId); + return authToken; } } diff --git a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerProxy.cs b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerProxy.cs index 0e1370d22..1fdd63df8 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerProxy.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerProxy.cs @@ -152,10 +152,10 @@ namespace NzbDrone.Core.Notifications.Plex.Server var requestBuilder = new HttpRequestBuilder($"{scheme}://{settings.Host}:{settings.Port}") .Accept(HttpAccept.Json) .AddQueryParam("X-Plex-Client-Identifier", _configService.PlexClientIdentifier) - .AddQueryParam("X-Plex-Product", "Lidarr") + .AddQueryParam("X-Plex-Product", BuildInfo.AppName) .AddQueryParam("X-Plex-Platform", "Windows") .AddQueryParam("X-Plex-Platform-Version", "7") - .AddQueryParam("X-Plex-Device-Name", "Lidarr") + .AddQueryParam("X-Plex-Device-Name", BuildInfo.AppName) .AddQueryParam("X-Plex-Version", BuildInfo.Version.ToString()); if (settings.AuthToken.IsNotNullOrWhiteSpace()) diff --git a/src/NzbDrone.Core/Notifications/Prowl/ProwlService.cs b/src/NzbDrone.Core/Notifications/Prowl/ProwlService.cs index e07861bd4..a49663686 100644 --- a/src/NzbDrone.Core/Notifications/Prowl/ProwlService.cs +++ b/src/NzbDrone.Core/Notifications/Prowl/ProwlService.cs @@ -1,6 +1,7 @@ using System; using FluentValidation.Results; using NLog; +using NzbDrone.Common.EnvironmentInfo; using Prowlin; namespace NzbDrone.Core.Notifications.Prowl @@ -26,7 +27,7 @@ namespace NzbDrone.Core.Notifications.Prowl { var notification = new Prowlin.Notification { - Application = "Lidarr", + Application = BuildInfo.AppName, Description = message, Event = title, Priority = priority, @@ -88,7 +89,7 @@ namespace NzbDrone.Core.Notifications.Prowl Verify(settings.ApiKey); const string title = "Test Notification"; - const string body = "This is a test message from Lidarr"; + string body = $"This is a test message from {BuildInfo.AppName}"; SendNotification(title, body, settings.ApiKey); } diff --git a/src/NzbDrone.Core/Rest/RestClientFactory.cs b/src/NzbDrone.Core/Rest/RestClientFactory.cs index 92526946e..cc657c4b6 100644 --- a/src/NzbDrone.Core/Rest/RestClientFactory.cs +++ b/src/NzbDrone.Core/Rest/RestClientFactory.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Core.Rest { var restClient = new RestClient(baseUrl) { - UserAgent = $"Lidarr/{BuildInfo.Version} ({OsInfo.Os})" + UserAgent = $"{BuildInfo.AppName}/{BuildInfo.Version} ({OsInfo.Os})" }; diff --git a/src/NzbDrone.Host/Owin/OwinServiceProvider.cs b/src/NzbDrone.Host/Owin/OwinServiceProvider.cs index 2c12a8d0a..d0ce2425e 100644 --- a/src/NzbDrone.Host/Owin/OwinServiceProvider.cs +++ b/src/NzbDrone.Host/Owin/OwinServiceProvider.cs @@ -8,6 +8,7 @@ using Microsoft.Owin.Hosting.Engine; using Microsoft.Owin.Hosting.Services; using Microsoft.Owin.Hosting.Tracing; using NLog; +using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; using NzbDrone.Host.Owin.MiddleWare; using Owin; @@ -60,7 +61,7 @@ namespace NzbDrone.Host.Owin if (ex.InnerException is HttpListenerException) { - throw new PortInUseException("Port {0} is already in use, please ensure Lidarr is not already running.", ex, _configFileProvider.Port); + throw new PortInUseException("Port {0} is already in use, please ensure {1} is not already running.", ex, _configFileProvider.Port, BuildInfo.AppName); } throw ex.InnerException; @@ -70,7 +71,7 @@ namespace NzbDrone.Host.Owin private void BuildApp(IAppBuilder appBuilder) { - appBuilder.Properties["host.AppName"] = "Lidarr"; + appBuilder.Properties["host.AppName"] = BuildInfo.AppName; foreach (var middleWare in _owinMiddleWares.OrderBy(c => c.Order)) {