add new subtitle preferences

This commit is contained in:
Luke Pulverenti 2014-05-12 18:30:32 -04:00
parent bf0e9d36a9
commit d4d10f6e43
16 changed files with 30 additions and 354 deletions

View File

@ -16,13 +16,6 @@ namespace MediaBrowser.Api
[Route("/Sessions", "GET", Summary = "Gets a list of sessions")]
public class GetSessions : IReturn<List<SessionInfoDto>>
{
/// <summary>
/// Gets or sets a value indicating whether [supports remote control].
/// </summary>
/// <value><c>null</c> if [supports remote control] contains no value, <c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
[ApiMember(Name = "SupportsRemoteControl", Description = "Optional. Filter by sessions that can be remote controlled.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? SupportsRemoteControl { get; set; }
[ApiMember(Name = "ControllableByUserId", Description = "Optional. Filter by sessions that a given user is allowed to remote control.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid? ControllableByUserId { get; set; }
@ -258,11 +251,6 @@ namespace MediaBrowser.Api
{
var result = _sessionManager.Sessions.Where(i => i.IsActive);
if (request.SupportsRemoteControl.HasValue)
{
result = result.Where(i => i.SupportsRemoteControl == request.SupportsRemoteControl.Value);
}
if (!string.IsNullOrEmpty(request.DeviceId))
{
result = result.Where(i => string.Equals(i.DeviceId, request.DeviceId, StringComparison.OrdinalIgnoreCase));

View File

@ -7,12 +7,6 @@ namespace MediaBrowser.Controller.Session
{
public interface ISessionController
{
/// <summary>
/// Gets a value indicating whether [supports media remote control].
/// </summary>
/// <value><c>true</c> if [supports media remote control]; otherwise, <c>false</c>.</value>
bool SupportsMediaRemoteControl { get; }
/// <summary>
/// Gets a value indicating whether this instance is session active.
/// </summary>

View File

@ -139,23 +139,6 @@ namespace MediaBrowser.Controller.Session
}
}
/// <summary>
/// Gets a value indicating whether [supports remote control].
/// </summary>
/// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
public bool SupportsRemoteControl
{
get
{
if (SessionController != null)
{
return SessionController.SupportsMediaRemoteControl;
}
return false;
}
}
public bool ContainsUser(Guid userId)
{
return (UserId ?? Guid.Empty) == UserId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));

View File

@ -38,11 +38,6 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly SsdpHandler _ssdpHandler;
private readonly string _serverAddress;
public bool SupportsMediaRemoteControl
{
get { return true; }
}
public bool IsSessionActive
{
get

View File

@ -560,9 +560,6 @@
<Compile Include="..\MediaBrowser.Model\MediaInfo\IBlurayExaminer.cs">
<Link>MediaInfo\IBlurayExaminer.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\MediaInfo\MediaStreamSelector.cs">
<Link>MediaInfo\MediaStreamSelector.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\MediaInfo\SubtitleFormat.cs">
<Link>MediaInfo\SubtitleFormat.cs</Link>
</Compile>
@ -839,9 +836,6 @@
<Compile Include="..\MediaBrowser.Model\Weather\WeatherUnits.cs">
<Link>Weather\WeatherUnits.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Web\QueryStringDictionary.cs">
<Link>Web\QueryStringDictionary.cs</Link>
</Compile>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>

View File

@ -541,9 +541,6 @@
<Compile Include="..\MediaBrowser.Model\MediaInfo\IBlurayExaminer.cs">
<Link>MediaInfo\IBlurayExaminer.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\MediaInfo\MediaStreamSelector.cs">
<Link>MediaInfo\MediaStreamSelector.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\MediaInfo\SubtitleFormat.cs">
<Link>MediaInfo\SubtitleFormat.cs</Link>
</Compile>
@ -820,9 +817,6 @@
<Compile Include="..\MediaBrowser.Model\Weather\WeatherUnits.cs">
<Link>Weather\WeatherUnits.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Web\QueryStringDictionary.cs">
<Link>Web\QueryStringDictionary.cs</Link>
</Compile>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>

View File

@ -172,7 +172,6 @@
<Compile Include="Logging\NullLogger.cs" />
<Compile Include="MediaInfo\AudioCodec.cs" />
<Compile Include="MediaInfo\Container.cs" />
<Compile Include="MediaInfo\MediaStreamSelector.cs" />
<Compile Include="MediaInfo\SubtitleFormat.cs" />
<Compile Include="MediaInfo\TransportStreamTimestamp.cs" />
<Compile Include="MediaInfo\VideoCodec.cs" />
@ -314,7 +313,6 @@
<Compile Include="Updates\PackageVersionInfo.cs" />
<Compile Include="Users\AuthenticationResult.cs" />
<Compile Include="Weather\WeatherUnits.cs" />
<Compile Include="Web\QueryStringDictionary.cs" />
<None Include="Fody.targets" />
<None Include="FodyWeavers.xml" />
<None Include="packages.config" />

View File

@ -10,10 +10,5 @@ namespace MediaBrowser.Model.Querying
/// Filter by sessions that are allowed to be controlled by a given user
/// </summary>
public string ControllableByUserId { get; set; }
/// <summary>
/// Filter by sessions that either do or do not support remote control. Default returns all sessions.
/// </summary>
public bool? SupportsRemoteControl { get; set; }
}
}

View File

@ -1,257 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace MediaBrowser.Model.Web
{
/// <summary>
/// Class QueryStringDictionary
/// </summary>
public class QueryStringDictionary : Dictionary<string, string>
{
/// <summary>
/// Initializes a new instance of the <see cref="QueryStringDictionary" /> class.
/// </summary>
public QueryStringDictionary()
: base(StringComparer.OrdinalIgnoreCase)
{
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void Add(string name, int value)
{
Add(name, value.ToString(CultureInfo.InvariantCulture));
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void Add(string name, long value)
{
Add(name, value.ToString(CultureInfo.InvariantCulture));
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void Add(string name, double value)
{
Add(name, value.ToString(CultureInfo.InvariantCulture));
}
/// <summary>
/// Adds if not null or empty.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNullOrEmpty(string name, string value)
{
if (!string.IsNullOrEmpty(value))
{
Add(name, value);
}
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNull(string name, int? value)
{
if (value.HasValue)
{
Add(name, value.Value);
}
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNull(string name, double? value)
{
if (value.HasValue)
{
Add(name, value.Value);
}
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNull(string name, long? value)
{
if (value.HasValue)
{
Add(name, value.Value);
}
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public void Add(string name, bool value)
{
Add(name, value.ToString());
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public void AddIfNotNull(string name, bool? value)
{
if (value.HasValue)
{
Add(name, value.Value);
}
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <exception cref="System.ArgumentNullException">value</exception>
public void Add(string name, IEnumerable<int> value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Add(name, string.Join(",", value.Select(v => v.ToString(CultureInfo.InvariantCulture)).ToArray()));
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNull(string name, IEnumerable<int> value)
{
if (value != null)
{
Add(name, value);
}
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <exception cref="System.ArgumentNullException">value</exception>
public void Add(string name, IEnumerable<string> value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
string paramValue = string.Join(",", value.ToArray());
Add(name, paramValue);
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddIfNotNull(string name, IEnumerable<string> value)
{
if (value != null)
{
Add(name, value);
}
}
/// <summary>
/// Adds the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <param name="delimiter">The delimiter.</param>
/// <exception cref="ArgumentNullException">value</exception>
public void Add(string name, IEnumerable<string> value, string delimiter)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
string paramValue = string.Join(delimiter, value.ToArray());
Add(name, paramValue);
}
/// <summary>
/// Adds if not null.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <param name="delimiter">The delimiter.</param>
public void AddIfNotNull(string name, IEnumerable<string> value, string delimiter)
{
if (value != null)
{
Add(name, value, delimiter);
}
}
/// <summary>
/// Gets the query string.
/// </summary>
/// <returns>System.String.</returns>
public string GetQueryString()
{
string[] queryParams = this.Select(i => string.Format("{0}={1}", i.Key, GetEncodedValue(i.Value))).ToArray();
return string.Join("&", queryParams);
}
/// <summary>
/// Gets the encoded value.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>System.String.</returns>
private string GetEncodedValue(string value)
{
return value;
}
/// <summary>
/// Gets the URL.
/// </summary>
/// <param name="prefix">The prefix.</param>
/// <returns>System.String.</returns>
public string GetUrl(string prefix)
{
string query = GetQueryString();
if (string.IsNullOrEmpty(query))
{
return prefix;
}
return prefix + "?" + query;
}
}
}

View File

@ -113,10 +113,26 @@ namespace MediaBrowser.Server.Implementations.Dto
if (user != null && dto.MediaSources != null && item is Video)
{
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 dto.MediaSources)
{
//source.DefaultAudioStreamIndex = GetDefaultAudioStreamIndex(source, user.Configuration);
//source.DefaultSubtitleStreamIndex = GetDefaultSubtitleStreamIndex(source, user.Configuration);
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);
}
}

View File

@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Model.MediaInfo
namespace MediaBrowser.Server.Implementations.Dto
{
public static class MediaStreamSelector
{

View File

@ -64,6 +64,13 @@
"LabelAudioLanguagePreference": "Audio language preference:",
"LabelSubtitleLanguagePreference": "Subtitle language preference:",
"OptionDefaultSubtitles": "Default",
"OptionOnlyForcedSubtitles": "Only forced subtitles",
"OptionAlwaysPlaySubtitles": "Always play subtitles",
"OptionNoSubtitles": "None",
"OptionDefaultSubtitlesHelp": "Subtitles matching the language preference will be loaded when the audio is in a foreign language.",
"OptionOnlyForcedSubtitlesHelp": "Only subtitles marked as forced will be loaded.",
"OptionAlwaysPlaySubtitlesHelp": "Subtitles matching the language preference will be loaded regardless of the audio language.",
"OptionNoSubtitlesHelp": "Subtitles will not be loaded by default.",
"TabProfiles": "Profiles",
"TabSecurity": "Security",
"ButtonAddUser": "Add User",

View File

@ -111,6 +111,7 @@
<Compile Include="Drawing\PlayedIndicatorDrawer.cs" />
<Compile Include="Drawing\UnplayedCountIndicator.cs" />
<Compile Include="Dto\DtoService.cs" />
<Compile Include="Dto\MediaStreamSelector.cs" />
<Compile Include="EntryPoints\AutomaticRestartEntryPoint.cs" />
<Compile Include="EntryPoints\ExternalPortForwarding.cs" />
<Compile Include="EntryPoints\LibraryChangedNotifier.cs" />

View File

@ -37,11 +37,6 @@ namespace MediaBrowser.Server.Implementations.Session
_postUrl = postUrl;
}
public bool SupportsMediaRemoteControl
{
get { return false; }
}
public bool IsSessionActive
{
get

View File

@ -704,24 +704,6 @@ namespace MediaBrowser.Server.Implementations.Session
return session;
}
/// <summary>
/// Gets the session for remote control.
/// </summary>
/// <param name="sessionId">The session id.</param>
/// <returns>SessionInfo.</returns>
/// <exception cref="ResourceNotFoundException"></exception>
private SessionInfo GetSessionForRemoteControl(string sessionId)
{
var session = GetSession(sessionId);
if (!session.SupportsRemoteControl)
{
throw new ArgumentException(string.Format("Session {0} does not support remote control.", session.Id));
}
return session;
}
public Task SendMessageCommand(string controllingSessionId, string sessionId, MessageCommand command, CancellationToken cancellationToken)
{
var generalCommand = new GeneralCommand
@ -742,7 +724,7 @@ namespace MediaBrowser.Server.Implementations.Session
public Task SendGeneralCommand(string controllingSessionId, string sessionId, GeneralCommand command, CancellationToken cancellationToken)
{
var session = GetSessionForRemoteControl(sessionId);
var session = GetSession(sessionId);
var controllingSession = GetSession(controllingSessionId);
AssertCanControl(session, controllingSession);
@ -752,7 +734,7 @@ namespace MediaBrowser.Server.Implementations.Session
public Task SendPlayCommand(string controllingSessionId, string sessionId, PlayRequest command, CancellationToken cancellationToken)
{
var session = GetSessionForRemoteControl(sessionId);
var session = GetSession(sessionId);
var user = session.UserId.HasValue ? _userManager.GetUserById(session.UserId.Value) : null;
@ -886,7 +868,7 @@ namespace MediaBrowser.Server.Implementations.Session
public Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken)
{
var session = GetSessionForRemoteControl(sessionId);
var session = GetSession(sessionId);
var controllingSession = GetSession(controllingSessionId);
AssertCanControl(session, controllingSession);
@ -1157,7 +1139,6 @@ namespace MediaBrowser.Server.Implementations.Session
Id = session.Id,
LastActivityDate = session.LastActivityDate,
NowPlayingPositionTicks = session.PlayState.PositionTicks,
SupportsRemoteControl = session.SupportsRemoteControl,
IsPaused = session.PlayState.IsPaused,
IsMuted = session.PlayState.IsMuted,
NowViewingItem = session.NowViewingItem,

View File

@ -27,14 +27,6 @@ namespace MediaBrowser.Server.Implementations.Session
Sockets = new List<IWebSocketConnection>();
}
public bool SupportsMediaRemoteControl
{
get
{
return Sockets.Any(i => i.State == WebSocketState.Open);
}
}
public bool IsSessionActive
{
get