|
@@ -5,8 +5,11 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
|
"github.com/Tnze/go.num/v2/zh"
|
|
|
- "github.com/allanpk716/ChineseSubFinder/common"
|
|
|
- "github.com/allanpk716/ChineseSubFinder/model"
|
|
|
+ common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/pkg"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/types"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/types/series"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
|
|
|
"github.com/go-rod/rod"
|
|
|
"github.com/go-rod/rod/lib/launcher"
|
|
|
"github.com/go-rod/rod/lib/proto"
|
|
@@ -25,17 +28,17 @@ import (
|
|
|
)
|
|
|
|
|
|
type Supplier struct {
|
|
|
- reqParam common.ReqParam
|
|
|
+ reqParam types.ReqParam
|
|
|
log *logrus.Logger
|
|
|
topic int
|
|
|
rodLauncher *launcher.Launcher
|
|
|
}
|
|
|
|
|
|
-func NewSupplier(_reqParam ...common.ReqParam) *Supplier {
|
|
|
+func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
|
|
|
|
|
|
sup := Supplier{}
|
|
|
- sup.log = model.GetLogger()
|
|
|
- sup.topic = common.DownloadSubsPerSite
|
|
|
+ sup.log = pkg.GetLogger()
|
|
|
+ sup.topic = common2.DownloadSubsPerSite
|
|
|
if len(_reqParam) > 0 {
|
|
|
sup.reqParam = _reqParam[0]
|
|
|
if sup.reqParam.Topic > 0 && sup.reqParam.Topic != sup.topic {
|
|
@@ -46,20 +49,20 @@ func NewSupplier(_reqParam ...common.ReqParam) *Supplier {
|
|
|
}
|
|
|
|
|
|
func (s Supplier) GetSupplierName() string {
|
|
|
- return common.SubSiteSubHd
|
|
|
+ return common2.SubSiteSubHd
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) GetReqParam() common.ReqParam{
|
|
|
+func (s Supplier) GetReqParam() types.ReqParam {
|
|
|
return s.reqParam
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) GetSubListFromFile4Movie(filePath string) ([]common.SupplierSubInfo, error){
|
|
|
+func (s Supplier) GetSubListFromFile4Movie(filePath string) ([]supplier.SubInfo, error){
|
|
|
return s.getSubListFromFile4Movie(filePath)
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) GetSubListFromFile4Series(seriesInfo *common.SeriesInfo) ([]common.SupplierSubInfo, error) {
|
|
|
+func (s Supplier) GetSubListFromFile4Series(seriesInfo *series.SeriesInfo) ([]supplier.SubInfo, error) {
|
|
|
|
|
|
- var subInfos = make([]common.SupplierSubInfo, 0)
|
|
|
+ var subInfos = make([]supplier.SubInfo, 0)
|
|
|
var subList = make([]HdListItem, 0)
|
|
|
for value := range seriesInfo.NeedDlSeasonDict {
|
|
|
// 第一级界面,找到影片的详情界面
|
|
@@ -99,7 +102,7 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *common.SeriesInfo) ([]co
|
|
|
// 下载字幕
|
|
|
var browser *rod.Browser
|
|
|
// 是用本地的 Browser 还是远程的,推荐是远程的
|
|
|
- browser, err := model.NewBrowser(s.reqParam.HttpProxy)
|
|
|
+ browser, err := pkg.NewBrowser(s.reqParam.HttpProxy)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -110,7 +113,7 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *common.SeriesInfo) ([]co
|
|
|
s.log.Errorln("subhd step2Ex", err)
|
|
|
continue
|
|
|
}
|
|
|
- oneSubInfo := common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, common.ChineseSimple, model.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0,
|
|
|
+ oneSubInfo := supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common2.SubSubHDRootUrl, item.Url), 0,
|
|
|
0, hdContent.Ext, hdContent.Data)
|
|
|
oneSubInfo.Season = item.Season
|
|
|
oneSubInfo.Episode = item.Episode
|
|
@@ -120,11 +123,11 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *common.SeriesInfo) ([]co
|
|
|
return subInfos, nil
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) GetSubListFromFile4Anime(seriesInfo *common.SeriesInfo) ([]common.SupplierSubInfo, error){
|
|
|
+func (s Supplier) GetSubListFromFile4Anime(seriesInfo *series.SeriesInfo) ([]supplier.SubInfo, error){
|
|
|
panic("not implemented")
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) getSubListFromFile4Movie(filePath string) ([]common.SupplierSubInfo, error) {
|
|
|
+func (s Supplier) getSubListFromFile4Movie(filePath string) ([]supplier.SubInfo, error) {
|
|
|
/*
|
|
|
虽然是传入视频文件路径,但是其实需要读取对应的视频文件目录下的
|
|
|
movie.xml 以及 *.nfo,找到 IMDB id
|
|
@@ -132,19 +135,19 @@ func (s Supplier) getSubListFromFile4Movie(filePath string) ([]common.SupplierSu
|
|
|
如果找不到,再靠文件名提取影片名称去查找
|
|
|
*/
|
|
|
// 得到这个视频文件名中的信息
|
|
|
- info, _, err := model.GetVideoInfoFromFileFullPath(filePath)
|
|
|
+ info, _, err := pkg.GetVideoInfoFromFileFullPath(filePath)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 找到这个视频文件,尝试得到 IMDB ID
|
|
|
// 目前测试来看,加入 年 这个关键词去搜索,对 2020 年后的影片有利,因为网站有统一的详细页面了,而之前的,没有,会影响识别
|
|
|
// 所以,year >= 2020 年,则可以多加一个关键词(年)去搜索影片
|
|
|
- imdbInfo, err := model.GetImdbInfo4Movie(filePath)
|
|
|
+ imdbInfo, err := pkg.GetImdbInfo4Movie(filePath)
|
|
|
if err != nil {
|
|
|
// 允许的错误,跳过,继续进行文件名的搜索
|
|
|
s.log.Errorln("model.GetImdbInfo", err)
|
|
|
}
|
|
|
- var subInfoList []common.SupplierSubInfo
|
|
|
+ var subInfoList []supplier.SubInfo
|
|
|
|
|
|
if imdbInfo.ImdbId != "" {
|
|
|
// 先用 imdb id 找
|
|
@@ -160,7 +163,7 @@ func (s Supplier) getSubListFromFile4Movie(filePath string) ([]common.SupplierSu
|
|
|
}
|
|
|
}
|
|
|
// 如果没有,那么就用文件名查找
|
|
|
- searchKeyword := model.VideoNameSearchKeywordMaker(info.Title, imdbInfo.Year)
|
|
|
+ searchKeyword := pkg.VideoNameSearchKeywordMaker(info.Title, imdbInfo.Year)
|
|
|
subInfoList, err = s.getSubListFromKeyword4Movie(searchKeyword)
|
|
|
if err != nil {
|
|
|
s.log.Errorln(s.GetSupplierName(), "keyword:", searchKeyword)
|
|
@@ -170,9 +173,9 @@ func (s Supplier) getSubListFromFile4Movie(filePath string) ([]common.SupplierSu
|
|
|
return subInfoList, nil
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]common.SupplierSubInfo, error) {
|
|
|
+func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]supplier.SubInfo, error) {
|
|
|
|
|
|
- var subInfos []common.SupplierSubInfo
|
|
|
+ var subInfos []supplier.SubInfo
|
|
|
detailPageUrl, err := s.step0(keyword)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -188,7 +191,7 @@ func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]common.Supplier
|
|
|
|
|
|
var browser *rod.Browser
|
|
|
// 是用本地的 Browser 还是远程的,推荐是远程的
|
|
|
- browser, err = model.NewBrowser(s.reqParam.HttpProxy)
|
|
|
+ browser, err = pkg.NewBrowser(s.reqParam.HttpProxy)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -201,27 +204,27 @@ func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]common.Supplier
|
|
|
s.log.Errorln("step2Ex", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
- subInfos = append(subInfos, *common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, common.ChineseSimple, model.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
|
|
|
+ subInfos = append(subInfos, *supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common2.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
|
|
|
}
|
|
|
|
|
|
return subInfos, nil
|
|
|
}
|
|
|
|
|
|
-func (s Supplier) whichEpisodeNeedDownloadSub(seriesInfo *common.SeriesInfo, allSubList []HdListItem) []HdListItem {
|
|
|
+func (s Supplier) whichEpisodeNeedDownloadSub(seriesInfo *series.SeriesInfo, allSubList []HdListItem) []HdListItem {
|
|
|
// 字幕很多,考虑效率,需要做成字典
|
|
|
// key SxEx - SubInfos
|
|
|
- var allSubDict = make(map[string][]HdListItem )
|
|
|
+ var allSubDict = make(map[string][]HdListItem)
|
|
|
// 全季的字幕列表
|
|
|
- var oneSeasonSubDict = make(map[string][]HdListItem )
|
|
|
+ var oneSeasonSubDict = make(map[string][]HdListItem)
|
|
|
for _, subInfo := range allSubList {
|
|
|
- _, season, episode, err := model.GetSeasonAndEpisodeFromSubFileName(subInfo.Title)
|
|
|
+ _, season, episode, err := pkg.GetSeasonAndEpisodeFromSubFileName(subInfo.Title)
|
|
|
if err != nil {
|
|
|
s.log.Errorln("whichEpisodeNeedDownloadSub.GetVideoInfoFromFileFullPath", subInfo.Title, err)
|
|
|
continue
|
|
|
}
|
|
|
subInfo.Season = season
|
|
|
subInfo.Episode = episode
|
|
|
- epsKey := model.GetEpisodeKeyName(season, episode)
|
|
|
+ epsKey := pkg.GetEpisodeKeyName(season, episode)
|
|
|
_, ok := allSubDict[epsKey]
|
|
|
if ok == false {
|
|
|
// 初始化
|
|
@@ -266,11 +269,11 @@ func (s Supplier) step0(keyword string) (string, error) {
|
|
|
var err error
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- model.Notify.Add("subhd_step0", err.Error())
|
|
|
+ pkg.Notify.Add("subhd_step0", err.Error())
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- result, err := s.httpGet(fmt.Sprintf(common.SubSubHDSearchUrl, url.QueryEscape(keyword)))
|
|
|
+ result, err := s.httpGet(fmt.Sprintf(common2.SubSubHDSearchUrl, url.QueryEscape(keyword)))
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
@@ -278,9 +281,9 @@ func (s Supplier) step0(keyword string) (string, error) {
|
|
|
re := regexp.MustCompile(`共\s*(\d+)\s*条`)
|
|
|
matched := re.FindAllStringSubmatch(result, -1)
|
|
|
if len(matched) < 1 {
|
|
|
- return "", common.SubHDStep0SubCountElementNotFound
|
|
|
+ return "", common2.SubHDStep0SubCountElementNotFound
|
|
|
}
|
|
|
- subCount, err := model.GetNumber2int(matched[0][0])
|
|
|
+ subCount, err := pkg.GetNumber2int(matched[0][0])
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
@@ -298,7 +301,7 @@ func (s Supplier) step0(keyword string) (string, error) {
|
|
|
if ok == true{
|
|
|
|
|
|
if len(imgSelection.Nodes) < 2 {
|
|
|
- return "", common.SubHDStep0ImgParentLessThan2
|
|
|
+ return "", common2.SubHDStep0ImgParentLessThan2
|
|
|
}
|
|
|
step1Url := ""
|
|
|
if imgSelection.Nodes[0].Parent.Data == "a" {
|
|
@@ -319,7 +322,7 @@ func (s Supplier) step0(keyword string) (string, error) {
|
|
|
}
|
|
|
}
|
|
|
if step1Url == "" {
|
|
|
- return "", common.SubHDStep0HrefIsNull
|
|
|
+ return "", common2.SubHDStep0HrefIsNull
|
|
|
}
|
|
|
return step1Url, nil
|
|
|
//imgName := filepath.Base(imgUrl)
|
|
@@ -331,7 +334,7 @@ func (s Supplier) step0(keyword string) (string, error) {
|
|
|
// return "/d/" + strings.ReplaceAll(imgName, imgExt, ""), nil
|
|
|
//}
|
|
|
} else{
|
|
|
- return "", common.SubHDStep0HrefIsNull
|
|
|
+ return "", common2.SubHDStep0HrefIsNull
|
|
|
}
|
|
|
//re = regexp.MustCompile(`<a\shref="(/d/[\w]+)">\s?<img`)
|
|
|
//matched = re.FindAllStringSubmatch(result, -1)
|
|
@@ -346,10 +349,10 @@ func (s Supplier) step1(detailPageUrl string, isMovieOrSeries bool) ([]HdListIte
|
|
|
var err error
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- model.Notify.Add("subhd_step1", err.Error())
|
|
|
+ pkg.Notify.Add("subhd_step1", err.Error())
|
|
|
}
|
|
|
}()
|
|
|
- detailPageUrl = model.AddBaseUrl(common.SubSubHDRootUrl, detailPageUrl)
|
|
|
+ detailPageUrl = pkg.AddBaseUrl(common2.SubSubHDRootUrl, detailPageUrl)
|
|
|
result, err := s.httpGet(detailPageUrl)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -378,18 +381,18 @@ func (s Supplier) step1(detailPageUrl string, isMovieOrSeries bool) ([]HdListIte
|
|
|
title := strings.TrimSpace(tr.Find(oneSubTrTitleKeyword).Text())
|
|
|
// 字幕类型
|
|
|
insideSubType := tr.Find(oneSubLangAndTypeKeyword).Text()
|
|
|
- if model.IsSubTypeWanted(insideSubType) == false {
|
|
|
+ if pkg.IsSubTypeWanted(insideSubType) == false {
|
|
|
return true
|
|
|
}
|
|
|
// 下载的次数
|
|
|
- downCount, err := model.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
|
|
|
+ downCount, err := pkg.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
|
|
|
if err != nil {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
listItem := HdListItem{}
|
|
|
listItem.Url = downUrl
|
|
|
- listItem.BaseUrl = common.SubSubHDRootUrl
|
|
|
+ listItem.BaseUrl = common2.SubSubHDRootUrl
|
|
|
listItem.Title = title
|
|
|
listItem.DownCount = downCount
|
|
|
|
|
@@ -413,21 +416,21 @@ func (s Supplier) step2Ex(browser *rod.Browser, subDownloadPageUrl string) (*HdC
|
|
|
var err error
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- model.Notify.Add("subhd_step2Ex", err.Error())
|
|
|
+ pkg.Notify.Add("subhd_step2Ex", err.Error())
|
|
|
}
|
|
|
}()
|
|
|
- subDownloadPageUrl = model.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
|
|
|
+ subDownloadPageUrl = pkg.AddBaseUrl(common2.SubSubHDRootUrl, subDownloadPageUrl)
|
|
|
// 默认超时是 60s,如果是调试模式则是 5 min
|
|
|
- tt := common.HTMLTimeOut
|
|
|
+ tt := common2.HTMLTimeOut
|
|
|
if s.reqParam.DebugMode == true {
|
|
|
- tt = common.OneVideoProcessTimeOut
|
|
|
+ tt = common2.OneVideoProcessTimeOut
|
|
|
}
|
|
|
- page, err := model.NewPageNavigate(browser, subDownloadPageUrl, tt, 5)
|
|
|
+ page, err := pkg.NewPageNavigate(browser, subDownloadPageUrl, tt, 5)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
page.MustSetUserAgent(&proto.NetworkSetUserAgentOverride{
|
|
|
- UserAgent: model.RandomUserAgent(true),
|
|
|
+ UserAgent: pkg.RandomUserAgent(true),
|
|
|
})
|
|
|
err = page.WaitLoad()
|
|
|
if err != nil {
|
|
@@ -451,7 +454,7 @@ func (s Supplier) step2Ex(browser *rod.Browser, subDownloadPageUrl string) (*HdC
|
|
|
|
|
|
if hasWaterWall == false && hasDownBtn == false {
|
|
|
// 都没有,则返回故障,无法下载
|
|
|
- return nil, common.SubHDStep2ExCannotFindDownloadBtn
|
|
|
+ return nil, common2.SubHDStep2ExCannotFindDownloadBtn
|
|
|
}
|
|
|
// 下载字幕
|
|
|
content, err := s.downloadSubFile(browser, page, hasWaterWall, BtnElemenString)
|
|
@@ -542,7 +545,7 @@ func (s Supplier) passWaterWall(page *rod.Page) {
|
|
|
shadowbg := slideBgEl.MustResource()
|
|
|
// 取得原始圖像
|
|
|
src := slideBgEl.MustProperty("src")
|
|
|
- fullbg, _, err := model.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
|
|
|
+ fullbg, _, err := pkg.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
@@ -612,7 +615,7 @@ search:
|
|
|
|
|
|
if s.reqParam.DebugMode == true {
|
|
|
//截圖保存
|
|
|
- nowProcessRoot, err := model.GetDebugFolder()
|
|
|
+ nowProcessRoot, err := pkg.GetDebugFolder()
|
|
|
if err == nil {
|
|
|
page.MustScreenshot(path.Join(nowProcessRoot, "result.png"))
|
|
|
} else {
|
|
@@ -623,7 +626,7 @@ search:
|
|
|
|
|
|
func (s Supplier) httpGet(url string) (string, error) {
|
|
|
s.reqParam.Referer = url
|
|
|
- httpClient := model.NewHttpClient(s.reqParam)
|
|
|
+ httpClient := pkg.NewHttpClient(s.reqParam)
|
|
|
resp, err := httpClient.R().Get(url)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
@@ -632,7 +635,7 @@ func (s Supplier) httpGet(url string) (string, error) {
|
|
|
//搜索验证 点击继续搜索
|
|
|
if strings.Contains(recvText, "搜索验证") || strings.Contains(recvText, "搜索频率") {
|
|
|
s.log.Debugln("搜索验证 or 搜索频率 reload", url)
|
|
|
- time.Sleep(model.RandomSecondDuration(5, 10))
|
|
|
+ time.Sleep(pkg.RandomSecondDuration(5, 10))
|
|
|
return s.httpGet(url)
|
|
|
}
|
|
|
return resp.String(), nil
|