From 3dd14c72c828a5da7842774245b2cd1616b1fda8 Mon Sep 17 00:00:00 2001 From: geogolem Date: Sun, 5 Mar 2017 02:02:24 -0500 Subject: [PATCH] store titleSlug in tags for exclusions and always use TMDBID --- .../NetImport/NetImportSearchService.cs | 37 +++++++---------- src/NzbDrone.Core/Tv/MovieService.cs | 6 +-- src/UI/JsLibraries/bootstrap.tagsinput.js | 41 ++++++++++++++++++- .../NetImport/Options/NetImportOptionsView.js | 9 +++- .../Options/NetImportOptionsViewTemplate.hbs | 4 +- 5 files changed, 67 insertions(+), 30 deletions(-) diff --git a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs index b616b293e..0bfe92b67 100644 --- a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs +++ b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs @@ -25,13 +25,11 @@ namespace NzbDrone.Core.NetImport private readonly ISearchForNewMovie _movieSearch; private readonly IRootFolderService _rootFolder; private readonly IConfigService _configService; - private readonly IProvideMovieInfo _movieInfo; - + public NetImportSearchService(INetImportFactory netImportFactory, IMovieService movieService, - ISearchForNewMovie movieSearch, IRootFolderService rootFolder, IConfigService configService, IProvideMovieInfo movieInfo, Logger logger) + ISearchForNewMovie movieSearch, IRootFolderService rootFolder, IConfigService configService, Logger logger) { - _movieInfo = movieInfo; _netImportFactory = netImportFactory; _movieService = movieService; _movieSearch = movieSearch; @@ -144,24 +142,15 @@ namespace NzbDrone.Core.NetImport foreach (var movie in movies) { bool shouldAdd = true; - var mapped = _movieSearch.MapMovieToTmdbMovie(movie); - if (mapped != null) + if (importExclusions != null) { - if (importExclusions != null) + foreach (var exclusion in importExclusions) { - foreach (var exclusion in importExclusions) + //var excludedTmdbId = exclusion.Substring(exclusion.LastIndexOf('-')+1); + int excludedTmdbId; + if (Int32.TryParse(exclusion.Substring(exclusion.LastIndexOf('-') + 1), out excludedTmdbId)) { - int tmdbId; - if (exclusion.StartsWith("tt")) - { - var result = _movieInfo.GetMovieInfo(exclusion); - tmdbId = result.TmdbId; - } - else - { - tmdbId = Int32.Parse(exclusion); - } - if (tmdbId == movie.TmdbId) + 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; @@ -169,10 +158,12 @@ namespace NzbDrone.Core.NetImport } } } - if (shouldAdd) - { - _movieService.AddMovie(mapped); - } + } + + var mapped = _movieSearch.MapMovieToTmdbMovie(movie); + if ((mapped != null) && shouldAdd) + { + _movieService.AddMovie(mapped); } } } diff --git a/src/NzbDrone.Core/Tv/MovieService.cs b/src/NzbDrone.Core/Tv/MovieService.cs index 110f82a40..d535a1dc4 100644 --- a/src/NzbDrone.Core/Tv/MovieService.cs +++ b/src/NzbDrone.Core/Tv/MovieService.cs @@ -244,11 +244,11 @@ namespace NzbDrone.Core.Tv { if (_configService.ImportExclusions.Empty()) { - _configService.ImportExclusions = movie.ImdbId; + _configService.ImportExclusions = movie.TitleSlug; } - else if (!_configService.ImportExclusions.Contains(movie.ImdbId) && !_configService.ImportExclusions.Contains(movie.TmdbId.ToString())) + else if (!_configService.ImportExclusions.Contains(movie.TitleSlug)) { - _configService.ImportExclusions += ',' + movie.ImdbId; + _configService.ImportExclusions += ',' + movie.TitleSlug; } } _movieRepository.Delete(movieId); diff --git a/src/UI/JsLibraries/bootstrap.tagsinput.js b/src/UI/JsLibraries/bootstrap.tagsinput.js index 93e7548a4..c48401bd8 100644 --- a/src/UI/JsLibraries/bootstrap.tagsinput.js +++ b/src/UI/JsLibraries/bootstrap.tagsinput.js @@ -95,6 +95,7 @@ } } + /* var itemValue = self.options.itemValue(item), itemText = self.options.itemText(item), tagClass = self.options.tagClass(item); @@ -113,7 +114,7 @@ // if length greater than limit if (self.items().toString().length + item.length + 1 > self.options.maxInputLength) return; - + */ // raise beforeItemAdd arg var beforeItemAddEvent = $.Event('beforeItemAdd', { item: item, cancel: false }); self.$element.trigger(beforeItemAddEvent); @@ -121,7 +122,45 @@ return; // register item in internal array and map + //self.itemsArray.push(item); + + // read var beforeItemAddEvent with new value + var item = beforeItemAddEvent.item; // Get text from event (BeforeItemAddEvent) + var itemValue = self.options.itemValue(item), + itemText = self.options.itemText(item), + tagClass = self.options.tagClass(item); + + // Ignore items allready added + var existing = $.grep(self.itemsArray, function(item) { return self.options.itemValue(item) === itemValue; } )[0]; + if (existing && !self.options.allowDuplicates) { + // Invoke onTagExists + if (self.options.onTagExists) { + var $existingTag = $(".tag", self.$container).filter(function() { return $(this).data("item") === existing; }); + self.options.onTagExists(item, $existingTag); + } + return; + } + + // if length greater than limit + if (self.items().toString().length + item.length + 1 > self.options.maxInputLength) + return; + + + // register item in internal array and map self.itemsArray.push(item); + + if (beforeItemAddEvent.tagClass !== undefined){ var tagClass = beforeItemAddEvent.tagClass; } + if (item != undefined){ + var items = item.toString().split(','); + if (items.length > 1) { + for (var i = 0; i < items.length; i++) { + this.add(items[i], true); + } + if (!dontPushVal) + self.pushVal(self.options.triggerChange); + return; + } + } // add a tag element var $tag = $('' + htmlEncode(itemText) + ''); diff --git a/src/UI/Settings/NetImport/Options/NetImportOptionsView.js b/src/UI/Settings/NetImport/Options/NetImportOptionsView.js index 13c5fc8e9..9b28af115 100644 --- a/src/UI/Settings/NetImport/Options/NetImportOptionsView.js +++ b/src/UI/Settings/NetImport/Options/NetImportOptionsView.js @@ -90,12 +90,19 @@ var view = Marionette.ItemView.extend({ }); promise.success(function(response) { event.cancel=false; + + //var newText = response['tmdbId']+'-'; + //if (event.item.startsWith('tt')) { + // newText = newText+'['+event.item+']'; + //} + event.item = response['titleSlug'];//+' ('+response['year']+')-'+response['tmdbId']; }); promise.error(function(request, status, error) { event.cancel = true; window.alert(event.item+' is not a valid! Must be valid tt#### IMDB ID or #### TMDB ID'); - }); + }); + return event; }); }, diff --git a/src/UI/Settings/NetImport/Options/NetImportOptionsViewTemplate.hbs b/src/UI/Settings/NetImport/Options/NetImportOptionsViewTemplate.hbs index 1cfc5b6dc..bd429de47 100644 --- a/src/UI/Settings/NetImport/Options/NetImportOptionsViewTemplate.hbs +++ b/src/UI/Settings/NetImport/Options/NetImportOptionsViewTemplate.hbs @@ -32,11 +32,11 @@
-
+
-
+