11// Package rtve provides a datasource implementation for fetching RTVE (Radio Televisión Española)
22// TV show episodes and their metadata using the rtve-go library.
33//
4+ // Logging: This datasource now uses the internal pkg/log wrapper.
5+ // - Routine progress messages -> Debugf (visible only when debug enabled globally or for the "rtve:<instance>" service)
6+ // - Warnings / recoverable issues -> Warnf
7+ //
48// This datasource allows fetching the latest episodes from RTVE shows by show ID,
59// with configurable limits on the number of episodes to retrieve.
610//
@@ -26,12 +30,13 @@ import (
2630 "encoding/json"
2731 "fmt"
2832 "io"
29- "log"
3033 "net/http"
3134 "regexp"
3235 "strings"
3336 "time"
3437
38+ "github.com/rubiojr/ergs/pkg/log"
39+
3540 "github.com/rubiojr/ergs/pkg/core"
3641 "github.com/rubiojr/rtve-go/api"
3742)
@@ -65,7 +70,7 @@ func parseVTTSubtitles(url string) (string, error) {
6570 }
6671 defer func () {
6772 if closeErr := resp .Body .Close (); closeErr != nil {
68- log .Printf ( "RTVE: Warning: failed to close response body: %v" , closeErr )
73+ log .ForService ( "rtve" ). Warnf ( " failed to close response body: %v" , closeErr )
6974 }
7075 }()
7176
@@ -296,7 +301,8 @@ func (d *Datasource) GetConfig() interface{} {
296301// - ctx: Context for cancellation and timeouts
297302// - blockCh: Channel to send created blocks through
298303func (d * Datasource ) FetchBlocks (ctx context.Context , blockCh chan <- core.Block ) error {
299- log .Printf ("RTVE: Fetching latest %d episodes from show '%s'" , d .config .MaxEpisodes , d .config .ShowID )
304+ l := log .ForService ("rtve:" + d .instanceName )
305+ l .Debugf ("Fetching latest %d episodes from show '%s'" , d .config .MaxEpisodes , d .config .ShowID )
300306
301307 // Create a visitor function that processes each video result
302308 // and sends it as a block through the channel
@@ -322,13 +328,13 @@ func (d *Datasource) FetchBlocks(ctx context.Context, blockCh chan<- core.Block)
322328 if sub .Lang == "es" && sub .Src != "" {
323329 jsonCues , err := parseVTTSubtitles (sub .Src )
324330 if err != nil {
325- log . Printf ( "RTVE: Warning: failed to fetch Spanish subtitles for video %s: %v" , result .Metadata .ID , err )
331+ l . Warnf ( " failed to fetch Spanish subtitles for video %s: %v" , result .Metadata .ID , err )
326332 } else {
327333 subtitleText = jsonCues
328334 // Count cues for logging
329335 var cues []VTTCue
330336 if json .Unmarshal ([]byte (jsonCues ), & cues ) == nil {
331- log . Printf ( "RTVE: Downloaded Spanish subtitles for '%s' (%d cues)" , result .Metadata .LongTitle , len (cues ))
337+ l . Debugf ( " Downloaded Spanish subtitles for '%s' (%d cues)" , result .Metadata .LongTitle , len (cues ))
332338 }
333339 }
334340 }
@@ -353,7 +359,7 @@ func (d *Datasource) FetchBlocks(ctx context.Context, blockCh chan<- core.Block)
353359 case <- ctx .Done ():
354360 return ctx .Err ()
355361 case blockCh <- block :
356- log . Printf ( "RTVE: Fetched episode '%s' (ID: %s)" , result .Metadata .LongTitle , result .Metadata .ID )
362+ l . Debugf ( " Fetched episode '%s' (ID: %s)" , result .Metadata .LongTitle , result .Metadata .ID )
357363 return nil
358364 }
359365 }
@@ -364,19 +370,19 @@ func (d *Datasource) FetchBlocks(ctx context.Context, blockCh chan<- core.Block)
364370 return fmt .Errorf ("error fetching RTVE show '%s': %w" , d .config .ShowID , err )
365371 }
366372
367- log . Printf ( "RTVE: Successfully fetched %d episodes from show '%s' (%d errors)" ,
373+ l . Debugf ( " Successfully fetched %d episodes from show '%s' (%d errors)" ,
368374 stats .VideosProcessed , d .config .ShowID , stats .ErrorCount )
369375
370376 // Log any non-fatal errors that occurred during fetching
371377 if stats .ErrorCount > 0 && len (stats .Errors ) > 0 {
372- log . Printf ( "RTVE: Encountered %d non-fatal errors:" , stats .ErrorCount )
378+ l . Warnf ( " Encountered %d non-fatal errors:" , stats .ErrorCount )
373379 for i , err := range stats .Errors {
374380 if i < 5 { // Limit to first 5 errors to avoid spam
375- log . Printf (" - %v" , err )
381+ l . Warnf (" - %v" , err )
376382 }
377383 }
378384 if len (stats .Errors ) > 5 {
379- log . Printf (" ... and %d more errors" , len (stats .Errors )- 5 )
385+ l . Warnf (" ... and %d more errors" , len (stats .Errors )- 5 )
380386 }
381387 }
382388
0 commit comments