/// <summary> /// /// </summary> /// <param name="srcPath"></param> /// <param name="destPath"></param> /// <returns></returns> public List <FileInfo> MoveMatchingSubtitlesOf(string srcPath, string destPath) { var subtitles = new List <FileInfo>(); var srcBasePath = Path.Combine(Path.GetDirectoryName(srcPath), Path.GetFileNameWithoutExtension(srcPath)); var destBasePath = Path.Combine(Path.GetDirectoryName(destPath), Path.GetFileNameWithoutExtension(destPath)); //reverse logic to iterate over folder MatchingSubtitlesExtensions.ForEach(subExt => { var subPath = srcBasePath + subExt; if (File.Exists(subPath)) { var srtDestPath = destBasePath + subExt; var srtDestPath2Letters = FilesystemHelper.ConvertToTwoLetterIsoLanguageNameSubtitle(srtDestPath); if (srtDestPath2Letters != null) { srtDestPath = srtDestPath2Letters; } FilesystemHelper.MoveOrReplace(subPath, srtDestPath); subtitles.Add(new FileInfo(srtDestPath)); } }); return(subtitles); }
public void ConvertToTwoLetterIsoLanguageNameSubtitleTest(string subExt, string expectedResultEndsWith) { var srtFilename = "the.big.bang.theory.s10.e01"; var srtBasePath = Path.Combine(Path.GetTempPath(), TestHelper.Uid(), srtFilename); var res = FilesystemHelper.ConvertToTwoLetterIsoLanguageNameSubtitle(srtBasePath + subExt); if (expectedResultEndsWith == null) { Assert.IsNull(res); } else { Assert.AreEqual(srtBasePath + expectedResultEndsWith, res); } }
public bool GetSubtitles(string path, out string srtPath, string lang = "eng", bool nonStrict = false) { // todo: wrap in requst/result object srtPath = ""; var args = "-get-subtitles " + path.Quoted() + " --lang " + lang.Quoted(); if (nonStrict) { args += " -non-strict "; } var expectedSrtPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)) + $".{lang}.srt"; logger.LogInformation("filebot " + args); Console.WriteLine("filebot " + args); var code = OsHelper.ExecuteCommand("filebot", args, out var output, out var error); var msg = $"code: {code}, output: {output}, error: {error}"; Console.WriteLine(msg); logger.LogInformation(msg); if (!File.Exists(expectedSrtPath)) { Console.WriteLine(expectedSrtPath + " does not exists"); return(false); } /* -get-subtitles option always returns 0 regardless of failure */ logger.LogInformation("Renaming to 2 letter iso code"); var twoLetterSrtPath = FilesystemHelper.ConvertToTwoLetterIsoLanguageNameSubtitle(expectedSrtPath); if (twoLetterSrtPath != null) { FilesystemHelper.MoveOrReplace(expectedSrtPath, twoLetterSrtPath); srtPath = twoLetterSrtPath; } return(true); }