Skip to content

Commit

Permalink
fix: add more linters and address problems
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhizhen committed Feb 2, 2023
1 parent 32f3462 commit 4ccdd13
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ linter-settings:

linters:
enable:
- bodyclose
- errcheck
- goconst
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- nilerr
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

issues:
exclude-use-default: false
Expand Down
2 changes: 0 additions & 2 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func New(option Options) *Downloader {

// caption downloads danmaku, subtitles, etc
func (downloader *Downloader) caption(url, fileName, ext string, transform func([]byte) ([]byte, error)) error {

refer := downloader.option.Refer
if refer == "" {
refer = url
Expand Down Expand Up @@ -358,7 +357,6 @@ func (downloader *Downloader) multiThreadSave(dataPart *extractors.Part, refer,
} else {
chunkSize = int64(downloader.option.ChunkSizeMB) * 1024 * 1024
}
end = computeEnd(part.Cur, chunkSize, part.End)
remainingSize := part.End - part.Cur + 1
if part.Cur == part.Start {
// Only write part to new file.
Expand Down
1 change: 0 additions & 1 deletion extractors/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ func getSubTitleCaptionPart(aid int, cid int) *extractors.CaptionPart {
},
Transform: subtitleTransform,
}

}

func subtitleTransform(body []byte) ([]byte, error) {
Expand Down
1 change: 1 addition & 0 deletions extractors/douyin/douyin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
if err != nil {
return nil, errors.WithStack(err)
}
defer resp.Body.Close() // nolint
url = resp.Header.Get("location")
}

Expand Down
2 changes: 1 addition & 1 deletion extractors/geekbang/geekbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (e *extractor) Extract(url string, _ extractors.Options) ([]*extractors.Dat
}

// Get video license token information
params = strings.NewReader("{\"source_type\":1,\"aid\":" + string(matches[2]) + ",\"video_id\":\"" + string(data.Data.VideoID) + "\"}")
params = strings.NewReader("{\"source_type\":1,\"aid\":" + matches[2] + ",\"video_id\":\"" + data.Data.VideoID + "\"}")
res, err = request.Request(http.MethodPost, "https://time.geekbang.org/serv/v3/source_auth/video_play_auth", params, heanders)
if err != nil {
return nil, errors.WithStack(err)
Expand Down
4 changes: 1 addition & 3 deletions extractors/ixigua/ixigua.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
if err != nil {
return nil, errors.WithStack(err)
}

defer resp.Body.Close() // nolint
// follow redirects, https://stackoverflow.com/a/16785343
finalURL = resp.Request.URL.String()
}
Expand All @@ -86,7 +86,6 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
query, err := gojq.Parse("{title: .data.title} + {qualities: [.data.videoResource.normal.video_list | .[] | {url: .main_url, size: .size, ext: .vtype, quality: .definition}]}")
if err != nil {
return nil, errors.WithStack(err)

}

video := Video{}
Expand Down Expand Up @@ -135,7 +134,6 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
URL: url,
},
}, nil

}

func base64Decode(t string) string {
Expand Down
3 changes: 2 additions & 1 deletion extractors/weibo/weibo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func getXSRFToken() (string, error) {
}
url := "https://weibo.com/ajax/getversion"
req, err := http.NewRequest(http.MethodHead, url, nil)

if err != nil {
return "", err
}
Expand All @@ -54,6 +53,8 @@ func getXSRFToken() (string, error) {
if err != nil {
return "", err
}
defer res.Body.Close() // nolint

token := utils.MatchOneOf(res.Header.Get("Set-Cookie"), `XSRF-TOKEN=(.+?);`)[1]
return token, nil
}
Expand Down
1 change: 0 additions & 1 deletion extractors/xinpianchang/xinpianchang.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
URL: url,
},
}, nil

}
1 change: 0 additions & 1 deletion extractors/youku/youku.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func youkuUps(vid string, option extractors.Options) (*youkuData, error) {
)
if strings.Contains(option.Cookie, "cna") {
utids = utils.MatchOneOf(option.Cookie, `cna=(.+?);`, `cna\s+(.+?)\s`, `cna\s+(.+?)$`)

} else {
headers, err := request.Headers("http://log.mmstat.com/eg.js", youkuReferer)
if err != nil {
Expand Down

0 comments on commit 4ccdd13

Please sign in to comment.