Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public ActionResult Save(string seriesId)
        {
            var series = _searchService.GetTvSeries(seriesId);

            _service.AddOrUpdate(series);
            _service.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public void ProcessMatchedEpisodes(List <TvEpisode> matchedEpisodes)
        {
            if (!matchedEpisodes.Any())
            {
                return;
            }

            foreach (var episode in matchedEpisodes)
            {
                var cleanEpisodeTitle = CleanFileName(episode.Title);
                var sourceFile        = _fileSystem.GetFile(episode.FileName);

                //TODO Refactor episode file naming somewhere centralized.
                var destinationFilename = $"{_destinationFolder.Path}\\{episode.SeriesName}\\Season {episode.Season:D2}\\S{episode.Season:D2}E{episode.EpisodeNumber:D2} - {cleanEpisodeTitle}{sourceFile.Extension}";

                if (!DestinationFileExists(episode))
                {
                    _logger.Info($"Skipped copying File {sourceFile} to {destinationFilename}.  Destination file already exists");
                    DeleteSourceFile(episode.FileName);
                    continue;
                }

                try
                {
                    sourceFile.Copy(destinationFilename);

                    _logger.Info($"Copying {sourceFile} to {destinationFilename}");
                    _analyticsService.ReportEvent(AnalyticEvent.Episode, $"Copying {sourceFile} to {destinationFilename}");
                }
                catch (Exception ex)
                {
                    _analyticsService.ReportEvent(AnalyticEvent.EpisodeFailed, $"Unable to copy {sourceFile} to {destinationFilename}");
                    _logger.Error(ex);
                }

                episode.FileName       = destinationFilename;
                episode.DownloadStatus = "HAVE";

                _tvService.AddOrUpdate(episode);
            }

            _tvService.SaveChanges();
        }