예제 #1
0
        public Task Invoke()
        {
            var items = repository.FindRecentCompletedItems(4);

            Log.Information($"[GetSubtitlesJob]: Found {items.Count} items needing subtitles");
            foreach (var item in items)
            {
                var videoFileRelPath = item.MovedFiles.OrderByDescending(x => x.Size).FirstOrDefault()?.Path;
                Log.Information($"[GetSubtitlesJob] handling [{videoFileRelPath}]");
                var videoFullPath = Path.Combine(settings.MediaLibraryPath, videoFileRelPath);
                var fileInfo      = new FileInfo(videoFullPath);
                if (!fileInfo.Exists || fileInfo.Directory == null)
                {
                    Log.Information($"[GetSubtitlesJob] cannot download missing subtitles for [{videoFileRelPath}] File has been moved");
                    continue;
                }

                var subs = fileInfo.Directory.EnumerateFiles("*.srt").ToList();
                Log.Information($"[GetSubtitlesJob] {subs.Count} found " + string.Join(", ", subs.Select(c => $"[{c}]")));
                if (subs.Count == 0)
                {
                    var resEngSub = filebot.GetSubtitles(videoFullPath, out _, "eng");
                    Log.Information($"[GetSubtitlesJob] [eng] subtites: { (resEngSub ? "OK" : "KO") }");
                    var resFraSub = filebot.GetSubtitles(videoFullPath, out _, "fra");
                    Log.Information($"[GetSubtitlesJob] [fra] subtites: { (resFraSub ? "OK" : "KO") }");
                }
            }
            return(Task.CompletedTask);
        }
예제 #2
0
        public List <FileSystemInfo> ProcessDir(string path)
        {
            var processedFiles = new List <FileSystemInfo>();
            var dirInfo        = new DirectoryInfo(path);
            var fsInfos        = dirInfo.EnumerateFiles("*", SearchOption.AllDirectories).ToList();

            foreach (var fsInfo in fsInfos)
            {
                logger.LogInformation("Handling " + fsInfo.Name);
                switch (Path.GetExtension(fsInfo.Name).ToLower())
                {
                case ".avi":
                case ".mp4":
                case ".mkv":
                    var createdMediaItems = MoveVideoFile(fsInfo.FullName);
                    processedFiles.AddRange(createdMediaItems);
                    var movedVideoFile = createdMediaItems.Last();
                    processedFiles.AddRange(MoveMatchingSubtitlesOf(fsInfo.FullName, movedVideoFile.FullName));
                    if (filebot.GetSubtitles(movedVideoFile.FullName, out var engSrtPath, "eng"))
                    {
                        processedFiles.Add(new FileInfo(engSrtPath));
                    }
                    if (filebot.GetSubtitles(movedVideoFile.FullName, out var fraSrtPath, "fra"))
                    {
                        processedFiles.Add(new FileInfo(fraSrtPath));
                    }
                    break;

                case ".flac":
                case ".mp3":
                    processedFiles.Add(MoveMusicFile(fsInfo.FullName));
                    break;

                case ".rar":
                    if (archiveExtractorService.HandleRarFile(fsInfo.FullName, out var destDir))
                    {
                        processedFiles.AddRange(ProcessDir(destDir));
                    }
                    else
                    {
                        processedFiles.AddRange(Directory.GetFiles(destDir, "*.rar", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)));
                    }
                    break;

                default:
                    processedFiles.Add(MoveUnknownFile(fsInfo.FullName));
                    break;
                }
            }
            return(processedFiles);
        }
        public PlainMediaItem GetSubtitles(PlainMediaItem item, string lang)
        {
            if (item.FileSystemInfo.IsDirectory())
            {
                logger.LogWarning("cannot getSubtitles: " + item.Path + " is a directory");
                return(null);
            }

            if (!filebot.GetSubtitles(item.FileSystemInfo.FullName, out var srtPath, lang))
            {
                logger.LogWarning("getSubtitles: " + item.Path + " subtitles not found");
                return(null);
            }

            return(new PlainMediaItem(new FileInfo(srtPath), settings.MediaLibraryPath));
        }