Пример #1
0
        public List <TextStream> GetStreams(FileInfo file)
        {
            List <TextStream> streams = new List <TextStream>();
            var language = SubtitleHelper.GetLanguageFromFilename(file.Name);

            MediaContainer    m        = MediaInfo.GetMediaInfo(file.FullName);
            List <TextStream> tStreams = m?.TextStreams;

            if (tStreams == null || tStreams.Count <= 0)
            {
                return(streams);
            }
            tStreams.ForEach(a =>
            {
                a.External = true;
                a.Filename = file.Name;
                if (language == null)
                {
                    return;
                }
                a.Language = language;
                Tuple <string, string> mapping = MediaInfoUtils.GetLanguageMapping(language);
                if (mapping == null)
                {
                    return;
                }
                a.LanguageCode = mapping.Item1;
                a.LanguageName = mapping.Item2;
            });
            streams.AddRange(tStreams);
            return(streams);
        }
Пример #2
0
        public static List <TextStream> GetSubtitleStreams(SVR_VideoLocal_Place vplace)
        {
            List <TextStream> ls = new VobSubSubtitles().GetStreams(vplace);

            ls.AddRange(new TextSubtitles().GetStreams(vplace));
            ls.ForEach(a =>
            {
                a.External  = true;
                string lang = GetLanguageFromFilename(vplace.FilePath);
                if (lang == null)
                {
                    return;
                }
                a.Language = lang;
                Tuple <string, string> mapping = MediaInfoUtils.GetLanguageMapping(lang);
                if (mapping == null)
                {
                    return;
                }
                a.LanguageCode = mapping.Item1;
                a.LanguageName = mapping.Item2;
            });
            return(ls);
        }
Пример #3
0
        public static MediaContainer GetMediaInfo_New(string filename)
        {
            try
            {
                string exe  = GetMediaInfoPathForOS();
                string args = $"--OUTPUT=JSON \"{filename}\"";

                var pProcess = GetProcess(exe, args);
                pProcess.Start();
                string output = pProcess.StandardOutput.ReadToEnd().Trim();
                //Wait for process to finish
                pProcess.WaitForExit();

                if (pProcess.ExitCode != 0 || !output.StartsWith("{"))
                {
                    // We have an error
                    if (string.IsNullOrWhiteSpace(output) || output.EqualsInvariantIgnoreCase("null"))
                    {
                        output = pProcess.StandardError.ReadToEnd().Trim();
                    }

                    if (string.IsNullOrWhiteSpace(output) || output.EqualsInvariantIgnoreCase("null"))
                    {
                        output = "No message";
                    }

                    logger.Error($"MediaInfo threw an error on {filename}: {output}");
                    return(null);
                }

                var settings = new JsonSerializerSettings
                {
                    Converters = new JsonConverter[]
                    {
                        new StreamJsonConverter(), new BooleanConverter(), new StringEnumConverter(),
                        new DateTimeConverter()
                        {
                            DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
                        }, new MultiIntConverter()
                    },
                    Error = (s, e) =>
                    {
                        logger.Error(e.ErrorContext.Error);
                        e.ErrorContext.Handled = true;
                    }
                };

                // assuming json, as it starts with {
                MediaContainer m = JsonConvert.DeserializeObject <MediaContainer>(output, settings);
                m.media.track.ForEach(a =>
                {
                    // Stream should never be null, but here we are
                    if (string.IsNullOrEmpty(a?.Language))
                    {
                        return;
                    }
                    Tuple <string, string> langs = MediaInfoUtils.GetLanguageMapping(a.Language);
                    if (langs == null)
                    {
                        logger.Error($"{filename} had a missing language code: {a.Language}");
                        return;
                    }
                    a.LanguageCode = langs.Item1;
                    a.LanguageName = langs.Item2;
                });
                return(m);
            }
            catch (Exception e)
            {
                logger.Error($"MediaInfo threw an error on {filename}: {e}");
                return(null);
            }
        }