From d9a6c4f2115f7a3d251328155fe9bbb29fdfbd86 Mon Sep 17 00:00:00 2001 From: Tim Turner Date: Sat, 7 Jan 2017 14:29:23 -0500 Subject: [PATCH] Update import UI & parse titles which contain years --- .../MetadataSource/SkyHook/SkyHookProxy.cs | 31 +++++++++++++++++++ src/UI/AddMovies/AddMoviesLayout.js | 6 ++-- ...w.js => AddExistingMovieCollectionView.js} | 6 ++-- ...ddExistingMovieCollectionViewTemplate.hbs} | 0 4 files changed, 37 insertions(+), 6 deletions(-) rename src/UI/AddMovies/Existing/{AddExistingSeriesCollectionView.js => AddExistingMovieCollectionView.js} (87%) rename src/UI/AddMovies/Existing/{AddExistingSeriesCollectionViewTemplate.hbs => AddExistingMovieCollectionViewTemplate.hbs} (100%) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index e0014a728..dc5a3a3ed 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -12,6 +12,7 @@ using NzbDrone.Core.MetadataSource.SkyHook.Resource; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Tv; using Newtonsoft.Json; +using System.Text.RegularExpressions; namespace NzbDrone.Core.MetadataSource.SkyHook { @@ -175,9 +176,38 @@ namespace NzbDrone.Core.MetadataSource.SkyHook return movie; } + private string[] SeparateYearFromTitle(string title) + { + var yearPattern = @"((?:19|20)\d{2})"; + var newTitle = title; + var substrings = Regex.Split(title, yearPattern); + var year = ""; + if (substrings.Length > 1) { + newTitle = substrings[0].TrimEnd("("); + year = substrings[1]; + } + + return new[] { newTitle.Trim(), year.Trim() }; + } + + private string StripTrailingTheFromTitle(string title) + { + if(title.EndsWith(", the") || title.EndsWith(",the")) + { + title = title.Substring(title.Length - 4); + } + return title; + } + public List SearchForNewMovie(string title) { var lowerTitle = title.ToLower(); + var yearCheck = SeparateYearFromTitle(lowerTitle); // TODO: Make this much less hacky! + + lowerTitle = yearCheck[0]; + var yearTerm = yearCheck[1]; + + lowerTitle = StripTrailingTheFromTitle(lowerTitle); if (lowerTitle.StartsWith("imdb:") || lowerTitle.StartsWith("imdbid:")) { @@ -209,6 +239,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook .SetSegment("id", "movie") .SetSegment("secondaryRoute", "") .AddQueryParam("query", searchTerm) + .AddQueryParam("year", yearTerm) .AddQueryParam("include_adult", false) .Build(); diff --git a/src/UI/AddMovies/AddMoviesLayout.js b/src/UI/AddMovies/AddMoviesLayout.js index 904d3f179..3dd299959 100644 --- a/src/UI/AddMovies/AddMoviesLayout.js +++ b/src/UI/AddMovies/AddMoviesLayout.js @@ -2,7 +2,7 @@ var vent = require('vent'); var AppLayout = require('../AppLayout'); var Marionette = require('marionette'); var RootFolderLayout = require('./RootFolders/RootFolderLayout'); -//var ExistingMoviesCollectionView = require('./Existing/AddExistingSeriesCollectionView'); +var ExistingMoviesCollectionView = require('./Existing/AddExistingMovieCollectionView'); var AddMoviesView = require('./AddMoviesView'); var ProfileCollection = require('../Profile/ProfileCollection'); var RootFolderCollection = require('./RootFolders/RootFolderCollection'); @@ -36,9 +36,9 @@ module.exports = Marionette.Layout.extend({ }, _folderSelected : function(options) { - //vent.trigger(vent.Commands.CloseModalCommand); + vent.trigger(vent.Commands.CloseModalCommand); //TODO: Fix this shit. - //this.workspace.show(new ExistingMoviesCollectionView({ model : options.model })); + this.workspace.show(new ExistingMoviesCollectionView({ model : options.model })); }, _importMovies : function() { diff --git a/src/UI/AddMovies/Existing/AddExistingSeriesCollectionView.js b/src/UI/AddMovies/Existing/AddExistingMovieCollectionView.js similarity index 87% rename from src/UI/AddMovies/Existing/AddExistingSeriesCollectionView.js rename to src/UI/AddMovies/Existing/AddExistingMovieCollectionView.js index 5c5eddc64..1e3d38b6a 100644 --- a/src/UI/AddMovies/Existing/AddExistingSeriesCollectionView.js +++ b/src/UI/AddMovies/Existing/AddExistingMovieCollectionView.js @@ -1,11 +1,11 @@ var Marionette = require('marionette'); -var AddSeriesView = require('../AddSeriesView'); +var AddMoviesView = require('../AddMoviesView'); var UnmappedFolderCollection = require('./UnmappedFolderCollection'); module.exports = Marionette.CompositeView.extend({ - itemView : AddSeriesView, + itemView : AddMoviesView, itemViewContainer : '.x-loading-folders', - template : 'AddSeries/Existing/AddExistingSeriesCollectionViewTemplate', + template : 'AddMovies/Existing/AddExistingMovieCollectionViewTemplate', ui : { loadingFolders : '.x-loading-folders' diff --git a/src/UI/AddMovies/Existing/AddExistingSeriesCollectionViewTemplate.hbs b/src/UI/AddMovies/Existing/AddExistingMovieCollectionViewTemplate.hbs similarity index 100% rename from src/UI/AddMovies/Existing/AddExistingSeriesCollectionViewTemplate.hbs rename to src/UI/AddMovies/Existing/AddExistingMovieCollectionViewTemplate.hbs