Parcourir la source

暂时不支持蓝光的预览

Signed-off-by: allan716 <[email protected]>
allan716 il y a 3 ans
Parent
commit
f791c3dc4d
3 fichiers modifiés avec 43 ajouts et 1 suppressions
  1. 14 0
      internal/backend/controllers/v1/preview.go
  2. 10 1
      pkg/ffmpeg_helper/ffmpeg_helper.go
  3. 19 0
      pkg/util.go

+ 14 - 0
internal/backend/controllers/v1/preview.go

@@ -4,6 +4,8 @@ import (
 	"net/http"
 	"net/http"
 	"strconv"
 	"strconv"
 
 
+	"github.com/allanpk716/ChineseSubFinder/pkg/decode"
+
 	"github.com/allanpk716/ChineseSubFinder/pkg"
 	"github.com/allanpk716/ChineseSubFinder/pkg"
 
 
 	"github.com/allanpk716/ChineseSubFinder/pkg/preview_queue"
 	"github.com/allanpk716/ChineseSubFinder/pkg/preview_queue"
@@ -26,6 +28,18 @@ func (cb *ControllerBase) PreviewAdd(c *gin.Context) {
 		return
 		return
 	}
 	}
 
 
+	// 暂时不支持蓝光的预览
+	if pkg.IsFile(job.VideoFPath) == false {
+		bok, _, _ := decode.IsFakeBDMVWorked(job.VideoFPath)
+		if bok == true {
+			c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "not support blu-ray preview"})
+			return
+		} else {
+			c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "video file not found"})
+			return
+		}
+	}
+
 	cb.cronHelper.Downloader.PreviewQueue.Add(&job)
 	cb.cronHelper.Downloader.PreviewQueue.Add(&job)
 	c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "ok"})
 	c.JSON(http.StatusOK, backend2.ReplyCommon{Message: "ok"})
 	return
 	return

+ 10 - 1
pkg/ffmpeg_helper/ffmpeg_helper.go

@@ -9,6 +9,8 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
 
 
+	"github.com/allanpk716/ChineseSubFinder/pkg/decode"
+
 	"github.com/allanpk716/ChineseSubFinder/pkg"
 	"github.com/allanpk716/ChineseSubFinder/pkg"
 
 
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/common"
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/common"
@@ -270,7 +272,14 @@ func (f *FFMPEGHelper) ExportVideoHLSAndSubByTimeRange(videoFullPath, subFullPat
 
 
 	// 导出视频
 	// 导出视频
 	if pkg.IsFile(videoFullPath) == false {
 	if pkg.IsFile(videoFullPath) == false {
-		return "", "", errors.New("video file not exist, maybe is bluray file, so not support yet")
+
+		bok, _, steamDirPath := decode.IsFakeBDMVWorked(videoFullPath)
+		if bok == true {
+			// 需要从 steamDirPath 搜索最大的一个文件出来
+			videoFullPath = pkg.GetMaxSizeFile(steamDirPath)
+		} else {
+			return "", "", errors.New("video file not found")
+		}
 	}
 	}
 
 
 	if pkg.IsFile(subFullPath) == false {
 	if pkg.IsFile(subFullPath) == false {

+ 19 - 0
pkg/util.go

@@ -10,6 +10,7 @@ import (
 	"encoding/hex"
 	"encoding/hex"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
+	"io/ioutil"
 	"math"
 	"math"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
@@ -710,6 +711,24 @@ func PrintPanicStack(log *logrus.Logger) {
 	log.Errorln(fmt.Sprintf("%s", buf[:n]))
 	log.Errorln(fmt.Sprintf("%s", buf[:n]))
 }
 }
 
 
+func GetMaxSizeFile(path string) string {
+	files, err := ioutil.ReadDir(path)
+	if err != nil {
+		return ""
+	}
+	var maxFile os.FileInfo
+	for _, file := range files {
+		if maxFile == nil {
+			maxFile = file
+		} else {
+			if file.Size() > maxFile.Size() {
+				maxFile = file
+			}
+		}
+	}
+	return filepath.Join(path, maxFile.Name())
+}
+
 var (
 var (
 	_wantedExtMap    = make(map[string]string) // 人工确认的需要监控的视频后缀名
 	_wantedExtMap    = make(map[string]string) // 人工确认的需要监控的视频后缀名
 	_defExtMap       = make(map[string]string) // 内置支持的视频后缀名列表
 	_defExtMap       = make(map[string]string) // 内置支持的视频后缀名列表