Explorar o código

预检测的时候,如果字幕提供站点当次失效,则跳过使用,不影响下次

Signed-off-by: allan716 <[email protected]>
allan716 %!s(int64=3) %!d(string=hai) anos
pai
achega
117a98057a

+ 14 - 15
cmd/chinesesubfinder/main.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/backend"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/cron_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/logic/scan_played_video_subinfo"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -43,20 +42,20 @@ func main() {
 	nowPort := readCustomPortFile()
 	log_helper.GetLogger().Infoln(fmt.Sprintf("WebUI will listen at 0.0.0.0:%d", nowPort))
 
-	scan, err := scan_played_video_subinfo.NewScanPlayedVideoSubInfo(*settings.GetSettings())
-	if err != nil {
-		log_helper.GetLogger().Panicln(err)
-	}
-	bok, err := scan.GetPlayedItemsSubtitle()
-	if err != nil {
-		log_helper.GetLogger().Panicln(err)
-	}
-	if bok == true {
-		err = scan.Scan()
-		if err != nil {
-			log_helper.GetLogger().Panicln(err)
-		}
-	}
+	//scan, err := scan_played_video_subinfo.NewScanPlayedVideoSubInfo(*settings.GetSettings())
+	//if err != nil {
+	//	log_helper.GetLogger().Panicln(err)
+	//}
+	//bok, err := scan.GetPlayedItemsSubtitle()
+	//if err != nil {
+	//	log_helper.GetLogger().Panicln(err)
+	//}
+	//if bok == true {
+	//	err = scan.Scan()
+	//	if err != nil {
+	//		log_helper.GetLogger().Panicln(err)
+	//	}
+	//}
 
 	// 支持在外部配置特殊的端口号,以防止本地本占用了无法使用
 	backend.StartBackEnd(nowPort, cronHelper)

+ 2 - 0
internal/ifaces/iSupplier.go

@@ -8,6 +8,8 @@ import (
 type ISupplier interface {
 	CheckAlive() (bool, int64)
 
+	IsAlive() bool
+
 	GetSupplierName() string
 
 	GetSubListFromFile4Movie(filePath string) ([]supplier.SubInfo, error)

+ 9 - 1
internal/logic/sub_supplier/shooter/shooter.go

@@ -25,6 +25,7 @@ type Supplier struct {
 	settings settings.Settings
 	log      *logrus.Logger
 	topic    int
+	isAlive  bool
 }
 
 func NewSupplier(_settings settings.Settings) *Supplier {
@@ -32,6 +33,7 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	sup := Supplier{}
 	sup.log = log_helper.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
+	sup.isAlive = true // 默认是可以使用的,如果 check 后,再调整状态
 
 	sup.settings = clone.Clone(_settings).(settings.Settings)
 	if sup.settings.AdvancedSettings.Topic > 0 && sup.settings.AdvancedSettings.Topic != sup.topic {
@@ -41,18 +43,24 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	return &sup
 }
 
-func (s Supplier) CheckAlive() (bool, int64) {
+func (s *Supplier) CheckAlive() (bool, int64) {
 	// 计算当前时间
 	startT := time.Now()
 	_, err := s.getSubInfos(checkFileHash, checkFileName, qLan)
 	if err != nil {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
+		s.isAlive = false
 		return false, 0
 	}
 	// 计算耗时
+	s.isAlive = true
 	return true, time.Since(startT).Milliseconds()
 }
 
+func (s *Supplier) IsAlive() bool {
+	return s.isAlive
+}
+
 func (s Supplier) GetSupplierName() string {
 	return common.SubSiteShooter
 }

+ 20 - 1
internal/logic/sub_supplier/subSupplierHub.go

@@ -45,6 +45,16 @@ func (d *SubSupplierHub) AddSubSupplier(one ifaces.ISupplier) {
 	d.Suppliers = append(d.Suppliers, one)
 }
 
+func (d *SubSupplierHub) DelSubSupplier(one ifaces.ISupplier) {
+
+	for i := 0; i < len(d.Suppliers); i++ {
+
+		if one.GetSupplierName() == d.Suppliers[i].GetSupplierName() {
+			d.Suppliers = append(d.Suppliers[:i], d.Suppliers[i+1:]...)
+		}
+	}
+}
+
 // DownloadSub4Movie 某一个电影字幕下载,下载完毕后,返回下载缓存每个字幕的位置
 func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int, forcedScanAndDownloadSub bool) ([]string, error) {
 
@@ -157,7 +167,7 @@ func (d SubSupplierHub) DownloadSub4SeriesFromEmby(seriesDirPath string, seriesL
 }
 
 // CheckSubSiteStatus 检测多个字幕提供的网站是否是有效的
-func (d SubSupplierHub) CheckSubSiteStatus() backend.ReplyCheckStatus {
+func (d *SubSupplierHub) CheckSubSiteStatus() backend.ReplyCheckStatus {
 
 	outStatus := backend.ReplyCheckStatus{
 		SubSiteStatus: make([]backend.SiteStatus, 0),
@@ -179,6 +189,15 @@ func (d SubSupplierHub) CheckSubSiteStatus() backend.ReplyCheckStatus {
 			Speed: speed,
 		})
 	}
+
+	suppliersLen := len(d.Suppliers)
+	for i := 0; i < suppliersLen; i++ {
+		if d.Suppliers[i].IsAlive() == false {
+			d.DelSubSupplier(d.Suppliers[i])
+		}
+		suppliersLen = len(d.Suppliers)
+	}
+
 	d.log.Infoln("Check Sub Supplier End")
 
 	return outStatus

+ 10 - 1
internal/logic/sub_supplier/subhd/subhd.go

@@ -42,6 +42,7 @@ type Supplier struct {
 	tt               time.Duration
 	debugMode        bool
 	httpProxyAddress string
+	isAlive          bool
 }
 
 func NewSupplier(_settings settings.Settings) *Supplier {
@@ -54,6 +55,7 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	if sup.settings.AdvancedSettings.Topic > 0 && sup.settings.AdvancedSettings.Topic != sup.topic {
 		sup.topic = sup.settings.AdvancedSettings.Topic
 	}
+	sup.isAlive = true // 默认是可以使用的,如果 check 后,再调整状态
 
 	// 默认超时是 2 * 60s,如果是调试模式则是 5 min
 	sup.tt = common.HTMLTimeOut
@@ -71,21 +73,28 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	return &sup
 }
 
-func (s Supplier) CheckAlive() (bool, int64) {
+func (s *Supplier) CheckAlive() (bool, int64) {
 
 	proxyStatus, proxySpeed, err := url_connectedness_helper.UrlConnectednessTest(common.SubSubHDRootUrl, s.settings.AdvancedSettings.ProxySettings.HttpProxyAddress)
 	if err != nil {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
+		s.isAlive = false
 		return false, 0
 	}
 	if proxyStatus == false {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Status != 200")
+		s.isAlive = false
 		return false, proxySpeed
 	}
 
+	s.isAlive = true
 	return true, proxySpeed
 }
 
+func (s *Supplier) IsAlive() bool {
+	return s.isAlive
+}
+
 func (s Supplier) GetSupplierName() string {
 	return common.SubSiteSubHd
 }

+ 10 - 1
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -25,6 +25,7 @@ type Supplier struct {
 	settings settings.Settings
 	log      *logrus.Logger
 	topic    int
+	isAlive  bool
 }
 
 func NewSupplier(_settings settings.Settings) *Supplier {
@@ -32,6 +33,7 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	sup := Supplier{}
 	sup.log = log_helper.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
+	sup.isAlive = true // 默认是可以使用的,如果 check 后,再调整状态
 
 	sup.settings = clone.Clone(_settings).(settings.Settings)
 	if sup.settings.AdvancedSettings.Topic > 0 && sup.settings.AdvancedSettings.Topic != sup.topic {
@@ -41,24 +43,31 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	return &sup
 }
 
-func (s Supplier) CheckAlive() (bool, int64) {
+func (s *Supplier) CheckAlive() (bool, int64) {
 
 	// 计算当前时间
 	startT := time.Now()
 	jsonList, err := s.getSubInfos(checkFileName, checkCID)
 	if err != nil {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
+		s.isAlive = false
 		return false, 0
 	}
 
 	if len(jsonList.Sublist) < 1 {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Sublist < 1")
+		s.isAlive = false
 		return false, 0
 	}
 
+	s.isAlive = true
 	return true, time.Since(startT).Milliseconds()
 }
 
+func (s *Supplier) IsAlive() bool {
+	return s.isAlive
+}
+
 func (s Supplier) GetSupplierName() string {
 	return common.SubSiteXunLei
 }

+ 10 - 1
internal/logic/sub_supplier/zimuku/zimuku.go

@@ -29,6 +29,7 @@ type Supplier struct {
 	settings settings.Settings
 	log      *logrus.Logger
 	topic    int
+	isAlive  bool
 }
 
 func NewSupplier(_settings settings.Settings) *Supplier {
@@ -36,6 +37,7 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	sup := Supplier{}
 	sup.log = log_helper.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
+	sup.isAlive = true // 默认是可以使用的,如果 check 后,再调整状态
 
 	sup.settings = clone.Clone(_settings).(settings.Settings)
 	if sup.settings.AdvancedSettings.Topic > 0 && sup.settings.AdvancedSettings.Topic != sup.topic {
@@ -44,21 +46,28 @@ func NewSupplier(_settings settings.Settings) *Supplier {
 	return &sup
 }
 
-func (s Supplier) CheckAlive() (bool, int64) {
+func (s *Supplier) CheckAlive() (bool, int64) {
 
 	proxyStatus, proxySpeed, err := url_connectedness_helper.UrlConnectednessTest(common.SubZiMuKuRootUrl, s.settings.AdvancedSettings.ProxySettings.HttpProxyAddress)
 	if err != nil {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
+		s.isAlive = false
 		return false, 0
 	}
 	if proxyStatus == false {
 		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Status != 200")
+		s.isAlive = false
 		return false, proxySpeed
 	}
 
+	s.isAlive = true
 	return true, proxySpeed
 }
 
+func (s *Supplier) IsAlive() bool {
+	return s.isAlive
+}
+
 func (s Supplier) GetSupplierName() string {
 	return common.SubSiteZiMuKu
 }