aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-06-06 10:33:11 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-06-06 10:33:11 -0400
commit1ddc193e588f6231c327a769b580f48cba03a77f (patch)
tree3c00a0e259828d375cf6423f664a7430e1c3825b /MediaBrowser.Controller
parent0f33dfe7027806c82b2b792b073e825be22364f7 (diff)
support xbmc naming convention for subtitles
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/Localization/ILocalizationManager.cs28
-rw-r--r--MediaBrowser.Controller/MediaBrowser.Controller.csproj1
-rw-r--r--MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs55
3 files changed, 72 insertions, 12 deletions
diff --git a/MediaBrowser.Controller/Localization/ILocalizationManager.cs b/MediaBrowser.Controller/Localization/ILocalizationManager.cs
new file mode 100644
index 0000000000..487c4a48e6
--- /dev/null
+++ b/MediaBrowser.Controller/Localization/ILocalizationManager.cs
@@ -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();
+ }
+}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index cdcc456223..04e0a31ac6 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -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" />
diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs
index c95f0771fa..91fd29b240 100644
--- a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs
+++ b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.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,25 +253,52 @@ 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)))
+ var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
+
+ // If the subtitle file matches the video file name
+ if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
{
- continue;
+ streams.Add(new MediaStream
+ {
+ Index = startIndex++,
+ Type = MediaStreamType.Subtitle,
+ IsExternal = true,
+ Path = fullName,
+ Codec = "srt"
+ });
}
-
- streams.Add(new MediaStream
+ else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
{
- Index = startIndex++,
- Type = MediaStreamType.Subtitle,
- IsExternal = true,
- Path = fullName,
- Codec = "srt"
- });
+ // 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)