public virtual bool DownloadReport(EpisodeParseResult parseResult) { var downloadTitle = GetDownloadTitle(parseResult); var provider = GetActiveDownloadClient(); var recentEpisode = ContainsRecentEpisode(parseResult); bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode); if (success) { logger.Trace("Download added to Queue: {0}", downloadTitle); foreach (var episode in parseResult.Episodes) { var history = new History { Date = DateTime.Now, Indexer = parseResult.Indexer, IsProper = parseResult.Quality.Proper, Quality = parseResult.Quality.Quality, NzbTitle = parseResult.OriginalString, EpisodeId = episode.EpisodeId, SeriesId = episode.SeriesId, NzbInfoUrl = parseResult.NzbInfoUrl, ReleaseGroup = parseResult.ReleaseGroup, }; _historyProvider.Add(history); _episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId); _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Downloading, null); } _externalNotificationProvider.OnGrab(downloadTitle); } return(success); }
public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false) { if (episodeFile == null) { throw new ArgumentNullException("episodeFile"); } var series = _seriesProvider.GetSeries(episodeFile.SeriesId); var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId); string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); //Only rename if existing and new filenames don't match if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) { Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); return(null); } if (!_diskProvider.FileExists(episodeFile.Path)) { Logger.Error("Episode file path does not exist, {0}", episodeFile.Path); return(null); } _diskProvider.CreateDirectory(newFile.DirectoryName); Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName); _diskProvider.MoveFile(episodeFile.Path, newFile.FullName); //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important. try { _diskProvider.InheritFolderPermissions(newFile.FullName); } catch (UnauthorizedAccessException ex) { Logger.Debug("Unable to apply folder permissions to: ", newFile.FullName); Logger.TraceException(ex.Message, ex); } episodeFile.Path = newFile.FullName; _mediaFileProvider.Update(episodeFile); var parseResult = Parser.ParsePath(episodeFile.Path); parseResult.Series = series; parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper }; parseResult.Episodes = episodes; var message = _downloadProvider.GetDownloadTitle(parseResult); if (newDownload) { _externalNotificationProvider.OnDownload(message, series); foreach (var episode in episodes) { _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Ready, parseResult.Quality); } } else { _externalNotificationProvider.OnRename(message, series); } return(episodeFile); }