Ver código fonte

尝试修复 #485 问题

Signed-off-by: allan716 <[email protected]>
allan716 3 anos atrás
pai
commit
359bdeb607

+ 12 - 1
pkg/path_helper/path_helper.go

@@ -1,6 +1,9 @@
 package path_helper
 
-import "strings"
+import (
+	"path/filepath"
+	"strings"
+)
 
 func FixShareFileProtocolsPath(orgPath string) string {
 
@@ -28,6 +31,14 @@ func fixSMBPath(orgPath string, prefixBase, prefixFull string) string {
 	}
 }
 
+// ChangePhysicalPathToSharePath 从物理地址转换为静态文件服务器分享地址
+func ChangePhysicalPathToSharePath(physicalFullPath, pathUrlMapKey, sharePrefixPath string) string {
+
+	dirName := strings.ReplaceAll(physicalFullPath, pathUrlMapKey, "")
+	outPath := filepath.Join(sharePrefixPath, dirName)
+	return outPath
+}
+
 const (
 	smbPrefixBase = "smb:/"
 	smbPrefixFull = "smb://"

+ 22 - 10
pkg/video_scan_and_refresh_helper/video_scan_and_refresh_helper.go

@@ -6,6 +6,8 @@ import (
 	"sync"
 	"time"
 
+	"github.com/allanpk716/ChineseSubFinder/pkg/path_helper"
+
 	"github.com/allanpk716/ChineseSubFinder/pkg/ifaces"
 	backend2 "github.com/allanpk716/ChineseSubFinder/pkg/types/backend"
 	common2 "github.com/allanpk716/ChineseSubFinder/pkg/types/common"
@@ -573,7 +575,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 		v.processLocker.Unlock()
 
 		// 匹配上了前缀就替换这个,并记录
-		movieFUrl := strings.ReplaceAll(oneMovieFPath, oneMovieDirRootPath, desUrl)
+		movieFUrl := path_helper.ChangePhysicalPathToSharePath(oneMovieFPath, oneMovieDirRootPath, desUrl)
+		//movieFUrl := strings.ReplaceAll(oneMovieFPath, oneMovieDirRootPath, desUrl)
 		oneMovieInfo := backend2.MovieInfo{
 			Name:         filepath.Base(movieFUrl),
 			DirRootUrl:   filepath.Dir(movieFUrl),
@@ -588,7 +591,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 		}
 		matchedSubFileByOneVideoUrl := make([]string, 0)
 		for _, oneSubFPath := range matchedSubFileByOneVideo {
-			oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneMovieDirRootPath, desUrl)
+			oneSubFUrl := path_helper.ChangePhysicalPathToSharePath(oneSubFPath, oneMovieDirRootPath, desUrl)
+			//oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneMovieDirRootPath, desUrl)
 			matchedSubFileByOneVideoUrl = append(matchedSubFileByOneVideoUrl, oneSubFUrl)
 		}
 		oneMovieInfo.SubFPathList = append(oneMovieInfo.SubFPathList, matchedSubFileByOneVideoUrl...)
@@ -656,7 +660,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 			v.log.Debugln("filterMovieAndSeriesNeedDownloadNormal.SeriesNeedDlSub bNeedDlSub == false", oneSeriesRootPathName)
 			return nil
 		}
-		seriesDirRootFUrl := strings.ReplaceAll(oneSeriesRootDir, oneSeriesRootPathName, desUrl)
+		seriesDirRootFUrl := path_helper.ChangePhysicalPathToSharePath(oneSeriesRootDir, oneSeriesRootPathName, desUrl)
+		//seriesDirRootFUrl := strings.ReplaceAll(oneSeriesRootDir, oneSeriesRootPathName, desUrl)
 		oneSeasonInfo := backend2.SeasonInfo{
 			Name:          filepath.Base(oneSeriesRootDir),
 			RootDirPath:   oneSeriesRootDir,
@@ -665,7 +670,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 		}
 		for _, epsInfo := range seriesInfo.EpList {
 
-			videoFUrl := strings.ReplaceAll(epsInfo.FileFullPath, oneSeriesRootPathName, desUrl)
+			videoFUrl := path_helper.ChangePhysicalPathToSharePath(epsInfo.FileFullPath, oneSeriesRootPathName, desUrl)
+			//videoFUrl := strings.ReplaceAll(epsInfo.FileFullPath, oneSeriesRootPathName, desUrl)
 			oneVideoInfo := backend2.OneVideoInfo{
 				Name:         epsInfo.Title,
 				VideoFPath:   epsInfo.FileFullPath,
@@ -682,7 +688,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 			}
 			matchedSubFileByOneVideoUrl := make([]string, 0)
 			for _, oneSubFPath := range matchedSubFileByOneVideo {
-				oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneSeriesRootPathName, desUrl)
+				oneSubFUrl := path_helper.ChangePhysicalPathToSharePath(oneSubFPath, oneSeriesRootPathName, desUrl)
+				//oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneSeriesRootPathName, desUrl)
 				matchedSubFileByOneVideoUrl = append(matchedSubFileByOneVideoUrl, oneSubFUrl)
 			}
 			oneVideoInfo.SubFPathList = append(oneVideoInfo.SubFPathList, matchedSubFileByOneVideoUrl...)
@@ -761,7 +768,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 				}
 				v.processLocker.Unlock()
 				// 匹配上了前缀就替换这个,并记录
-				movieFUrl := strings.ReplaceAll(oneMovieMixInfo.PhysicalVideoFileFullPath, oneMovieDirPath.Path, desUrl)
+				movieFUrl := path_helper.ChangePhysicalPathToSharePath(oneMovieMixInfo.PhysicalVideoFileFullPath, oneMovieDirPath.Path, desUrl)
+				//movieFUrl := strings.ReplaceAll(oneMovieMixInfo.PhysicalVideoFileFullPath, oneMovieDirPath.Path, desUrl)
 				oneMovieInfo := backend2.MovieInfo{
 					Name:                     filepath.Base(movieFUrl),
 					DirRootUrl:               filepath.Dir(movieFUrl),
@@ -778,7 +786,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 				}
 				matchedSubFileByOneVideoUrl := make([]string, 0)
 				for _, oneSubFPath := range matchedSubFileByOneVideo {
-					oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneMovieDirPath.Path, desUrl)
+					oneSubFUrl := path_helper.ChangePhysicalPathToSharePath(oneSubFPath, oneMovieDirPath.Path, desUrl)
+					//oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneMovieDirPath.Path, desUrl)
 					matchedSubFileByOneVideoUrl = append(matchedSubFileByOneVideoUrl, oneSubFUrl)
 				}
 				oneMovieInfo.SubFPathList = append(oneMovieInfo.SubFPathList, matchedSubFileByOneVideoUrl...)
@@ -848,7 +857,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 					break
 				}
 				// 匹配上了前缀就替换这个,并记录
-				epsFUrl := strings.ReplaceAll(oneEpsMixInfo.PhysicalVideoFileFullPath, oneSeriesDirPath.Path, desUrl)
+				epsFUrl := path_helper.ChangePhysicalPathToSharePath(oneEpsMixInfo.PhysicalVideoFileFullPath, oneSeriesDirPath.Path, desUrl)
+				//epsFUrl := strings.ReplaceAll(oneEpsMixInfo.PhysicalVideoFileFullPath, oneSeriesDirPath.Path, desUrl)
 				oneVideoInfo := backend2.OneVideoInfo{
 					Name:                     videoFileName,
 					VideoFPath:               oneEpsMixInfo.PhysicalVideoFileFullPath,
@@ -866,7 +876,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 				}
 				matchedSubFileByOneVideoUrl := make([]string, 0)
 				for _, oneSubFPath := range matchedSubFileByOneVideo {
-					oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneSeriesDirPath.Path, desUrl)
+					oneSubFUrl := path_helper.ChangePhysicalPathToSharePath(oneSubFPath, oneSeriesDirPath.Path, desUrl)
+					//oneSubFUrl := strings.ReplaceAll(oneSubFPath, oneSeriesDirPath.Path, desUrl)
 					matchedSubFileByOneVideoUrl = append(matchedSubFileByOneVideoUrl, oneSubFUrl)
 				}
 				oneVideoInfo.SubFPathList = append(oneVideoInfo.SubFPathList, matchedSubFileByOneVideoUrl...)
@@ -903,7 +914,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 					v.log.Warningln("scrabbleUpVideoListEmby.seriesProcess.pathUrlMap", oneSeriesDirPath.Path)
 					continue
 				}
-				dirRootUrl := strings.ReplaceAll(oneEpsMixInfo.PhysicalSeriesRootDir, oneSeriesDirPath.Path, desUrl)
+				dirRootUrl := path_helper.ChangePhysicalPathToSharePath(oneEpsMixInfo.PhysicalSeriesRootDir, oneSeriesDirPath.Path, desUrl)
+				//dirRootUrl := strings.ReplaceAll(oneEpsMixInfo.PhysicalSeriesRootDir, oneSeriesDirPath.Path, desUrl)
 
 				oneSeasonInfo = backend2.SeasonInfo{
 					Name:          seriesName,