public long GetDownloadedSize(string hash) { OsHelper.ExecuteCommand("transmission-remote", $"{TrAuth} -t {hash} -i", out var output, out var _); if (string.IsNullOrEmpty(output)) { return(0); } return(new TransmissionItem(output, null).DownloadedSize); }
public bool AddTorrent(string torrentPath, string downloadDirPath) { var args = $"{TrAuth} -a " + torrentPath.Quoted() + " -w " + downloadDirPath.Quoted() + " --torrent-done-script " + settings.TorrentDoneScript.Quoted(); logger.LogInformation("transmission-remote " + args); var result = OsHelper.ExecuteCommand("transmission-remote", args, out var output, out var error); logger.LogInformation($"output: {output} error: {error}"); return(result == 0); }
public bool TryGetDuration(string path, out TimeSpan duration) { duration = TimeSpan.FromMilliseconds(0); if (OsHelper.ExecuteCommand("mediainfo", $"--Inform=\"General;%Duration%\" \"{path}\"", out var outputDuration, out var stderr) != 0) { return(false); } if (!double.TryParse(outputDuration, out var value)) { return(false); } duration = TimeSpan.FromMilliseconds(value); return(true); }
/// <summary> /// Get the media location for the file /// </summary> /// <param name="request"></param> /// <returns></returns> public RenameResult Rename(RenameRequest request) { var result = new RenameResult(); var destFormat = request.BaseDestPath + Path.DirectorySeparatorChar + "{plex}"; var args = "-rename " + request.Path.Quoted() + " --format " + destFormat.Quoted() + " -non-strict --action " + request.Action.Quoted(); if (request.Db != null) { args += " --db " + request.Db.Quoted(); } logger.LogInformation("filebot " + args); result.RawExecutedCommand = $"filebot {args}"; result.ExitCode = OsHelper.ExecuteCommand("filebot", args, out var stdout, out var stderr); result.StandardOutput = stdout; result.StandardError = stderr; logger.LogInformation($"code: {result.ExitCode}, output: {result.StandardOutput}, error: {result.StandardError}"); if (result.ExitCode != 0) { var match = FileAlreadyExistsPattern.Match(result.StandardOutput); if (match.Success && match.Groups["dest"].Success) { result.DestPath = match.Groups["dest"].Value; logger.LogInformation($"Filebot.TryRename [SUCCESS] [FileAlreadyExists] [{result.DestPath}]"); result.Reason = "File already exists at dest location"; result.Succeeded = true; return(result); } } var p = new Regex(@"\[" + request.Action.ToUpper() + @"\].*\[.*\] to \[(?<dest>.*)\]").Match(result.StandardOutput); if (p.Success && p.Groups["dest"].Success) { result.DestPath = p.Groups["dest"].Value; result.Succeeded = true; result.Reason = "Found"; logger.LogWarning($"Filebot.TryRename [SUCCESS] [{result.DestPath}]"); return(result); } result.Succeeded = false; result.Reason = "Failed to capture destPath in stdout"; logger.LogWarning("Filebot.TryRename [FAILED] to capture destPath in output: ", result.StandardOutput); return(result); }
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); }
public bool RemoveTorrent(string hash) { return(OsHelper.ExecuteCommand("transmission-remote", $"{TrAuth} -t {hash} -r", out _, out _) == 0); }
public int DownloadTorrentFile(string magnetLink, string downloadFolder, TimeSpan?timeout = null) { return(OsHelper.ExecuteCommand("aria2c", "--bt-metadata-only=true --bt-save-metadata=true -q " + magnetLink.Quoted() + " -d " + downloadFolder.Quoted(), out _, out _, timeout)); }