diff --git a/Emby.Dlna/Eventing/DlnaEventManager.cs b/Emby.Dlna/Eventing/DlnaEventManager.cs
index c0eacf5d83..ecbbdf9df9 100644
--- a/Emby.Dlna/Eventing/DlnaEventManager.cs
+++ b/Emby.Dlna/Eventing/DlnaEventManager.cs
@@ -164,7 +164,7 @@ namespace Emby.Dlna.Eventing
try
{
- using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
+ using var response = await _httpClientFactory.CreateClient(NamedClient.DirectIp)
.SendAsync(options, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
}
catch (OperationCanceledException)
diff --git a/Emby.Server.Implementations/IO/ExtendedFileSystemInfo.cs b/Emby.Server.Implementations/IO/ExtendedFileSystemInfo.cs
deleted file mode 100644
index 545d73e05f..0000000000
--- a/Emby.Server.Implementations/IO/ExtendedFileSystemInfo.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma warning disable CS1591
-
-namespace Emby.Server.Implementations.IO
-{
- public class ExtendedFileSystemInfo
- {
- public bool IsHidden { get; set; }
-
- public bool IsReadOnly { get; set; }
-
- public bool Exists { get; set; }
- }
-}
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index 55f384ae8f..1fffdfbfa0 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -267,25 +267,6 @@ namespace Emby.Server.Implementations.IO
return result;
}
- private static ExtendedFileSystemInfo GetExtendedFileSystemInfo(string path)
- {
- var result = new ExtendedFileSystemInfo();
-
- var info = new FileInfo(path);
-
- if (info.Exists)
- {
- result.Exists = true;
-
- var attributes = info.Attributes;
-
- result.IsHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
- result.IsReadOnly = (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
- }
-
- return result;
- }
-
///
/// Takes a filename and removes invalid characters.
///
@@ -403,19 +384,18 @@ namespace Emby.Server.Implementations.IO
return;
}
- var info = GetExtendedFileSystemInfo(path);
+ var info = new FileInfo(path);
- if (info.Exists && info.IsHidden != isHidden)
+ if (info.Exists &&
+ ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) != isHidden)
{
if (isHidden)
{
- File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
+ File.SetAttributes(path, info.Attributes | FileAttributes.Hidden);
}
else
{
- var attributes = File.GetAttributes(path);
- attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
- File.SetAttributes(path, attributes);
+ File.SetAttributes(path, info.Attributes & ~FileAttributes.Hidden);
}
}
}
@@ -428,19 +408,20 @@ namespace Emby.Server.Implementations.IO
return;
}
- var info = GetExtendedFileSystemInfo(path);
+ var info = new FileInfo(path);
if (!info.Exists)
{
return;
}
- if (info.IsReadOnly == readOnly && info.IsHidden == isHidden)
+ if (((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) == readOnly
+ && ((info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) == isHidden)
{
return;
}
- var attributes = File.GetAttributes(path);
+ var attributes = info.Attributes;
if (readOnly)
{
@@ -448,7 +429,7 @@ namespace Emby.Server.Implementations.IO
}
else
{
- attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
+ attributes &= ~FileAttributes.ReadOnly;
}
if (isHidden)
@@ -457,17 +438,12 @@ namespace Emby.Server.Implementations.IO
}
else
{
- attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
+ attributes &= ~FileAttributes.Hidden;
}
File.SetAttributes(path, attributes);
}
- private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
- {
- return attributes & ~attributesToRemove;
- }
-
///
/// Swaps the files.
///
diff --git a/Emby.Server.Implementations/Localization/Core/sn.json b/Emby.Server.Implementations/Localization/Core/sn.json
new file mode 100644
index 0000000000..74720e7646
--- /dev/null
+++ b/Emby.Server.Implementations/Localization/Core/sn.json
@@ -0,0 +1,28 @@
+{
+ "HeaderAlbumArtists": "Vaimbi vemadambarefu",
+ "HeaderContinueWatching": "Simudzira kuona",
+ "HeaderFavoriteSongs": "Nziyo dzaunofarira",
+ "Albums": "Dambarefu",
+ "AppDeviceValues": "Apu: {0}, Dhivhaisi: {1}",
+ "Application": "Purogiramu",
+ "Artists": "Vaimbi",
+ "AuthenticationSucceededWithUserName": "apinda",
+ "Books": "Mabhuku",
+ "CameraImageUploadedFrom": "Mufananidzo mutsva vabva pakamera {0}",
+ "Channels": "Machanewo",
+ "ChapterNameValue": "Chikamu {0}",
+ "Collections": "Akafanana",
+ "Default": "Zvakasarudzwa Kare",
+ "DeviceOfflineWithName": "{0} haasisipo",
+ "DeviceOnlineWithName": "{0} aripo",
+ "External": "Zvekunze",
+ "FailedLoginAttemptWithUserName": "Vatadza kuloga chimboedza kushandisa {0}",
+ "Favorites": "Zvaunofarira",
+ "Folders": "Mafoodha",
+ "Forced": "Zvekumanikidzira",
+ "Genres": "Mhando",
+ "HeaderFavoriteAlbums": "Madambarefu aunofarira",
+ "HeaderFavoriteArtists": "Vaimbi vaunofarira",
+ "HeaderFavoriteEpisodes": "Maepisodhi aunofarira",
+ "HeaderFavoriteShows": "Masirisi aunofarira"
+}
diff --git a/Emby.Server.Implementations/Localization/Core/zh-HK.json b/Emby.Server.Implementations/Localization/Core/zh-HK.json
index 610f503ddb..e8b8c2c5fa 100644
--- a/Emby.Server.Implementations/Localization/Core/zh-HK.json
+++ b/Emby.Server.Implementations/Localization/Core/zh-HK.json
@@ -15,7 +15,7 @@
"Favorites": "我的最愛",
"Folders": "資料夾",
"Genres": "風格",
- "HeaderAlbumArtists": "專輯藝人",
+ "HeaderAlbumArtists": "專輯歌手",
"HeaderContinueWatching": "繼續觀看",
"HeaderFavoriteAlbums": "最愛的專輯",
"HeaderFavoriteArtists": "最愛的藝人",
diff --git a/Jellyfin.Api/Auth/FirstTimeSetupPolicy/FirstTimeSetupHandler.cs b/Jellyfin.Api/Auth/FirstTimeSetupPolicy/FirstTimeSetupHandler.cs
index 28ba258503..688a13bc0b 100644
--- a/Jellyfin.Api/Auth/FirstTimeSetupPolicy/FirstTimeSetupHandler.cs
+++ b/Jellyfin.Api/Auth/FirstTimeSetupPolicy/FirstTimeSetupHandler.cs
@@ -38,7 +38,15 @@ namespace Jellyfin.Api.Auth.FirstTimeSetupPolicy
return Task.CompletedTask;
}
- if (requirement.RequireAdmin && !context.User.IsInRole(UserRoles.Administrator))
+ var contextUser = context.User;
+ if (requirement.RequireAdmin && !contextUser.IsInRole(UserRoles.Administrator))
+ {
+ context.Fail();
+ return Task.CompletedTask;
+ }
+
+ var userId = contextUser.GetUserId();
+ if (userId.Equals(default))
{
context.Fail();
return Task.CompletedTask;
@@ -50,7 +58,7 @@ namespace Jellyfin.Api.Auth.FirstTimeSetupPolicy
return Task.CompletedTask;
}
- var user = _userManager.GetUserById(context.User.GetUserId());
+ var user = _userManager.GetUserById(userId);
if (user is null)
{
throw new ResourceNotFoundException();
diff --git a/Jellyfin.Api/Controllers/SystemController.cs b/Jellyfin.Api/Controllers/SystemController.cs
index 91901518fa..a29790961e 100644
--- a/Jellyfin.Api/Controllers/SystemController.cs
+++ b/Jellyfin.Api/Controllers/SystemController.cs
@@ -59,10 +59,12 @@ public class SystemController : BaseJellyfinApiController
/// Gets information about the server.
///
/// Information retrieved.
+ /// User does not have permission to retrieve information.
/// A with info about the system.
[HttpGet("Info")]
[Authorize(Policy = Policies.FirstTimeSetupOrIgnoreParentalControl)]
[ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult GetSystemInfo()
{
return _appHost.GetSystemInfo(Request);
@@ -97,10 +99,12 @@ public class SystemController : BaseJellyfinApiController
/// Restarts the application.
///
/// Server restarted.
+ /// User does not have permission to restart server.
/// No content. Server restarted.
[HttpPost("Restart")]
[Authorize(Policy = Policies.LocalAccessOrRequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult RestartApplication()
{
Task.Run(async () =>
@@ -115,10 +119,12 @@ public class SystemController : BaseJellyfinApiController
/// Shuts down the application.
///
/// Server shut down.
+ /// User does not have permission to shutdown server.
/// No content. Server shut down.
[HttpPost("Shutdown")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult ShutdownApplication()
{
Task.Run(async () =>
@@ -133,10 +139,12 @@ public class SystemController : BaseJellyfinApiController
/// Gets a list of available server log files.
///
/// Information retrieved.
+ /// User does not have permission to get server logs.
/// An array of with the available log files.
[HttpGet("Logs")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult GetServerLogs()
{
IEnumerable files;
@@ -170,10 +178,12 @@ public class SystemController : BaseJellyfinApiController
/// Gets information about the request endpoint.
///
/// Information retrieved.
+ /// User does not have permission to get endpoint information.
/// with information about the endpoint.
[HttpGet("Endpoint")]
[Authorize]
[ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
public ActionResult GetEndpointInfo()
{
return new EndPointInfo
@@ -188,10 +198,12 @@ public class SystemController : BaseJellyfinApiController
///
/// The name of the log file to get.
/// Log file retrieved.
+ /// User does not have permission to get log files.
/// The log file.
[HttpGet("Logs/Log")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesFile(MediaTypeNames.Text.Plain)]
public ActionResult GetLogFile([FromQuery, Required] string name)
{
diff --git a/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs b/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs
new file mode 100644
index 0000000000..59e6956c71
--- /dev/null
+++ b/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs
@@ -0,0 +1,120 @@
+/*
+The MIT License (MIT)
+
+Copyright (c) .NET Foundation and Contributors
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+using System.IO;
+using System.Net.Http;
+using System.Net.Sockets;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Jellyfin.Networking.HappyEyeballs
+{
+ ///
+ /// Defines the class.
+ ///
+ /// Implementation taken from https://github.com/ppy/osu-framework/pull/4191 .
+ ///
+ public static class HttpClientExtension
+ {
+ ///
+ /// Gets or sets a value indicating whether the client should use IPv6.
+ ///
+ public static bool UseIPv6 { get; set; } = true;
+
+ ///
+ /// Implements the httpclient callback method.
+ ///
+ /// The instance.
+ /// The instance.
+ /// The http steam.
+ public static async ValueTask OnConnect(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
+ {
+ if (!UseIPv6)
+ {
+ return await AttemptConnection(AddressFamily.InterNetwork, context, cancellationToken).ConfigureAwait(false);
+ }
+
+ using var cancelIPv6 = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
+ var tryConnectAsyncIPv6 = AttemptConnection(AddressFamily.InterNetworkV6, context, cancelIPv6.Token);
+
+ // GetAwaiter().GetResult() is used instead of .Result as this results in improved exception handling.
+ // The tasks have already been completed.
+ // See https://github.com/dotnet/corefx/pull/29792/files#r189415885 for more details.
+ if (await Task.WhenAny(tryConnectAsyncIPv6, Task.Delay(200, cancelIPv6.Token)).ConfigureAwait(false) == tryConnectAsyncIPv6 && tryConnectAsyncIPv6.IsCompletedSuccessfully)
+ {
+ cancelIPv6.Cancel();
+ return tryConnectAsyncIPv6.GetAwaiter().GetResult();
+ }
+
+ using var cancelIPv4 = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
+ var tryConnectAsyncIPv4 = AttemptConnection(AddressFamily.InterNetwork, context, cancelIPv4.Token);
+
+ if (await Task.WhenAny(tryConnectAsyncIPv6, tryConnectAsyncIPv4).ConfigureAwait(false) == tryConnectAsyncIPv6)
+ {
+ if (tryConnectAsyncIPv6.IsCompletedSuccessfully)
+ {
+ cancelIPv4.Cancel();
+ return tryConnectAsyncIPv6.GetAwaiter().GetResult();
+ }
+
+ return tryConnectAsyncIPv4.GetAwaiter().GetResult();
+ }
+ else
+ {
+ if (tryConnectAsyncIPv4.IsCompletedSuccessfully)
+ {
+ cancelIPv6.Cancel();
+ return tryConnectAsyncIPv4.GetAwaiter().GetResult();
+ }
+
+ return tryConnectAsyncIPv6.GetAwaiter().GetResult();
+ }
+ }
+
+ private static async Task AttemptConnection(AddressFamily addressFamily, SocketsHttpConnectionContext context, CancellationToken cancellationToken)
+ {
+ // The following socket constructor will create a dual-mode socket on systems where IPV6 is available.
+ var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp)
+ {
+ // Turn off Nagle's algorithm since it degrades performance in most HttpClient scenarios.
+ NoDelay = true
+ };
+
+ try
+ {
+ await socket.ConnectAsync(context.DnsEndPoint, cancellationToken).ConfigureAwait(false);
+ // The stream should take the ownership of the underlying socket,
+ // closing it when it's disposed.
+ return new NetworkStream(socket, ownsSocket: true);
+ }
+ catch
+ {
+ socket.Dispose();
+ throw;
+ }
+ }
+ }
+}
diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.cs
index f0f95f5fc8..1b1e91e9fe 100644
--- a/Jellyfin.Networking/Manager/NetworkManager.cs
+++ b/Jellyfin.Networking/Manager/NetworkManager.cs
@@ -184,9 +184,16 @@ namespace Jellyfin.Networking.Manager
{
Thread.Sleep(2000);
var networkConfig = _configurationManager.GetNetworkConfiguration();
- InitialiseLan(networkConfig);
- InitialiseInterfaces();
- EnforceBindSettings(networkConfig);
+ if (IsIPv6Enabled && !Socket.OSSupportsIPv6)
+ {
+ UpdateSettings(networkConfig);
+ }
+ else
+ {
+ InitialiseInterfaces();
+ InitialiseLan(networkConfig);
+ EnforceBindSettings(networkConfig);
+ }
NetworkChanged?.Invoke(this, EventArgs.Empty);
}
@@ -519,6 +526,7 @@ namespace Jellyfin.Networking.Manager
ArgumentNullException.ThrowIfNull(configuration);
var config = (NetworkConfiguration)configuration;
+ HappyEyeballs.HttpClientExtension.UseIPv6 = config.EnableIPv6;
InitialiseLan(config);
InitialiseRemote(config);
diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs
index 866262d22f..abfdcd77d5 100644
--- a/Jellyfin.Server/Migrations/MigrationRunner.cs
+++ b/Jellyfin.Server/Migrations/MigrationRunner.cs
@@ -22,8 +22,7 @@ namespace Jellyfin.Server.Migrations
private static readonly Type[] _preStartupMigrationTypes =
{
typeof(PreStartupRoutines.CreateNetworkConfiguration),
- typeof(PreStartupRoutines.MigrateMusicBrainzTimeout),
- typeof(PreStartupRoutines.MigrateRatingLevels)
+ typeof(PreStartupRoutines.MigrateMusicBrainzTimeout)
};
///
@@ -41,7 +40,8 @@ namespace Jellyfin.Server.Migrations
typeof(Routines.MigrateDisplayPreferencesDb),
typeof(Routines.RemoveDownloadImagesInAdvance),
typeof(Routines.MigrateAuthenticationDb),
- typeof(Routines.FixPlaylistOwner)
+ typeof(Routines.FixPlaylistOwner),
+ typeof(Routines.MigrateRatingLevels)
};
///
diff --git a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateRatingLevels.cs b/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateRatingLevels.cs
deleted file mode 100644
index 465bbd7fe1..0000000000
--- a/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateRatingLevels.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-
-using Emby.Server.Implementations;
-using MediaBrowser.Controller;
-using Microsoft.Extensions.Logging;
-using SQLitePCL.pretty;
-
-namespace Jellyfin.Server.Migrations.PreStartupRoutines
-{
- ///
- /// Migrate rating levels to new rating level system.
- ///
- internal class MigrateRatingLevels : IMigrationRoutine
- {
- private const string DbFilename = "library.db";
- private readonly ILogger _logger;
- private readonly IServerApplicationPaths _applicationPaths;
-
- public MigrateRatingLevels(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
- {
- _applicationPaths = applicationPaths;
- _logger = loggerFactory.CreateLogger();
- }
-
- ///
- public Guid Id => Guid.Parse("{67445D54-B895-4B24-9F4C-35CE0690EA07}");
-
- ///
- public string Name => "MigrateRatingLevels";
-
- ///
- public bool PerformOnNewInstall => false;
-
- ///
- public void Perform()
- {
- var dataPath = _applicationPaths.DataPath;
- var dbPath = Path.Combine(dataPath, DbFilename);
- using (var connection = SQLite3.Open(
- dbPath,
- ConnectionFlags.ReadWrite,
- null))
- {
- // Back up the database before deleting any entries
- for (int i = 1; ; i++)
- {
- var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
- if (!File.Exists(bakPath))
- {
- try
- {
- File.Copy(dbPath, bakPath);
- _logger.LogInformation("Library database backed up to {BackupPath}", bakPath);
- break;
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Cannot make a backup of {Library} at path {BackupPath}", DbFilename, bakPath);
- throw;
- }
- }
- }
-
- // Migrate parental rating levels to new schema
- _logger.LogInformation("Migrating parental rating levels.");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = NULL WHERE OfficialRating = 'NR'");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = NULL WHERE InheritedParentalRatingValue = ''");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = NULL WHERE InheritedParentalRatingValue = 0");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 1000 WHERE InheritedParentalRatingValue = 100");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 1000 WHERE InheritedParentalRatingValue = 15");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 18 WHERE InheritedParentalRatingValue = 10");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 18 WHERE InheritedParentalRatingValue = 9");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 16 WHERE InheritedParentalRatingValue = 8");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 12 WHERE InheritedParentalRatingValue = 7");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 12 WHERE InheritedParentalRatingValue = 6");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 12 WHERE InheritedParentalRatingValue = 5");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 7 WHERE InheritedParentalRatingValue = 4");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 6 WHERE InheritedParentalRatingValue = 3");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 6 WHERE InheritedParentalRatingValue = 2");
- connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = 0 WHERE InheritedParentalRatingValue = 1");
- }
- }
- }
-}
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs b/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs
new file mode 100644
index 0000000000..9dee520a50
--- /dev/null
+++ b/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Globalization;
+using System.IO;
+
+using Emby.Server.Implementations.Data;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Model.Globalization;
+using Microsoft.Extensions.Logging;
+using SQLitePCL.pretty;
+
+namespace Jellyfin.Server.Migrations.Routines
+{
+ ///
+ /// Migrate rating levels to new rating level system.
+ ///
+ internal class MigrateRatingLevels : IMigrationRoutine
+ {
+ private const string DbFilename = "library.db";
+ private readonly ILogger _logger;
+ private readonly IServerApplicationPaths _applicationPaths;
+ private readonly ILocalizationManager _localizationManager;
+ private readonly IItemRepository _repository;
+
+ public MigrateRatingLevels(
+ IServerApplicationPaths applicationPaths,
+ ILoggerFactory loggerFactory,
+ ILocalizationManager localizationManager,
+ IItemRepository repository)
+ {
+ _applicationPaths = applicationPaths;
+ _localizationManager = localizationManager;
+ _repository = repository;
+ _logger = loggerFactory.CreateLogger();
+ }
+
+ ///
+ public Guid Id => Guid.Parse("{67445D54-B895-4B24-9F4C-35CE0690EA07}");
+
+ ///
+ public string Name => "MigrateRatingLevels";
+
+ ///
+ public bool PerformOnNewInstall => false;
+
+ ///
+ public void Perform()
+ {
+ var dbPath = Path.Combine(_applicationPaths.DataPath, DbFilename);
+
+ // Back up the database before modifying any entries
+ for (int i = 1; ; i++)
+ {
+ var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
+ if (!File.Exists(bakPath))
+ {
+ try
+ {
+ File.Copy(dbPath, bakPath);
+ _logger.LogInformation("Library database backed up to {BackupPath}", bakPath);
+ break;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Cannot make a backup of {Library} at path {BackupPath}", DbFilename, bakPath);
+ throw;
+ }
+ }
+ }
+
+ // Migrate parental rating strings to new levels
+ _logger.LogInformation("Recalculating parental rating levels based on rating string.");
+ using (var connection = SQLite3.Open(
+ dbPath,
+ ConnectionFlags.ReadWrite,
+ null))
+ {
+ var queryResult = connection.Query("SELECT DISTINCT OfficialRating FROM TypedBaseItems");
+ foreach (var entry in queryResult)
+ {
+ var ratingString = entry[0].ToString();
+ if (string.IsNullOrEmpty(ratingString))
+ {
+ connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = NULL WHERE OfficialRating IS NULL OR OfficialRating='';");
+ }
+ else
+ {
+ var ratingValue = _localizationManager.GetRatingLevel(ratingString).ToString();
+ if (string.IsNullOrEmpty(ratingValue))
+ {
+ ratingValue = "NULL";
+ }
+
+ var statement = connection.PrepareStatement("UPDATE TypedBaseItems SET InheritedParentalRatingValue = @Value WHERE OfficialRating = @Rating;");
+ statement.TryBind("@Value", ratingValue);
+ statement.TryBind("@Rating", ratingString);
+ statement.ExecuteQuery();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs
index 6120b3022a..5b9397e30d 100644
--- a/Jellyfin.Server/Startup.cs
+++ b/Jellyfin.Server/Startup.cs
@@ -8,6 +8,7 @@ using System.Text;
using Jellyfin.Api.Middleware;
using Jellyfin.MediaEncoding.Hls.Extensions;
using Jellyfin.Networking.Configuration;
+using Jellyfin.Networking.HappyEyeballs;
using Jellyfin.Server.Extensions;
using Jellyfin.Server.HealthChecks;
using Jellyfin.Server.Implementations;
@@ -26,6 +27,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
+using Microsoft.VisualBasic;
using Prometheus;
namespace Jellyfin.Server
@@ -78,6 +80,13 @@ namespace Jellyfin.Server
var acceptJsonHeader = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json, 1.0);
var acceptXmlHeader = new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Xml, 0.9);
var acceptAnyHeader = new MediaTypeWithQualityHeaderValue("*/*", 0.8);
+ Func eyeballsHttpClientHandlerDelegate = (_) => new SocketsHttpHandler()
+ {
+ AutomaticDecompression = DecompressionMethods.All,
+ RequestHeaderEncodingSelector = (_, _) => Encoding.UTF8,
+ ConnectCallback = HttpClientExtension.OnConnect
+ };
+
Func defaultHttpClientHandlerDelegate = (_) => new SocketsHttpHandler()
{
AutomaticDecompression = DecompressionMethods.All,
@@ -91,7 +100,7 @@ namespace Jellyfin.Server
c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
})
- .ConfigurePrimaryHttpMessageHandler(defaultHttpClientHandlerDelegate);
+ .ConfigurePrimaryHttpMessageHandler(eyeballsHttpClientHandlerDelegate);
services.AddHttpClient(NamedClient.MusicBrainz, c =>
{
@@ -100,6 +109,15 @@ namespace Jellyfin.Server
c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
})
+ .ConfigurePrimaryHttpMessageHandler(eyeballsHttpClientHandlerDelegate);
+
+ services.AddHttpClient(NamedClient.DirectIp, c =>
+ {
+ c.DefaultRequestHeaders.UserAgent.Add(productHeader);
+ c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
+ c.DefaultRequestHeaders.Accept.Add(acceptXmlHeader);
+ c.DefaultRequestHeaders.Accept.Add(acceptAnyHeader);
+ })
.ConfigurePrimaryHttpMessageHandler(defaultHttpClientHandlerDelegate);
services.AddHttpClient(NamedClient.Dlna, c =>
diff --git a/MediaBrowser.Common/Net/NamedClient.cs b/MediaBrowser.Common/Net/NamedClient.cs
index a6cacd4f17..9c5544b0ff 100644
--- a/MediaBrowser.Common/Net/NamedClient.cs
+++ b/MediaBrowser.Common/Net/NamedClient.cs
@@ -1,4 +1,4 @@
-namespace MediaBrowser.Common.Net
+namespace MediaBrowser.Common.Net
{
///
/// Registered http client names.
@@ -6,7 +6,7 @@
public static class NamedClient
{
///
- /// Gets the value for the default named http client.
+ /// Gets the value for the default named http client which implements happy eyeballs.
///
public const string Default = nameof(Default);
@@ -19,5 +19,10 @@
/// Gets the value for the DLNA named http client.
///
public const string Dlna = nameof(Dlna);
+
+ ///
+ /// Non happy eyeballs implementation.
+ ///
+ public const string DirectIp = nameof(DirectIp);
}
}
diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs
index ba2d2db2f7..dab36625e5 100644
--- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs
+++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs
@@ -32,6 +32,7 @@ namespace MediaBrowser.Providers.Manager
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
+ private static readonly ImageType[] AllImageTypes = Enum.GetValues();
///
/// Image types that are only one per item.
@@ -90,11 +91,12 @@ namespace MediaBrowser.Providers.Manager
///
/// The to validate images for.
/// The providers to use, must include (s) for local scanning.
- /// The directory service for s to use.
+ /// The refresh options.
/// true if changes were made to the item; otherwise false.
- public bool ValidateImages(BaseItem item, IEnumerable providers, IDirectoryService directoryService)
+ public bool ValidateImages(BaseItem item, IEnumerable providers, ImageRefreshOptions refreshOptions)
{
var hasChanges = false;
+ IDirectoryService directoryService = refreshOptions?.DirectoryService;
if (item is not Photo)
{
@@ -102,7 +104,7 @@ namespace MediaBrowser.Providers.Manager
.SelectMany(i => i.GetImages(item, directoryService))
.ToList();
- if (MergeImages(item, images))
+ if (MergeImages(item, images, refreshOptions))
{
hasChanges = true;
}
@@ -381,15 +383,36 @@ namespace MediaBrowser.Providers.Manager
item.RemoveImages(images);
}
+ ///
+ /// Merges a list of images into the provided item, validating existing images and replacing them or adding new images as necessary.
+ ///
+ /// The refresh options.
+ /// List of imageTypes to remove from ReplaceImages.
+ public void UpdateReplaceImages(ImageRefreshOptions refreshOptions, ICollection dontReplaceImages)
+ {
+ if (refreshOptions is not null)
+ {
+ if (refreshOptions.ReplaceAllImages)
+ {
+ refreshOptions.ReplaceAllImages = false;
+ refreshOptions.ReplaceImages = AllImageTypes.ToList();
+ }
+
+ refreshOptions.ReplaceImages = refreshOptions.ReplaceImages.Except(dontReplaceImages).ToList();
+ }
+ }
+
///
/// Merges a list of images into the provided item, validating existing images and replacing them or adding new images as necessary.
///
/// The to modify.
/// The new images to place in item.
+ /// The refresh options.
/// true if changes were made to the item; otherwise false.
- public bool MergeImages(BaseItem item, IReadOnlyList images)
+ public bool MergeImages(BaseItem item, IReadOnlyList images, ImageRefreshOptions refreshOptions)
{
var changed = item.ValidateImages();
+ var foundImageTypes = new List();
for (var i = 0; i < _singularImages.Length; i++)
{
@@ -399,6 +422,11 @@ namespace MediaBrowser.Providers.Manager
if (image is not null)
{
var currentImage = item.GetImageInfo(type, 0);
+ // if image file is stored with media, don't replace that later
+ if (item.ContainingFolderPath is not null && item.ContainingFolderPath.Contains(Path.GetDirectoryName(image.FileInfo.FullName), StringComparison.OrdinalIgnoreCase))
+ {
+ foundImageTypes.Add(type);
+ }
if (currentImage is null || !string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase))
{
@@ -425,6 +453,12 @@ namespace MediaBrowser.Providers.Manager
if (UpdateMultiImages(item, images, ImageType.Backdrop))
{
changed = true;
+ foundImageTypes.Add(ImageType.Backdrop);
+ }
+
+ if (foundImageTypes.Count > 0)
+ {
+ UpdateReplaceImages(refreshOptions, foundImageTypes);
}
return changed;
diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs
index bcc9b809c2..80f77f7c3a 100644
--- a/MediaBrowser.Providers/Manager/MetadataService.cs
+++ b/MediaBrowser.Providers/Manager/MetadataService.cs
@@ -26,8 +26,6 @@ namespace MediaBrowser.Providers.Manager
where TItemType : BaseItem, IHasLookupInfo, new()
where TIdType : ItemLookupInfo, new()
{
- private static readonly ImageType[] AllImageTypes = Enum.GetValues();
-
protected MetadataService(IServerConfigurationManager serverConfigurationManager, ILogger> logger, IProviderManager providerManager, IFileSystem fileSystem, ILibraryManager libraryManager)
{
ServerConfigurationManager = serverConfigurationManager;
@@ -110,7 +108,7 @@ namespace MediaBrowser.Providers.Manager
try
{
// Always validate images and check for new locally stored ones.
- if (ImageProvider.ValidateImages(item, allImageProviders.OfType(), refreshOptions.DirectoryService))
+ if (ImageProvider.ValidateImages(item, allImageProviders.OfType(), refreshOptions))
{
updateType |= ItemUpdateType.ImageUpdate;
}
@@ -674,8 +672,7 @@ namespace MediaBrowser.Providers.Manager
}
var hasLocalMetadata = false;
- var replaceImages = AllImageTypes.ToList();
- var localImagesFound = false;
+ var foundImageTypes = new List();
foreach (var provider in providers.OfType>())
{
@@ -703,9 +700,8 @@ namespace MediaBrowser.Providers.Manager
await ProviderManager.SaveImage(item, remoteImage.Url, remoteImage.Type, null, cancellationToken).ConfigureAwait(false);
refreshResult.UpdateType |= ItemUpdateType.ImageUpdate;
- // remove imagetype that has just been downloaded
- replaceImages.Remove(remoteImage.Type);
- localImagesFound = true;
+ // remember imagetype that has just been downloaded
+ foundImageTypes.Add(remoteImage.Type);
}
catch (HttpRequestException ex)
{
@@ -713,13 +709,12 @@ namespace MediaBrowser.Providers.Manager
}
}
- if (localImagesFound)
+ if (foundImageTypes.Count > 0)
{
- options.ReplaceAllImages = false;
- options.ReplaceImages = replaceImages;
+ imageService.UpdateReplaceImages(options, foundImageTypes);
}
- if (imageService.MergeImages(item, localItem.Images))
+ if (imageService.MergeImages(item, localItem.Images, options))
{
refreshResult.UpdateType |= ItemUpdateType.ImageUpdate;
}
diff --git a/deployment/Dockerfile.fedora.amd64 b/deployment/Dockerfile.fedora.amd64
index 275b379b3d..8d708f9028 100644
--- a/deployment/Dockerfile.fedora.amd64
+++ b/deployment/Dockerfile.fedora.amd64
@@ -1,4 +1,4 @@
-FROM fedora:36
+FROM fedora:39
# Docker build arguments
ARG SOURCE_DIR=/jellyfin
ARG ARTIFACT_DIR=/dist
diff --git a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs
index 08b343cd89..925e8fa199 100644
--- a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs
+++ b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs
@@ -94,7 +94,7 @@ namespace Jellyfin.Providers.Tests.Manager
public void MergeImages_EmptyItemNewImagesEmpty_NoChange()
{
var itemImageProvider = GetItemImageProvider(null, null);
- var changed = itemImageProvider.MergeImages(new Video(), Array.Empty());
+ var changed = itemImageProvider.MergeImages(new Video(), Array.Empty(), new ImageRefreshOptions(Mock.Of()));
Assert.False(changed);
}
@@ -108,7 +108,7 @@ namespace Jellyfin.Providers.Tests.Manager
var images = GetImages(imageType, imageCount, false);
var itemImageProvider = GetItemImageProvider(null, null);
- var changed = itemImageProvider.MergeImages(item, images);
+ var changed = itemImageProvider.MergeImages(item, images, new ImageRefreshOptions(Mock.Of()));
Assert.True(changed);
// adds for types that allow multiple, replaces singular type images
@@ -151,7 +151,7 @@ namespace Jellyfin.Providers.Tests.Manager
var images = GetImages(imageType, imageCount, true);
var itemImageProvider = GetItemImageProvider(null, fileSystem);
- var changed = itemImageProvider.MergeImages(item, images);
+ var changed = itemImageProvider.MergeImages(item, images, new ImageRefreshOptions(Mock.Of()));
if (updateTime)
{