Browse Source

新增,csf 搜索、下载逻辑,修复 download 时候获取任务 seaon eps = 0 的bug

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
2b542cdfce

+ 8 - 1
internal/backend/controllers/base/proxy.go

@@ -1,14 +1,16 @@
 package base
 package base
 
 
 import (
 import (
+	"net/http"
+
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/assrt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/assrt"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/csf"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
-	"net/http"
 )
 )
 
 
 func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
 func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
@@ -50,6 +52,11 @@ func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
 		subSupplierHub.AddSubSupplier(assrt.NewSupplier(cb.fileDownloader))
 		subSupplierHub.AddSubSupplier(assrt.NewSupplier(cb.fileDownloader))
 	}
 	}
 
 
+	if cb.fileDownloader.Settings.ExperimentalFunction.ShareSubSettings.ShareSubEnabled == true {
+		// 如果开启了分享字幕功能,那么就可以开启这个功能
+		subSupplierHub.AddSubSupplier(csf.NewSupplier(cb.fileDownloader))
+	}
+
 	outStatus := subSupplierHub.CheckSubSiteStatus()
 	outStatus := subSupplierHub.CheckSubSiteStatus()
 
 
 	defer func() {
 	defer func() {

+ 6 - 0
internal/logic/pre_download_process/pre_download_proces.go

@@ -6,6 +6,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/assrt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/assrt"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/csf"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
@@ -112,6 +113,11 @@ func (p *PreDownloadProcess) Init() *PreDownloadProcess {
 			// 如果找到 code 了,那么就可以继续用这个实例
 			// 如果找到 code 了,那么就可以继续用这个实例
 			p.SubSupplierHub.AddSubSupplier(subhd.NewSupplier(p.fileDownloader))
 			p.SubSupplierHub.AddSubSupplier(subhd.NewSupplier(p.fileDownloader))
 		}
 		}
+
+		if p.settings.ExperimentalFunction.ShareSubSettings.ShareSubEnabled == true {
+			// 如果开启了分享字幕功能,那么就可以开启这个功能
+			p.SubSupplierHub.AddSubSupplier(csf.NewSupplier(p.fileDownloader))
+		}
 	}
 	}
 	// ------------------------------------------------------------------------
 	// ------------------------------------------------------------------------
 	// 清理自定义的 rod 缓存目录
 	// 清理自定义的 rod 缓存目录

+ 10 - 5
internal/logic/sub_supplier/csf/csf.go

@@ -3,8 +3,6 @@ package csf
 import (
 import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
-	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
@@ -12,6 +10,9 @@ import (
 	"strings"
 	"strings"
 	"time"
 	"time"
 
 
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
+	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
+
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/subtitle_best_api"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/subtitle_best_api"
 
 
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -227,7 +228,7 @@ func (s *Supplier) findAndDownload(videoFPath string, isMovie bool, Season, Epis
 		if len(findSubReply.Subtitle) < 1 {
 		if len(findSubReply.Subtitle) < 1 {
 			return outSubInfoList, nil
 			return outSubInfoList, nil
 		}
 		}
-		bestOneSub = findBestSub(findSubReply.Subtitle)
+		bestOneSub = s.findBestSub(findSubReply.Subtitle)
 	}
 	}
 
 
 	tmpFolder, err := my_folder.GetRootTmpFolder()
 	tmpFolder, err := my_folder.GetRootTmpFolder()
@@ -371,7 +372,7 @@ func (s *Supplier) askFindSubProcess(VideoFeature, ImdbId, TmdbId, Season, Episo
 			1. match_video_feature,是否匹配传入的视频特征
 			1. match_video_feature,是否匹配传入的视频特征
 			2. low_trust,是否是低可信
 			2. low_trust,是否是低可信
 		*/
 		*/
-		bestOneSub = findBestSub(askFindSubReply.Subtitle)
+		bestOneSub = s.findBestSub(askFindSubReply.Subtitle)
 		return
 		return
 	} else if askFindSubReply.Status == 2 {
 	} else if askFindSubReply.Status == 2 {
 		// 放入队列,或者已经在队列中了,根据服务器安排的时间去请求排队下载
 		// 放入队列,或者已经在队列中了,根据服务器安排的时间去请求排队下载
@@ -417,13 +418,14 @@ func (s *Supplier) askDownloadSubProcess(SubSha256, DownloadSubToken, ApiKey str
 	}
 	}
 }
 }
 
 
-func findBestSub(subtitles []subtitle_best_api.Subtitle) (bestOneSub subtitle_best_api.Subtitle) {
+func (s *Supplier) findBestSub(subtitles []subtitle_best_api.Subtitle) (bestOneSub subtitle_best_api.Subtitle) {
 	found := false
 	found := false
 	for _, subtitle := range subtitles {
 	for _, subtitle := range subtitles {
 		if subtitle.MatchVideoFeature == true && subtitle.LowTrust == false {
 		if subtitle.MatchVideoFeature == true && subtitle.LowTrust == false {
 			// 匹配视频 且 高可信
 			// 匹配视频 且 高可信
 			bestOneSub = subtitle
 			bestOneSub = subtitle
 			found = true
 			found = true
+			s.log.Infoln("Find Best Subtitle, MatchVideoFeature == true and HighTrust", subtitle.SubSha256)
 			break
 			break
 		}
 		}
 	}
 	}
@@ -434,6 +436,7 @@ func findBestSub(subtitles []subtitle_best_api.Subtitle) (bestOneSub subtitle_be
 				// 高可信
 				// 高可信
 				bestOneSub = subtitle
 				bestOneSub = subtitle
 				found = true
 				found = true
+				s.log.Infoln("Find Best Subtitle, HighTrust", subtitle.SubSha256)
 				break
 				break
 			}
 			}
 		}
 		}
@@ -444,6 +447,7 @@ func findBestSub(subtitles []subtitle_best_api.Subtitle) (bestOneSub subtitle_be
 			if subtitle.MatchVideoFeature == false {
 			if subtitle.MatchVideoFeature == false {
 				// 匹配视频
 				// 匹配视频
 				bestOneSub = subtitle
 				bestOneSub = subtitle
+				s.log.Infoln("Find Best Subtitle, MatchVideoFeature == true", subtitle.SubSha256)
 				found = true
 				found = true
 				break
 				break
 			}
 			}
@@ -452,6 +456,7 @@ func findBestSub(subtitles []subtitle_best_api.Subtitle) (bestOneSub subtitle_be
 	if found == false {
 	if found == false {
 		// 上面的都没触发,那么就返回第一个字幕吧
 		// 上面的都没触发,那么就返回第一个字幕吧
 		bestOneSub = subtitles[0]
 		bestOneSub = subtitles[0]
+		s.log.Infoln("Find Best Subtitle, LowTrust", bestOneSub.SubSha256)
 	}
 	}
 	return
 	return
 }
 }

+ 3 - 1
internal/pkg/downloader/downloader.go

@@ -70,6 +70,7 @@ func NewDownloader(inSubFormatter ifaces.ISubFormatter, fileDownloader *file_dow
 	// TODO 这里写固定了抉择字幕的顺序
 	// TODO 这里写固定了抉择字幕的顺序
 	sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
 	sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
 	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
 	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
+	sitesSequence = append(sitesSequence, common.SubSiteChineseSubFinder)
 	sitesSequence = append(sitesSequence, common.SubSiteAssrt)
 	sitesSequence = append(sitesSequence, common.SubSiteAssrt)
 	sitesSequence = append(sitesSequence, common.SubSiteShooter)
 	sitesSequence = append(sitesSequence, common.SubSiteShooter)
 	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
 	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
@@ -388,7 +389,7 @@ func (d *Downloader) seriesDlFunc(ctx context.Context, job taskQueue2.OneJob, do
 	epsMap := make(map[int][]int, 0)
 	epsMap := make(map[int][]int, 0)
 	epsMap[job.Season] = []int{job.Episode}
 	epsMap[job.Season] = []int{job.Episode}
 
 
-	if job.VideoType == common.Series && (job.SeriesRootDirPath == "" || job.Season < 0 || job.Episode < 0) {
+	if job.VideoType == common.Series && (job.SeriesRootDirPath == "" || job.Season <= 0 || job.Episode <= 0) {
 		// 连续剧的时候需要额外提交信息
 		// 连续剧的时候需要额外提交信息
 		epsVideoNfoInfo, err := decode.GetVideoNfoInfo4OneSeriesEpisode(job.VideoFPath)
 		epsVideoNfoInfo, err := decode.GetVideoNfoInfo4OneSeriesEpisode(job.VideoFPath)
 		if err != nil {
 		if err != nil {
@@ -404,6 +405,7 @@ func (d *Downloader) seriesDlFunc(ctx context.Context, job taskQueue2.OneJob, do
 		job.Episode = epsVideoNfoInfo.Episode
 		job.Episode = epsVideoNfoInfo.Episode
 		job.SeriesRootDirPath = seriesInfoDirPath
 		job.SeriesRootDirPath = seriesInfoDirPath
 		// 如果进来的时候是 Season 和 Eps 是 -1, 那么就需要重新赋值那些集是需要下载的,否则后面会跳过
 		// 如果进来的时候是 Season 和 Eps 是 -1, 那么就需要重新赋值那些集是需要下载的,否则后面会跳过
+		epsMap = make(map[int][]int, 0)
 		epsMap[job.Season] = []int{job.Episode}
 		epsMap[job.Season] = []int{job.Episode}
 	}
 	}