1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Revert "Fix movie title slugs"

This commit is contained in:
Devin Buhl 2017-01-13 18:20:22 -05:00 committed by GitHub
parent 7df283e57f
commit 5dc63e5607
3 changed files with 20 additions and 125 deletions

View File

@ -1,72 +0,0 @@
using System.Data;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
using System.Text;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(117)]
public class fix_movie_slugs : 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.GetString(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;
}
}
}

View File

@ -13,7 +13,6 @@
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Text;
namespace NzbDrone.Core.MetadataSource.SkyHook namespace NzbDrone.Core.MetadataSource.SkyHook
{ {
@ -30,7 +29,7 @@ public class SkyHookProxy : IProvideSeriesInfo, ISearchForNewSeries, IProvideMov
public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, IMovieService movieService, Logger logger) public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, IMovieService movieService, Logger logger)
{ {
_httpClient = httpClient; _httpClient = httpClient;
_requestBuilder = requestBuilder.SkyHookTvdb; _requestBuilder = requestBuilder.SkyHookTvdb;
_movieBuilder = requestBuilder.TMDB; _movieBuilder = requestBuilder.TMDB;
_configService = configService; _configService = configService;
_movieService = movieService; _movieService = movieService;
@ -89,7 +88,7 @@ public Movie GetMovieInfo(int TmdbId)
movie.TmdbId = TmdbId; movie.TmdbId = TmdbId;
movie.ImdbId = resource.imdb_id; movie.ImdbId = resource.imdb_id;
movie.Title = resource.title; movie.Title = resource.title;
movie.TitleSlug = ToUrlSlug(movie.Title); movie.TitleSlug = movie.Title.ToLower().Replace(" ", "-");
movie.CleanTitle = Parser.Parser.CleanSeriesTitle(movie.Title); movie.CleanTitle = Parser.Parser.CleanSeriesTitle(movie.Title);
movie.SortTitle = Parser.Parser.NormalizeTitle(movie.Title); movie.SortTitle = Parser.Parser.NormalizeTitle(movie.Title);
movie.Overview = resource.overview; movie.Overview = resource.overview;
@ -105,21 +104,20 @@ public Movie GetMovieInfo(int TmdbId)
{ {
_logger.Debug("Movie with this title slug already exists. Adding year..."); _logger.Debug("Movie with this title slug already exists. Adding year...");
} }
//movie.TitleSlug += "-" + movie.Year.ToString();
movie.TitleSlug += "-" + movie.Year.ToString(); movie.TitleSlug += "-" + movie.Year.ToString();
movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page! movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page!
movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner)); movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner));
movie.Runtime = resource.runtime; movie.Runtime = resource.runtime;
foreach (Title title in resource.alternative_titles.titles) foreach(Title title in resource.alternative_titles.titles)
{ {
movie.AlternativeTitles.Add(title.title); movie.AlternativeTitles.Add(title.title);
} }
foreach (ReleaseDates releaseDates in resource.release_dates.results) foreach(ReleaseDates releaseDates in resource.release_dates.results)
{ {
foreach (ReleaseDate releaseDate in releaseDates.release_dates) foreach(ReleaseDate releaseDate in releaseDates.release_dates)
{ {
if (releaseDate.type == 5 || releaseDate.type == 4) if (releaseDate.type == 5 || releaseDate.type == 4)
{ {
@ -142,7 +140,7 @@ public Movie GetMovieInfo(int TmdbId)
movie.Ratings.Votes = resource.vote_count; movie.Ratings.Votes = resource.vote_count;
movie.Ratings.Value = (decimal)resource.vote_average; movie.Ratings.Value = (decimal)resource.vote_average;
foreach (Genre genre in resource.genres) foreach(Genre genre in resource.genres)
{ {
movie.Genres.Add(genre.name); movie.Genres.Add(genre.name);
} }
@ -178,11 +176,10 @@ public Movie GetMovieInfo(string ImdbId)
private string StripTrailingTheFromTitle(string title) private string StripTrailingTheFromTitle(string title)
{ {
if (title.EndsWith(",the")) if(title.EndsWith(",the"))
{ {
title = title.Substring(0, title.Length - 4); title = title.Substring(0, title.Length - 4);
} } else if(title.EndsWith(", the"))
else if (title.EndsWith(", the"))
{ {
title = title.Substring(0, title.Length - 5); title = title.Substring(0, title.Length - 5);
} }
@ -205,7 +202,7 @@ public List<Movie> SearchForNewMovie(string title)
{ {
yearTerm = parserResult.Year.ToString(); yearTerm = parserResult.Year.ToString();
} }
if (parserResult.ImdbId.IsNotNullOrWhiteSpace()) if (parserResult.ImdbId.IsNotNullOrWhiteSpace())
{ {
return new List<Movie> { GetMovieInfo(parserResult.ImdbId) }; return new List<Movie> { GetMovieInfo(parserResult.ImdbId) };
@ -301,14 +298,14 @@ public List<Series> SearchForNewSeries(string title)
} }
} }
var httpRequest = _requestBuilder.Create() var httpRequest = _requestBuilder.Create()
.SetSegment("route", "search") .SetSegment("route", "search")
.AddQueryParam("term", title.ToLower().Trim()) .AddQueryParam("term", title.ToLower().Trim())
.Build(); .Build();
var httpResponse = _httpClient.Get<List<ShowResource>>(httpRequest); var httpResponse = _httpClient.Get<List<ShowResource>>(httpRequest);
@ -333,8 +330,8 @@ private Movie MapMovie(MovieResult result)
{ {
imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title); imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title);
imdbMovie.Title = result.title; imdbMovie.Title = result.title;
string titleSlug = ToUrlSlug(result.title); string titleSlug = result.title;
// imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-"); imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-");
if (result.release_date.IsNotNullOrWhiteSpace()) if (result.release_date.IsNotNullOrWhiteSpace())
{ {
@ -343,16 +340,12 @@ private Movie MapMovie(MovieResult result)
//var slugResult = _movieService.FindByTitleSlug(titleSlug); var slugResult = _movieService.FindByTitleSlug(imdbMovie.TitleSlug);
//if (slugResult != null) if (slugResult != null)
//{ {
// _logger.Debug("Movie with this title slug already exists. Adding year..."); _logger.Debug("Movie with this title slug already exists. Adding year...");
//} }
//imdbMovie.TitleSlug += "-" + imdbMovie.Year.ToString(); imdbMovie.TitleSlug += "-" + imdbMovie.Year.ToString();
titleSlug += "-" + imdbMovie.Year.ToString(); ;
imdbMovie.TitleSlug = titleSlug;
imdbMovie.Images = new List<MediaCover.MediaCover>(); imdbMovie.Images = new List<MediaCover.MediaCover>();
imdbMovie.Overview = result.overview; imdbMovie.Overview = result.overview;
@ -426,7 +419,7 @@ private static Series MapSeries(ShowResource show)
{ {
series.Certification = show.ContentRating.ToUpper(); series.Certification = show.ContentRating.ToUpper();
} }
series.Actors = show.Actors.Select(MapActors).ToList(); series.Actors = show.Actors.Select(MapActors).ToList();
series.Seasons = show.Seasons.Select(MapSeason).ToList(); series.Seasons = show.Seasons.Select(MapSeason).ToList();
series.Images = show.Images.Select(MapImage).ToList(); series.Images = show.Images.Select(MapImage).ToList();
@ -532,30 +525,5 @@ private static MediaCoverTypes MapCoverType(string coverType)
return MediaCoverTypes.Unknown; 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;
}
} }
} }

View File

@ -294,7 +294,6 @@
</Compile> </Compile>
<Compile Include="Datastore\Migration\110_add_physical_release_to_table.cs" /> <Compile Include="Datastore\Migration\110_add_physical_release_to_table.cs" />
<Compile Include="Datastore\Migration\109_add_movie_formats_to_naming_config.cs" /> <Compile Include="Datastore\Migration\109_add_movie_formats_to_naming_config.cs" />
<Compile Include="Datastore\Migration\117_fix_movie_slugs.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" /> <Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />