DownloadTheTvdbPlugin.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Linq;
  3. using MediaBrowser.Common.Updates;
  4. using Microsoft.Extensions.Logging;
  5. namespace Jellyfin.Server.Migrations.Routines
  6. {
  7. /// <summary>
  8. /// Download TheTvdb plugin after update.
  9. /// </summary>
  10. public class DownloadTheTvdbPlugin : IMigrationRoutine
  11. {
  12. private readonly Guid _tvdbPluginId = new Guid("a677c0da-fac5-4cde-941a-7134223f14c8");
  13. private readonly IInstallationManager _installationManager;
  14. private readonly ILogger<DownloadTheTvdbPlugin> _logger;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="DownloadTheTvdbPlugin"/> class.
  17. /// </summary>
  18. /// <param name="installationManager">Instance of the <see cref="IInstallationManager"/> interface.</param>
  19. /// <param name="logger">Instance of the <see cref="ILogger{DownloadTvdbPlugin}"/> interface.</param>
  20. public DownloadTheTvdbPlugin(IInstallationManager installationManager, ILogger<DownloadTheTvdbPlugin> logger)
  21. {
  22. _installationManager = installationManager;
  23. _logger = logger;
  24. }
  25. /// <inheritdoc />
  26. public Guid Id => new Guid("42E45BB4-5D78-4EE2-8C45-9095216D4769");
  27. /// <inheritdoc />
  28. public string Name => "DownloadTheTvdbPlugin";
  29. /// <inheritdoc />
  30. public bool PerformOnNewInstall => false;
  31. /// <inheritdoc />
  32. public void Perform()
  33. {
  34. try
  35. {
  36. var packages = _installationManager.GetAvailablePackages().GetAwaiter().GetResult();
  37. var package = _installationManager.GetCompatibleVersions(
  38. packages,
  39. guid: _tvdbPluginId)
  40. .FirstOrDefault();
  41. if (package == null)
  42. {
  43. _logger.LogWarning("TheTVDB Plugin not found, skipping migration.");
  44. return;
  45. }
  46. _installationManager.InstallPackage(package).GetAwaiter().GetResult();
  47. _logger.LogInformation("TheTVDB Plugin installed, please restart Jellyfin.");
  48. }
  49. catch (Exception e)
  50. {
  51. _logger.LogWarning(e, "Unable to install TheTVDB Plugin.");
  52. }
  53. }
  54. }
  55. }