1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01: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:
Devin Buhl 2017-03-06 22:09:03 -05:00 committed by GitHub
parent 7cfa0531dc
commit 4d0226e0d5
15 changed files with 130 additions and 114 deletions

View File

@ -61,6 +61,10 @@ protected override string AddFromMagnetLink(RemoteMovie remoteMovie, string hash
var retryDelay = 500;
if (WaitForTorrent(hash, tries, retryDelay))
{
_logger.Info("Resolved magnet for {0}", remoteMovie.Movie.CleanTitle);
SetDownloadDirectory(hash);
_proxy.SetTorrentLabel(hash, Settings.MovieCategory, Settings);
_proxy.StartTorrent(hash, Settings);
return hash;
}
else

View File

@ -58,7 +58,8 @@ public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchC
}
else
{
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", $"&q={Parser.Parser.NormalizeTitle(searchCriteria.Movie.Title)}%20{searchCriteria.Movie.Year}"));
var searchTitle = Parser.Parser.ReplaceGermanUmlauts(Parser.Parser.NormalizeTitle(searchCriteria.Movie.Title));
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", $"&q={searchTitle}%20{searchCriteria.Movie.Year}"));
}
return pageableRequests;

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.IndexerSearch.Definitions;
@ -20,60 +19,18 @@ public RarbgRequestGenerator(IRarbgTokenProvider tokenProvider)
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("list", null, null));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber));
pageableRequests.Add(GetMovieRequest(searchCriteria));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}", searchCriteria.SeasonNumber));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "\"{0:yyyy MM dd}\"", searchCriteria.AirDate));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
foreach (var queryTitle in searchCriteria.EpisodeQueryTitles)
{
var query = queryTitle.Replace('+', ' ');
query = System.Web.HttpUtility.UrlEncode(query);
pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, query));
}
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? imdbId, string query, params object[] args)
{
var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)
.Resource("/pubapi_v2.php")
@ -87,9 +44,9 @@ private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, s
requestBuilder.AddQueryParam("mode", mode);
if (tvdbId.HasValue)
if (imdbId.HasValue)
{
requestBuilder.AddQueryParam("search_tvdb", tvdbId.Value);
requestBuilder.AddQueryParam("search_imdb", imdbId.Value);
}
if (query.IsNotNullOrWhiteSpace())
@ -102,11 +59,11 @@ private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, s
requestBuilder.AddQueryParam("ranked", "0");
}
requestBuilder.AddQueryParam("category", "tv");
requestBuilder.AddQueryParam("category", "movies");
requestBuilder.AddQueryParam("limit", "100");
requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings));
requestBuilder.AddQueryParam("format", "json_extended");
requestBuilder.AddQueryParam("app_id", "Sonarr");
requestBuilder.AddQueryParam("app_id", "Radarr");
yield return new IndexerRequest(requestBuilder.Build());
}
@ -136,22 +93,34 @@ private IEnumerable<IndexerRequest> GetMovieRequest(MovieSearchCriteria searchCr
requestBuilder.AddQueryParam("limit", "100");
requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings));
requestBuilder.AddQueryParam("format", "json_extended");
requestBuilder.AddQueryParam("app_id", "Sonarr");
requestBuilder.AddQueryParam("app_id", "Radarr");
yield return new IndexerRequest(requestBuilder.Build());
}
public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
var pageableRequests = new IndexerPageableRequestChain();
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
pageableRequests.Add(GetMovieRequest(searchCriteria));
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
return pageableRequests;
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
}
}
}

View File

@ -31,7 +31,7 @@ public string GetToken(RarbgSettings settings)
{
var requestBuilder = new HttpRequestBuilder(settings.BaseUrl.Trim('/'))
.WithRateLimit(3.0)
.Resource("/pubapi_v2.php?get_token=get_token&app_id=Sonarr")
.Resource("/pubapi_v2.php?get_token=get_token&app_id=Radarr")
.Accept(HttpAccept.Json);
if (settings.CaptchaToken.IsNotNullOrWhiteSpace())

View File

@ -30,7 +30,8 @@ public NetImportFactory(INetImportRepository providerRepository,
protected override List<NetImportDefinition> Active()
{
return base.Active().Where(c => c.Enabled).ToList();
// return base.Active().Where(c => c.Enabled).ToList(); // use this for when/if we add a setting to enable/disable lists
return base.Active().ToList();
}
public override void SetProviderCharacteristics(INetImport provider, NetImportDefinition definition)

View File

@ -0,0 +1,11 @@
namespace NzbDrone.Core.NetImport
{
public enum NetImportCleanLibraryLevels
{
Disabled,
LogOnly,
KeepAndUnmonitor,
RemoveAndKeep,
RemoveAndDelete
}
}

View File

@ -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.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 @@ public class NetImportSearchService : IFetchNetImport, IExecute<NetImportSyncCom
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 @@ public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto = false)
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 @@ public void Execute(NetImportSyncCommand message)
}
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 @@ public void Execute(NetImportSyncCommand message)
}
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 @@ public void Execute(NetImportSyncCommand message)
//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);
}
}
}
}

View File

@ -11,7 +11,7 @@ public class RSSImport : HttpNetImportBase<RSSImportSettings>
{
public override string Name => "RSSList";
public override bool Enabled => true;
public override bool EnableAuto => true;
public override bool EnableAuto => false;
public RSSImport(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, configService, parsingService, logger)

View File

@ -9,7 +9,7 @@ public class StevenLuImport : HttpNetImportBase<StevenLuSettings>
{
public override string Name => "StevenLu";
public override bool Enabled => true;
public override bool EnableAuto => true;
public override bool EnableAuto => false;
public StevenLuImport(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, configService, parsingService, logger)

View File

@ -11,6 +11,7 @@ public class TMDbImport : HttpNetImportBase<TMDbSettings>
public override string Name => "TMDb Lists";
public override bool Enabled => true;
public override bool EnableAuto => false;
private readonly IHttpClient _httpClient;
private readonly Logger _logger;

View File

@ -10,6 +10,7 @@ public class TraktImport : HttpNetImportBase<TraktSettings>
public override string Name => "Trakt List";
public override bool Enabled => true;
public override bool EnableAuto => false;
private readonly IHttpClient _httpClient;
public IConfigService _configService;

View File

@ -32,7 +32,7 @@ public void SendNotification(string title, string message, string apiKey, Notify
var request = new RestRequest("notify", Method.POST);
request.RequestFormat = DataFormat.Xml;
request.AddParameter("apikey", apiKey);
request.AddParameter("application", "Sonarr");
request.AddParameter("application", "Radarr");
request.AddParameter("event", title);
request.AddParameter("description", message);
request.AddParameter("priority", (int)priority);

View File

@ -224,8 +224,8 @@ private RestRequest GetPlexTvRequest(string resource, Method method)
request.AddHeader("X-Plex-Platform-Version", "7");
request.AddHeader("X-Plex-Provides", "player");
request.AddHeader("X-Plex-Client-Identifier", "AB6CCCC7-5CF5-4523-826A-B969E0FFD8A0");
request.AddHeader("X-Plex-Device-Name", "Sonarr");
request.AddHeader("X-Plex-Product", "Sonarr");
request.AddHeader("X-Plex-Device-Name", "Radarr");
request.AddHeader("X-Plex-Product", "Radarr");
request.AddHeader("X-Plex-Version", BuildInfo.Version.ToString());
return request;

View File

@ -132,6 +132,7 @@
<Compile Include="Datastore\Migration\133_add_minimumavailability.cs" />
<Compile Include="IndexerSearch\CutoffUnmetMoviesSearchCommand.cs" />
<Compile Include="Indexers\HDBits\HDBitsInfo.cs" />
<Compile Include="NetImport\NetImportListLevels.cs" />
<Compile Include="NetImport\TMDb\TMDbLanguageCodes.cs" />
<Compile Include="NetImport\TMDb\TMDbSettings.cs" />
<Compile Include="NetImport\TMDb\TMDbListType.cs" />

View File

@ -543,7 +543,7 @@ private void AddEpisodeFileTokens(Dictionary<string, Func<TokenMatch, string>> t
{
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile);
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile);
tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup ?? m.DefaultValue("Sonarr");
tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup ?? m.DefaultValue("Radarr");
}
private void AddMovieFileTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, MovieFile episodeFile)
@ -551,7 +551,7 @@ private void AddMovieFileTokens(Dictionary<string, Func<TokenMatch, string>> tok
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile);
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile);
//tokenHandlers["{IMDb Id}"] = m =>
tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup ?? m.DefaultValue("Sonarr");
tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup ?? m.DefaultValue("Radarr");
}
private void AddQualityTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Series series, EpisodeFile episodeFile)