From 16c1a2ee50cb3f6346f361b84e5943d8a2f47336 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sat, 14 Jan 2017 12:27:16 -0500 Subject: [PATCH 1/2] Torpotato username regression --- .../TorrentPotato/TorrentPotatoRequestGenerator.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/NzbDrone.Core/Indexers/TorrentPotato/TorrentPotatoRequestGenerator.cs b/src/NzbDrone.Core/Indexers/TorrentPotato/TorrentPotatoRequestGenerator.cs index b9856250b..808a40b89 100644 --- a/src/NzbDrone.Core/Indexers/TorrentPotato/TorrentPotatoRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/TorrentPotato/TorrentPotatoRequestGenerator.cs @@ -82,6 +82,11 @@ private IEnumerable GetPagedRequests(string mode, int? tvdbId, s { requestBuilder.AddQueryParam("user", Settings.User); } + else + { + requestBuilder.AddQueryParam("user", ""); + } + requestBuilder.AddQueryParam("search", "the"); yield return new IndexerRequest(requestBuilder.Build()); @@ -98,6 +103,10 @@ private IEnumerable GetMovieRequest(MovieSearchCriteria searchCr { requestBuilder.AddQueryParam("user", Settings.User); } + else + { + requestBuilder.AddQueryParam("user", ""); + } if (searchCriteria.Movie.ImdbId.IsNotNullOrWhiteSpace()) { From 4bb58574442798ecd5f8864f459c0a58ea96e18e Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sat, 14 Jan 2017 13:14:42 -0500 Subject: [PATCH 2/2] Fixed TitleSlug For Realz! --- .../Migration/118_update_movie_slug.cs | 71 +++++++++++++++++++ .../MetadataSource/SkyHook/SkyHookProxy.cs | 47 ++++++++---- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 3 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs b/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs new file mode 100644 index 000000000..f7026ae5d --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/118_update_movie_slug.cs @@ -0,0 +1,71 @@ +using System.Data; +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; +using System.Text; +using System.Text.RegularExpressions; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(118)] + public class update_movie_slug : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(SetTitleSlug); + } + + private void SetTitleSlug(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand getSeriesCmd = conn.CreateCommand()) + { + getSeriesCmd.Transaction = tran; + getSeriesCmd.CommandText = @"SELECT Id, Title, Year FROM Movies"; + using (IDataReader seriesReader = getSeriesCmd.ExecuteReader()) + { + while (seriesReader.Read()) + { + var id = seriesReader.GetInt32(0); + var title = seriesReader.GetString(1); + var year = seriesReader.GetInt32(2); + + var titleSlug = ToUrlSlug(title + "-" + year); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE Movies SET TitleSlug = ? WHERE Id = ?"; + updateCmd.AddParameter(titleSlug); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + + 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/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 318dccbd4..6f1534ed7 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -13,6 +13,7 @@ using NzbDrone.Core.Tv; using Newtonsoft.Json; using System.Text.RegularExpressions; +using System.Text; namespace NzbDrone.Core.MetadataSource.SkyHook { @@ -88,7 +89,7 @@ public Movie GetMovieInfo(int TmdbId) movie.TmdbId = TmdbId; movie.ImdbId = resource.imdb_id; movie.Title = resource.title; - movie.TitleSlug = movie.Title.ToLower().Replace(" ", "-"); + movie.TitleSlug = ToUrlSlug(movie.Title); movie.CleanTitle = Parser.Parser.CleanSeriesTitle(movie.Title); movie.SortTitle = Parser.Parser.NormalizeTitle(movie.Title); movie.Overview = resource.overview; @@ -99,11 +100,6 @@ public Movie GetMovieInfo(int TmdbId) movie.Year = movie.InCinemas.Value.Year; } - var slugResult = _movieService.FindByTitleSlug(movie.TitleSlug); - if (slugResult != null) - { - _logger.Debug("Movie with this title slug already exists. Adding year..."); - } movie.TitleSlug += "-" + movie.Year.ToString(); movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page! @@ -330,21 +326,18 @@ private Movie MapMovie(MovieResult result) { imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title); imdbMovie.Title = result.title; - string titleSlug = result.title; + string titleSlug = ToUrlSlug(result.title); imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-"); if (result.release_date.IsNotNullOrWhiteSpace()) { imdbMovie.Year = DateTime.Parse(result.release_date).Year; } - - - - var slugResult = _movieService.FindByTitleSlug(imdbMovie.TitleSlug); - if (slugResult != null) - { - _logger.Debug("Movie with this title slug already exists. Adding year..."); - } + //var slugResult = _movieService.FindByTitleSlug(imdbMovie.TitleSlug); + //if (slugResult != null) + //{ + // _logger.Debug("Movie with this title slug already exists. Adding year..."); + //} imdbMovie.TitleSlug += "-" + imdbMovie.Year.ToString(); imdbMovie.Images = new List(); @@ -525,5 +518,29 @@ private static MediaCoverTypes MapCoverType(string coverType) return MediaCoverTypes.Unknown; } } + + 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; + } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 7e70c9898..e69a850e7 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -183,6 +183,7 @@ +