diff --git a/.gitignore b/.gitignore index d4a1236..99afb18 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,3 @@ fyne-cross/ # binary comics-downloader - diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d0c14..a16f916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +[Changes][v0.32.1] + + +# [0.32.1 (v0.32.1)](https://github.com/Girbons/comics-downloader/releases/tag/v0.32.1) - 20 Oct 2021 + +# Fixes + +- #94: Range option ignores non integers. -- (Thanks @Jan0660) + [Changes][v0.32.0] diff --git a/README.md b/README.md index 5258409..8bc3c0b 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ Download the latest release: -- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader) -- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-osx) -- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader.exe) -- [Linux ARM](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-linux-arm) -- [Linux ARM64](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-linux-arm64) +- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader) +- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-osx) +- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader.exe) +- [Linux ARM](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-linux-arm) +- [Linux ARM64](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-linux-arm64) Download the latest GUI release: -- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-gui) -- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-gui-osx) -- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.32.0/comics-downloader-gui-windows.exe) +- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-gui) +- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-gui-osx) +- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.32.1/comics-downloader-gui-windows.exe) ## Usage @@ -208,7 +208,6 @@ To avoid that use `-create-default-path` flag. - [soup](https://github.com/anaskhan96/soup) - [progressbar](https://github.com/schollz/progressbar) - [logrus](https://github.com/sirupsen/logrus) -- [mangadex](https://github.com/bake/mangadex) - [archiver](https://github.com/mholt/archiver) - [regexp2](https://github.com/dlclark/regexp2) diff --git a/cmd/app/downloader.go b/cmd/app/downloader.go index 0d31eab..771981e 100644 --- a/cmd/app/downloader.go +++ b/cmd/app/downloader.go @@ -11,6 +11,7 @@ import ( "github.com/Girbons/comics-downloader/internal/version" "github.com/Girbons/comics-downloader/pkg/config" "github.com/Girbons/comics-downloader/pkg/detector" + "github.com/Girbons/comics-downloader/pkg/http" "github.com/Girbons/comics-downloader/pkg/sites" "github.com/sirupsen/logrus" ) @@ -105,6 +106,7 @@ func GuiRun(options *config.Options) { // Run will start the CLI app func Run(options *config.Options) { options.Logger = logger.NewLogger(false, Messages) + options.Client = http.NewComicClient() // link is required if options.URL == "" { diff --git a/internal/version/version.go b/internal/version/version.go index 60d0923..3292a1e 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -9,7 +9,7 @@ import ( // Tag specifies the current release tag. // It needs to be manually updated. -const Tag = "v0.32.0" +const Tag = "v0.32.1" // IsNewAvailable will fetch the latest project releases // and will compare the latest release Tag against the current Tag. diff --git a/pkg/config/options.go b/pkg/config/options.go index d037fff..653182f 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -1,6 +1,9 @@ package config -import "github.com/Girbons/comics-downloader/internal/logger" +import ( + "github.com/Girbons/comics-downloader/internal/logger" + "github.com/Girbons/comics-downloader/pkg/http" +) // Options represents the comics downloader options. type Options struct { @@ -22,5 +25,6 @@ type Options struct { Source string IssuesRange string + Client *http.ComicClient Logger *logger.Logger } diff --git a/pkg/core/core.go b/pkg/core/core.go index 347d912..cbe726a 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -5,10 +5,8 @@ import ( "fmt" "image" "io/ioutil" - "net/http" "os" "strings" - "time" "golang.org/x/sync/errgroup" @@ -260,13 +258,6 @@ func (comic *Comic) DownloadImages(options *config.Options) (string, error) { return dir, err } - client := &http.Client{ - Transport: &http.Transport{ - MaxIdleConns: 11, - IdleConnTimeout: 30 * time.Second, - }, - } - g := new(errgroup.Group) for i, link := range comic.Links { @@ -278,13 +269,7 @@ func (comic *Comic) DownloadImages(options *config.Options) (string, error) { } g.Go(func() error { - req, err := http.NewRequest("GET", link, nil) - if err != nil { - return err - } - // we need this so that MangaKakalot doesn't 403 forbid the request - req.Header.Add("Referer", link) - rsp, err := client.Do(req) + rsp, err := options.Client.Get(link) if err != nil { return err } diff --git a/pkg/http/client.go b/pkg/http/client.go new file mode 100644 index 0000000..c7598e4 --- /dev/null +++ b/pkg/http/client.go @@ -0,0 +1,41 @@ +package http + +import ( + "net/http" + "strings" +) + +// ComicClient is the custom client. +type ComicClient struct { + Client *http.Client +} + +// NewComicClient returns a ComicClient instance. +func NewComicClient() *ComicClient { + return &ComicClient{ + Client: &http.Client{}, + } +} + +// PrepareRequest setup a `GET` request with customs headers. +func (c *ComicClient) PrepareRequest(link string) (*http.Request, error) { + req, err := http.NewRequest("GET", link, nil) + + if strings.Contains(link, "mangakakalot") { + // avoid that MangaKakalot forbids the request. + req.Header.Add("Referer", link) + } + + return req, err +} + +// GET Performs a Get request.. +func (c *ComicClient) Get(link string) (*http.Response, error) { + request, err := c.PrepareRequest(link) + + if err != nil { + return nil, err + } + + return c.Client.Do(request) +} diff --git a/pkg/http/client_test.go b/pkg/http/client_test.go new file mode 100644 index 0000000..3b31274 --- /dev/null +++ b/pkg/http/client_test.go @@ -0,0 +1,25 @@ +package http + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPrepareRequestMangakakalot(t *testing.T) { + cc := NewComicClient() + link := "http://mangakakalot.com" + req, err := cc.PrepareRequest(link) + + assert.Equal(t, req.Header["Referer"], []string{link}) + assert.Nil(t, err) +} + +func TestPrepareRequest(t *testing.T) { + cc := NewComicClient() + link := "http://foo.com" + req, err := cc.PrepareRequest(link) + + assert.Equal(t, len(req.Header["Referer"]), 0) + assert.Nil(t, err) +}