Exemplo n.º 1
0
        public void ToTimeString()
        {
            SrtConverter converter = new SrtConverter();
            string       result    = converter.ToTimeString(new TimeSpan(0, 1, 2, 3, 400));

            Assert.Equal("01:02:03,400", result);
        }
        static void Main(string[] args)
        {
            string batchFile = args[0];

            FileProvider fileProvider = new FileProvider();
            IEnumerable <SubtitleFileInfo> subtilesInfos = fileProvider.ReadTxtFile(batchFile);

            MVAXml2Subs.Parser.XmlParser parser = new MVAXml2Subs.Parser.XmlParser();

            SrtConverter subtitleConverter = new SrtConverter();

            foreach (var subtitleFileInfo in subtilesInfos)
            {
                IEnumerable <SubtitleModel> lines = parser.Parse(fileProvider.ReadFile(subtitleFileInfo.Incoming));

                string subtitleText = subtitleConverter.Create(lines);

                fileProvider.WriteFile(subtitleFileInfo.Outcoming, subtitleText);
            }
        }
Exemplo n.º 3
0
        public void Create()
        {
            IEnumerable <SubtitleModel> set = new[]
            {
                new SubtitleModel
                {
                    Start = new TimeSpan(0, 0, 0, 0, 200),
                    End   = new TimeSpan(0, 0, 0, 1, 900),
                    Value = "Hello World!",
                }
            };

            SrtConverter converter = new SrtConverter();
            string       result    = converter.Create(set);

            string expect = @"1
00:00:00,200 --> 00:00:01,900
Hello World!";

            Assert.Equal(expect, result);
        }
Exemplo n.º 4
0
        public void TrimUavLogs()
        {
            int    counter = 0;
            string line;

            // Read the file and display it line by line.
            DjiSrtVideoLogModel        djiSrtVideoLogModel  = new DjiSrtVideoLogModel();
            List <DjiSrtVideoLogModel> djiSrtVideoLogModels = new List <DjiSrtVideoLogModel>();

            using (System.IO.StreamReader file = new System.IO.StreamReader(@"H:\Code\UavLogTool\UavLogToolTest\Data\DJI_0012.SRT"))
            {
                int lineCount = 0;
                int id        = 0;
                while ((line = file.ReadLine()) != null)
                {
                    int idTemp;
                    if (int.TryParse(line, out idTemp))
                    {
                        djiSrtVideoLogModel = new DjiSrtVideoLogModel();
                        id = idTemp;
                        lineCount++;
                    }
                    if (id >= 1)
                    {
                        switch (lineCount)
                        {
                        case 1:
                            djiSrtVideoLogModel.Id = id;
                            lineCount++;
                            break;

                        case 2:
                            djiSrtVideoLogModel = SrtConverter.GetTimeStamp(line, ref djiSrtVideoLogModel);
                            lineCount++;
                            break;

                        case 3:
                            djiSrtVideoLogModel = SrtConverter.GetHomePointAndDateTime(line, ref djiSrtVideoLogModel);
                            lineCount++;
                            break;

                        case 4:
                            djiSrtVideoLogModel = SrtConverter.GetGpsPointAndBarometer(line, ref djiSrtVideoLogModel);
                            lineCount++;
                            break;

                        case 5:
                            djiSrtVideoLogModel = SrtConverter.GetCameraInfo(line, ref djiSrtVideoLogModel);
                            djiSrtVideoLogModels.Add(djiSrtVideoLogModel);
                            lineCount = 0;
                            break;

                        default:
                            break;
                        }
                    }
                    counter++;
                }
            }

            var filePath = Path.Combine(@"C:\Temp\", "djiSrtVideo.csv");

            var noko         = SrtConverter.ConvertSrtToUavLog(djiSrtVideoLogModels);
            var csvVideoLogs = CsvUtilities.ToCsv(",", djiSrtVideoLogModels.ToArray());
            var saved        = CsvUtilities.SaveCsvTofile(filePath, csvVideoLogs);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetCsvFromSrt(IFormFile srtLog)
        {
            long   size      = srtLog.Length;
            string extension = Path.GetExtension(srtLog.FileName).ToLower();

            if (size > 0)
            {
                if (!extension.Equals(".SRT", StringComparison.OrdinalIgnoreCase))
                {
                    return(BadRequest("wrong file format"));
                }
            }
            else
            {
                return(BadRequest("SRT File Not Found"));
            }
            string line;

            DjiSrtVideoLogModel        djiSrtVideoLogModel  = new DjiSrtVideoLogModel();
            List <DjiSrtVideoLogModel> djiSrtVideoLogModels = new List <DjiSrtVideoLogModel>();

            try
            {
                using (System.IO.StreamReader file = new System.IO.StreamReader(srtLog.OpenReadStream()))
                {
                    int lineCount = 0;
                    int id        = 0;
                    while ((line = file.ReadLine()) != null)
                    {
                        int idTemp;
                        if (int.TryParse(line, out idTemp))
                        {
                            djiSrtVideoLogModel = new DjiSrtVideoLogModel();
                            id = idTemp;
                            lineCount++;
                        }
                        if (id >= 1)
                        {
                            switch (lineCount)
                            {
                            case 1:
                                djiSrtVideoLogModel.Id = id;
                                lineCount++;
                                break;

                            case 2:
                                djiSrtVideoLogModel = SrtConverter.GetTimeStamp(line, ref djiSrtVideoLogModel);
                                lineCount++;
                                break;

                            case 3:
                                djiSrtVideoLogModel = SrtConverter.GetHomePointAndDateTime(line, ref djiSrtVideoLogModel);
                                lineCount++;
                                break;

                            case 4:
                                djiSrtVideoLogModel = SrtConverter.GetGpsPointAndBarometer(line, ref djiSrtVideoLogModel);
                                lineCount++;
                                break;

                            case 5:
                                djiSrtVideoLogModel = SrtConverter.GetCameraInfo(line, ref djiSrtVideoLogModel);
                                djiSrtVideoLogModels.Add(djiSrtVideoLogModel);
                                lineCount = 0;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    if (djiSrtVideoLogModels.Any())
                    {
                        var csvVideoInfoModels       = CsvUtilities.ToCsv(",", djiSrtVideoLogModels);
                        var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(srtLog.FileName);
                        var saved = CsvUtilities.SaveCsvTofile(Path.Combine(@"C:\Temp\", $"{fileNameWithoutExtension}_resume.csv"), csvVideoInfoModels);

                        return(Ok("Ok creating Srt to Csv"));
                    }
                    else
                    {
                        return(BadRequest("djiSrtVideoLogModels dont have any record"));
                    }
                }
            }
            catch (Exception)
            {
                return(BadRequest("Problem saving Srt to csv"));
            }
        }