diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html index 5c97cf6..0e35aa4 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html @@ -541,7 +541,7 @@

Introduction timestamp editor

All times are displayed in the format (HH:MM:SS)


- +
@@ -639,7 +639,7 @@

- @@ -683,6 +692,7 @@ // settings elements var visualizer = document.querySelector("details#visualizer"); var support = document.querySelector("details#support"); + var storage = document.querySelector("details#storage"); var btnEraseIntroTimestamps = document.querySelector("button#btnEraseIntroTimestamps"); var btnEraseCreditTimestamps = document.querySelector("button#btnEraseCreditTimestamps"); @@ -852,6 +862,21 @@ } } + // fetch the storage whenever the detail section is opened. + async function storageToggled() { + if (!storage.open) { + return; + } + + // Fetch the support bundle + const bundle = await fetchWithAuth("IntroSkipper/Storage", "GET", null); + const bundleText = await bundle.text(); + + // Display it to the user + const ta = document.querySelector("textarea#storage"); + ta.value = bundleText; + } + // show changed, populate seasons async function showChanged() { clearSelect(selectSeason); @@ -1149,6 +1174,7 @@ visualizer.addEventListener("toggle", visualizerToggled); support.addEventListener("toggle", supportToggled); + storage.addEventListener("toggle", storageToggled); txtOffset.addEventListener("change", renderTroubleshooter); selectShow.addEventListener("change", showChanged); selectSeason.addEventListener("change", seasonChanged); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs index c64ae6f..79d9c51 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/TroubleshootingController.cs @@ -1,9 +1,11 @@ using System; +using System.Globalization; +using System.IO; using System.Net.Mime; using System.Text; using MediaBrowser.Common; using MediaBrowser.Common.Api; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Library; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -19,6 +21,7 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers; [Route("IntroSkipper")] public class TroubleshootingController : ControllerBase { + private readonly ILibraryManager _libraryManager; private readonly IApplicationHost _applicationHost; private readonly ILogger _logger; @@ -26,11 +29,14 @@ public class TroubleshootingController : ControllerBase /// Initializes a new instance of the class. /// /// Application host. + /// Library Manager. /// Logger. public TroubleshootingController( IApplicationHost applicationHost, + ILibraryManager libraryManager, ILogger logger) { + _libraryManager = libraryManager; _applicationHost = applicationHost; _logger = logger; } @@ -85,4 +91,61 @@ public class TroubleshootingController : ControllerBase return bundle.ToString(); } + + /// + /// Gets a Markdown formatted support bundle. + /// + /// Support bundle created. + /// Support bundle. + [HttpGet("Storage")] + [Produces(MediaTypeNames.Text.Plain)] + public ActionResult GetFreeSpace() + { + ArgumentNullException.ThrowIfNull(Plugin.Instance); + var bundle = new StringBuilder(); + + var libraries = _libraryManager.GetVirtualFolders(); + foreach (var library in libraries) + { + try + { + DriveInfo driveInfo = new DriveInfo(library.Locations[0]); + // Get available free space in bytes + long availableFreeSpace = driveInfo.AvailableFreeSpace; + + // Get total size of the drive in bytes + long totalSize = driveInfo.TotalSize; + + // Get total used space in Percentage + double usedSpacePercentage = totalSize > 0 ? (totalSize - availableFreeSpace) / (double)totalSize * 100 : 0; + + bundle.Append(CultureInfo.CurrentCulture, $"Library: {library.Name}\n"); + bundle.Append(CultureInfo.CurrentCulture, $"Drive: {driveInfo.Name}\n"); + bundle.Append(CultureInfo.CurrentCulture, $"Total Size: {GetHumanReadableSize(totalSize)}\n"); + bundle.Append(CultureInfo.CurrentCulture, $"Available Free Space: {GetHumanReadableSize(availableFreeSpace)}\n"); + bundle.Append(CultureInfo.CurrentCulture, $"Total used in Percentage: {Math.Round(usedSpacePercentage, 2)}%\n\n"); + } + catch (Exception ex) + { + _logger.LogWarning("Unable to get DriveInfo: {Exception}", ex); + } + } + + return bundle.ToString().TrimEnd('\n'); + } + + private string GetHumanReadableSize(long bytes) + { + string[] sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + double len = bytes; + int order = 0; + + while (len >= 1024 && order < sizes.Length - 1) + { + order++; + len = len / 1024; + } + + return $"{len:0.##} {sizes[order]}"; + } }
Episode Section