mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-23 18:44:45 +01:00
add new subtitle preferences
This commit is contained in:
@@ -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" />
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Model.MediaInfo
|
||||
{
|
||||
public static class MediaStreamSelector
|
||||
{
|
||||
public static int? GetDefaultAudioStreamIndex(List<MediaStream> streams, IEnumerable<string> preferredLanguages, bool preferDefaultTrack)
|
||||
{
|
||||
streams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages.ToList())
|
||||
.ToList();
|
||||
|
||||
if (preferDefaultTrack)
|
||||
{
|
||||
var defaultStream = streams.FirstOrDefault(i => i.IsDefault);
|
||||
|
||||
if (defaultStream != null)
|
||||
{
|
||||
return defaultStream.Index;
|
||||
}
|
||||
}
|
||||
|
||||
var stream = streams.FirstOrDefault();
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
return stream.Index;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int? GetDefaultSubtitleStreamIndex(List<MediaStream> streams,
|
||||
IEnumerable<string> preferredLanguages,
|
||||
SubtitlePlaybackMode mode,
|
||||
string audioTrackLanguage)
|
||||
{
|
||||
var languages = preferredLanguages as List<string> ?? preferredLanguages.ToList();
|
||||
streams = GetSortedStreams(streams, MediaStreamType.Subtitle, languages).ToList();
|
||||
|
||||
var full = streams.Where(s => !s.IsForced);
|
||||
var forced = streams.Where(s => s.IsForced && string.Equals(s.Language, audioTrackLanguage, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
MediaStream stream = null;
|
||||
|
||||
if (mode == SubtitlePlaybackMode.None)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mode == SubtitlePlaybackMode.Default)
|
||||
{
|
||||
// if the audio language is not understood by the user, load their preferred subs, if there are any
|
||||
if (!ContainsOrdinal(languages, audioTrackLanguage))
|
||||
{
|
||||
stream = full.FirstOrDefault(s => ContainsOrdinal(languages, s.Language));
|
||||
}
|
||||
}
|
||||
else if (mode == SubtitlePlaybackMode.Always)
|
||||
{
|
||||
// always load the most suitable full subtitles
|
||||
stream = full.FirstOrDefault();
|
||||
}
|
||||
|
||||
// load forced subs if we have found no suitable full subtitles
|
||||
stream = stream ?? forced.FirstOrDefault();
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
return stream.Index;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ContainsOrdinal(IEnumerable<string> list, string item)
|
||||
{
|
||||
return list.Any(i => string.Equals(i, item, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static IEnumerable<MediaStream> GetSortedStreams(IEnumerable<MediaStream> streams, MediaStreamType type, List<string> languagePreferences)
|
||||
{
|
||||
var orderStreams = streams
|
||||
.Where(i => i.Type == type);
|
||||
|
||||
if (languagePreferences.Count == 0)
|
||||
{
|
||||
return orderStreams.OrderBy(i => i.IsDefault)
|
||||
.ThenBy(i => i.Index)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return orderStreams.OrderBy(i => languagePreferences.FindIndex(l => string.Equals(i.Language, l, StringComparison.OrdinalIgnoreCase)))
|
||||
.ThenBy(i => i.IsDefault)
|
||||
.ThenBy(i => i.Index)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user