Refactor Various HouseKeepers

pull/94/head
Qstick 7 years ago
parent a956e22ce1
commit 6685644c5c

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
{
artist.Should().NotBeNull();
artist.Name.Should().NotBeNullOrWhiteSpace();
artist.CleanName.Should().Be(Parser.Parser.CleanSeriesTitle(artist.Name));
artist.CleanName.Should().Be(Parser.Parser.CleanArtistName(artist.Name));
artist.SortName.Should().Be(Parser.Parser.NormalizeTitle(artist.Name));
artist.Overview.Should().NotBeNullOrWhiteSpace();
artist.Images.Should().NotBeEmpty();

@ -31,7 +31,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
return Decision.Accept();
}
if (Parser.Parser.CleanArtistTitle(singleAlbumSpec.AlbumTitle) != Parser.Parser.CleanArtistTitle(remoteAlbum.ParsedAlbumInfo.AlbumTitle))
if (Parser.Parser.CleanArtistName(singleAlbumSpec.AlbumTitle) != Parser.Parser.CleanArtistName(remoteAlbum.ParsedAlbumInfo.AlbumTitle))
{
_logger.Debug("Album does not match searched album title, skipping.");
return Decision.Reject("Wrong album");

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Marr.Data;
using NzbDrone.Common.Serializer;
@ -19,7 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
var mapper = _database.GetDataMapper();
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "Restrictions" }
var usedTags = new[] { "Artists", "Notifications", "DelayProfiles", "Restrictions" }
.SelectMany(v => GetUsedTags(v, mapper))
.Distinct()
.ToArray();

@ -1,30 +1,30 @@
using System;
using System;
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Extras.Metadata.Files;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class DeleteBadMediaCovers : IHousekeepingTask
{
private readonly IMetadataFileService _metaFileService;
private readonly ISeriesService _seriesService;
private readonly IArtistService _artistService;
private readonly IDiskProvider _diskProvider;
private readonly IConfigService _configService;
private readonly Logger _logger;
public DeleteBadMediaCovers(IMetadataFileService metaFileService,
ISeriesService seriesService,
IArtistService artistService,
IDiskProvider diskProvider,
IConfigService configService,
Logger logger)
{
_metaFileService = metaFileService;
_seriesService = seriesService;
_artistService = artistService;
_diskProvider = diskProvider;
_configService = configService;
_logger = logger;
@ -34,18 +34,18 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
if (!_configService.CleanupMetadataImages) return;
var series = _seriesService.GetAllSeries();
var artists = _artistService.GetAllArtists();
foreach (var show in series)
foreach (var artist in artists)
{
var images = _metaFileService.GetFilesBySeries(show.Id)
var images = _metaFileService.GetFilesBySeries(artist.Id)
.Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && c.RelativePath.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase));
foreach (var image in images)
{
try
{
var path = Path.Combine(show.Path, image.RelativePath);
var path = Path.Combine(artist.Path, image.RelativePath);
if (!IsValid(path))
{
_logger.Debug("Deleting invalid image file " + path);
@ -84,4 +84,4 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
return !text.ToLowerInvariant().Contains("html");
}
}
}
}

@ -0,0 +1,27 @@
using System.Linq;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class UpdateCleanTitleForArtist : IHousekeepingTask
{
private readonly IArtistRepository _artistRepository;
public UpdateCleanTitleForArtist(IArtistRepository artistRepository)
{
_artistRepository = artistRepository;
}
public void Clean()
{
var artists = _artistRepository.All().ToList();
artists.ForEach(s =>
{
s.CleanName = s.CleanName.CleanArtistName();
_artistRepository.Update(s);
});
}
}
}

@ -1,27 +0,0 @@
using System.Linq;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class UpdateCleanTitleForSeries : IHousekeepingTask
{
private readonly ISeriesRepository _seriesRepository;
public UpdateCleanTitleForSeries(ISeriesRepository seriesRepository)
{
_seriesRepository = seriesRepository;
}
public void Clean()
{
var series = _seriesRepository.All().ToList();
series.ForEach(s =>
{
s.CleanTitle = s.CleanTitle.CleanSeriesTitle();
_seriesRepository.Update(s);
});
}
}
}

@ -43,7 +43,17 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId);
SetCustomProvider();
if (primaryAlbumTypes == null)
{
primaryAlbumTypes = new List<string>();
}
if (secondaryAlbumTypes == null)
{
secondaryAlbumTypes = new List<string>();
}
var httpRequest = customerRequestBuilder.Create()
.SetSegment("route", "artists/" + foreignArtistId)
.AddQueryParam("primTypes", string.Join("|",primaryAlbumTypes))
@ -143,7 +153,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
album.Title = resource.Title;
album.ForeignAlbumId = resource.Id;
album.ReleaseDate = resource.ReleaseDate;
album.CleanTitle = Parser.Parser.CleanArtistTitle(album.Title);
album.CleanTitle = Parser.Parser.CleanArtistName(album.Title);
album.AlbumType = resource.Type;
album.Images = resource.Images.Select(MapImage).ToList();
album.Label = resource.Label;
@ -174,8 +184,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
artist.ForeignArtistId = resource.Id;
artist.Genres = resource.Genres;
artist.Overview = resource.Overview;
artist.NameSlug = Parser.Parser.CleanArtistTitle(artist.Name);
artist.CleanName = Parser.Parser.CleanArtistTitle(artist.Name);
artist.NameSlug = Parser.Parser.CleanArtistName(artist.Name);
artist.CleanName = Parser.Parser.CleanArtistName(artist.Name);
artist.SortName = Parser.Parser.NormalizeTitle(artist.Name);
artist.Disambiguation = resource.Disambiguation;
artist.ArtistType = resource.Type;

@ -53,7 +53,7 @@ namespace NzbDrone.Core.Music
newArtist.Path = Path.Combine(newArtist.RootFolderPath, folderName);
}
newArtist.CleanName = newArtist.Name.CleanArtistTitle();
newArtist.CleanName = newArtist.Name.CleanArtistName();
newArtist.SortName = ArtistNameNormalizer.Normalize(newArtist.Name, newArtist.ForeignArtistId); // There is no Sort Title
newArtist.Added = DateTime.UtcNow;

@ -177,7 +177,7 @@ namespace NzbDrone.Core.Music
public Album FindByTitle(int artistId, string title)
{
title = Parser.Parser.CleanArtistTitle(title);
title = Parser.Parser.CleanArtistName(title);
return Query.Where(s => s.CleanTitle == title)
.AndWhere(s => s.ArtistId == artistId)
@ -186,7 +186,7 @@ namespace NzbDrone.Core.Music
public Album FindByArtistAndName(string artistName, string cleanTitle)
{
var cleanArtistName = Parser.Parser.CleanArtistTitle(artistName);
var cleanArtistName = Parser.Parser.CleanArtistName(artistName);
cleanTitle = cleanTitle.ToLowerInvariant();
var query = Query.Join<Album, Artist>(JoinType.Inner, album => album.Artist, (album, artist) => album.ArtistId == artist.Id)
.Where<Artist>(artist => artist.CleanName == cleanArtistName)

@ -77,7 +77,7 @@ namespace NzbDrone.Core.Music
public Artist FindByName(string title)
{
return _artistRepository.FindByName(title.CleanArtistTitle());
return _artistRepository.FindByName(title.CleanArtistName());
}
public Artist FindByTitleInexact(string title)

@ -76,7 +76,7 @@ namespace NzbDrone.Core.Music
albumToUpdate.LastInfoSync = DateTime.UtcNow;
albumToUpdate.CleanTitle = album.CleanTitle;
albumToUpdate.Title = album.Title ?? "Unknown";
albumToUpdate.CleanTitle = Parser.Parser.CleanArtistTitle(albumToUpdate.Title);
albumToUpdate.CleanTitle = Parser.Parser.CleanArtistName(albumToUpdate.Title);
albumToUpdate.ArtistId = artist.Id;
albumToUpdate.AlbumType = album.AlbumType;
albumToUpdate.Genres = album.Genres;

@ -608,7 +608,7 @@
<Compile Include="Housekeeping\Housekeepers\DeleteBadMediaCovers.cs" />
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasks.cs" />
<Compile Include="Housekeeping\Housekeepers\TrimLogDatabase.cs" />
<Compile Include="Housekeeping\Housekeepers\UpdateCleanTitleForSeries.cs" />
<Compile Include="Housekeeping\Housekeepers\UpdateCleanTitleForArtist.cs" />
<Compile Include="Housekeeping\HousekeepingCommand.cs" />
<Compile Include="Housekeeping\HousekeepingService.cs" />
<Compile Include="Housekeeping\IHousekeepingTask.cs" />

@ -789,15 +789,15 @@ namespace NzbDrone.Core.Parser
return NormalizeRegex.Replace(title, string.Empty).ToLower().RemoveAccent();
}
public static string CleanArtistTitle(this string title)
public static string CleanArtistName(this string name)
{
long number = 0;
//If Title only contains numbers return it as is.
if (long.TryParse(title, out number))
return title;
if (long.TryParse(name, out number))
return name;
return NormalizeRegex.Replace(title, string.Empty).ToLower().RemoveAccent();
return NormalizeRegex.Replace(name, string.Empty).ToLower().RemoveAccent();
}
public static string NormalizeEpisodeTitle(string title)

Loading…
Cancel
Save