예제 #1
0
        public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)
        {
            var result = item.Clone();

            var contentPaths = _proxy.GetTorrentContentPaths(item.DownloadId, Settings);

            if (contentPaths.Count < 1)
            {
                throw new DownloadClientUnavailableException($"Failed to fetch list of contents of torrent: {item.DownloadId}");
            }

            if (contentPaths.Count == 1)
            {
                // For single-file torrent, OutputPath should be the path of file.
                result.OutputPath = item.OutputPath + new OsPath(contentPaths[0]);
            }
            else
            {
                // For multi-file torrent, OutputPath should be the path of base directory of torrent.
                var baseDirectoryPaths = contentPaths.ConvertAll(path =>
                                                                 path.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries)[0]);

                // Check first segment (directory) of paths of contents. If all contents share the same directory, use that directory.
                if (baseDirectoryPaths.TrueForAll(path => path == baseDirectoryPaths[0]))
                {
                    result.OutputPath = item.OutputPath + new OsPath(baseDirectoryPaths[0]);
                }

                // Otherwise, OutputPath is already the base directory.
            }

            return(result);
        }
예제 #2
0
        public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)
        {
            // On API version >= 2.6.1 this is already set correctly
            if (!item.OutputPath.IsEmpty)
            {
                return(item);
            }

            var files = Proxy.GetTorrentFiles(item.DownloadId.ToLower(), Settings);

            if (!files.Any())
            {
                _logger.Debug($"No files found for torrent {item.Title} in qBittorrent");
                return(item);
            }

            var properties = Proxy.GetTorrentProperties(item.DownloadId.ToLower(), Settings);
            var savePath   = new OsPath(properties.SavePath);

            var result = item.Clone();

            // get the first subdirectory - QBittorrent returns `/` path separators even on windows...
            var relativePath = new OsPath(files[0].Name);

            while (!relativePath.Directory.IsEmpty)
            {
                relativePath = relativePath.Directory;
            }

            var outputPath = savePath + relativePath.FileName;

            result.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath);

            return(result);
        }