Exemplo n.º 1
0
        private void btnReadFile_Click(object sender, RoutedEventArgs e)
        {
            string ccFilePath = textBoxInputFile.Text.Trim();

            if (!File.Exists(ccFilePath))
            {
                string message = "File doesn't exist";
                DisplayStatusInfo(message);
                return;
            }

            string fileExtension = System.IO.Path.GetExtension(ccFilePath);
            List <ClosedCaptionConverter.Library.ClosedCaption> listOfClosedCaptions = null;

            if (fileExtension.ToLower() == ".vtt")
            {
                VTTHandler vttHandler = new VTTHandler();
                listOfClosedCaptions = vttHandler.ReadFile(ccFilePath);
            }
            else if (fileExtension.ToLower() == ".srt")
            {
                SRTHandler srtHandler = new SRTHandler();
                listOfClosedCaptions = srtHandler.ReadFile(ccFilePath);
            }
            else if (fileExtension.ToLower() == ".ttml" || fileExtension.ToLower() == ".xml")
            {
                TTMLHandler ttmlHandler = new TTMLHandler();
                listOfClosedCaptions = ttmlHandler.ReadFile(ccFilePath);
            }
            else
            {
                string message = "Your selected file type doesn't support.";
                DisplayStatusInfo(message);
            }

            if (listOfClosedCaptions != null)
            {
                listViewClosedCaptions.ItemsSource = listOfClosedCaptions;
                string message = $"Transcript loads successfully, total {listOfClosedCaptions.Count} lines.";

                DisplayStatusInfo(message);
            }
        }
        public void ReadFileTestMethod2()
        {
            string inputFile = @"TestData\TTML_sample1.ttml";
            int    expectedClosedCaptionCount = 547;
            string expectedFirstStartPoint    = "00:00:00.560";
            string expectedFirstTranscript    = "&gt;&gt; Everybody, as the top of the hour,";

            TTMLHandler ttmlHandler = new TTMLHandler();
            var         CCs         = ttmlHandler.ReadFile(inputFile);

            Assert.AreEqual(expectedClosedCaptionCount, CCs.Count);

            if (CCs.Count == 547)
            {
                string actualFirstStartPoint = CCs[0].StartPoint;

                Assert.AreEqual(expectedFirstStartPoint, actualFirstStartPoint);

                string actualFirstTranscript = CCs[0].Transcript;
                Assert.AreEqual(expectedFirstTranscript, actualFirstTranscript);
            }
        }
        public void ReadFileTestMethod1()
        {
            string inputFile = @"TestData\TTML_sample1.ttml";
            int    expectedClosedCaptionCount = 547;
            string expectedLastStartPoint     = "00:24:34.656";
            string expectedLastTranscript     = "Thank you so much and have a great day.";

            TTMLHandler ttmlHandler = new TTMLHandler();
            var         CCs         = ttmlHandler.ReadFile(inputFile);

            Assert.AreEqual(expectedClosedCaptionCount, CCs.Count);

            if (CCs.Count == 547)
            {
                string actualLastStartPoint = CCs[546].StartPoint;

                Assert.AreEqual(expectedLastStartPoint, actualLastStartPoint);

                string actualLastTranscript = CCs[546].Transcript;
                Assert.AreEqual(expectedLastTranscript, actualLastTranscript);
            }
        }
Exemplo n.º 4
0
        private void ConvertFiles(string targetFormat)
        {
            string folderPath = textBoxInputFolder.Text.Trim();

            if (!Directory.Exists(folderPath))
            {
                string message = "Folder doesn't exist.";
                DisplayStatusInfo(message);
                return;
            }

            string targetFolder = Directory.CreateDirectory(System.IO.Path.Combine(folderPath, targetFormat)).FullName;

            List <string> ccFiles = new List <string>();
            // get closed caption files in this folder
            DirectoryInfo dirInfo = new DirectoryInfo(folderPath);

            foreach (FileInfo file in dirInfo.GetFiles())
            {
                if (file.Extension.ToLower() == ".vtt" || file.Extension.ToLower() == ".srt" || file.Extension.ToLower() == ".ttml" || file.Extension.ToLower() == ".xml")
                {
                    ccFiles.Add(file.FullName);
                }
            }

            if (ccFiles.Count > 0)
            {
                VTTHandler  vttHandler  = new VTTHandler();
                SRTHandler  srtHandler  = new SRTHandler();
                TTMLHandler ttmlHandler = new TTMLHandler();

                StringBuilder sbLog = new StringBuilder();
                foreach (string file in ccFiles)
                {
                    string extension = System.IO.Path.GetExtension(file).ToLower();
                    List <ClosedCaptionConverter.Library.ClosedCaption> Transcripts = null;
                    if (extension == ".vtt" || extension == ".srt")
                    {
                        Transcripts = srtHandler.ReadFile(file);
                    }
                    else if (extension == ".ttml" || extension == ".xml")
                    {
                        Transcripts = ttmlHandler.ReadFile(file);
                    }

                    if (Transcripts != null && Transcripts.Count > 0)
                    {
                        string fileName = System.IO.Path.GetFileNameWithoutExtension(file);
                        if (targetFormat == "vtt")
                        {
                            vttHandler.WriteFile(System.IO.Path.Combine(targetFolder, fileName + ".vtt"), Transcripts);
                        }
                        else if (targetFormat == "srt")
                        {
                            srtHandler.WriteFile(System.IO.Path.Combine(targetFolder, fileName + ".srt"), Transcripts);
                        }
                        else if (targetFormat == "ttml")
                        {
                            ttmlHandler.WriteFile(System.IO.Path.Combine(targetFolder, fileName + ".ttml"), Transcripts);
                        }
                    }
                    else
                    {
                        sbLog.AppendLine($"File failed convert - {file}.");
                    }
                }

                if (sbLog.ToString() != string.Empty)
                {
                    using (StreamWriter writer = new StreamWriter(System.IO.Path.Combine(targetFolder, "log.txt")))
                    {
                        writer.Write(sbLog.ToString());
                        writer.Flush();
                        writer.Close();
                    }
                }
            }
            DisplayStatusInfo($"Conversion Complete, total converted {ccFiles.Count} files.");
        }