Skip to content

Commit

Permalink
add hudbt site
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Nov 19, 2023
1 parent c875743 commit 2206b2c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/batchdl/batchdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func init() {
command.Flags().StringVarP(&minTorrentSizeStr, "min-torrent-size", "", "-1", "Skip torrent with size smaller than (<) this value. -1 == no limit")
command.Flags().StringVarP(&maxTorrentSizeStr, "max-torrent-size", "", "-1", "Skip torrent with size larger than (>) this value. -1 == no limit")
command.Flags().StringVarP(&maxTotalSizeStr, "max-total-size", "", "-1", "Will at most download torrents with total contents size of this value. -1 == no limit")
command.Flags().Int64VarP(&minSeeders, "min-seeders", "", -1, "Skip torrent with seeders less than (<) this value. -1 == no limit")
command.Flags().Int64VarP(&minSeeders, "min-seeders", "", 1, "Skip torrent with seeders less than (<) this value. -1 == no limit")
command.Flags().Int64VarP(&maxSeeders, "max-seeders", "", -1, "Skip torrent with seeders more than (>) this value. -1 == no limit")
command.Flags().StringVarP(&freeTimeAtLeastStr, "free-time", "", "", "Used with --free. Set the allowed minimal remaining torrent free time. eg. 12h, 1d")
command.Flags().StringVarP(&filter, "filter", "", "", "If set, skip torrent which name does NOT contains this string")
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type SiteConfigStruct struct {
UserAgent string `yaml:"userAgent"`
Ja3 string `yaml:"ja3"`
Proxy string `yaml:"proxy"`
Insecure bool `yaml:"insecure"` // 访问站点时跳过TLS证书安全校验
TorrentUploadSpeedLimit string `yaml:"torrentUploadSpeedLimit"`
GlobalHnR bool `yaml:"globalHnR"`
Timezone string `yaml:"timezone"`
Expand Down
37 changes: 22 additions & 15 deletions site/nexusphp/nexusphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ func (npclient *Site) GetAllTorrents(sort string, desc bool, pageMarker string,
return nil, "", fmt.Errorf("not logined (cookie may has expired)")
}

lastPage := int64(0)
if pageMarker == "" {
paginationEls := doc.Find(`*[href*="&page="]`)
lastPage := int64(0)
pageRegexp := regexp.MustCompile(`&page=(?P<page>\d+)`)
paginationEls.Each(func(i int, s *goquery.Selection) {
m := pageRegexp.FindStringSubmatch(s.AttrOr("href", ""))
Expand All @@ -192,20 +192,21 @@ func (npclient *Site) GetAllTorrents(sort string, desc bool, pageMarker string,
}
}
})
if lastPage > 0 {
page = lastPage
pageStr = "page=" + fmt.Sprint(page)
now = util.Now()
doc, res, error = util.GetUrlDoc(pageUrl+queryString+pageStr, npclient.HttpClient,
npclient.SiteConfig.Cookie, npclient.SiteConfig.UserAgent, nil)
if error != nil {
err = fmt.Errorf("failed to fetch torrents page dom: %v", error)
return
}
if res.Request.URL.Path == "/login.php" {
err = fmt.Errorf("not logined (cookie may has expired)")
return
}
}
labelLastPage:
if pageMarker == "" && lastPage > 0 {
page = lastPage
pageStr = "page=" + fmt.Sprint(page)
now = util.Now()
doc, res, error = util.GetUrlDoc(pageUrl+queryString+pageStr, npclient.HttpClient,
npclient.SiteConfig.Cookie, npclient.SiteConfig.UserAgent, nil)
if error != nil {
err = fmt.Errorf("failed to fetch torrents page dom: %v", error)
return
}
if res.Request.URL.Path == "/login.php" {
err = fmt.Errorf("not logined (cookie may has expired)")
return
}
}

Expand All @@ -214,6 +215,12 @@ func (npclient *Site) GetAllTorrents(sort string, desc bool, pageMarker string,
log.Tracef("Failed to get torrents from doc: %v", err)
return
}
// 部分站点(如蝴蝶)有 bug,分页栏的最后一页内容有时是空的
if pageMarker == "" && lastPage > 1 && len(torrents) == 0 {
lastPage--
log.Warnf("Last torrents page is empty, access second last page instead")
goto labelLastPage
}
if page > 0 {
nextPageMarker = fmt.Sprint(page - 1)
}
Expand Down
4 changes: 4 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package site

import (
"crypto/tls"
"fmt"
"io"
"mime"
Expand Down Expand Up @@ -221,6 +222,9 @@ func CreateSiteHttpClient(siteConfig *config.SiteConfigStruct, config *config.Co
}
transport.Proxy = http.ProxyURL(proxyUrl)
}
if siteConfig.Insecure {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
httpClient.Transport = transport
return httpClient, nil
}
Expand Down
9 changes: 9 additions & 0 deletions site/tpl/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ var (
TorrentsExtraUrls: []string{"live.php"},
Comment: "海棠",
},
"hudbt": {
Type: "nexusphp",
Url: "https://hudbt.hust.edu.cn/",
Insecure: true, // 该站点的 TLS 证书有问题 (2023-11 测试)
SelectorTorrent: `a[href*="/download.php?id="]`,
SelectorTorrentDetailsLink: `a[href*="/details.php?id="]`,
SelectorTorrentFree: `img.free, img.twoupfree`,
Comment: "蝴蝶",
},
"icc2022": {
Type: "nexusphp",
Aliases: []string{"icc"},
Expand Down

0 comments on commit 2206b2c

Please sign in to comment.