public async Task <List <TorrentDescriptor> > Handle(GetCompletedTorrents request, CancellationToken cancellationToken) { m_logger.LogDebug("Getting completed torrents"); try { return(await GetCompletedTorrents(request)); } catch (System.Exception ex) { m_logger.LogError(ex, "Couldnt get completed torrents"); throw; } }
public async Task <List <TorrentDescriptor> > Handle(GetCompletedTorrents request, CancellationToken cancellationToken) { await API.Login(m_username, m_password); m_logger.LogInformation("Getting completed torrents"); var completed = new List <TorrentDescriptor>(); try { var torrents = await API.GetTorrents(); m_logger.LogInformation("Found {count} torrents", torrents.Count); foreach (var torrent in torrents) { if (torrent.Progress == 1000.0) { // Log( "Label " + torrent.Label.ToString() ); if (torrent.Category == "TV" && request.Type == TorrentMediaType.TV) { m_logger.LogInformation("Torrent TV {name} is completed", torrent.Name); completed.Add(ToDescriptor(torrent)); } else if (torrent.Category.Contains("Movie") && request.Type == TorrentMediaType.Movie) { m_logger.LogInformation("Torrent Movie {name} is completed", torrent.Name); completed.Add(ToDescriptor(torrent)); } else { m_logger.LogInformation("Torrent {name} has label {label} which didnt match", torrent.Name, torrent.Category); } } } } catch (Exception ex) { m_logger.LogError(ex, "Could not acquire list of torrents"); throw; } return(completed); }
private async Task <List <TorrentDescriptor> > GetCompletedTorrents(GetCompletedTorrents request) { var completed = new List <TorrentDescriptor>(); var list = await m_client.GetListAsync(); if (list.Error != null) { m_logger.LogError(list.Error, "Could not acquire list of torrents"); throw list.Error; } var torrents = list.Result.Torrents; m_logger.LogInformation("Found {count} torrents", torrents.Count); foreach (var torrent in torrents) { if (torrent.Progress == 1000.0) { // Log( "Label " + torrent.Label.ToString() ); if (torrent.Label == "TV" && request.Type == TorrentMediaType.TV) { m_logger.LogInformation("Torrent TV {name} is completed", torrent.Name); completed.Add(ToDescriptor(torrent)); } else if (torrent.Label.Contains("Movie") && request.Type == TorrentMediaType.Movie) { m_logger.LogInformation("Torrent Movie {name} is completed", torrent.Name); completed.Add(ToDescriptor(torrent)); } else { m_logger.LogInformation("Torrent {name} has label {label} which didnt match", torrent.Name, torrent.Label); } } } return(completed); }