From ff980dc42c4ebc31151a3dd4bc4d8dac738fd801 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 14 May 2016 14:02:06 -0400 Subject: [PATCH] add DisplayTitle to media streams --- .../Playback/BaseStreamingService.cs | 2 +- .../Encoder/BaseEncoder.cs | 2 +- .../Probing/ProbeResultNormalizer.cs | 16 ++++ MediaBrowser.Model/Entities/MediaStream.cs | 89 ++++++++++++++++++- .../Persistence/MediaStreamColumns.cs | 32 +++++++ .../Persistence/SqliteItemRepository.cs | 11 ++- 6 files changed, 147 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 792e468429..0f58a9db82 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -460,7 +460,7 @@ namespace MediaBrowser.Api.Playback // Boost volume to 200% when downsampling from 6ch to 2ch if (channels.HasValue && channels.Value <= 2) { - if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5) + if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5 && !ApiEntryPoint.Instance.GetEncodingOptions().DownMixAudioBoost.Equals(1)) { volParam = ",volume=" + ApiEntryPoint.Instance.GetEncodingOptions().DownMixAudioBoost.ToString(UsCulture); } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 0ea48fab62..d551d5c8c0 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -1008,7 +1008,7 @@ namespace MediaBrowser.MediaEncoding.Encoder // Boost volume to 200% when downsampling from 6ch to 2ch if (channels.HasValue && channels.Value <= 2) { - if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5) + if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5 && !GetEncodingOptions().DownMixAudioBoost.Equals(1)) { volParam = ",volume=" + GetEncodingOptions().DownMixAudioBoost.ToString(UsCulture); } diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index c7c001cee7..1a95bdf9d7 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -432,6 +432,7 @@ namespace MediaBrowser.MediaEncoding.Probing { stream.Language = GetDictionaryValue(streamInfo.tags, "language"); stream.Comment = GetDictionaryValue(streamInfo.tags, "comment"); + stream.Title = GetDictionaryValue(streamInfo.tags, "title"); } if (string.Equals(streamInfo.codec_type, "audio", StringComparison.OrdinalIgnoreCase)) @@ -540,9 +541,24 @@ namespace MediaBrowser.MediaEncoding.Probing stream.IsForced = string.Equals(isForced, "1", StringComparison.OrdinalIgnoreCase); } + NormalizeStreamTitle(stream); + return stream; } + private void NormalizeStreamTitle(MediaStream stream) + { + if (string.Equals(stream.Title, "sdh", StringComparison.OrdinalIgnoreCase)) + { + stream.Title = null; + } + + if (stream.Type == MediaStreamType.EmbeddedImage) + { + stream.Title = null; + } + } + /// /// Gets a string from an FFProbeResult tags dictionary /// diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 25252956b2..9b814c5ccc 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Model.Dlna; +using System; +using System.Collections.Generic; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Extensions; using System.Diagnostics; @@ -34,6 +36,91 @@ namespace MediaBrowser.Model.Entities /// The comment. public string Comment { get; set; } + public string Title { get; set; } + + public string DisplayTitle + { + get + { + if (!string.IsNullOrEmpty(Title)) + { + return Title; + } + + if (Type == MediaStreamType.Audio) + { + List attributes = new List(); + + if (!string.IsNullOrEmpty(Language)) + { + attributes.Add(Language); + } + if (!string.IsNullOrEmpty(Codec) && !StringHelper.EqualsIgnoreCase(Codec, "dca")) + { + attributes.Add(Codec); + } + if (!string.IsNullOrEmpty(Profile) && !StringHelper.EqualsIgnoreCase(Profile, "lc")) + { + attributes.Add(Profile); + } + + if (Channels.HasValue) + { + attributes.Add(StringHelper.ToStringCultureInvariant(Channels.Value) + " ch"); + } + + string name = string.Join(" ", attributes.ToArray()); + + if (IsDefault) + { + name += " (D)"; + } + + return name; + } + + if (Type == MediaStreamType.Subtitle) + { + List attributes = new List(); + + if (!string.IsNullOrEmpty(Language)) + { + attributes.Add(Language); + } + if (!string.IsNullOrEmpty(Codec)) + { + attributes.Add(Codec); + } + + string name = string.Join(" ", attributes.ToArray()); + + if (IsDefault) + { + name += " (D)"; + } + + if (IsForced) + { + name += " (F)"; + } + + if (IsExternal) + { + name += " (EXT)"; + } + + return name; + } + + if (Type == MediaStreamType.Video) + { + + } + + return null; + } + } + public string NalLengthSize { get; set; } /// diff --git a/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs b/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs index 76682c63b8..948e99cb82 100644 --- a/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs +++ b/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs @@ -27,6 +27,7 @@ namespace MediaBrowser.Server.Implementations.Persistence AddCommentColumn(); AddNalColumn(); AddIsAvcColumn(); + AddTitleColumn(); } private void AddIsAvcColumn() @@ -60,6 +61,37 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.RunQueries(new[] { builder.ToString() }, _logger); } + private void AddTitleColumn() + { + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "PRAGMA table_info(mediastreams)"; + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) + { + while (reader.Read()) + { + if (!reader.IsDBNull(1)) + { + var name = reader.GetString(1); + + if (string.Equals(name, "Title", StringComparison.OrdinalIgnoreCase)) + { + return; + } + } + } + } + } + + var builder = new StringBuilder(); + + builder.AppendLine("alter table mediastreams"); + builder.AppendLine("add column Title TEXT"); + + _connection.RunQueries(new[] { builder.ToString() }, _logger); + } + private void AddNalColumn() { using (var cmd = _connection.CreateCommand()) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 308ca90e0a..8f7119b4ab 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -120,7 +120,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false); var createMediaStreamsTableCommand - = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, PRIMARY KEY (ItemId, StreamIndex))"; + = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; string[] queries = { @@ -386,7 +386,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "CodecTag", "Comment", "NalLengthSize", - "IsAvc" + "IsAvc", + "Title" }; /// @@ -3403,6 +3404,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveStreamCommand.GetParameter(index++).Value = stream.Comment; _saveStreamCommand.GetParameter(index++).Value = stream.NalLengthSize; _saveStreamCommand.GetParameter(index++).Value = stream.IsAVC; + _saveStreamCommand.GetParameter(index++).Value = stream.Title; _saveStreamCommand.Transaction = transaction; _saveStreamCommand.ExecuteNonQuery(); @@ -3571,6 +3573,11 @@ namespace MediaBrowser.Server.Implementations.Persistence item.IsAVC = reader.GetBoolean(28); } + if (!reader.IsDBNull(29)) + { + item.Title = reader.GetString(29); + } + return item; }