Пример #1
0
        public List <FileSystemInfo> MoveVideoFile(string videoSrcPath)
        {
            var filesystemItems = new List <FileSystemInfo>();

            string videoDestPath;
            var    renameResult = filebot.Rename(new RenameRequest {
                Path = videoSrcPath, BaseDestPath = settings.MediaLibraryPath
            });

            if (!renameResult.Succeeded)
            {
                //fallback strategy to move video file based on duration
                logger.LogInformation("[MoveVideoFile] TryRename failed, executing fallback logic");
                mediaInfo.TryGetDuration(videoSrcPath, out var duration);
                var minutesDuration = duration.TotalMinutes;
                var fallbackDir     = "Others";
                if (minutesDuration > 0 && minutesDuration < 105)
                {
                    fallbackDir = "TV Shows";
                }
                else if (minutesDuration >= 105)
                {
                    fallbackDir = "Movies";
                }
                logger.LogInformation($"[MoveVideoFile] TryRename fallback destDir is [{fallbackDir}]");
                videoDestPath = Path.Combine(settings.MediaLibraryPath, fallbackDir, Path.GetFileName(videoSrcPath));
            }
            else
            {
                videoDestPath = renameResult.DestPath;
                logger.LogInformation("[MoveVideoFile] TryRename Succeeded videoDestPath: " + renameResult.DestPath);
            }

            //create dest dir if it does not exists and move item
            var destDirInfo = new DirectoryInfo(Path.GetDirectoryName(videoDestPath));

            //track created directories
            for (var tempDirInfo = destDirInfo; !tempDirInfo.Exists; tempDirInfo = tempDirInfo.Parent)
            {
                filesystemItems.Add(tempDirInfo);
            }

            if (!destDirInfo.Exists)
            {
                destDirInfo.Create();
            }
            filesystemItems.Add(new FileInfo(videoDestPath));
            FilesystemHelper.MoveOrReplace(videoSrcPath, videoDestPath, logger);
            return(filesystemItems);
        }