diff --git a/common/fetch/fetch.go b/common/fetch/fetch.go index 589cfc81..99fc5c5f 100644 --- a/common/fetch/fetch.go +++ b/common/fetch/fetch.go @@ -1,6 +1,7 @@ package fetch import ( + "crypto/tls" "io" "net/http" "net/http/cookiejar" @@ -36,6 +37,10 @@ type Config struct { // Custom HTTP Transport. Transport http.RoundTripper + + // Skip TLS verification. Applies only + // to *http.Transport based transport. + SkipVerify bool } type Fetcher struct { @@ -82,6 +87,15 @@ func Default(cfg *Config) *Fetcher { if cfg.Transport != nil { c.HTTPClient.Transport = cfg.Transport } + if cfg.SkipVerify { + if transport, ok := c.HTTPClient.Transport.(*http.Transport); ok { + if transport.TLSClientConfig == nil { + // init TLS config if is nil. + transport.TLSClientConfig = &tls.Config{} + } + transport.TLSClientConfig.InsecureSkipVerify = true + } + } return New(c.StandardClient(), cfg) } diff --git a/provider/avbase/avbase.go b/provider/avbase/avbase.go index 9cbcb05b..a90b8ca8 100644 --- a/provider/avbase/avbase.go +++ b/provider/avbase/avbase.go @@ -12,6 +12,7 @@ import ( "github.com/gocolly/colly/v2" + "github.com/metatube-community/metatube-sdk-go/common/fetch" "github.com/metatube-community/metatube-sdk-go/common/number" "github.com/metatube-community/metatube-sdk-go/common/parser" "github.com/metatube-community/metatube-sdk-go/common/singledo" @@ -43,6 +44,7 @@ const ( ) type AVBase struct { + *fetch.Fetcher *scraper.Scraper single *singledo.Single providers map[string]provider.MovieProvider @@ -50,6 +52,7 @@ type AVBase struct { func New() *AVBase { return &AVBase{ + Fetcher: fetch.Default(&fetch.Config{SkipVerify: true}), Scraper: scraper.NewDefaultScraper(Name, baseURL, Priority, scraper.WithHeaders(map[string]string{ "Referer": baseURL,