Просмотр исходного кода

Change subtitles DisplayTitle behavior

redSpoutnik 6 лет назад
Родитель
Сommit
427688a0a0

+ 3 - 2
Emby.Server.Implementations/ApplicationHost.cs

@@ -703,7 +703,7 @@ namespace Emby.Server.Implementations
             var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
             var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
             serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
             serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
 
 
-            ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, assemblyInfo);
+            ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, assemblyInfo, LocalizationManager);
             serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
             serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
 
 
             AuthenticationRepository = GetAuthenticationRepository();
             AuthenticationRepository = GetAuthenticationRepository();
@@ -979,7 +979,8 @@ namespace Emby.Server.Implementations
                 HttpClient,
                 HttpClient,
                 ZipClient,
                 ZipClient,
                 ProcessFactory,
                 ProcessFactory,
-                5000);
+                5000,
+                LocalizationManager);
 
 
             MediaEncoder = mediaEncoder;
             MediaEncoder = mediaEncoder;
             serviceCollection.AddSingleton(MediaEncoder);
             serviceCollection.AddSingleton(MediaEncoder);

+ 12 - 1
Emby.Server.Implementations/Data/SqliteItemRepository.cs

@@ -22,6 +22,7 @@ using MediaBrowser.Controller.Persistence;
 using MediaBrowser.Controller.Playlists;
 using MediaBrowser.Controller.Playlists;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Globalization;
 using MediaBrowser.Model.LiveTv;
 using MediaBrowser.Model.LiveTv;
 using MediaBrowser.Model.Querying;
 using MediaBrowser.Model.Querying;
 using MediaBrowser.Model.Reflection;
 using MediaBrowser.Model.Reflection;
@@ -56,6 +57,8 @@ namespace Emby.Server.Implementations.Data
         private readonly IServerConfigurationManager _config;
         private readonly IServerConfigurationManager _config;
         private IServerApplicationHost _appHost;
         private IServerApplicationHost _appHost;
 
 
+        private readonly ILocalizationManager _localization;
+
         public IImageProcessor ImageProcessor { get; set; }
         public IImageProcessor ImageProcessor { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -66,7 +69,8 @@ namespace Emby.Server.Implementations.Data
             IServerApplicationHost appHost,
             IServerApplicationHost appHost,
             IJsonSerializer jsonSerializer,
             IJsonSerializer jsonSerializer,
             ILoggerFactory loggerFactory,
             ILoggerFactory loggerFactory,
-            IAssemblyInfo assemblyInfo)
+            IAssemblyInfo assemblyInfo,
+            ILocalizationManager localization)
             : base(loggerFactory.CreateLogger(nameof(SqliteItemRepository)))
             : base(loggerFactory.CreateLogger(nameof(SqliteItemRepository)))
         {
         {
             if (config == null)
             if (config == null)
@@ -83,6 +87,7 @@ namespace Emby.Server.Implementations.Data
             _config = config;
             _config = config;
             _jsonSerializer = jsonSerializer;
             _jsonSerializer = jsonSerializer;
             _typeMapper = new TypeMapper(assemblyInfo);
             _typeMapper = new TypeMapper(assemblyInfo);
+            _localization = localization;
 
 
             DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
             DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
         }
         }
@@ -6189,6 +6194,12 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
                 item.ColorTransfer = reader[34].ToString();
                 item.ColorTransfer = reader[34].ToString();
             }
             }
 
 
+            if (item.Type == MediaStreamType.Subtitle){
+                item.localizedUndefined = _localization.GetLocalizedString("Undefined");
+                item.localizedDefault = _localization.GetLocalizedString("Default");
+                item.localizedForced = _localization.GetLocalizedString("Forced");
+            }
+
             return item;
             return item;
         }
         }
     }
     }

+ 6 - 2
MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs

@@ -19,6 +19,7 @@ using MediaBrowser.Model.Configuration;
 using MediaBrowser.Model.Diagnostics;
 using MediaBrowser.Model.Diagnostics;
 using MediaBrowser.Model.Dlna;
 using MediaBrowser.Model.Dlna;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Globalization;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.Serialization;
 using MediaBrowser.Model.Serialization;
@@ -69,6 +70,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
         private readonly string _originalFFMpegPath;
         private readonly string _originalFFMpegPath;
         private readonly string _originalFFProbePath;
         private readonly string _originalFFProbePath;
         private readonly int DefaultImageExtractionTimeoutMs;
         private readonly int DefaultImageExtractionTimeoutMs;
+        private readonly ILocalizationManager _localization;
 
 
         public MediaEncoder(
         public MediaEncoder(
             ILoggerFactory loggerFactory,
             ILoggerFactory loggerFactory,
@@ -88,7 +90,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
             IHttpClient httpClient,
             IHttpClient httpClient,
             IZipClient zipClient,
             IZipClient zipClient,
             IProcessFactory processFactory,
             IProcessFactory processFactory,
-            int defaultImageExtractionTimeoutMs)
+            int defaultImageExtractionTimeoutMs,
+            ILocalizationManager localization)
         {
         {
             _logger = loggerFactory.CreateLogger(nameof(MediaEncoder));
             _logger = loggerFactory.CreateLogger(nameof(MediaEncoder));
             _jsonSerializer = jsonSerializer;
             _jsonSerializer = jsonSerializer;
@@ -110,6 +113,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
             _originalFFProbePath = ffProbePath;
             _originalFFProbePath = ffProbePath;
             _originalFFMpegPath = ffMpegPath;
             _originalFFMpegPath = ffMpegPath;
             _hasExternalEncoder = hasExternalEncoder;
             _hasExternalEncoder = hasExternalEncoder;
+            _localization = localization;
         }
         }
 
 
         public string EncoderLocationType
         public string EncoderLocationType
@@ -537,7 +541,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
                         }
                         }
                     }
                     }
 
 
-                    return new ProbeResultNormalizer(_logger, FileSystem).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol);
+                    return new ProbeResultNormalizer(_logger, FileSystem, _localization).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol);
                 }
                 }
                 catch
                 catch
                 {
                 {

+ 7 - 1
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -9,6 +9,7 @@ using MediaBrowser.Controller.Library;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Extensions;
 using MediaBrowser.Model.Extensions;
+using MediaBrowser.Model.Globalization;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.MediaInfo;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
@@ -20,11 +21,13 @@ namespace MediaBrowser.MediaEncoding.Probing
         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
         private readonly ILogger _logger;
         private readonly ILogger _logger;
         private readonly IFileSystem _fileSystem;
         private readonly IFileSystem _fileSystem;
+        private readonly ILocalizationManager _localization;
 
 
-        public ProbeResultNormalizer(ILogger logger, IFileSystem fileSystem)
+        public ProbeResultNormalizer(ILogger logger, IFileSystem fileSystem, ILocalizationManager localization)
         {
         {
             _logger = logger;
             _logger = logger;
             _fileSystem = fileSystem;
             _fileSystem = fileSystem;
+            _localization = localization;
         }
         }
 
 
         public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
         public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
@@ -599,6 +602,9 @@ namespace MediaBrowser.MediaEncoding.Probing
             {
             {
                 stream.Type = MediaStreamType.Subtitle;
                 stream.Type = MediaStreamType.Subtitle;
                 stream.Codec = NormalizeSubtitleCodec(stream.Codec);
                 stream.Codec = NormalizeSubtitleCodec(stream.Codec);
+                stream.localizedUndefined = _localization.GetLocalizedString("Undefined");
+                stream.localizedDefault = _localization.GetLocalizedString("Default");
+                stream.localizedForced = _localization.GetLocalizedString("Forced");
             }
             }
             else if (string.Equals(streamInfo.codec_type, "video", StringComparison.OrdinalIgnoreCase))
             else if (string.Equals(streamInfo.codec_type, "video", StringComparison.OrdinalIgnoreCase))
             {
             {

+ 21 - 5
MediaBrowser.Model/Entities/MediaStream.cs

@@ -1,6 +1,8 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Globalization;
+using System.Linq;
+using System.Text;
 using MediaBrowser.Model.Dlna;
 using MediaBrowser.Model.Dlna;
 using MediaBrowser.Model.Extensions;
 using MediaBrowser.Model.Extensions;
 using MediaBrowser.Model.MediaInfo;
 using MediaBrowser.Model.MediaInfo;
@@ -65,6 +67,10 @@ namespace MediaBrowser.Model.Entities
             }
             }
         }
         }
 
 
+        public string localizedUndefined  { get; set; }
+        public string localizedDefault  { get; set; }
+        public string localizedForced  { get; set; }
+
         public string DisplayTitle
         public string DisplayTitle
         {
         {
             get
             get
@@ -141,22 +147,30 @@ namespace MediaBrowser.Model.Entities
                     }
                     }
                     else
                     else
                     {
                     {
-                        attributes.Add("Und");
+                        attributes.Add(string.IsNullOrEmpty(localizedUndefined) ? "Und" : localizedUndefined);
                     }
                     }
 
 
                     if (IsDefault)
                     if (IsDefault)
                     {
                     {
-                        attributes.Add("Default");
+                        attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
                     }
                     }
 
 
                     if (IsForced)
                     if (IsForced)
                     {
                     {
-                        attributes.Add("Forced");
+                        attributes.Add(string.IsNullOrEmpty(localizedForced) ? "Forced" : localizedForced);
                     }
                     }
 
 
-                    string name = string.Join(" ", attributes.ToArray());
+                    if (!string.IsNullOrEmpty(Title))
+                    {
+                        return attributes.AsEnumerable()
+                        // keep Tags that are not already in Title
+                        .Where(tag => Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
+                        // attributes concatenation, starting with Title
+                        .Aggregate(new StringBuilder(Title), (builder, attr) => builder.Append(" - ").Append(attr))
+                        .ToString();
+                    }
 
 
-                    return name;
+                    return string.Join(" - ", attributes.ToArray());
                 }
                 }
 
 
                 if (Type == MediaStreamType.Video)
                 if (Type == MediaStreamType.Video)
@@ -220,6 +234,7 @@ namespace MediaBrowser.Model.Entities
             return null;
             return null;
         }
         }
 
 
+        /*
         private string AddLanguageIfNeeded(string title)
         private string AddLanguageIfNeeded(string title)
         {
         {
             if (!string.IsNullOrEmpty(Language) &&
             if (!string.IsNullOrEmpty(Language) &&
@@ -241,6 +256,7 @@ namespace MediaBrowser.Model.Entities
 
 
             return false;
             return false;
         }
         }
+        */
 
 
         public string NalLengthSize { get; set; }
         public string NalLengthSize { get; set; }