示例#1
0
        public void UpdateTimings()
        {
            var xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
                <RawMovie_t xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
                  <SourceFiles>
                    <MediaSourceFile_t>
                      <DurationTicks>123600000</DurationTicks>
                    </MediaSourceFile_t>
                  </SourceFiles>
                  <CreateDate>2019-06-08T04:03:47Z</CreateDate>
                  <MediaTimeMappings />
                </RawMovie_t>";

            var expectedDoc = new XmlDocument();

            // 12.36 second clip starting at 04:03:47
            expectedDoc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                <RawMovie_t xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
                  <SourceFiles>
                    <MediaSourceFile_t>
                      <DurationTicks>123600000</DurationTicks>
                    </MediaSourceFile_t>
                  </SourceFiles>
                  <CreateDate>2019-06-08T04:03:47Z</CreateDate>
                  <MediaTimeMappings>
                    <MediaTimeMapping_t>
                      <TelemetryTime>2019-06-08T04:03:47.0000000Z</TelemetryTime>
                      <MediaTimeTicks>0</MediaTimeTicks>
                    </MediaTimeMapping_t>
                    <MediaTimeMapping_t>
                      <TelemetryTime>2019-06-08T04:03:59.3600000Z</TelemetryTime>
                      <MediaTimeTicks>123600000</MediaTimeTicks>
                    </MediaTimeMapping_t>
                  </MediaTimeMappings>
                </RawMovie_t>");

            var result = _videoXml.UpdateTimings(xml);

            var actualDoc = new XmlDocument();

            actualDoc.LoadXml(result);

            Assert.Equal(expectedDoc.OuterXml, actualDoc.OuterXml);
        }
示例#2
0
        static async Task Main(string[] args)
        {
            string appData         = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var    virbDatabase    = Path.Combine(appData, "GARMIN\\VIRB Edit\\Database\\7");
            var    rawMovies       = Path.Combine(virbDatabase, "RawMovies");
            var    videoXml        = new VideoXml();
            string scanResultToUse = null;

            foreach (var clipDirectory in Directory.EnumerateDirectories(rawMovies))
            {
                var videoXmlPath = Path.Combine(clipDirectory, "video.xml");
                var videoXmlFile = await File.ReadAllTextAsync(videoXmlPath);

                var scanResult = videoXml.ScanForGMetrix(videoXmlFile);

                if (scanResult != null)
                {
                    scanResultToUse = scanResult;
                }
            }

            if (scanResultToUse == null)
            {
                throw new ScanException("Did not find any video clip with G-Metrix connected.");
            }

            Console.WriteLine($"Will use the following G-Metrix data on all clips:\n{scanResultToUse}\n");

            foreach (var clipDirectory in Directory.EnumerateDirectories(rawMovies))
            {
                var videoXmlPath = Path.Combine(clipDirectory, "video.xml");
                var videoXmlFile = await File.ReadAllTextAsync(videoXmlPath);

                var updatedFile = videoXml.SetGMetrix(videoXmlFile, scanResultToUse);
                updatedFile = videoXml.UpdateTimings(updatedFile);
                await File.WriteAllTextAsync(videoXmlPath, updatedFile);
            }

            Console.WriteLine("Updated all clips.");
        }