public override async Task Decode(EbmlParser parser, bool forceDecode = false) { if (Decoded && !forceDecode) { return; } if (parser == null) { throw new ArgumentNullException(nameof(parser)); } if (parser.DataAccessor == null) { throw new InvalidOperationException( ExceptionsResourceManager.ResourceManager.GetString("InvalidDecodeState", CultureInfo.CurrentCulture)); } var buffer = new byte[8]; parser.DataAccessor.Position = DataPosition; await parser.DataAccessor.ReadAsync(buffer, 0, (int)DataSize.DataSize).ConfigureAwait(false); Value = BitConverter.ToInt64(buffer, 0); Decoded = true; }
public async Task TestMethod1() { EbmlElementFactory.RegisterFactory(MatroskaIds.SegmentId.Size, new SegmentFactory()); var dataAccessor = new FileDataAccessor( @"C:\Users\jorge\source\repos\Otchi.Core\Otchi.Core.Console\bin\Debug\netcoreapp3.0\Downloads\[HorribleSubs] Radiant S2 - 06 [1080p].mkv"); var parser = new EbmlParser(dataAccessor); var document = await parser.ParseDocument(); Console.WriteLine(document); }
public async Task Decode(EbmlParser parser, bool force, bool recursive) { if (Decoded && !force) { return; } if (parser == null) { throw new ArgumentNullException(nameof(parser)); } if (parser.DataAccessor == null) { throw new InvalidOperationException( ExceptionsResourceManager.ResourceManager.GetString("InvalidDecodeState", CultureInfo.CurrentCulture)); } if (DataPosition >= EndPosition) { Console.WriteLine($"Element {this} contains no children"); return; } await _parserSemaphoreSlim.WaitAsync().ConfigureAwait(false); try { _parserPosition = DataPosition; while (_parserPosition < EndPosition) { var element = await parser.ParseElementAt(_parserPosition, Parent).ConfigureAwait(false); if (element == null) { _parserPosition = parser.DataAccessor.Position; continue; } if (recursive) { await element.Decode(parser).ConfigureAwait(false); } _parserPosition = parser.DataAccessor.Position; InsertElement(element); } Decoded = true; } finally { _parserSemaphoreSlim.Release(1); } }
public async Task <T> TryGetChild <T>(EbmlParser parser) where T : EbmlElement { if (parser == null) { throw new ArgumentNullException(nameof(parser)); } await foreach (var child in GetAsyncEnumerable(parser)) { if (child is T element) { return(element); } } throw new ParseFailedException("Could not parse child"); }
static async Task yeet() { var factoryList = new List <Dictionary <long, EbmlElementFactory> > { MatroskaFactories.MatroskaSegmentFactories, MatroskaFactories.AttachmentFactories, MatroskaFactories.ChapterFactories, MatroskaFactories.CueingDataFactories, MatroskaFactories.MetaSeekInformationFactories, MatroskaFactories.TaggingFactories, MatroskaFactories.TrackFactories, EbmlFactories.AllEbmlHeadFactories }; var factories = EbmlFactories.Merge(factoryList); var sw = new Stopwatch(); sw.Restart(); var dataAccessor = new FileDataAccessor(@"C:\Users\paravicinij\source\repos\Otchi.Core\Otchi.Core.Console\bin\Debug\netcoreapp3.0\Downloads\[HorribleSubs] Radiant S2 - 06 [1080p].mkv"); var parser = new EbmlParser(dataAccessor, factories); EbmlDocument?document = null; try { document = await parser.ParseDocument(false); await document.Head.Decode(parser); await foreach (var child in document.Body.GetAsyncEnumerable(parser)) { try { await(child?.Decode(parser) ?? Task.CompletedTask); } catch (DecodeException exception) { System.Console.WriteLine(exception.Message); } } } catch (DecodeException exception) { System.Console.WriteLine(exception.Message); } var seekHead = await document.Body.TryGetChild <SeekHead>(parser); foreach (var(key, value) in seekHead) { var seek = (Seek)value; System.Console.WriteLine($"Pos: {seek.SeekPosition} Id: {seek.SeekId:X}"); } }
public override async Task Decode(EbmlParser parser, bool forceDecode = false) { if (Decoded && !forceDecode) { return; } if (parser == null) { throw new ArgumentNullException(nameof(parser)); } if (parser.DataAccessor == null) { throw new InvalidOperationException( ExceptionsResourceManager.ResourceManager.GetString("InvalidDecodeState", CultureInfo.CurrentCulture)); } switch (DataSize.DataSize) { case 0: Value = 0; break; case 4: var floatBuffer = new byte[4]; parser.DataAccessor.Position = DataPosition; await parser.DataAccessor.ReadAsync(floatBuffer, 0, 4).ConfigureAwait(false); Utility.ConvertEndiannes(floatBuffer); Value = BitConverter.ToSingle(floatBuffer); break; case 8: var doubleBuffer = new byte[8]; parser.DataAccessor.Position = DataPosition; await parser.DataAccessor.ReadAsync(doubleBuffer, 0, 8).ConfigureAwait(false); Utility.ConvertEndiannes(doubleBuffer); Value = BitConverter.ToDouble(doubleBuffer); break; default: throw new DecodeException("Can not decode a decimal number that is not either 0, 4 or 8 bytes long"); } Decoded = true; }
public async Task <EbmlElement?> DecodeChildAt(EbmlParser parser, long index) { if (parser is null) { throw new ArgumentNullException(nameof(parser)); } if (index < DataPosition || index >= EndPosition) { throw new ArgumentOutOfRangeException(nameof(index)); } var child = await parser.ParseElementAt(index).ConfigureAwait(false); if (child != null) { InsertElement(child); } return(child); }
static async Task Meh() { var parser = new EbmlParser(new FileDataAccessor( @"F:\repos\Otchi.Core\Otchi.Core.Console\bin\Debug\netcoreapp3.0\Downloads\[HorribleSubs] Radiant S2 - 06 [1080p].mkv"), EbmlFactories.Merge(new[] { EbmlFactories.AllEbmlHeadFactories, MatroskaFactories.AllMatroskaFactories })); EbmlDocument?document = null; try { document = parser.ParseDocument(false).Result; document.Head.Decode(parser, true, true).Wait(); var seekHead = await document.Body.TryGetChild <SeekHead>(parser); await seekHead.Decode(parser); } catch (DecodeException) { System.Console.WriteLine($"Failed at: {parser.DataAccessor.Position}"); } System.Console.WriteLine(document); }
public async Task <EbmlElement?> DecodeNextChild(EbmlParser parser) { if (parser is null) { throw new ArgumentNullException(nameof(parser)); } var lastChild = _children.LastOrDefault().Value; if (lastChild.Position > EndPosition) { throw new EndOfMasterException(ExceptionsResourceManager.ResourceManager.GetString("NoChildLeft", CultureInfo.CurrentCulture)); } var index = lastChild.EndPosition; var child = await parser.ParseElementAt(index).ConfigureAwait(false); if (child != null) { InsertElement(child); } return(child); }
public async IAsyncEnumerable <EbmlElement?> GetAsyncEnumerable(EbmlParser parser) { if (parser == null) { throw new ArgumentNullException(nameof(parser)); } var position = DataPosition; while (position < EndPosition) { EbmlElement?child; if (_children.ContainsKey(position)) { child = _children[position]; } else { child = await DecodeChildAt(parser, position).ConfigureAwait(false); } position = child?.EndPosition ?? parser.DataAccessor.Position; yield return(child); } }
public override async Task Decode(EbmlParser parser, bool forceDecode = false) { await base.Decode(parser, forceDecode).ConfigureAwait(false); }
public override Task Decode(EbmlParser parser, bool forceDecode = false) { return(Decode(parser, forceDecode, true)); }
public abstract Task Decode(EbmlParser parser, bool forceDecode = false);