Skip to content

Commit 5de7496

Browse files
committed
chore: translate infos
perf: after finishing
1 parent 9f28cf5 commit 5de7496

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

cmd/start-concurrent-engine.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func main() {
3434

3535
var req *engine.Request
3636

37-
fmt.Println("欢迎使用B站视频下载器 v2022-05-01")
37+
fmt.Println("欢迎使用B站视频下载器 v1.0.1")
3838
fmt.Println("项目地址: https://github.com/laorange/FastestBilibiliDownloader")
3939
fmt.Println("原项目地址:https://github.com/sodaling/FastestBilibiliDownloader")
4040
fmt.Println("\n\n支持以下几种格式的输入:")
@@ -83,8 +83,10 @@ func main() {
8383

8484
queueScheduler := scheduler.NewConcurrentScheduler()
8585
conEngine := engine.NewConcurrentEngine(30, queueScheduler, itemChan)
86-
log.Println("Start working.")
86+
log.Println("开始下载...")
8787
conEngine.Run(req)
8888
wg.Wait()
89-
log.Println("All work has done")
89+
log.Print("所有视频均已下载完成。按 Ctrl+C 来退出程序。")
90+
var eof string
91+
fmt.Scan(&eof)
9092
}

fetcher/downloader.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ func GenVideoFetcher(video *model.Video) FetchFun {
4040

4141
resp, err := client.Do(request)
4242
if err != nil {
43-
log.Fatalf("Fail to download the video %d, err is %s", video.ParCid.Cid, err)
43+
log.Fatalf("下载 %d 时出错, 错误信息:%s", video.ParCid.Cid, err)
4444
return nil, err
4545
}
4646

4747
if resp.StatusCode != http.StatusPartialContent {
48-
log.Fatalf("Fail to download the video %d, status code is %d", video.ParCid.Cid, resp.StatusCode)
49-
return nil, fmt.Errorf("wrong status code: %d", resp.StatusCode)
48+
log.Fatalf("下载 %d 时出错, 错误码:%d", video.ParCid.Cid, resp.StatusCode)
49+
return nil, fmt.Errorf("错误码: %d", resp.StatusCode)
5050
}
5151
defer resp.Body.Close()
5252

@@ -59,18 +59,18 @@ func GenVideoFetcher(video *model.Video) FetchFun {
5959
}
6060
defer file.Close()
6161

62-
log.Println(video.ParCid.ParAid.Title + ":" + filename + " is downloading.")
62+
log.Println("正在下载:" + video.ParCid.ParAid.Title + "\\" + filename)
6363
_, err = io.Copy(file, resp.Body)
6464
if err != nil {
65-
log.Printf("Failed to download video aid: %d, cid: %d, title: %s, part: %s",
66-
video.ParCid.ParAid.Aid, video.ParCid.Cid, video.ParCid.ParAid.Title, video.ParCid.Part)
67-
log.Println("The error message is: ", err)
65+
log.Printf("下载失败 aid: %d, cid: %d, title: %s, part: %s",
66+
video.ParCid.ParAid.Aid, video.ParCid.Cid, video.ParCid.ParAid.Title, video.ParCid.Part)
67+
log.Println("错误信息:", err)
6868

6969
// request again
70-
go requestLater(file, resp, video)
70+
go requestLater(file, resp, video)
7171
return nil, err
7272
}
73-
log.Println(video.ParCid.ParAid.Title + ":" + filename + " has finished.")
73+
log.Println("下载完成:" + video.ParCid.ParAid.Title + "\\" + filename)
7474

7575
return nil, nil
7676
}
@@ -83,17 +83,15 @@ func genCheckRedirectfun(referer string) func(req *http.Request, via []*http.Req
8383
}
8484
}
8585

86-
func requestLater(file *os.File, resp *http.Response, video *model.Video) error{
86+
func requestLater(file *os.File, resp *http.Response, video *model.Video) error {
8787

88-
log.Println("Unable to open the file due to the remote host, request in 30 seconds.")
89-
time.Sleep(time.Second*30)
88+
log.Println("连接失败,30秒后重试 (Unable to open the file due to the remote host, request in 30 seconds)")
89+
time.Sleep(time.Second * 30)
9090

91-
_, err := io.Copy(file, resp.Body)
92-
if err != nil {
93-
log.Printf("Failed to download video aid: %d, cid: %d, title: %s, part: %s again",
94-
video.ParCid.ParAid.Aid, video.ParCid.Cid, video.ParCid.ParAid.Title, video.ParCid.Part)
95-
}
96-
return err
91+
_, err := io.Copy(file, resp.Body)
92+
if err != nil {
93+
log.Printf("下载失败 aid: %d, cid: %d, title: %s, part: %s again",
94+
video.ParCid.ParAid.Aid, video.ParCid.Cid, video.ParCid.ParAid.Title, video.ParCid.Part)
95+
}
96+
return err
9797
}
98-
99-

parser/cid.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package parser
33
import (
44
"crypto/md5"
55
"fmt"
6+
"github.com/tidwall/gjson"
67
"simple-golang-crawler/engine"
78
"simple-golang-crawler/fetcher"
89
"simple-golang-crawler/model"
910
"simple-golang-crawler/tool"
1011
"strconv"
11-
"github.com/tidwall/gjson"
1212
)
1313

14-
1514
var _entropy = "rbMCKn@KuamXWlPMoJGsKcbiJKUfkPF_8dABscJntvqhRSETg"
1615
var _paramsTemp = "appkey=%s&cid=%s&otype=json&qn=%s&quality=%s&type="
1716
var _playApiTemp = "https://interface.bilibili.com/v2/playurl?%s&sign=%s"
@@ -21,13 +20,13 @@ func GenGetAidChildrenParseFun(videoAid *model.VideoAid) engine.ParseFunc {
2120
return func(contents []byte, url string) engine.ParseResult {
2221

2322
var retParseResult engine.ParseResult
24-
if videoAid.Title == strconv.FormatInt(videoAid.Aid, 10) { // call from aid-related, we need to get the title of the video
25-
title := gjson.GetBytes(contents, "data.title").String()
26-
title = tool.TitleEdit(title) // remove special characters
27-
videoAid.Title = title
28-
}
23+
if videoAid.Title == strconv.FormatInt(videoAid.Aid, 10) { // call from aid-related, we need to get the title of the video
24+
title := gjson.GetBytes(contents, "data.title").String()
25+
title = tool.TitleEdit(title) // remove special characters
26+
videoAid.Title = title
27+
}
2928
data := gjson.GetBytes(contents, "data.pages").Array()
30-
fmt.Println("data",videoAid.Title)
29+
fmt.Println("即将开始下载:", videoAid.Title)
3130
appKey, sec := tool.GetAppKey(_entropy)
3231

3332
var videoTotalPage int64
@@ -64,4 +63,3 @@ func GetRequestByAid(aid int64) *engine.Request {
6463
req := engine.NewRequest(reqUrl, reqParseFunction, fetcher.DefaultFetcher)
6564
return req
6665
}
67-

0 commit comments

Comments
 (0)