Skip to content

Commit

Permalink
Prepare v0.32.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Girbons committed Oct 20, 2021
1 parent 9160a6e commit 85bc2a6
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ fyne-cross/

# binary
comics-downloader

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[Changes][v0.32.1]
<a name="v0.32.1"></a>

# [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]
<a name="v0.32.0"></a>

Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions cmd/app/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 == "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion pkg/config/options.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -22,5 +25,6 @@ type Options struct {
Source string
IssuesRange string

Client *http.ComicClient
Logger *logger.Logger
}
17 changes: 1 addition & 16 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"fmt"
"image"
"io/ioutil"
"net/http"
"os"
"strings"
"time"

"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
41 changes: 41 additions & 0 deletions pkg/http/client.go
Original file line number Diff line number Diff line change
@@ -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") {

This comment has been minimized.

Copy link
@Jan0660

Jan0660 Apr 3, 2022

Contributor

Why check the link here? I recall it didn't break the other sites when I added it.
Since Mangakakalot and the other sites' image urls are on random domains the if statement is false, the Referer header doesn't get added and the response's body is error code: 1020.

This comment has been minimized.

Copy link
@Girbons

Girbons Apr 3, 2022

Author Owner

I Thought it was the right place to manage the http client.

Since Mangakakalot and the other sites' image urls are on random domains the if statement is false, the Referer header doesn't get added and the response's body is error code: 1020.

My bad here, you're right, I didn't recall that the images were taken from random domains.

The if statatement can be removed or this header can be set when mangakakalot is detected as source.

// 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)
}
25 changes: 25 additions & 0 deletions pkg/http/client_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 85bc2a6

Please sign in to comment.