mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-19 21:46:50 -04:00
Patch/onedr0p (#1048)
* Replace Sonarr with Radarr in some more places, update rTorrent to use * Uncomment some lines * Fix CP importing * Upon first sync with adding movies with Lists, it will search for the movie. * Update rarbg indexer, add method to netimportsearch service * Replace german chars in movie title when searching newznab. Update netimportsearchservice
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
@@ -8,6 +9,10 @@ using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
|
||||
namespace NzbDrone.Core.NetImport
|
||||
{
|
||||
@@ -25,14 +30,19 @@ namespace NzbDrone.Core.NetImport
|
||||
private readonly ISearchForNewMovie _movieSearch;
|
||||
private readonly IRootFolderService _rootFolder;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
private readonly ISearchForNzb _nzbSearchService;
|
||||
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
||||
|
||||
|
||||
public NetImportSearchService(INetImportFactory netImportFactory, IMovieService movieService,
|
||||
ISearchForNewMovie movieSearch, IRootFolderService rootFolder, IConfigService configService, Logger logger)
|
||||
ISearchForNewMovie movieSearch, IRootFolderService rootFolder, ISearchForNzb nzbSearchService,
|
||||
IProcessDownloadDecisions processDownloadDecisions, IConfigService configService, Logger logger)
|
||||
{
|
||||
_netImportFactory = netImportFactory;
|
||||
_movieService = movieService;
|
||||
_movieSearch = movieSearch;
|
||||
_nzbSearchService = nzbSearchService;
|
||||
_processDownloadDecisions = processDownloadDecisions;
|
||||
_rootFolder = rootFolder;
|
||||
_logger = logger;
|
||||
_configService = configService;
|
||||
@@ -74,6 +84,8 @@ namespace NzbDrone.Core.NetImport
|
||||
return movies;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Execute(NetImportSyncCommand message)
|
||||
{
|
||||
//if there are no lists that are enabled for automatic import then dont do anything
|
||||
@@ -84,13 +96,69 @@ namespace NzbDrone.Core.NetImport
|
||||
}
|
||||
|
||||
var listedMovies = Fetch(0, true);
|
||||
|
||||
CleanLibrary(listedMovies);
|
||||
|
||||
listedMovies = listedMovies.Where(x => !_movieService.MovieExists(x)).ToList();
|
||||
if (listedMovies.Any())
|
||||
{
|
||||
_logger.Info($"Found {listedMovies.Count()} movies on your auto enabled lists not in your library");
|
||||
}
|
||||
|
||||
|
||||
var importExclusions = new List<string>();
|
||||
if (_configService.ImportExclusions != null)
|
||||
{
|
||||
// Replace `movie-title-tmdbid` with just tmdbid in exclusions
|
||||
importExclusions = _configService.ImportExclusions.Split(',').Select(x => Regex.Replace(x, @"^.*\-(.*)$", "$1")).ToList();
|
||||
// listedMovies = listedMovies.Where(ah => importExclusions.Any(h => ah.TmdbId.ToString() != h)).ToList();
|
||||
}
|
||||
|
||||
var downloadedCount = 0;
|
||||
foreach (var movie in listedMovies)
|
||||
{
|
||||
var mapped = _movieSearch.MapMovieToTmdbMovie(movie);
|
||||
if (mapped != null && !importExclusions.Any(x => x == mapped.TmdbId.ToString()))
|
||||
{
|
||||
List<DownloadDecision> decisions;
|
||||
mapped.AddOptions = new AddMovieOptions {SearchForMovie = true};
|
||||
_movieService.AddMovie(mapped);
|
||||
|
||||
// Search for movie
|
||||
try
|
||||
{
|
||||
decisions = _nzbSearchService.MovieSearch(mapped.Id, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, $"Unable to search in list for movie {mapped.Id}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
|
||||
downloadedCount += processed.Grabbed.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mapped != null)
|
||||
{
|
||||
_logger.Info($"{mapped.Title} ({mapped.TitleSlug}) will not be added since it was found on the exclusions list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.ProgressInfo("Movie search completed. {0} reports downloaded.", downloadedCount);
|
||||
}
|
||||
|
||||
private void CleanLibrary(List<Movie> movies)
|
||||
{
|
||||
if (_configService.ListSyncLevel != "disabled")
|
||||
{
|
||||
var moviesInLibrary = _movieService.GetAllMovies();
|
||||
foreach (var movie in moviesInLibrary)
|
||||
{
|
||||
{
|
||||
bool foundMatch = false;
|
||||
foreach (var listedMovie in listedMovies)
|
||||
foreach (var listedMovie in movies)
|
||||
{
|
||||
if (movie.TmdbId == listedMovie.TmdbId)
|
||||
{
|
||||
@@ -101,7 +169,7 @@ namespace NzbDrone.Core.NetImport
|
||||
}
|
||||
if (!foundMatch)
|
||||
{
|
||||
switch(_configService.ListSyncLevel)
|
||||
switch (_configService.ListSyncLevel)
|
||||
{
|
||||
case "logOnly":
|
||||
_logger.Info("{0} was in your library, but not found in your lists --> You might want to unmonitor or remove it", movie);
|
||||
@@ -120,51 +188,10 @@ namespace NzbDrone.Core.NetImport
|
||||
//TODO: for some reason the files are not deleted in this case... any idea why?
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<string> importExclusions = null;
|
||||
if (_configService.ImportExclusions != String.Empty)
|
||||
{
|
||||
importExclusions = _configService.ImportExclusions.Split(',').ToList();
|
||||
}
|
||||
|
||||
var movies = listedMovies.Where(x => !_movieService.MovieExists(x)).ToList();
|
||||
|
||||
if (movies.Count > 0)
|
||||
{
|
||||
_logger.Info("Found {0} movies on your auto enabled lists not in your library", movies.Count);
|
||||
}
|
||||
|
||||
foreach (var movie in movies)
|
||||
{
|
||||
bool shouldAdd = true;
|
||||
if (importExclusions != null)
|
||||
{
|
||||
foreach (var exclusion in importExclusions)
|
||||
{
|
||||
//var excludedTmdbId = exclusion.Substring(exclusion.LastIndexOf('-')+1);
|
||||
int excludedTmdbId;
|
||||
if (Int32.TryParse(exclusion.Substring(exclusion.LastIndexOf('-') + 1), out excludedTmdbId))
|
||||
{
|
||||
if (excludedTmdbId == movie.TmdbId)
|
||||
{
|
||||
_logger.Info("Movie: {0} was found but will not be added because {1} was found on your exclusion list", movie, exclusion);
|
||||
shouldAdd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mapped = _movieSearch.MapMovieToTmdbMovie(movie);
|
||||
if ((mapped != null) && shouldAdd)
|
||||
{
|
||||
_movieService.AddMovie(mapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user