diff --git a/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs b/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs index f7026ae5d..c0eb85b42 100644 --- a/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs +++ b/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs @@ -19,7 +19,7 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran) using (IDbCommand getSeriesCmd = conn.CreateCommand()) { getSeriesCmd.Transaction = tran; - getSeriesCmd.CommandText = @"SELECT Id, Title, Year FROM Movies"; + getSeriesCmd.CommandText = @"SELECT Id, Title, Year, TmdbId FROM Movies"; using (IDataReader seriesReader = getSeriesCmd.ExecuteReader()) { while (seriesReader.Read()) @@ -27,8 +27,9 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran) var id = seriesReader.GetInt32(0); var title = seriesReader.GetString(1); var year = seriesReader.GetInt32(2); + var tmdbId = seriesReader.GetInt32(3); - var titleSlug = ToUrlSlug(title + "-" + year); + var titleSlug = Parser.Parser.ToUrlSlug(title + "-" + tmdbId); using (IDbCommand updateCmd = conn.CreateCommand()) { @@ -43,29 +44,5 @@ private void SetTitleSlug(IDbConnection conn, IDbTransaction tran) } } } - - public static string ToUrlSlug(string value) - { - //First to lower case - value = value.ToLowerInvariant(); - - //Remove all accents - var bytes = Encoding.GetEncoding("Cyrillic").GetBytes(value); - value = Encoding.ASCII.GetString(bytes); - - //Replace spaces - value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled); - - //Remove invalid chars - value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled); - - //Trim dashes from end - value = value.Trim('-', '_'); - - //Replace double occurences of - or _ - value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); - - return value; - } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 955816c64..6e9695ec3 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -30,14 +30,12 @@ public class CompletedDownloadService : ICompletedDownloadService private readonly IParsingService _parsingService; private readonly IMovieService _movieService; private readonly Logger _logger; - private readonly ISeriesService _seriesService; public CompletedDownloadService(IConfigService configService, IEventAggregator eventAggregator, IHistoryService historyService, IDownloadedMovieImportService downloadedMovieImportService, IParsingService parsingService, - ISeriesService seriesService, IMovieService movieService, Logger logger) { @@ -48,7 +46,6 @@ public CompletedDownloadService(IConfigService configService, _parsingService = parsingService; _movieService = movieService; _logger = logger; - _seriesService = seriesService; } public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false) diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index b7c4b205a..c8068c044 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -137,16 +137,16 @@ public void DownloadReport(RemoteMovie remoteMovie) throw; } - var episodeGrabbedEvent = new MovieGrabbedEvent(remoteMovie); - episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name; + var movieGrabbedEvent = new MovieGrabbedEvent(remoteMovie); + movieGrabbedEvent.DownloadClient = downloadClient.GetType().Name; if (!string.IsNullOrWhiteSpace(downloadClientId)) { - episodeGrabbedEvent.DownloadId = downloadClientId; + movieGrabbedEvent.DownloadId = downloadClientId; } _logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle); - _eventAggregator.PublishEvent(episodeGrabbedEvent); + _eventAggregator.PublishEvent(movieGrabbedEvent); } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 4168e0451..45e83439e 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -87,9 +87,9 @@ private void PublishDownloadFailedEvent(List historyItems, stri var downloadFailedEvent = new DownloadFailedEvent { - SeriesId = historyItem.SeriesId, + SeriesId = 0, MovieId = historyItem.MovieId, - EpisodeIds = historyItems.Select(h => h.EpisodeId).ToList(), + EpisodeIds = null, Quality = historyItem.Quality, SourceTitle = historyItem.SourceTitle, DownloadClient = historyItem.Data.GetValueOrDefault(History.History.DOWNLOAD_CLIENT), diff --git a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs index f49f3772e..2784d35c0 100644 --- a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs @@ -12,17 +12,17 @@ namespace NzbDrone.Core.Download public class RedownloadFailedDownloadService : IHandleAsync { private readonly IConfigService _configService; - private readonly IEpisodeService _episodeService; + private readonly IMovieService _movieService; private readonly IManageCommandQueue _commandQueueManager; private readonly Logger _logger; public RedownloadFailedDownloadService(IConfigService configService, - IEpisodeService episodeService, + IMovieService movieService, IManageCommandQueue commandQueueManager, Logger logger) { _configService = configService; - _episodeService = episodeService; + _movieService = movieService; _commandQueueManager = commandQueueManager; _logger = logger; } @@ -38,40 +38,8 @@ public void HandleAsync(DownloadFailedEvent message) if (message.MovieId != 0) { _logger.Debug("Failed download contains a movie, searching again."); - _commandQueueManager.Push(new MoviesSearchCommand { MovieIds = new List { message.MovieId } }); - - return; } - - if (message.EpisodeIds.Count == 1) - { - _logger.Debug("Failed download only contains one episode, searching again"); - - _commandQueueManager.Push(new EpisodeSearchCommand(message.EpisodeIds)); - - return; - } - - var seasonNumber = _episodeService.GetEpisode(message.EpisodeIds.First()).SeasonNumber; - var episodesInSeason = _episodeService.GetEpisodesBySeason(message.SeriesId, seasonNumber); - - if (message.EpisodeIds.Count == episodesInSeason.Count) - { - _logger.Debug("Failed download was entire season, searching again"); - - _commandQueueManager.Push(new SeasonSearchCommand - { - SeriesId = message.SeriesId, - SeasonNumber = seasonNumber - }); - - return; - } - - _logger.Debug("Failed download contains multiple episodes, probably a double episode, searching again"); - - _commandQueueManager.Push(new EpisodeSearchCommand(message.EpisodeIds)); } } } diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs index cf9124d19..7a88f1713 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/DownloadMonitoringService.cs @@ -135,7 +135,7 @@ private List ProcessClientItems(IDownloadClient downloadClient, } catch (Exception e) { - _logger.Error(e, "Couldn't process tracked download " + downloadItem.Title); + _logger.Error(e, $"Couldn't process tracked download {downloadItem.Title}"); } return trackedDownloads; diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 8973ec8d3..72a6c0a54 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -9,11 +9,7 @@ using NzbDrone.Core.Exceptions; using NzbDrone.Core.MediaCover; using NzbDrone.Core.MetadataSource.SkyHook.Resource; -using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Tv; -using Newtonsoft.Json; -using System.Text.RegularExpressions; -using System.Text; using System.Threading; using NzbDrone.Core.Parser; using NzbDrone.Core.Profiles; @@ -133,7 +129,7 @@ public Movie GetMovieInfo(int TmdbId, Profile profile = null) movie.TmdbId = TmdbId; movie.ImdbId = resource.imdb_id; movie.Title = resource.title; - movie.TitleSlug = ToUrlSlug(resource.title); + movie.TitleSlug = Parser.Parser.ToUrlSlug(resource.title); movie.CleanTitle = Parser.Parser.CleanSeriesTitle(resource.title); movie.SortTitle = Parser.Parser.NormalizeTitle(resource.title); movie.Overview = resource.overview; @@ -475,7 +471,7 @@ private Movie MapMovie(MovieResult result) { imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title); imdbMovie.Title = result.title; - imdbMovie.TitleSlug = ToUrlSlug(result.title); + imdbMovie.TitleSlug = Parser.Parser.ToUrlSlug(result.title); if (result.release_date.IsNotNullOrWhiteSpace()) { @@ -662,30 +658,6 @@ private static MediaCoverTypes MapCoverType(string coverType) } } - public static string ToUrlSlug(string value) - { - //First to lower case - value = value.ToLowerInvariant(); - - //Remove all accents - var bytes = Encoding.GetEncoding("ISO-8859-8").GetBytes(value); - value = Encoding.ASCII.GetString(bytes); - - //Replace spaces - value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled); - - //Remove invalid chars - value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled); - - //Trim dashes from end - value = value.Trim('-', '_'); - - //Replace double occurences of - or _ - value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); - - return value; - } - public Movie MapMovieToTmdbMovie(Movie movie) { Movie newMovie = movie; diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs index 3ee8c6014..5013d1f7f 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs @@ -1,6 +1,8 @@ using NzbDrone.Common.Http; using System; using System.Collections.Generic; +using System.Text.RegularExpressions; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; @@ -87,42 +89,43 @@ private IEnumerable GetMovies(string searchParameters) { var link = Settings.Link.Trim(); - var filters = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Ceritification.ToLower()}"; + var filtersAndLimit = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Ceritification.ToLower()}&limit={Settings.Limit}"; switch (Settings.ListType) { case (int)TraktListType.UserCustomList: - link = link + $"/users/{Settings.Username.Trim()}/lists/{Settings.Listname.Trim()}/items/movies"; + var listName = Parser.Parser.ToUrlSlug(Settings.Listname.Trim()); + link = link + $"/users/{Settings.Username.Trim()}/lists/{listName}/items/movies?limit={Settings.Limit}"; break; case (int)TraktListType.UserWatchList: - link = link + $"/users/{Settings.Username.Trim()}/watchlist/movies"; + link = link + $"/users/{Settings.Username.Trim()}/watchlist/movies?limit={Settings.Limit}"; break; case (int)TraktListType.UserWatchedList: - link = link + $"/users/{Settings.Username.Trim()}/watched/movies"; + link = link + $"/users/{Settings.Username.Trim()}/watched/movies?limit={Settings.Limit}"; break; case (int)TraktListType.Trending: - link = link + "/movies/trending" + filters; + link = link + "/movies/trending" + filtersAndLimit; break; case (int)TraktListType.Popular: - link = link + "/movies/popular" + filters; + link = link + "/movies/popular" + filtersAndLimit; break; case (int)TraktListType.Anticipated: - link = link + "/movies/anticipated" + filters; + link = link + "/movies/anticipated" + filtersAndLimit; break; case (int)TraktListType.BoxOffice: - link = link + "/movies/boxoffice" + filters; + link = link + "/movies/boxoffice" + filtersAndLimit; break; case (int)TraktListType.TopWatchedByWeek: - link = link + "/movies/watched/weekly" + filters; + link = link + "/movies/watched/weekly" + filtersAndLimit; break; case (int)TraktListType.TopWatchedByMonth: - link = link + "/movies/watched/monthly" + filters; + link = link + "/movies/watched/monthly" + filtersAndLimit; break; case (int)TraktListType.TopWatchedByYear: - link = link + "/movies/watched/yearly" + filters; + link = link + "/movies/watched/yearly" + filtersAndLimit; break; case (int)TraktListType.TopWatchedByAllTime: - link = link + "/movies/watched/all" + filters; + link = link + "/movies/watched/all" + filtersAndLimit; break; } @@ -131,7 +134,7 @@ private IEnumerable GetMovies(string searchParameters) var request = new NetImportRequest($"{link}", HttpAccept.Json); request.HttpRequest.Headers.Add("trakt-api-version", "2"); request.HttpRequest.Headers.Add("trakt-api-key", "964f67b126ade0112c4ae1f0aea3a8fb03190f71117bd83af6a0560a99bc52e6"); //aeon - if (_configService.TraktAuthToken != null) + if (_configService.TraktAuthToken.IsNotNullOrWhiteSpace()) { request.HttpRequest.Headers.Add("Authorization", "Bearer " + _configService.TraktAuthToken); } diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs index cc4d29399..3cfa5ccc0 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs @@ -43,6 +43,11 @@ public TraktSettingsValidator() .Matches(@"^\d+(\-\d+)?$", RegexOptions.IgnoreCase) .When(c => c.Years.IsNotNullOrWhiteSpace()) .WithMessage("Not a valid year or range of years"); + + // Limit not smaller than 1 and not larger than 100 + RuleFor(c => c.Limit) + .InclusiveBetween(1, 500) + .WithMessage("Must be 1 thru 500"); } } @@ -60,6 +65,7 @@ public TraktSettings() Ceritification = "NR,G,PG,PG-13,R,NC-17"; Genres = ""; Years = ""; + Limit = 100; } [FieldDefinition(0, Label = "Trakt API URL", HelpText = "Link to to Trakt API URL, do not change unless you know what you are doing.")] @@ -86,6 +92,9 @@ public TraktSettings() [FieldDefinition(7, Label = "Years", HelpText = "Filter movies by year or year range")] public string Years { get; set; } + [FieldDefinition(8, Label = "Limit", HelpText = "Limit the number of movies to get")] + public int Limit { get; set; } + public NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index d56d241a6..84e3b3190 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.Extensions; @@ -608,6 +609,30 @@ public static string NormalizeImdbId(string imdbId) return null; } + public static string ToUrlSlug(string value) + { + //First to lower case + value = value.ToLowerInvariant(); + + //Remove all accents + var bytes = Encoding.GetEncoding("ISO-8859-8").GetBytes(value); + value = Encoding.ASCII.GetString(bytes); + + //Replace spaces + value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled); + + //Remove invalid chars + value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled); + + //Trim dashes from end + value = value.Trim('-', '_'); + + //Replace double occurences of - or _ + value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); + + return value; + } + public static string ParseSeriesName(string title) { Logger.Debug("Parsing string '{0}'", title); diff --git a/src/UI/Navbar/NavbarLayoutTemplate.hbs b/src/UI/Navbar/NavbarLayoutTemplate.hbs index cb2237964..873887929 100644 --- a/src/UI/Navbar/NavbarLayoutTemplate.hbs +++ b/src/UI/Navbar/NavbarLayoutTemplate.hbs @@ -19,8 +19,9 @@