diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs index 195d5a4..bb42920 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs @@ -7,6 +7,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; +using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.TubeArchivistMetadata { @@ -20,10 +21,12 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata /// /// Instance of the interface. /// Instance of the interface. - public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + /// Instance of the interface. + public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger logger) : base(applicationPaths, xmlSerializer) { Instance = this; + Logger = logger; HttpClientHandler handler = new HttpClientHandler(); handler.AllowAutoRedirect = false; handler.CheckCertificateRevocationList = true; @@ -43,7 +46,12 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata public static Plugin? Instance { get; private set; } /// - /// Gets the HTTP client used globally in the plugin. + /// Gets the logger instance used globally by the plugin. + /// + public ILogger Logger { get; } + + /// + /// Gets the HTTP client used globally by the plugin. /// public HttpClient HttpClient { get; } diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs index 34363ac..ede5bd8 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Threading; @@ -11,6 +12,8 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { @@ -19,6 +22,23 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers /// public class EpisodeImageProvider : IRemoteImageProvider { + private ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public EpisodeImageProvider() + { + if (Plugin.Instance == null) + { + throw new DataException("Uninitialized plugin!"); + } + else + { + _logger = Plugin.Instance.Logger; + } + } + /// /// Gets the provider name. /// @@ -40,6 +60,8 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var taApi = TubeArchivistApi.GetInstance(); var videoTAId = item.Path.Split("/").Last().Split(".").First(); var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true); + _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting images for video: {0} ({1})", video?.Title, videoTAId)); + _logger.LogInformation("{Message}", "Thumb URI: " + video?.VidThumbUrl); if (video != null) { @@ -49,7 +71,6 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers Type = ImageType.Primary, Url = video.VidThumbUrl }); - Console.WriteLine("ThumbURL: " + video.VidThumbUrl); } return list; diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs index cfce945..3c80faa 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Threading; @@ -11,6 +12,7 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers @@ -20,6 +22,23 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers /// public class EpisodeMetadataProvider : IRemoteMetadataProvider { + private ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public EpisodeMetadataProvider() + { + if (Plugin.Instance == null) + { + throw new DataException("Uninitialized plugin!"); + } + else + { + _logger = Plugin.Instance.Logger; + } + } + /// /// Gets the provider name. /// @@ -32,9 +51,8 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var taApi = TubeArchivistApi.GetInstance(); var videoTAId = info.Path.Split("/").Last().Split(".").First(); var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true); - Console.WriteLine("Metadata video received: "); - Console.WriteLine(JsonConvert.SerializeObject(video)); - Console.WriteLine("Media YT id: " + videoTAId); + _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting metadata for video: {0} ({1})", video?.Title, videoTAId)); + _logger.LogInformation("{Message}", "Received metadata: \n" + JsonConvert.SerializeObject(video)); if (video != null) { @@ -51,7 +69,6 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers result.People = peopleInfo; } - Console.WriteLine(result.Item.ProductionYear); return result; } diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs index 8b81b6d..bdf14d7 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Threading; @@ -11,6 +12,7 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { @@ -19,6 +21,23 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers /// public class SeriesImageProvider : IRemoteImageProvider { + private ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public SeriesImageProvider() + { + if (Plugin.Instance == null) + { + throw new DataException("Uninitialized plugin!"); + } + else + { + _logger = Plugin.Instance.Logger; + } + } + /// /// Gets the provider name. /// @@ -40,6 +59,10 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var taApi = TubeArchivistApi.GetInstance(); var channelTAId = item.Path.Split("/").Last(); var channel = await taApi.GetChannel(channelTAId).ConfigureAwait(true); + _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting images for channel: {0} ({1})", channel?.Name, channelTAId)); + _logger.LogInformation("{Message}", "Thumb URI: " + channel?.ThumbUrl); + _logger.LogInformation("{Message}", "TVArt URI: " + channel?.TvartUrl); + _logger.LogInformation("{Message}", "Banner URI: " + channel?.BannerUrl); if (channel != null) { @@ -75,7 +98,6 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers } else { - Console.WriteLine("Channel images: " + Plugin.Instance.Configuration.TubeArchivistUrl + url); return await Plugin.Instance.HttpClient.GetAsync(new Uri(Plugin.Instance.Configuration.TubeArchivistUrl + url), cancellationToken).ConfigureAwait(false); } } diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs index b44983b..4438898 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Threading; @@ -11,6 +12,7 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers @@ -20,6 +22,23 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers /// public class SeriesMetadataProvider : IRemoteMetadataProvider { + private ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + public SeriesMetadataProvider() + { + if (Plugin.Instance == null) + { + throw new DataException("Uninitialized plugin!"); + } + else + { + _logger = Plugin.Instance.Logger; + } + } + /// /// Gets the provider name. /// @@ -32,6 +51,8 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var taApi = TubeArchivistApi.GetInstance(); var channelTAId = info.Path.Split("/").Last(); var channel = await taApi.GetChannel(channelTAId).ConfigureAwait(true); + _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting metadata for channel: {0} ({1})", channel?.Name, channelTAId)); + _logger.LogInformation("{Message}", "Received metadata: \n" + JsonConvert.SerializeObject(channel)); if (channel != null) { diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/TubeArchivist/TubeArchivistApi.cs b/Jellyfin.Plugin.TubeArchivistMetadata/TubeArchivist/TubeArchivistApi.cs index 8242000..f7cb1a1 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/TubeArchivist/TubeArchivistApi.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/TubeArchivist/TubeArchivistApi.cs @@ -4,6 +4,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist @@ -13,6 +14,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist /// public class TubeArchivistApi { + private ILogger _logger; private HttpClient client; private static TubeArchivistApi _taApiInstance = null!; @@ -22,6 +24,15 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist /// HTTP client to make requests to TubeArchivist API. private TubeArchivistApi(HttpClient httpClient) { + if (Plugin.Instance == null) + { + throw new DataException("Uninitialized plugin!"); + } + else + { + _logger = Plugin.Instance.Logger; + } + client = httpClient; } @@ -54,34 +65,22 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist public async Task GetChannel(string channelId) { ResponseContainer? channel = null; - Console.WriteLine(Plugin.Instance?.Configuration.TubeArchivistUrl); - Console.WriteLine(Plugin.Instance?.Configuration.TubeArchivistApiKey); - - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", Plugin.Instance?.Configuration.TubeArchivistApiKey); var channelsEndpoint = "/api/channel/"; var url = new Uri(Plugin.Instance?.Configuration.TubeArchivistUrl + channelsEndpoint + channelId); var response = await client.GetAsync(url).ConfigureAwait(true); - Console.WriteLine(response.StatusCode); while (response.StatusCode == HttpStatusCode.Moved) { - Console.WriteLine("Received redirect to: " + response.Headers.Location); + _logger.LogInformation("{Message}", "Received redirect to: " + response.Headers.Location); response = await client.GetAsync(response.Headers.Location).ConfigureAwait(true); } - Console.WriteLine(url + ": " + response.StatusCode); + _logger.LogInformation("{Message}", url + ": " + response.StatusCode); if (response.IsSuccessStatusCode) { string rawData = await response.Content.ReadAsStringAsync().ConfigureAwait(true); channel = JsonConvert.DeserializeObject>(rawData); - - Console.WriteLine("Channel null? " + channel == null); - Console.WriteLine("Channel: " + channel?.Data?.Name); - if (channel != null && channel.Data != null) - { - Console.WriteLine(JsonConvert.SerializeObject(channel)); - } } return channel?.Data; @@ -95,22 +94,17 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist public async Task GetVideo(string videoId) { ResponseContainer