소스 검색

修复,path 在 Windows 下获取 Dir 的问题,替换为 filepath

Signed-off-by: allan716 <[email protected]>
allan716 4 년 전
부모
커밋
07e28738a7
2개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 2
      internal/dao/init.go
  2. 4 3
      internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper.go

+ 2 - 2
internal/dao/init.go

@@ -9,7 +9,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sqlite"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sqlite"
 	"gorm.io/gorm"
 	"gorm.io/gorm"
 	"os"
 	"os"
-	"path"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"sync"
 	"sync"
 )
 )
@@ -62,7 +62,7 @@ func InitDb() error {
 you need implement getDbName() in file: internal/dao/init.go `))
 you need implement getDbName() in file: internal/dao/init.go `))
 	}
 	}
 
 
-	dbDir := path.Dir(nowDbFileName)
+	dbDir := filepath.Dir(nowDbFileName)
 	if pkg.IsDir(dbDir) == false {
 	if pkg.IsDir(dbDir) == false {
 		_ = os.MkdirAll(dbDir, os.ModePerm)
 		_ = os.MkdirAll(dbDir, os.ModePerm)
 	}
 	}

+ 4 - 3
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper.go

@@ -17,6 +17,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"os"
 	"os"
 	"path"
 	"path"
+	"path/filepath"
 	"strings"
 	"strings"
 	"time"
 	"time"
 )
 )
@@ -66,7 +67,7 @@ func (s SubTimelineFixerHelper) FixRecentlyItemsSubTimeline(movieRootDir, series
 	// 先做电影的字幕校正、然后才是连续剧的
 	// 先做电影的字幕校正、然后才是连续剧的
 	for _, info := range movieList {
 	for _, info := range movieList {
 		// path.Dir 在 Windows 有梗,所以换个方式获取路径
 		// path.Dir 在 Windows 有梗,所以换个方式获取路径
-		videoRootPath := strings.ReplaceAll(info.VideoFileFullPath, info.VideoFileName, "")
+		videoRootPath := filepath.Dir(info.VideoFileFullPath)
 		err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 		err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
@@ -75,7 +76,7 @@ func (s SubTimelineFixerHelper) FixRecentlyItemsSubTimeline(movieRootDir, series
 	for _, infos := range seriesList {
 	for _, infos := range seriesList {
 		for _, info := range infos {
 		for _, info := range infos {
 			// path.Dir 在 Windows 有梗,所以换个方式获取路径
 			// path.Dir 在 Windows 有梗,所以换个方式获取路径
-			videoRootPath := strings.ReplaceAll(info.VideoFileFullPath, info.VideoFileName, "")
+			videoRootPath := filepath.Dir(info.VideoFileFullPath)
 			err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 			err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 			if err != nil {
 			if err != nil {
 				return err
 				return err
@@ -174,7 +175,7 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubF
 	if err != nil {
 	if err != nil {
 		return false, nil, err
 		return false, nil, err
 	}
 	}
-	offsetTime, err := sub_timeline_fixer.GetOffsetTime(infoBase, infoSrc, path.Join(cacheTmpPath, infoSrcNameWithOutExt+"-bar.html"))
+	offsetTime, err := sub_timeline_fixer.GetOffsetTime(infoBase, infoSrc, path.Join(cacheTmpPath, infoSrcNameWithOutExt+"-bar.html"), path.Join(cacheTmpPath, infoSrcNameWithOutExt+".log"))
 	if err != nil {
 	if err != nil {
 		return false, nil, err
 		return false, nil, err
 	}
 	}