瀏覽代碼

移除不使用的 ws 功能

Signed-off-by: allan716 <[email protected]>
allan716 3 年之前
父節點
當前提交
40d303cbcc

+ 3 - 0
internal/backend/routers/base_router.go

@@ -50,5 +50,8 @@ func InitRouter(fileDownloader *file_downloader.FileDownloader, router *gin.Engi
 		GroupV1.GET("/jobs/list", cbV1.JobsListHandler)
 		GroupV1.POST("/jobs/change-job-status", cbV1.ChangeJobStatusHandler)
 		GroupV1.POST("/jobs/log", cbV1.JobLogHandler)
+
+		GroupV1.POST("/video/list/movies", cbV1.MovieListHandler)
+		GroupV1.POST("/video/list/series", cbV1.SeriesListHandler)
 	}
 }

+ 0 - 109
internal/backend/ws_helper/client.go

@@ -3,11 +3,8 @@ package ws_helper
 import (
 	"bytes"
 	"encoding/json"
-	"errors"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend/ws"
-	"github.com/allanpk716/ChineseSubFinder/internal/types/log_hub"
 	"github.com/gorilla/websocket"
 	"github.com/sirupsen/logrus"
 	"net/http"
@@ -34,10 +31,6 @@ const (
 	upGraderReadBufferSize = 5 * 1024
 
 	upGraderWriteBufferSize = 5 * 1024
-	// 字幕扫描任务执行状态
-	subScanJobStatusInterval = 5 * time.Second
-	// 字幕扫描运行中任务日志信息
-	runningLogInterval = 5 * time.Second
 )
 
 var upGrader = websocket.Upgrader{
@@ -165,14 +158,8 @@ func (c *Client) writePump() {
 
 	// 心跳计时器
 	pingTicker := time.NewTicker(pingPeriod)
-	// 字幕扫描任务状态计时器
-	subScanJobStatusTicker := time.NewTicker(subScanJobStatusInterval)
-	// 正在运行扫描器的日志
-	runningLogTicker := time.NewTicker(runningLogInterval)
 	defer func() {
 		pingTicker.Stop()
-		subScanJobStatusTicker.Stop()
-		runningLogTicker.Stop()
 		c.close()
 	}()
 
@@ -226,47 +213,6 @@ func (c *Client) writePump() {
 				c.log.Debugln("writePump.pingTicker.C.WriteMessage", err)
 				return
 			}
-		case <-subScanJobStatusTicker.C:
-			// 字幕扫描任务状态
-			if c.authed == false {
-				// 没有认证通过,就无需处理次定时器时间
-				continue
-			}
-			// 如果没有开启总任务,或者停止总任务了,那么这里获取到的应该是 nil,不应该继续往下
-			info := common.GetSubScanJobStatus()
-			if info == nil {
-				continue
-			}
-			// 统一丢到 send 里面得了
-			outLogsBytes, err := SubScanJobStatusReply(info)
-			if err != nil {
-				c.log.Debugln("writePump.SubScanJobStatusReply", err)
-				return
-			}
-			c.send <- outLogsBytes
-
-		case <-runningLogTicker.C:
-			// 正在运行扫描日志
-			if c.authed == false {
-				// 没有认证通过,就无需处理次定时器时间
-				continue
-			}
-			nowRunningLog := log_helper.GetOnceLog4Running()
-			if nowRunningLog == nil {
-				continue
-			}
-			// 找到日志,把当前已有的日志发送出去,然后记录发送到哪里了
-			// 这里需要考虑一次性的信息太多,超过发送的缓冲区,所以需要拆分发送
-			outLogsBytes, err := RunningLogReply(nowRunningLog, c.sendLogLineIndex)
-			if err != nil {
-				c.log.Debugln("writePump.RunningLogReply", err)
-				return
-			}
-			// 拆分到一条日志来发送
-			for _, logsByte := range outLogsBytes {
-				c.send <- logsByte
-				c.sendLogLineIndex += 1
-			}
 		}
 	}
 }
@@ -291,61 +237,6 @@ func AuthReply(inType ws.AuthMessage) ([]byte, error) {
 	return outBytes, nil
 }
 
-// RunningLogReply 发送的 Running Log 数据,iPreSendLines 之前俺发送到第几条数据,则不发发送过的
-func RunningLogReply(log *log_hub.OnceLog, iPreSendLines ...int) ([][]byte, error) {
-
-	if log == nil {
-		return nil, errors.New("RunningLogReply input log is nil")
-	}
-
-	var outLogBytes = make([][]byte, 0)
-	var err error
-	var preSendLines = 0
-	if len(iPreSendLines) > 0 {
-		preSendLines = iPreSendLines[0]
-		if preSendLines < 0 {
-			preSendLines = 0
-		}
-		log.LogLines = log.LogLines[preSendLines:]
-	}
-
-	logs := log_helper.GetSpiltOnceLog(log)
-	for _, onceLog := range logs {
-		var outData, outBytes []byte
-		outData, err = json.Marshal(onceLog)
-		if err != nil {
-			return nil, err
-		}
-
-		outBytes, err = ws.NewBaseMessage(ws.RunningLog.String(), string(outData)).Bytes()
-		if err != nil {
-			return nil, err
-		}
-
-		outLogBytes = append(outLogBytes, outBytes)
-	}
-
-	return outLogBytes, nil
-}
-
-// SubScanJobStatusReply 当前字幕扫描的进度信息
-func SubScanJobStatusReply(info *ws.SubDownloadJobInfo) ([]byte, error) {
-
-	var err error
-	var outData, outBytes []byte
-	outData, err = json.Marshal(info)
-	if err != nil {
-		return nil, err
-	}
-
-	outBytes, err = ws.NewBaseMessage(ws.SubDownloadJobsStatus.String(), string(outData)).Bytes()
-	if err != nil {
-		return nil, err
-	}
-
-	return outBytes, nil
-}
-
 // ServeWs 每个 Client 连接 ws 上线时触发
 func ServeWs(log *logrus.Logger, hub *Hub, w http.ResponseWriter, r *http.Request) {
 

+ 2 - 7
internal/logic/cron_helper/cron_helper.go

@@ -3,7 +3,6 @@ package cron_helper
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/scan_played_video_subinfo"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/downloader"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter"
@@ -140,8 +139,6 @@ func (ch *CronHelper) Start(runImmediately bool) {
 
 		// 不会马上启动扫描,那么就需要设置当前的时间,且为 waiting
 		tttt := ch.c.Entry(ch.entryIDScanVideoProcess).Next.Format("2006-01-02 15:04:05")
-		common.SetSubScanJobStatusWaiting(tttt)
-
 		ch.log.Infoln("Next Sub Scan Will Process At:", tttt)
 	} else {
 		ch.log.Errorln("Can't get cron jobs, will not send SubScanJobStatus")
@@ -185,8 +182,6 @@ func (ch *CronHelper) Stop() {
 	ch.cronHelperRunning = false
 	ch.stopping = false
 	ch.cronLock.Unlock()
-
-	common.SetSubScanJobStatusNil()
 }
 
 func (ch *CronHelper) scanPlayedVideoSub() {
@@ -243,11 +238,11 @@ func (ch *CronHelper) scanVideoProcessAdd2DownloadQueue() {
 
 		// 下载完后,应该继续是等待
 		tttt := ch.c.Entry(ch.entryIDScanVideoProcess).Next.Format("2006-01-02 15:04:05")
-		common.SetSubScanJobStatusWaiting(tttt)
+		ch.log.Infoln("Next Sub Scan Will Process At:", tttt)
 	}()
 
 	// 扫描字幕任务开始,先是扫描阶段,那么是拿不到有多少视频需要扫描的数量的
-	common.SetSubScanJobStatusPreparing(time.Now().Format("2006-01-02 15:04:05"))
+	ch.log.Infoln("scanVideoProcessAdd2DownloadQueue Start:", time.Now().Format("2006-01-02 15:04:05"))
 	// ----------------------------------------------------------------------------------------
 	// ----------------------------------------------------------------------------------------
 	// 扫描有那些视频需要下载字幕,放入队列中,然后会有下载者去这个队列取出来进行下载

+ 0 - 4
internal/logic/sub_supplier/shooter/shooter.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
-	pkgcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
@@ -230,9 +229,6 @@ func (s *Supplier) downloadSub4Series(seriesInfo *series.SeriesInfo) ([]supplier
 	for _, episodeInfo := range seriesInfo.NeedDlEpsKeyList {
 
 		index++
-		pkgcommon.SetSubScanJobStatusScanSeriesSub(index, len(seriesInfo.NeedDlEpsKeyList),
-			fmt.Sprintf("%v - S%v-E%v", episodeInfo.Title, episodeInfo.Season, episodeInfo.Episode))
-
 		one, err := s.getSubListFromFile(episodeInfo.FileFullPath)
 		if err != nil {
 			s.log.Errorln(s.GetSupplierName(), "getSubListFromFile", episodeInfo.FileFullPath)

+ 0 - 4
internal/logic/sub_supplier/subhd/subhd.go

@@ -7,7 +7,6 @@ import (
 	"github.com/PuerkitoBio/goquery"
 	"github.com/Tnze/go.num/v2/zh"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
-	pkgcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -176,9 +175,6 @@ func (s *Supplier) GetSubListFromFile4Series(seriesInfo *series.SeriesInfo) ([]s
 	// 下载字幕
 	for i, item := range subInfoNeedDownload {
 
-		pkgcommon.SetSubScanJobStatusScanSeriesSub(i+1, len(seriesInfo.NeedDlEpsKeyList),
-			fmt.Sprintf("%v - S%v-E%v", item.Title, item.Season, item.Episode))
-
 		subInfo, err := s.fileDownloader.GetEx(s.GetSupplierName(), browser, item.Url, int64(i), item.Season, item.Episode, s.DownFile)
 		if err != nil {
 			s.log.Errorln(s.GetSupplierName(), "GetEx", subInfo.Name, err)

+ 0 - 4
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
-	pkgcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -248,9 +247,6 @@ func (s *Supplier) downloadSub4Series(seriesInfo *series.SeriesInfo) ([]supplier
 	for _, episodeInfo := range seriesInfo.NeedDlEpsKeyList {
 
 		index++
-		pkgcommon.SetSubScanJobStatusScanSeriesSub(index, len(seriesInfo.NeedDlEpsKeyList),
-			fmt.Sprintf("%v - S%v-E%v", episodeInfo.Title, episodeInfo.Season, episodeInfo.Episode))
-
 		one, err := s.getSubListFromFile(episodeInfo.FileFullPath)
 		if err != nil {
 			s.log.Errorln(s.GetSupplierName(), "getSubListFromFile", episodeInfo.Season, episodeInfo.Episode,

+ 0 - 4
internal/logic/sub_supplier/zimuku/zimuku.go

@@ -6,7 +6,6 @@ import (
 	"github.com/PuerkitoBio/goquery"
 	"github.com/Tnze/go.num/v2/zh"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
-	pkgcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
@@ -370,9 +369,6 @@ func (s *Supplier) whichSubInfoNeedDownload(browser *rod.Browser, subInfos SubIn
 	var outSubInfoList = make([]supplier.SubInfo, 0)
 	for i := range subInfos {
 
-		pkgcommon.SetSubScanJobStatusScanSeriesSub(i+1, len(subInfos),
-			fmt.Sprintf("%v - S%v-E%v", subInfos[i].Name, subInfos[i].Season, subInfos[i].Episode))
-
 		err = s.step2(browser, &subInfos[i])
 		if err != nil {
 			s.log.Error(s.GetSupplierName(), "step 2", subInfos[i].Name, err)

+ 0 - 115
internal/pkg/common/global_value.go

@@ -1,8 +1,6 @@
 package common
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/types/backend/ws"
-	"github.com/huandu/go-clone"
 	"sync"
 )
 
@@ -20,120 +18,7 @@ func GetAccessToken() string {
 	return accessToken
 }
 
-// GetSubScanJobStatus 只用于获取,不是设置值,因为创建了实例的副本
-func GetSubScanJobStatus() *ws.SubDownloadJobInfo {
-
-	var tmpSubDownloadJobInfoLock *ws.SubDownloadJobInfo
-	subDownloadJobInfoLock.Lock()
-	tmpSubDownloadJobInfoLock = clone.Clone(subDownloadJobInfo).(*ws.SubDownloadJobInfo)
-	subDownloadJobInfoLock.Unlock()
-	return tmpSubDownloadJobInfoLock
-}
-
-// SetSubScanJobStatusPreparing 设置扫描字幕任务的状态为准备
-func SetSubScanJobStatusPreparing(startedTime string) {
-
-	subDownloadJobInfoLock.Lock()
-	if subDownloadJobInfo == nil {
-		subDownloadJobInfo = &ws.SubDownloadJobInfo{}
-	}
-	subDownloadJobInfo.Status = ws.Preparing
-	subDownloadJobInfo.StartedTime = startedTime
-	subDownloadJobInfoLock.Unlock()
-}
-
-// SetSubScanJobStatusScanMovie 设置扫描字幕任务的状态为运行
-func SetSubScanJobStatusScanMovie(WorkingUnitIndex, UnitCount int, WorkingUnitName string) {
-
-	subDownloadJobInfoLock.Lock()
-
-	if subDownloadJobInfo == nil {
-		subDownloadJobInfo = &ws.SubDownloadJobInfo{}
-	}
-	subDownloadJobInfo.Status = ws.ScanMovie
-	subDownloadJobInfo.WorkingUnitIndex = WorkingUnitIndex
-	subDownloadJobInfo.UnitCount = UnitCount
-	subDownloadJobInfo.WorkingUnitName = WorkingUnitName
-
-	subDownloadJobInfoLock.Unlock()
-}
-
-// SetSubScanJobStatusScanSeriesMain 设置扫描字幕任务的状态为运行
-func SetSubScanJobStatusScanSeriesMain(WorkingUnitIndex, UnitCount int, WorkingUnitName string) {
-
-	subDownloadJobInfoLock.Lock()
-
-	if subDownloadJobInfo == nil {
-		subDownloadJobInfo = &ws.SubDownloadJobInfo{}
-	}
-	subDownloadJobInfo.Status = ws.ScanSeries
-	subDownloadJobInfo.WorkingUnitIndex = WorkingUnitIndex
-	subDownloadJobInfo.UnitCount = UnitCount
-	subDownloadJobInfo.WorkingUnitName = WorkingUnitName
-
-	subDownloadJobInfo.WorkingVideoIndex = 0
-	subDownloadJobInfo.VideoCount = 0
-	subDownloadJobInfo.WorkingVideoName = ""
-
-	subDownloadJobInfoLock.Unlock()
-}
-
-// SetSubScanJobStatusScanSeriesSub 设置扫描字幕任务的状态为运行
-func SetSubScanJobStatusScanSeriesSub(WorkingVideoIndex, VideoCount int, WorkingVideoName string) {
-
-	subDownloadJobInfoLock.Lock()
-
-	if subDownloadJobInfo == nil {
-		subDownloadJobInfo = &ws.SubDownloadJobInfo{}
-	}
-	subDownloadJobInfo.Status = ws.ScanSeries
-	update := false
-	// 因为这里不同于movie的逻辑,movie 是在字幕下载者之前进行的统计更新
-	// 而对应 series 则是进入到具体的一个下载者中进行的任务进度更新,所以需要考虑并发情况,以最大值来更新
-	if subDownloadJobInfo.WorkingVideoIndex < WorkingVideoIndex {
-		subDownloadJobInfo.WorkingVideoIndex = WorkingVideoIndex
-		update = true
-	}
-
-	if subDownloadJobInfo.VideoCount < VideoCount {
-		subDownloadJobInfo.VideoCount = VideoCount
-		update = true
-	}
-
-	if update == true {
-		subDownloadJobInfo.WorkingVideoName = WorkingVideoName
-	}
-
-	subDownloadJobInfoLock.Unlock()
-}
-
-// SetSubScanJobStatusWaiting 设置扫描字幕任务的状态为等待
-func SetSubScanJobStatusWaiting(startedTime string) {
-
-	subDownloadJobInfoLock.Lock()
-	if subDownloadJobInfo == nil {
-		subDownloadJobInfo = &ws.SubDownloadJobInfo{}
-	}
-	subDownloadJobInfo.Status = ws.Waiting
-	subDownloadJobInfo.StartedTime = startedTime
-	subDownloadJobInfoLock.Unlock()
-}
-
-// SetSubScanJobStatusNil 如果总任务停止了,那么就需要设置为 nil,这样定时器发送的时候就会判断是否为 nil,是就不会继续触发
-// 如果总任务开始了,是否是立即开始都会由实例化操作
-func SetSubScanJobStatusNil() {
-
-	subDownloadJobInfoLock.Lock()
-	subDownloadJobInfo = nil
-	subDownloadJobInfoLock.Unlock()
-}
-
 var (
 	accessToken      = ""
 	mutexAccessToken sync.Mutex
 )
-
-var (
-	subDownloadJobInfo     *ws.SubDownloadJobInfo
-	subDownloadJobInfoLock sync.Mutex
-)

+ 0 - 12
internal/types/backend/ws/sub_download_jobs_info.go

@@ -1,12 +0,0 @@
-package ws
-
-type SubDownloadJobInfo struct {
-	Status            string `json:"status"`              // "running", "waiting",不是运行中,就是等待中
-	StartedTime       string `json:"started_time"`        // 任务开始的时间
-	WorkingUnitIndex  int    `json:"working_unit_index"`  // 正在处理到第几部电影或者连续剧
-	UnitCount         int    `json:"unit_count"`          // 一共有多少部电影或者连续剧
-	WorkingUnitName   string `json:"working_unit_name"`   // 电影名称,或者连续剧的名称
-	WorkingVideoIndex int    `json:"working_video_index"` // 正在处理到第几个视频
-	VideoCount        int    `json:"video_count"`         // 一共有几个视频
-	WorkingVideoName  string `json:"working_video_name"`  // 正在处理到第几个视频的名称
-}