diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-14 14:24:20 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-14 14:24:20 -0400 |
| commit | 0b60e7ca67394b24f4f1725b7d43405387c3e067 (patch) | |
| tree | 27de71b817df95686f9b5dae39ed2c68ac8a29fc /MediaBrowser.Controller/Entities | |
| parent | ffc4db41282be2d0762cbd198f14bbe0c9bd1540 (diff) | |
fixes #843 - Update Dlna to respect user audio/subtitle language settings
Diffstat (limited to 'MediaBrowser.Controller/Entities')
| -rw-r--r-- | MediaBrowser.Controller/Entities/IHasMediaSources.cs | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/MediaBrowser.Controller/Entities/IHasMediaSources.cs b/MediaBrowser.Controller/Entities/IHasMediaSources.cs index 0b0dd1bf83..da040f296a 100644 --- a/MediaBrowser.Controller/Entities/IHasMediaSources.cs +++ b/MediaBrowser.Controller/Entities/IHasMediaSources.cs @@ -1,5 +1,9 @@ -using MediaBrowser.Model.Dto; +using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using System; using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -12,4 +16,53 @@ namespace MediaBrowser.Controller.Entities /// <returns>Task{IEnumerable{MediaSourceInfo}}.</returns> IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution); } + + public static class HasMediaSourceExtensions + { + public static IEnumerable<MediaSourceInfo> GetMediaSources(this IHasMediaSources item, bool enablePathSubstitution, User user) + { + if (item == null) + { + throw new ArgumentNullException("item"); + } + + if (!(item is Video)) + { + return item.GetMediaSources(enablePathSubstitution); + } + + if (user == null) + { + throw new ArgumentNullException("user"); + } + + var sources = item.GetMediaSources(enablePathSubstitution).ToList(); + + var preferredAudio = string.IsNullOrEmpty(user.Configuration.AudioLanguagePreference) + ? new string[] { } + : new[] { user.Configuration.AudioLanguagePreference }; + + var preferredSubs = string.IsNullOrEmpty(user.Configuration.SubtitleLanguagePreference) + ? new string[] { } + : new[] { user.Configuration.SubtitleLanguagePreference }; + + foreach (var source in sources) + { + source.DefaultAudioStreamIndex = MediaStreamSelector.GetDefaultAudioStreamIndex( + source.MediaStreams, preferredAudio, user.Configuration.PlayDefaultAudioTrack); + + var defaultAudioIndex = source.DefaultAudioStreamIndex; + var audioLangage = defaultAudioIndex == null + ? null + : source.MediaStreams.Where(i => i.Type == MediaStreamType.Audio && i.Index == defaultAudioIndex).Select(i => i.Language).FirstOrDefault(); + + source.DefaultSubtitleStreamIndex = MediaStreamSelector.GetDefaultSubtitleStreamIndex(source.MediaStreams, + preferredSubs, + user.Configuration.SubtitleMode, + audioLangage); + } + + return sources; + } + } } |
