Skip to content

Commit

Permalink
update 弹出浏览器
Browse files Browse the repository at this point in the history
  • Loading branch information
zhudw committed Jan 16, 2024
1 parent 2b55998 commit abec36b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/cuhk.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *Cuhk) Init(iTask int, sUrl string) (msg string, err error) {
return "requested URL was not found.", err
}
r.dt.Jar, _ = cookiejar.New(nil)
OpenWebBrowser(sUrl, nil)
OpenWebBrowser(sUrl, []string{})
return r.download()
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func (r *Cuhk) do(imgUrls []string) (msg string, err error) {
if err == nil && resp.GetStatusCode() == 200 {
break
}
OpenWebBrowser(r.dt.Url, nil)
WaitNewCookie()
}
util.PrintSleepTime(config.Conf.Speed)
fmt.Println()
Expand Down
41 changes: 32 additions & 9 deletions app/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,47 @@ func CreateDirectory(domain, bookId, volumeId string) string {
}

func OpenWebBrowser(sUrl string, args []string) {
_ = os.Remove(config.Conf.CookieFile)
var wg sync.WaitGroup
wg.Add(1)

wg.Add(2)
go func() {
defer wg.Done()
argv := []string{sUrl}
if args != nil {
argv = append(argv, args...)
}
if ret := util.OpenGUI(argv); ret == true {
for i := 0; i < 600; i++ {
if FileExist(config.Conf.CookieFile) {
break
}
fmt.Printf("请在打开的浏览器中,完成登录用户,并且“刷新”网页.\r")
time.Sleep(time.Second * 3)
return
}
}()

//WaitNewCookie
_ = os.Remove(config.Conf.CookieFile)
go func() {
defer wg.Done()
for i := 0; i < 3600; i++ {
if FileExist(config.Conf.CookieFile) {
break
}
fmt.Printf("请使用 bookget-gui 浏览器,打开图书网址,完成「真人验证 / 登录用户」,然后 「刷新」 网页.\r")
time.Sleep(time.Second * 3)
}
}()

wg.Wait()
}

func WaitNewCookie() {
_ = os.Remove(config.Conf.CookieFile)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 3600; i++ {
if FileExist(config.Conf.CookieFile) {
break
}
fmt.Printf("请使用 bookget-gui 浏览器,打开图书网址,完成「真人验证 / 登录用户」,然后 「刷新」 网页.\r")
time.Sleep(time.Second * 3)
}
}()
wg.Wait()
Expand Down
1 change: 1 addition & 0 deletions app/familysearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (r *Familysearch) Init(iTask int, sUrl string) (msg string, err error) {
r.dt.Jar, _ = cookiejar.New(nil)
// "https://www.familysearch.org/search/filmdata/filmdatainfo"
r.apiUrl = r.dt.UrlParsed.Scheme + "://" + r.dt.UrlParsed.Host + "/search/filmdata/filmdatainfo"
WaitNewCookie()
return r.download()
}

Expand Down

0 comments on commit abec36b

Please sign in to comment.