Exemplo n.º 1
0
        public bool ConvertSubtitles(string title, Track[] trackNumbers, string directory, bool verbose)
        {
            try
            {
                foreach (var track in trackNumbers)
                {
                    var extractProcess = new Process
                    {
                        StartInfo =
                        {
                            FileName = Bdsup2SubPath,
                            Arguments =
                                String.Format("\"{0}\\{1}_track{2}.sup\" \"{0}\\{1}_track{2}_exp.sub\" /lang:{3}",
                                              directory, title, track.TrackNumber, track.TrackLanguage.BDSupCode),
                            UseShellExecute = false,
                            RedirectStandardOutput = true
                        }
                    };
                    extractProcess.Start();
                    var output = extractProcess.StandardOutput;
                    while (output.EndOfStream == false)
                    {
                        var line = output.ReadLine();
                        if (line != null && line.ToLower().Contains("forced"))
                        {
                            var oldColor = Console.ForegroundColor;
                            Console.ForegroundColor = !line.ToLower().Contains(" 0 ") ? ConsoleColor.Red : ConsoleColor.Yellow;

                            SpecialWriter.WriteLine("track {0}: {1}", track.TrackNumber, line);
                            Console.ForegroundColor = oldColor;
                        }
                        if (verbose)
                        {
                            SpecialWriter.WriteLine(line);
                        }
                    }
                    extractProcess.WaitForExit();
                }

            }
            catch(Exception e)
            {
                Console.WriteLine(e);
                return false;
            }
            return true;
        }
Exemplo n.º 2
0
 public IEnumerable<Track> GetTrackInfo(string file, bool verbose)
 {
     var infoProcess = new Process
                           {
                               StartInfo =
                                   {
                                       FileName = MkvinfoPath,
                                       Arguments = String.Format("\"{0}\"", file),
                                       UseShellExecute = false,
                                       RedirectStandardOutput = true
                                   }
                           };
     infoProcess.Start();
     var output = infoProcess.StandardOutput;
     var tracks = new List<Track>();
     Track currentTrack = null;
     while(output.EndOfStream == false)
     {
         var line = output.ReadLine();
         if (String.IsNullOrEmpty(line))
         {
             continue;
         }
         if (verbose)
         {
             Console.WriteLine(line);
         }
         if (line == "| + A track")
         {
             if (currentTrack != null)
             {
                 tracks.Add(currentTrack);
             }
             currentTrack = new Track {TrackLanguage = Constants.Languages[0]};
             continue;
         }
         if (line.StartsWith("| +") || line.StartsWith("|+"))
         {
             continue;
         }
         if (currentTrack == null)
         {
             continue;
         }
         line = line.TrimStart('|', ' ', '+');
         const string trackNumber = "Track number: ";
         if (line.StartsWith(trackNumber))
         {
             var space = line.LastIndexOf(' ');
             var rightParen = line.LastIndexOf(')');
             var startIndex = space + 1;
             currentTrack.TrackNumber = line.Substring(startIndex, line.Length - (startIndex + 1));
             //currentTrack.TrackNumber = line.Substring(trackNumber.Length, line.Length - trackNumber.Length);
         }
         const string trackType = "Track type: ";
         if (line.StartsWith(trackType))
         {
             currentTrack.TrackType = GetTrackType(line);
         }
         else
         {
             const string codecId = "Codec ID: ";
             if (line.Contains(codecId))
             {
                 currentTrack.CodecId = line.Substring(codecId.Length, line.Length - codecId.Length);
             }
             else
             {
                 const string languageString = "Language: ";
                 if (line.StartsWith(languageString))
                 {
                     var languageCode = line.Substring(languageString.Length, line.Length - languageString.Length);
                     var language = Constants.Languages.FirstOrDefault(x => x.MKVCode == languageCode) ??
                                    Constants.Languages[0];
                     currentTrack.TrackLanguage = language;
                 }
             }
         }
     }
     if (currentTrack != null)
     {
         tracks.Add(currentTrack);
     }
     infoProcess.WaitForExit();
     return tracks;
 }