Skip to content

Commit

Permalink
Allow overwriting ytchannel default http client
Browse files Browse the repository at this point in the history
  • Loading branch information
xoltia committed Nov 25, 2023
1 parent 2af9b33 commit 01c5811
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/ytchannel/ytchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
)

var client = http.DefaultClient
var HTTPClient = http.DefaultClient
var ytInitialDataRegex = regexp.MustCompile(`var ytInitialData\s*=\s*(\{.+?\});`)

var ErrInvalidChannelIdentifier = errors.New("invalid channel identifier string, you should either provide a handle (starting with '@') or an ID (starting with 'UC')")
Expand Down Expand Up @@ -73,7 +73,7 @@ func GetYoutubeChannel(ctx context.Context, handle string) (ch *Channel, err err
return
}

resp, err := client.Do(req)
resp, err := HTTPClient.Do(req)

if err != nil {
return
Expand All @@ -87,10 +87,10 @@ func GetYoutubeChannel(ctx context.Context, handle string) (ch *Channel, err err
return
}

data := ytInitialDataRegex.FindSubmatch(body)

var initialData ytInitialData

data := ytInitialDataRegex.FindSubmatch(body)

if len(data) < 2 {
err = ErrYtInitialDataNotFound
return
Expand Down

0 comments on commit 01c5811

Please sign in to comment.