public async Task TreatDownloadedMovie(MovieMagnet magnet) { try { await _localFileService.GenerateMovieFile(magnet); List <MovieMagnet> movieMagnets = new List <MovieMagnet>(); if (magnet.HasSub) { _logger.LogInformation("Movie {movieNumber} has downloaded sub version. Checking non-sub folder and delete it.", magnet.MovieNumber); movieMagnets = _movieMagnetService.FindMovieMagnetByStatus(MagnetStatus.Finished, magnet.IdMovie); foreach (MovieMagnet movieMagnet in movieMagnets) { await _localFileService.DeleteFolder(movieMagnet.SavePath); movieMagnet.IdStatus = MagnetStatus.Archived; } } movieMagnets.Add(magnet); _movieMagnetService.SaveMovieMagnetList(movieMagnets); await _qbittorrentService.DeleteTorrentAsync(magnet.Hash, false); Movie movie = _movieService.FindMovieById(magnet.IdMovie); _movieService.UpdateStatus(movie, magnet.HasSub ? MovieStatus.Finished : MovieStatus.Downloaded); _movieService.SaveMovie(movie); } catch (Exception ex) { _logger.LogError(ex, "Error occurred when generating the downloaded movie file - {movieNumber}", magnet.MovieNumber); magnet.IdStatus = MagnetStatus.InError; _movieMagnetService.SaveMovieMagnet(magnet); } }
public void ScrapeMovieMagnet(Movie movie) { try { List <MovieMagnet> magnets = new List <MovieMagnet>(); foreach (MagnetSource magnetSource in _magnetSettings.GetSearchSources()) { switch (magnetSource) { case MagnetSource.Javbus: magnets.AddRange(SearchMagnetFromJavbus(movie)); break; case MagnetSource.Sukebei: magnets.AddRange(SearchMagnetFromSukebei(movie)); break; } } magnets.RemoveAll(m => m.Size == 0 || _movieMagnetService.FindMovieMagnetByHash(m.Hash) != null); magnets = magnets.GroupBy(x => x.Hash.ToLower()).Select(x => x.First()).OrderByDescending(x => x.HasSub).ThenByDescending(x => x.IsHD).ThenByDescending(x => x.DtMagnet).ThenByDescending(x => x.Size).ToList(); if (magnets.Count > 0) { _movieMagnetService.SaveMovieMagnetList(magnets); _movieService.UpdateStatus(movie, MovieStatus.HasTorrent); _movieService.SaveMovie(movie); _logger?.LogInformation("Scrape magnet for movie {movieNumber}: {magCount} new torrents inserted", movie.Number, magnets.Count); } else { _logger?.LogWarning("Scrape magnet for movie {movieNumber}: no new torrent found.", movie.Number); } } catch (Exception ex) { _logger?.LogError(ex, "Error occurred when scraping magnet for movie: {movieNumber}", movie.Number); } }