@@ -379,13 +379,13 @@ func NewCSTVBroadcastParserWithConfig(baseUrl string, config ParserConfig) (Pars
379379 return NewParserWithConfig (r , config ), nil
380380}
381381
382- type ConfigureParserCallback func (Parser ) error
382+ type ParserCallback func (Parser ) error
383383
384384// ParseWithConfig parses a demo from the given io.Reader with a custom configuration.
385385// The handler is called with the Parser instance.
386386//
387387// Returns an error if the parser encounters an error.
388- func ParseWithConfig (r io.Reader , config ParserConfig , configure ConfigureParserCallback ) error {
388+ func ParseWithConfig (r io.Reader , config ParserConfig , configure ParserCallback ) error {
389389 p := NewParserWithConfig (r , config )
390390 defer p .Close ()
391391
@@ -406,15 +406,15 @@ func ParseWithConfig(r io.Reader, config ParserConfig, configure ConfigureParser
406406// The handler is called with the Parser instance.
407407//
408408// Returns an error if the parser encounters an error.
409- func Parse (r io.Reader , configure ConfigureParserCallback ) error {
409+ func Parse (r io.Reader , configure ParserCallback ) error {
410410 return ParseWithConfig (r , DefaultParserConfig , configure )
411411}
412412
413413// ParseFileWithConfig parses a demo file at the given path with a custom configuration.
414414// The handler is called with the Parser instance.
415415//
416416// Returns an error if the file can't be opened or if the parser encounters an error.
417- func ParseFileWithConfig (path string , config ParserConfig , configure ConfigureParserCallback ) error {
417+ func ParseFileWithConfig (path string , config ParserConfig , configure ParserCallback ) error {
418418 f , err := os .Open (path )
419419 if err != nil {
420420 return fmt .Errorf ("failed to open file: %w" , err )
@@ -429,10 +429,45 @@ func ParseFileWithConfig(path string, config ParserConfig, configure ConfigurePa
429429// The handler is called with the Parser instance.
430430//
431431// Returns an error if the file can't be opened or if the parser encounters an error.
432- func ParseFile (path string , configure ConfigureParserCallback ) error {
432+ func ParseFile (path string , configure ParserCallback ) error {
433433 return ParseFileWithConfig (path , DefaultParserConfig , configure )
434434}
435435
436+ // ParseCSTVBroadcastWithConfig parses a live CSTV broadcast from the given base URL with a custom configuration.
437+ // The handler is called with the Parser instance.
438+ // The baseUrl is the base URL of the CSTV broadcast, e.g. "http://localhost:8080/s85568392932860274t1733091777".
439+ // Returns an error if the CSTV reader can't be created or if the parser encounters an error.
440+ // Note that the CSTV broadcast is a live stream and will not end until the broadcast ends.
441+ func ParseCSTVBroadcastWithConfig (baseUrl string , config ParserConfig , configure ParserCallback ) error {
442+ p , err := NewCSTVBroadcastParserWithConfig (baseUrl , config )
443+ if err != nil {
444+ return fmt .Errorf ("failed to create CSTV broadcast parser: %w" , err )
445+ }
446+
447+ defer p .Close ()
448+
449+ err = configure (p )
450+ if err != nil {
451+ return fmt .Errorf ("failed to configure parser: %w" , err )
452+ }
453+
454+ err = p .ParseToEnd ()
455+ if err != nil {
456+ return fmt .Errorf ("failed to parse CSTV broadcast: %w" , err )
457+ }
458+
459+ return nil
460+ }
461+
462+ // ParseCSTVBroadcast parses a live CSTV broadcast from the given base URL.
463+ // The handler is called with the Parser instance.
464+ // The baseUrl is the base URL of the CSTV broadcast, e.g. "http://localhost:8080/s85568392932860274t1733091777".
465+ // Returns an error if the CSTV reader can't be created or if the parser encounters an error.
466+ // Note that the CSTV broadcast is a live stream and will not end until the broadcast ends.
467+ func ParseCSTVBroadcast (baseUrl string , configure ParserCallback ) error {
468+ return ParseCSTVBroadcastWithConfig (baseUrl , DefaultParserConfig , configure )
469+ }
470+
436471// ParserConfig contains the configuration for creating a new Parser.
437472type ParserConfig struct {
438473 // MsgQueueBufferSize defines the size of the internal net-message queue.
0 commit comments