support xbmc naming convention for subtitles
This commit is contained in:
parent
0f33dfe702
commit
1ddc193e58
|
@ -1,10 +1,8 @@
|
|||
using MediaBrowser.Controller.Localization;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MoreLinq;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
|
@ -41,6 +39,20 @@ namespace MediaBrowser.Api
|
|||
/// </summary>
|
||||
public class LocalizationService : BaseApiService
|
||||
{
|
||||
/// <summary>
|
||||
/// The _localization
|
||||
/// </summary>
|
||||
private readonly ILocalizationManager _localization;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalizationService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="localization">The localization.</param>
|
||||
public LocalizationService(ILocalizationManager localization)
|
||||
{
|
||||
_localization = localization;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
|
@ -48,10 +60,7 @@ namespace MediaBrowser.Api
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetParentalRatings request)
|
||||
{
|
||||
var ratings =
|
||||
Ratings.RatingsDict.Select(k => new ParentalRating { Name = k.Key, Value = k.Value });
|
||||
|
||||
var result = ratings.OrderBy(p => p.Value).Where(p => p.Value > 0).ToList();
|
||||
var result = _localization.GetParentalRatings().ToList();
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
@ -63,22 +72,7 @@ namespace MediaBrowser.Api
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetCountries request)
|
||||
{
|
||||
var result = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
|
||||
|
||||
.Select(c => new RegionInfo(c.LCID))
|
||||
.OrderBy(c => c.DisplayName)
|
||||
|
||||
// Try to eliminate dupes
|
||||
.DistinctBy(c => c.TwoLetterISORegionName)
|
||||
|
||||
.Select(c => new CountryInfo
|
||||
{
|
||||
Name = c.Name,
|
||||
DisplayName = c.DisplayName,
|
||||
TwoLetterISORegionName = c.TwoLetterISORegionName,
|
||||
ThreeLetterISORegionName = c.ThreeLetterISORegionName
|
||||
})
|
||||
.ToList();
|
||||
var result = _localization.GetCountries().ToList();
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
@ -90,20 +84,7 @@ namespace MediaBrowser.Api
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetCultures request)
|
||||
{
|
||||
var result = CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||
.OrderBy(c => c.DisplayName)
|
||||
|
||||
// Try to eliminate dupes
|
||||
.DistinctBy(c => c.TwoLetterISOLanguageName + c.ThreeLetterISOLanguageName)
|
||||
|
||||
.Select(c => new CultureDto
|
||||
{
|
||||
Name = c.Name,
|
||||
DisplayName = c.DisplayName,
|
||||
ThreeLetterISOLanguageName = c.ThreeLetterISOLanguageName,
|
||||
TwoLetterISOLanguageName = c.TwoLetterISOLanguageName
|
||||
})
|
||||
.ToList();
|
||||
var result = _localization.GetCultures().ToList();
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
|
28
MediaBrowser.Controller/Localization/ILocalizationManager.cs
Normal file
28
MediaBrowser.Controller/Localization/ILocalizationManager.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Controller.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface ILocalizationManager
|
||||
/// </summary>
|
||||
public interface ILocalizationManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the cultures.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{CultureDto}.</returns>
|
||||
IEnumerable<CultureDto> GetCultures();
|
||||
/// <summary>
|
||||
/// Gets the countries.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{CountryInfo}.</returns>
|
||||
IEnumerable<CountryInfo> GetCountries();
|
||||
/// <summary>
|
||||
/// Gets the parental ratings.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{ParentalRating}.</returns>
|
||||
IEnumerable<ParentalRating> GetParentalRatings();
|
||||
}
|
||||
}
|
|
@ -76,6 +76,7 @@
|
|||
<Compile Include="Entities\MusicVideo.cs" />
|
||||
<Compile Include="Library\ILibraryPostScanTask.cs" />
|
||||
<Compile Include="Library\ILibraryPrescanTask.cs" />
|
||||
<Compile Include="Localization\ILocalizationManager.cs" />
|
||||
<Compile Include="Providers\Movies\FanArtMovieUpdatesPrescanTask.cs" />
|
||||
<Compile Include="Providers\Movies\MovieDbImagesProvider.cs" />
|
||||
<Compile Include="Providers\Music\ArtistsPostScanTask.cs" />
|
||||
|
|
|
@ -3,6 +3,7 @@ using MediaBrowser.Common.MediaInfo;
|
|||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Localization;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
|
@ -21,7 +22,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
|||
/// </summary>
|
||||
public class FFProbeVideoInfoProvider : BaseFFProbeProvider<Video>
|
||||
{
|
||||
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IMediaEncoder mediaEncoder)
|
||||
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IMediaEncoder mediaEncoder, ILocalizationManager localization)
|
||||
: base(logManager, configurationManager, mediaEncoder, jsonSerializer)
|
||||
{
|
||||
if (isoManager == null)
|
||||
|
@ -34,6 +35,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
|||
}
|
||||
|
||||
_blurayExaminer = blurayExaminer;
|
||||
_localization = localization;
|
||||
_isoManager = isoManager;
|
||||
}
|
||||
|
||||
|
@ -48,6 +50,8 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
|||
/// </summary>
|
||||
private readonly IIsoManager _isoManager;
|
||||
|
||||
private readonly ILocalizationManager _localization;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
|
||||
/// </summary>
|
||||
|
@ -249,17 +253,18 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
|||
var startIndex = video.MediaStreams == null ? 0 : video.MediaStreams.Count;
|
||||
var streams = new List<MediaStream>();
|
||||
|
||||
var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);
|
||||
|
||||
foreach (var file in fileSystemChildren
|
||||
.Where(f => !f.Attributes.HasFlag(FileAttributes.Directory) && string.Equals(Path.GetExtension(f.FullName), ".srt", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
var fullName = file.FullName;
|
||||
|
||||
// The subtitle filename must match video filename
|
||||
if (!string.Equals(Path.GetFileNameWithoutExtension(video.Path), Path.GetFileNameWithoutExtension(fullName)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
|
||||
|
||||
// If the subtitle file matches the video file name
|
||||
if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
streams.Add(new MediaStream
|
||||
{
|
||||
Index = startIndex++,
|
||||
|
@ -269,6 +274,32 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
|
|||
Codec = "srt"
|
||||
});
|
||||
}
|
||||
else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Support xbmc naming conventions - 300.spanish.srt
|
||||
var language = fileNameWithoutExtension.Split('.').LastOrDefault();
|
||||
|
||||
// Try to translate to three character code
|
||||
// Be flexible and check against all properties
|
||||
var culture = _localization.GetCultures()
|
||||
.FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (culture != null)
|
||||
{
|
||||
language = culture.ThreeLetterISOLanguageName;
|
||||
}
|
||||
|
||||
streams.Add(new MediaStream
|
||||
{
|
||||
Index = startIndex++,
|
||||
Type = MediaStreamType.Subtitle,
|
||||
IsExternal = true,
|
||||
Path = fullName,
|
||||
Codec = "srt",
|
||||
Language = language
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (video.MediaStreams == null)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
using MediaBrowser.Controller.Localization;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MoreLinq;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// Class LocalizationManager
|
||||
/// </summary>
|
||||
public class LocalizationManager : ILocalizationManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the cultures.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{CultureDto}.</returns>
|
||||
public IEnumerable<CultureDto> GetCultures()
|
||||
{
|
||||
return CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||
.OrderBy(c => c.DisplayName)
|
||||
.DistinctBy(c => c.TwoLetterISOLanguageName + c.ThreeLetterISOLanguageName)
|
||||
.Select(c => new CultureDto
|
||||
{
|
||||
Name = c.Name,
|
||||
DisplayName = c.DisplayName,
|
||||
ThreeLetterISOLanguageName = c.ThreeLetterISOLanguageName,
|
||||
TwoLetterISOLanguageName = c.TwoLetterISOLanguageName
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the countries.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{CountryInfo}.</returns>
|
||||
public IEnumerable<CountryInfo> GetCountries()
|
||||
{
|
||||
return CultureInfo.GetCultures(CultureTypes.SpecificCultures)
|
||||
.Select(c => new RegionInfo(c.LCID))
|
||||
.OrderBy(c => c.DisplayName)
|
||||
.DistinctBy(c => c.TwoLetterISORegionName)
|
||||
.Select(c => new CountryInfo
|
||||
{
|
||||
Name = c.Name,
|
||||
DisplayName = c.DisplayName,
|
||||
TwoLetterISORegionName = c.TwoLetterISORegionName,
|
||||
ThreeLetterISORegionName = c.ThreeLetterISORegionName
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parental ratings.
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{ParentalRating}.</returns>
|
||||
public IEnumerable<ParentalRating> GetParentalRatings()
|
||||
{
|
||||
return Ratings.RatingsDict
|
||||
.Select(k => new ParentalRating {Name = k.Key, Value = k.Value})
|
||||
.OrderBy(p => p.Value)
|
||||
.Where(p => p.Value > 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -138,6 +138,7 @@
|
|||
<Compile Include="Library\Resolvers\TV\SeriesResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\VideoResolver.cs" />
|
||||
<Compile Include="Library\UserManager.cs" />
|
||||
<Compile Include="Localization\LocalizationManager.cs" />
|
||||
<Compile Include="MediaEncoder\MediaEncoder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\ProviderManager.cs" />
|
||||
|
|
|
@ -35,6 +35,7 @@ using MediaBrowser.Server.Implementations.Configuration;
|
|||
using MediaBrowser.Server.Implementations.HttpServer;
|
||||
using MediaBrowser.Server.Implementations.IO;
|
||||
using MediaBrowser.Server.Implementations.Library;
|
||||
using MediaBrowser.Server.Implementations.Localization;
|
||||
using MediaBrowser.Server.Implementations.MediaEncoder;
|
||||
using MediaBrowser.Server.Implementations.Providers;
|
||||
using MediaBrowser.Server.Implementations.ServerManager;
|
||||
|
@ -284,6 +285,9 @@ namespace MediaBrowser.ServerApplication
|
|||
ServerManager = new ServerManager(this, JsonSerializer, Logger, ServerConfigurationManager);
|
||||
RegisterSingleInstance(ServerManager);
|
||||
|
||||
var localizationManager = new LocalizationManager();
|
||||
RegisterSingleInstance<ILocalizationManager>(localizationManager);
|
||||
|
||||
var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
|
||||
var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
|
||||
var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
|
||||
|
|
Loading…
Reference in New Issue
Block a user