浏览代码

修复 emby 下多级目录目录拼接问题 fix #198

Signed-off-by: 716 <[email protected]>
716 3 年之前
父节点
当前提交
ca16aa3552

+ 36 - 31
internal/logic/emby_helper/embyhelper.go

@@ -135,27 +135,27 @@ func (em *EmbyHelper) RefreshEmbySubList() (bool, error) {
 // findMappingPath 从 Emby 内置路径匹配到物理路径
 // X:\电影    - /mnt/share1/电影
 // X:\连续剧  - /mnt/share1/连续剧
-func (em *EmbyHelper) findMappingPath(videoEmbyFullPath string, isMovieOrSeries bool) (bool, string, string) {
+func (em *EmbyHelper) findMappingPath(mixInfo *emby.EmbyMixInfo, isMovieOrSeries bool) bool {
 	// 这里进行路径匹配的时候需要考虑嵌套路径的问题
 	// 比如,映射了 /电影  以及 /电影/AA ,那么如果有一部电影 /电影/AA/xx/xx.mkv 那么,应该匹配的是最长的路径 /电影/AA
 	matchedEmbyPaths := make([]string, 0)
 	if isMovieOrSeries == true {
 		// 电影的情况
 		for _, embyPath := range em.EmbyConfig.MoviePathsMapping {
-			if strings.Contains(videoEmbyFullPath, embyPath) == true {
+			if strings.HasPrefix(mixInfo.VideoInfo.Path, embyPath) == true {
 				matchedEmbyPaths = append(matchedEmbyPaths, embyPath)
 			}
 		}
 	} else {
 		// 连续剧的情况
 		for _, embyPath := range em.EmbyConfig.SeriesPathsMapping {
-			if strings.Contains(videoEmbyFullPath, embyPath) == true {
+			if strings.HasPrefix(mixInfo.VideoInfo.Path, embyPath) == true {
 				matchedEmbyPaths = append(matchedEmbyPaths, embyPath)
 			}
 		}
 	}
 	if len(matchedEmbyPaths) < 1 {
-		return false, "", ""
+		return false
 	}
 	// 排序得到匹配上的路径,最长的那个
 	pathSlices := sortStringSliceByLength(matchedEmbyPaths)
@@ -181,12 +181,39 @@ func (em *EmbyHelper) findMappingPath(videoEmbyFullPath string, isMovieOrSeries
 	}
 	// 如果匹配不上
 	if nowPhRootPath == "" {
-		return false, "", ""
+		return false
 	}
 
+	if isMovieOrSeries == true {
+		// 电影
+		mixInfo.PhysicalVideoFileFullPath = strings.ReplaceAll(mixInfo.VideoInfo.Path, pathSlices[0].Path, nowPhRootPath)
+		// 因为电影搜索的时候使用的是完整的视频目录,所以这个字段并不重要
+		//mixInfo.PhysicalRootPath = strings.ReplaceAll(mixInfo.VideoInfo.Path, pathSlices[0].Path, nowPhRootPath)
+		// 这个电影的文件夹
+		mixInfo.VideoFolderName = filepath.Base(filepath.Dir(mixInfo.VideoInfo.Path))
+		mixInfo.VideoFileName = filepath.Base(mixInfo.VideoInfo.Path)
+	} else {
+		// 连续剧
+		ancestorIndex := -1
+		// 找到连续剧文件夹这一层
+		for i, ancestor := range mixInfo.Ancestors {
+			if ancestor.Type == "Series" {
+				ancestorIndex = i
+				break
+			}
+		}
+		if ancestorIndex == -1 {
+			// 说明没有找到连续剧文件夹的名称,那么就应该跳过
+			return false
+		}
+		mixInfo.PhysicalVideoFileFullPath = strings.ReplaceAll(mixInfo.VideoInfo.Path, pathSlices[0].Path, nowPhRootPath)
+		mixInfo.PhysicalRootPath = mixInfo.Ancestors[ancestorIndex+1].Path
+		// 这个剧集的文件夹
+		mixInfo.VideoFolderName = filepath.Base(mixInfo.Ancestors[ancestorIndex].Path)
+		mixInfo.VideoFileName = filepath.Base(mixInfo.VideoInfo.Path)
+	}
 
-	outPhFullPath := strings.ReplaceAll(videoEmbyFullPath, pathSlices[0].Path, nowPhRootPath)
-	return true, outPhFullPath, nowPhRootPath
+	return true
 }
 
 func (em *EmbyHelper) filterEmbyVideoList(videoIdList []string, isMovieOrSeries bool) ([]emby.EmbyMixInfo, error) {
@@ -205,39 +232,17 @@ func (em *EmbyHelper) filterEmbyVideoList(videoIdList []string, isMovieOrSeries
 		if isMovieOrSeries == true {
 			// 电影
 			// 过滤掉不符合要求的,拼接绝对路径
-			isFit, physicalVideoFPath, physicalRootPath := em.findMappingPath(info.Path, isMovieOrSeries)
+			isFit := em.findMappingPath(&mixInfo, isMovieOrSeries)
 			if isFit == false {
 				return nil, err
 			}
-			mixInfo.VideoFileFullPath = physicalVideoFPath
-			mixInfo.PhysicalRootPath = physicalRootPath
-			// 这个电影的文件夹
-			mixInfo.VideoFolderName = filepath.Base(filepath.Dir(mixInfo.VideoInfo.Path))
-			mixInfo.VideoFileName = filepath.Base(mixInfo.VideoInfo.Path)
 		} else {
 			// 连续剧
 			// 过滤掉不符合要求的,拼接绝对路径
-			isFit, physicalVideoFPath, physicalRootPath := em.findMappingPath(info.Path, isMovieOrSeries)
+			isFit := em.findMappingPath(&mixInfo, isMovieOrSeries)
 			if isFit == false {
 				return nil, err
 			}
-			mixInfo.VideoFileFullPath = physicalVideoFPath
-			mixInfo.PhysicalRootPath = physicalRootPath
-			// 这个剧集的文件夹
-			ancestorIndex := -1
-			// 找到连续剧文件夹这一层
-			for i, ancestor := range mixInfo.Ancestors {
-				if ancestor.Type == "Series" {
-					ancestorIndex = i
-					break
-				}
-			}
-			if ancestorIndex == -1 {
-				// 说明没有找到连续剧文件夹的名称,那么就应该跳过
-				return nil, err
-			}
-			mixInfo.VideoFolderName = filepath.Base(mixInfo.Ancestors[ancestorIndex].Path)
-			mixInfo.VideoFileName = filepath.Base(mixInfo.VideoInfo.Path)
 		}
 
 		return &mixInfo, nil

+ 1 - 1
internal/logic/series_helper/seriesHelper.go

@@ -110,7 +110,7 @@ func ReadSeriesInfoFromEmby(seriesDir string, imdbInfo *imdb.Title, seriesList [
 	EpisodeDict := make(map[string]series.EpisodeInfo)
 	SubDict := make(map[string][]series.SubInfo)
 	for _, info := range seriesList {
-		getEpsInfoAndSubDic(info.VideoFileFullPath, EpisodeDict, SubDict)
+		getEpsInfoAndSubDic(info.PhysicalVideoFileFullPath, EpisodeDict, SubDict)
 	}
 
 	for _, episodeInfo := range EpisodeDict {

+ 2 - 2
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper.go

@@ -91,7 +91,7 @@ package sub_timeline_fixer
 //	// 先做电影的字幕校正、然后才是连续剧的
 //	for _, info := range movieList {
 //		// path.Dir 在 Windows 有梗,所以换个方式获取路径
-//		videoRootPath := filepath.Dir(info.VideoFileFullPath)
+//		videoRootPath := filepath.Dir(info.PhysicalVideoFileFullPath)
 //		err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 //		if err != nil {
 //			return err
@@ -103,7 +103,7 @@ package sub_timeline_fixer
 //	for _, infos := range seriesList {
 //		for _, info := range infos {
 //			// path.Dir 在 Windows 有梗,所以换个方式获取路径
-//			videoRootPath := filepath.Dir(info.VideoFileFullPath)
+//			videoRootPath := filepath.Dir(info.PhysicalVideoFileFullPath)
 //			err = s.fixOneVideoSub(info.VideoInfo.Id, videoRootPath)
 //			if err != nil {
 //				return err

+ 1 - 1
internal/pkg/downloader/downloader.go

@@ -145,7 +145,7 @@ func (d *Downloader) GetUpdateVideoListFromEmby() error {
 	}
 	// 获取全路径
 	for _, info := range movieList {
-		d.movieFileFullPathList = append(d.movieFileFullPathList, info.VideoFileFullPath)
+		d.movieFileFullPathList = append(d.movieFileFullPathList, info.PhysicalVideoFileFullPath)
 	}
 	// 输出调试信息
 	d.log.Debugln("GetUpdateVideoListFromEmby - DebugInfo - seriesSubNeedDlMap Start")

+ 6 - 6
internal/types/emby/type.go

@@ -151,12 +151,12 @@ func (info EmbyVideoInfoByUserId) GetDefaultSubIndex() int {
 }
 
 type EmbyMixInfo struct {
-	VideoFolderName   string // 电影就是电影的文件夹名称,连续剧就是对应的剧集的 root 文件夹
-	VideoFileName     string // 视频文件名
-	VideoFileFullPath string // 视频的物理路径(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
-	PhysicalRootPath  string // 视频在那个物理根目录中(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
-	Ancestors         []EmbyItemsAncestors
-	VideoInfo         EmbyVideoInfo
+	VideoFolderName           string // 电影就是电影的文件夹名称,连续剧就是对应的剧集的 root 文件夹
+	VideoFileName             string // 视频文件名
+	PhysicalVideoFileFullPath string // 视频的物理路径(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
+	PhysicalRootPath          string // 视频在那个物理根目录中(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
+	Ancestors                 []EmbyItemsAncestors
+	VideoInfo                 EmbyVideoInfo
 }
 
 type Time time.Time