public string Get(TorrentData request) { UpdateTorrentList(); var totalDownloadRate = FileSizeConversions.SizeSuffix(Torrents.Sum(t => Convert.ToInt32(t.DownloadSpeed))).Split(' '); var totalUploadRate = FileSizeConversions.SizeSuffix(Torrents.Sum(t => Convert.ToInt32(t.UploadSpeed))).Split(' '); var totalRecordCount = Torrents.Count; //if (request.StartIndex != null) //{ // Torrents = Torrents.GetRange(request.StartIndex.Value, 20); //} switch (request.SortBy) { case "DateAdded": Torrents = Torrents.OrderBy(t => DateTime.Parse(t.AddedDate)).Reverse().ToList(); break; case "Name": Torrents = Torrents.OrderBy(t => t.Name).ToList(); break; case "FileSize": Torrents = Torrents.OrderBy(t => Convert.ToInt64(t.TotalBytes)).Reverse().ToList(); break; } return(JsonSerializer.SerializeToString(new TorrentData() { torrents = Torrents, TotalRecordCount = totalRecordCount, sizeDownload = totalDownloadRate[0], sizeSuffixDownload = totalDownloadRate[1], sizeUpload = totalUploadRate[0], sizeSuffixUpload = totalUploadRate[1], sizeTotalDriveSpace = FileSizeConversions.SizeSuffix(Torrents.Sum(t => Convert.ToInt64(t.TotalBytes))), sizeTotalDriveSpaceBytes = Torrents.Sum(t => Convert.ToInt64(t.TotalBytes)).ToString() })); }
public static List <Torrent> ParseTorrentListInfo(List <object[]> obj) { var config = Plugin.Instance.Configuration; var dir = config.FinishedDownloadsLocation ?? string.Empty; // ReSharper disable once ComplexConditionExpression var list = obj.Select(t => new Torrent { Hash = (string)t[0], Status = (string)t[1] == "201" ? "started" : (string)t[1] == "136" ? "stopped" : (string)t[1] == "233" ? "paused" : (string)t[1] == "130" ? "re-check" : "queued", Name = (string)t[2], Size = FileSizeConversions.SizeSuffix(Convert.ToInt64((string)t[3])), TotalBytes = (string)t[3], Progress = (string)t[4], Downloaded = (string)t[5], Uploaded = (string)t[6], Ratio = (string)t[7], UploadSpeed = (string)t[8], DownloadSpeedFriendly = FileSizeConversions.SizeSuffix(Convert.ToInt64((string)t[9])), DownloadSpeed = (string)t[9], Eta = (Convert.ToInt32((string)t[10]) / 60) + " minute(s)", Label = (string)t[11], PeersConnected = (string)t[12], PeersInSwarm = (string)t[13], SeedsConnected = (string)t[14], SeedsInSwarm = (string)t[15], Availability = (string)t[16], TorrentQueueOrder = (string)t[17], Remaining = (string)t[18], AddedDate = getAddedDate(dir, (string)t[2]) }); return(list.ToList()); }
public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress) { var config = Plugin.Instance.Configuration; if (Equals(config.MonitoredFolder, null) || Equals(config.EmbyAutoOrganizeFolderPath, null)) { return; } logger = LogManager.GetLogger(Plugin.Instance.Name); var directoryInfo = FileSystem.GetDirectories(path: config.MonitoredFolder); var directoryInfoList = directoryInfo.ToList(); logger.Info("Found: " + directoryInfoList.Count() + " folders in " + config.MonitoredFolder); foreach (var newMediaFolder in directoryInfoList) { if (FileSystem.FileExists(newMediaFolder.FullName + "\\####emby.extracted####")) { continue; } logger.Info("New media file: " + newMediaFolder.FullName); logger.Info("Creating compression marker " + newMediaFolder.FullName + "\\####emby.extracted####"); using (var sr = new StreamWriter(newMediaFolder.FullName + "\\####emby.extracted####")) { sr.Flush(); } var newMediaFiles = FileSystem.GetFiles(newMediaFolder.FullName); foreach (var file in newMediaFiles) { if (file.FullName.IndexOf("sample", StringComparison.OrdinalIgnoreCase) >= 0) { continue; } logger.Info("File checked: " + file.Name); switch (file.Extension) { case ".rar": logger.Info("Found new compressed file to decompress: " + file.Name); await Task.Run( () => UnzipAndCopyFiles.BeginDecompressionAndCopy(file.FullName, file.Name, logger, progress, config), cancellationToken); config.CompletedItems.Add(new ExtractionInfo { Name = newMediaFolder.Name, completed = DateTime.Now.ToString("yyyy-M-dd--HH:mm-ss"), size = FileSizeConversions.SizeSuffix(file.Length), extention = file.Extension, CreationTimeUTC = file.CreationTimeUtc, CopyType = "Unpacked" }); break; // ReSharper disable RedundantCaseLabel case ".mkv": case ".avi": case ".mp4": logger.Info("Found New File to Copy: " + file.Name); await Task.Run( () => CopyFiles.BeginCopy(file.FullName, file.Name, progress, Plugin.Instance.Configuration), cancellationToken); config.CompletedItems.Add(new ExtractionInfo { Name = newMediaFolder.Name, completed = DateTime.Now.ToString("yyyy-M-dd--HH:mm-ss"), size = FileSizeConversions.SizeSuffix(file.Length), extention = file.Extension, CreationTimeUTC = file.CreationTimeUtc, CopyType = "Copied" }); break; } } Plugin.Instance.UpdateConfiguration(new PluginConfiguration { EmbyAutoOrganizeFolderPath = config.EmbyAutoOrganizeFolderPath, MonitoredFolder = config.MonitoredFolder, CompletedItems = config.CompletedItems }); } progress.Report(100); }
public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress) { var config = Plugin.Instance.Configuration; if (config.MonitoredFolder is null || config.EmbyAutoOrganizeFolderPath is null) { return; } logger = LogManager.GetLogger(Plugin.Instance.Name); var monitoredDirectoryInfo = FileSystem.GetDirectories(path: config.MonitoredFolder); var monitoredDirectoryContents = monitoredDirectoryInfo.ToList(); logger.Info("Found: " + monitoredDirectoryContents.Count() + " folders in " + config.MonitoredFolder); foreach (var mediaFolder in monitoredDirectoryContents) { //Ignore this directory if there is an 'extraction marker' file present because we have already extracted the contents of this folder. if (FileSystem.FileExists(mediaFolder.FullName + "\\####emby.extracted####")) { continue; } logger.Info("New media folder: " + mediaFolder.FullName); CreateExtractionMarker(mediaFolder.FullName, logger); var newMediaFiles = FileSystem.GetFiles(mediaFolder.FullName); foreach (var file in newMediaFiles) { if (file.FullName.IndexOf("sample", StringComparison.OrdinalIgnoreCase) >= 0) { continue; } logger.Info("File checked: " + file.Name); switch (file.Extension) { case ".rar": logger.Info("Found new compressed file to extract: " + file.Name); await Task.Run( () => UnzipAndCopyFiles.BeginCompressedFileExtraction(file.FullName, file.Name, logger, progress, config, SessionManager), cancellationToken); config.CompletedItems.Add(new ExtractionInfo { Name = mediaFolder.Name, completed = DateTime.Now, size = FileSizeConversions.SizeSuffix(file.Length), extension = file.Extension, CopyType = "Unpacked" }); break; case ".mkv": case ".avi": case ".mp4": logger.Info("Found new file to copy: " + file.Name); await Task.Run( () => CopyFiles.BeginFileCopy(file.FullName, file.Name, progress, Plugin.Instance.Configuration, SessionManager), cancellationToken); config.CompletedItems.Add(new ExtractionInfo { Name = mediaFolder.Name, completed = DateTime.Now, size = FileSizeConversions.SizeSuffix(file.Length), extension = file.Extension, CopyType = "Copied" }); break; } } Plugin.Instance.UpdateConfiguration(new PluginConfiguration { EmbyAutoOrganizeFolderPath = config.EmbyAutoOrganizeFolderPath, MonitoredFolder = config.MonitoredFolder, CompletedItems = config.CompletedItems.Where(i => i.completed > DateTime.Now.AddDays(-30)).ToList() //No need to keep a list of items that are 30 days old }); } progress.Report(100); }