Пример #1
0
        public async Task DownloadWantedEpisodes()
        {
            var episodesToDownload = _service.GetWantedEpisodes();

            foreach (var episode in episodesToDownload)
            {
                var search  = BuildSearchQuery(episode);
                var torrent = _searchProvider.GetTorrent(search);

                if (torrent == null)
                {
                    _logger.Info($"No torrent found for {search}");
                    _analyticsService.ReportEvent(AnalyticEvent.SearchFailed);
                    continue;
                }

                try
                {
                    var torrentFileName = $"{_settings.TorrentWatchFolder}{torrent.Name}.torrent";
                    await _webClient.DownloadFileAsync(torrent.DownloadUrl, torrentFileName);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }

                episode.DownloadStatus = "DOWN";
                _service.AddOrUpdate(episode);
                _logger.Debug($"Updating {episode.SeriesName} s{episode.Season:D2}e{episode.EpisodeNumber:D2} as Downloaded");
            }

            _service.SaveChanges();
        }