Ejemplo n.º 1
0
        private static bool PopulateLanguages(EmbeddedSubtitle sub)
        {
            bool _result = false;

            if (sub != null && !string.IsNullOrEmpty(sub.Language))
            {
                if (FileManager.Configuration.Options.MovieSheetsOptions.IgnoreOtherLanguages &&
                    sub.Language.ToLowerInvariant() != FileManager.Configuration.Options.MovieSheetsOptions.DefaultExternalSubtitlesLanguage.ToLowerInvariant())
                {
                    return(false);
                }
                try
                {
                    CultureInfo _ci = null;
                    try
                    {
                        _ci = Helpers.GetCultureInfo(sub.Language != "iw" ? sub.Language : "he");
                    }
                    catch (Exception ex)
                    {
                        Loggy.Logger.DebugException("Cannot create culture from: " + sub.Language, ex);
                    }
                    if (_ci != null && _ci != CultureInfo.InvariantCulture)
                    {
                        // store the native displayname
                        TextInfo _UsaTextInfo = CultureInfo.GetCultureInfo("en-US").TextInfo;
                        try
                        {
                            sub.Language = _UsaTextInfo.ToTitleCase(_ci.NativeName);
                        }
                        catch
                        {
                            sub.Language = _ci.NativeName;
                        }
                        // store the EnglishName
                        sub.EnglishLanguage = _ci.EnglishName;
                        // ok
                        _result = true;
                    }
                }
                catch { }
            }

            return(_result);
        }
Ejemplo n.º 2
0
 private static void ProcessSubtitles(MediaInfoData result, MediaInfo mi, string filePath)
 {
     // check embedded subtitles
     // process each sub and add it to the list
     if (mi != null && !IsISO(filePath))
     {
         try
         {
             int _subsCnt = mi.Count_Get(StreamKind.Text);
             if (_subsCnt != 0)
             {
                 for (int _i = 0; _i < _subsCnt; _i++)
                 {
                     EmbeddedSubtitle _sub = new EmbeddedSubtitle();
                     _sub.Format   = mi.Get(StreamKind.Text, _i, "Format");
                     _sub.Language = mi.Get(StreamKind.Text, _i, "Language");
                     if (string.IsNullOrEmpty(_sub.Language))
                     {
                         _sub.Language = mi.Get(StreamKind.Text, _i, "Title");
                     }
                     _sub.Language = string.IsNullOrEmpty(_sub.Language) ? FileManager.Configuration.Options.MovieSheetsOptions.DefaultExternalSubtitlesLanguage : _sub.Language;
                     if (PopulateLanguages(_sub))
                     {
                         if (!string.IsNullOrEmpty(_sub.Language) && !string.IsNullOrEmpty(_sub.Format))
                         {
                             result.EmbeddedSubtitles.Add(_sub);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Loggy.Logger.DebugException("Embedded subs: ", ex);
         }
     }
     // process also the external subtitles
     try
     {
         ExternalSubtitlesInfo _subtitles = CollectExternalSubtitles(filePath, false);
         if (_subtitles.HasExternalSubtitles)
         {
             foreach (ExtSubData _subData in _subtitles.SubFiles)
             {
                 EmbeddedSubtitle _sub = new EmbeddedSubtitle();
                 _sub.Format   = _subData.Format;
                 _sub.Language = _subData.TwoLetterLanguageCode;
                 if (PopulateLanguages(_sub))
                 {
                     if (!string.IsNullOrEmpty(_sub.Language) && !string.IsNullOrEmpty(_sub.Format))
                     {
                         result.ExternalSubtitlesList.Add(_sub);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Loggy.Logger.DebugException("External subs: ", ex);
     }
 }