diff --git a/mediaportal/Core/Player/FFDShow/FFDShowEngine.cs b/mediaportal/Core/Player/FFDShow/FFDShowEngine.cs index 3d4b783981e..5aab6f85b69 100644 --- a/mediaportal/Core/Player/FFDShow/FFDShowEngine.cs +++ b/mediaportal/Core/Player/FFDShow/FFDShowEngine.cs @@ -38,6 +38,7 @@ public class FFDShowEngine : SubSettings, ISubEngine, IPostProcessingEngine private FFDShowAPI ffdshowAPI; private bool hasPostProcessing = false; protected int audiodelayInterval; + private string _SubtitleFilename = null; public static void DisableFFDShowSubtitles(IGraphBuilder graphBuilder) { @@ -161,6 +162,8 @@ public void SetDevice(IntPtr device) {} public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename) { + this._SubtitleFilename = filename; + LoadSettings(); //remove DirectVobSub @@ -348,6 +351,8 @@ public bool AutoShow set { autoShow = value; } } + public string FileName { get => this._SubtitleFilename; } + #endregion #region IPostProcessing Members diff --git a/mediaportal/Core/Player/Subtitles/DirectVobSubEngine.cs b/mediaportal/Core/Player/Subtitles/DirectVobSubEngine.cs index 3fbafae64b4..b287f932a72 100644 --- a/mediaportal/Core/Player/Subtitles/DirectVobSubEngine.cs +++ b/mediaportal/Core/Player/Subtitles/DirectVobSubEngine.cs @@ -43,6 +43,7 @@ public class DirectVobSubEngine : SubSettings, ISubEngine private List SubtitleNames = new List(); private int extCount; private int current; + private string _SubtitleFilename = null; #region ISubEngine Members @@ -50,6 +51,8 @@ public void SetDevice(IntPtr device) {} public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename) { + this._SubtitleFilename = filename; + FreeSubtitles(); LoadSettings(); @@ -383,6 +386,8 @@ public bool AutoShow } } + public string FileName { get => this._SubtitleFilename; } + #endregion } diff --git a/mediaportal/Core/Player/Subtitles/MpcEngine.cs b/mediaportal/Core/Player/Subtitles/MpcEngine.cs index c17cc0ba493..70396096b29 100644 --- a/mediaportal/Core/Player/Subtitles/MpcEngine.cs +++ b/mediaportal/Core/Player/Subtitles/MpcEngine.cs @@ -35,6 +35,8 @@ namespace MediaPortal.Player.Subtitles { public class MpcEngine : SubSettings, ISubEngine { + private string _SubtitleFilename = null; + protected override void LoadAdvancedSettings(Settings xmlreader) { int subPicsBufferAhead = xmlreader.GetValueAsInt("subtitles", "subPicsBufferAhead", 3); @@ -117,6 +119,7 @@ public void SetDevice(IntPtr device) public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename) { + this._SubtitleFilename = filename; LoadSettings(); MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle); if (selectionOff) @@ -288,6 +291,8 @@ public bool AutoShow } } + public string FileName { get => this._SubtitleFilename; } + #endregion private class MpcSubtitles diff --git a/mediaportal/Core/Player/Subtitles/SubEngine.cs b/mediaportal/Core/Player/Subtitles/SubEngine.cs index 17e558129b9..1947854d871 100644 --- a/mediaportal/Core/Player/Subtitles/SubEngine.cs +++ b/mediaportal/Core/Player/Subtitles/SubEngine.cs @@ -73,6 +73,8 @@ public interface ISubEngine void DelayMinus(int subtitleDelay); bool AutoShow { get; set; } + + string FileName { get; } } public class SubEngine @@ -123,12 +125,15 @@ public static ISubEngine GetInstance(bool forceinitialize) public class DummyEngine : ISubEngine { + private string _SubtitleFilename = null; + #region ISubEngine Members public void SetDevice(IntPtr device) {} public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename) { + this._SubtitleFilename = filename; DirectVobSubUtil.RemoveFromGraph(graphBuilder); return false; } @@ -207,6 +212,8 @@ public bool AutoShow set { } } + public string FileName { get => this._SubtitleFilename; } + #endregion } } diff --git a/mediaportal/Core/Player/VideoPlayerVMR7.cs b/mediaportal/Core/Player/VideoPlayerVMR7.cs index 63b49542657..e20e9da876b 100644 --- a/mediaportal/Core/Player/VideoPlayerVMR7.cs +++ b/mediaportal/Core/Player/VideoPlayerVMR7.cs @@ -1826,48 +1826,49 @@ public override string SubtitleLanguage(int iStream) { string streamName = SubEngine.GetInstance().GetLanguage(iStream); string langName = SubEngine.GetInstance().GetLanguage(iStream); - string streamNameUND = SubEngine.GetInstance().GetSubtitleName(iStream); + string streamNameUND = SubEngine.GetInstance().GetSubtitleName(iStream); + string strSubtitleFileName = SubEngine.GetInstance().FileName; //filename used to load subtitle engine if (streamName == null) { return Strings.Unknown; } - - //MPC-HC 2.0.0 - //"[Local] 4-3 bar test.English-Forced.srt\tEnglish" - Regex regexMPCHC = new Regex(@"^\[([^\]]+)\]\s(?[^\t]+)(\t(?.+))?"); - Match match = regexMPCHC.Match(streamName); - if (match.Success) - { - // Group grLng = match.Groups["lng"]; - // if (grLng.Success) - // return grLng.Value; - // - // string strVideNoExt = Path.GetFileNameWithoutExtension(this.m_strCurrentFile); - // string strSubNoExt = Path.GetFileNameWithoutExtension(match.Groups["file"].Value); - // if (strVideNoExt.Equals(strSubNoExt, StringComparison.CurrentCultureIgnoreCase)) - // return "Undetermined"; - string strVideNoExt = Path.GetFileNameWithoutExtension(this.m_strCurrentFile); - string strSubNoExt = Path.GetFileNameWithoutExtension(match.Groups["file"].Value); - if (strSubNoExt.StartsWith(strVideNoExt, StringComparison.CurrentCultureIgnoreCase)) + if (!string.IsNullOrWhiteSpace(strSubtitleFileName)) + { + //MPC-HC 2.0.0 + //"[Local] 4-3 bar test.English-Forced.srt\tEnglish" + Regex regexMPCHC = new Regex(@"^\[([^\]]+)\]\s(?[^\t]+)(\t(?.+))?"); + Match match = regexMPCHC.Match(streamName); + if (match.Success) { - if (strSubNoExt.Length > strVideNoExt.Length) - streamName = strSubNoExt.Substring(strVideNoExt.Length + 1); + Group grLng = match.Groups["lng"]; + if (grLng.Success) + return grLng.Value; //language parsed by MPC-HC + + string strVideNoExt = Path.GetFileNameWithoutExtension(strSubtitleFileName); + string strSubNoExt = Path.GetFileNameWithoutExtension(match.Groups["file"].Value); + if (strVideNoExt.Equals(strSubNoExt, StringComparison.CurrentCultureIgnoreCase)) + return "Undetermined"; //no subtitle suffix + else if (strSubNoExt.StartsWith(strVideNoExt, StringComparison.CurrentCultureIgnoreCase)) + { + if (strSubNoExt.Length > strVideNoExt.Length) + streamName = strSubNoExt.Substring(strVideNoExt.Length + 1); //Subtitle filename has a suffix + else + streamName = string.Empty; + + if (string.IsNullOrWhiteSpace(streamName)) + streamName = strVideNoExt; + } else - streamName = string.Empty; + { + //difference between m_strCurrentFile and ISubEngine.LoadSubtitles call + streamName = strSubNoExt; + } - if (string.IsNullOrWhiteSpace(streamName)) - streamName = strVideNoExt; - } - else - { - //difference between m_strCurrentFile and ISubEngine.LoadSubtitles call - streamName = strSubNoExt; + langName = streamName; + streamNameUND = streamName; } - - langName = streamName; - streamNameUND = streamName; } // remove prefix, which is added by Haali Media Splitter @@ -1941,35 +1942,54 @@ public override string SubtitleName(int iStream) { string streamName = SubEngine.GetInstance().GetSubtitleName(iStream); string streamNameFalse = SubEngine.GetInstance().GetSubtitleName(iStream); - string langName = SubEngine.GetInstance().GetLanguage(iStream); + string langName = SubEngine.GetInstance().GetLanguage(iStream); + string strSubtitleFileName = SubEngine.GetInstance().FileName; //filename used to load subtitle engine + if (streamName == null) { return Strings.Unknown; } - //MPC-HC 2.0.0 - //"[Local] 4-3 bar test.English-Forced.srt\tEnglish" - Regex regexMPCHC = new Regex(@"^\[([^\]]+)\]\s(?[^\t]+)(\t(?.+))?"); - Match match = regexMPCHC.Match(streamName); - if (match.Success) + if (!string.IsNullOrWhiteSpace(strSubtitleFileName)) { - string strVideNoExt = Path.GetFileNameWithoutExtension(this.m_strCurrentFile); - string strSubNoExt = Path.GetFileNameWithoutExtension(match.Groups["file"].Value); - if (strSubNoExt.StartsWith(strVideNoExt, StringComparison.CurrentCultureIgnoreCase)) + //MPC-HC 2.0.0 + //"[Local] 4-3 bar test.English-Forced.srt\tEnglish" + Regex regexMPCHC = new Regex(@"^\[([^\]]+)\]\s(?[^\t]+)(\t(?.+))?"); + Match match = regexMPCHC.Match(streamName); + if (match.Success) { - if (strSubNoExt.Length > strVideNoExt.Length) - streamName = strSubNoExt.Substring(strVideNoExt.Length + 1); + string strVideNoExt = Path.GetFileNameWithoutExtension(strSubtitleFileName); + string strSubNoExt = Path.GetFileNameWithoutExtension(match.Groups["file"].Value); + if (strSubNoExt.StartsWith(strVideNoExt, StringComparison.CurrentCultureIgnoreCase)) + { + if (strSubNoExt.Length > strVideNoExt.Length) + { + //Subtitle filename has a suffix + Group grLng = match.Groups["lng"]; + if (grLng.Success) + { + //Try to extract additional suffix following the language + match = Regex.Match(strSubNoExt.Substring(strVideNoExt.Length), @"[-\._](?[A-Za-z]+)[-\._\[]+(?.+?)\]?\z"); + if (match.Success) + return match.Groups["suffix"].Value; + else + return string.Empty; //no additional suffix - just language + } + + //Unknown subtitle filename suffix + return strSubNoExt.Substring(strVideNoExt.Length + 1); + } + else + return string.Empty; + } else - streamName = string.Empty; - } - else - { - //difference between m_strCurrentFile and ISubEngine.LoadSubtitles call - streamName = strSubNoExt; + { + //difference between m_strCurrentFile and ISubEngine.LoadSubtitles call + streamName = strSubNoExt; + streamNameFalse = streamName; + langName = streamName; + } } - - streamNameFalse = streamName; - langName = streamName; } // remove prefix, which is added by Haali Media Splitter