Null Checks for Track Parsing, Parse by Title if TrackNumber is missing

This commit is contained in:
Qstick 2017-09-14 23:33:13 -04:00
parent 02716c26f6
commit 5fec72395c
12 changed files with 204 additions and 67 deletions

View File

@ -13,7 +13,7 @@ namespace Lidarr.Api.V3.Albums
{
public string Title { get; set; }
public int ArtistId { get; set; }
public string Label { get; set; }
public string AlbumLabel { get; set; }
public bool Monitored { get; set; }
public string Path { get; set; }
public int ProfileId { get; set; }
@ -41,7 +41,7 @@ namespace Lidarr.Api.V3.Albums
{
Id = model.Id,
ArtistId = model.ArtistId,
Label = model.Label,
AlbumLabel = model.Label,
Path = model.Path,
ProfileId = model.ProfileId,
Monitored = model.Monitored,

View File

@ -53,9 +53,9 @@ namespace Lidarr.Api.V3.Indexers
private Response DownloadRelease(ReleaseResource release)
{
var remoteEpisode = _remoteAlbumCache.Find(release.Guid);
var remoteAlbum = _remoteAlbumCache.Find(release.Guid);
if (remoteEpisode == null)
if (remoteAlbum == null)
{
_logger.Debug("Couldn't find requested release in cache, cache timeout probably expired.");
@ -64,7 +64,7 @@ namespace Lidarr.Api.V3.Indexers
try
{
_downloadService.DownloadReport(remoteEpisode);
_downloadService.DownloadReport(remoteAlbum);
}
catch (ReleaseDownloadException ex)
{
@ -77,15 +77,15 @@ namespace Lidarr.Api.V3.Indexers
private List<ReleaseResource> GetReleases()
{
if (Request.Query.episodeId.HasValue)
if (Request.Query.albumId.HasValue)
{
return GetEpisodeReleases(Request.Query.episodeId);
return GetAlbumReleases(Request.Query.albumId);
}
return GetRss();
}
private List<ReleaseResource> GetEpisodeReleases(int albumId)
private List<ReleaseResource> GetAlbumReleases(int albumId)
{
try
{
@ -96,7 +96,7 @@ namespace Lidarr.Api.V3.Indexers
}
catch (Exception ex)
{
_logger.ErrorException("Episode search failed: " + ex.Message, ex);
_logger.ErrorException("Album search failed: " + ex.Message, ex);
}
return new List<ReleaseResource>();

View File

@ -64,7 +64,7 @@ namespace Lidarr.Api.V3.Indexers
public static ReleaseResource ToResource(this DownloadDecision model)
{
var releaseInfo = model.RemoteAlbum.Release;
var parsedEpisodeInfo = model.RemoteAlbum.ParsedAlbumInfo;
var parsedAlbumInfo = model.RemoteAlbum.ParsedAlbumInfo;
var remoteEpisode = model.RemoteAlbum;
var torrentInfo = (model.RemoteAlbum.Release as TorrentInfo) ?? new TorrentInfo();
@ -72,7 +72,7 @@ namespace Lidarr.Api.V3.Indexers
return new ReleaseResource
{
Guid = releaseInfo.Guid,
Quality = parsedEpisodeInfo.Quality,
Quality = parsedAlbumInfo.Quality,
//QualityWeight
Age = releaseInfo.Age,
AgeHours = releaseInfo.AgeHours,
@ -80,14 +80,14 @@ namespace Lidarr.Api.V3.Indexers
Size = releaseInfo.Size,
IndexerId = releaseInfo.IndexerId,
Indexer = releaseInfo.Indexer,
ReleaseGroup = parsedEpisodeInfo.ReleaseGroup,
ReleaseHash = parsedEpisodeInfo.ReleaseHash,
ReleaseGroup = parsedAlbumInfo.ReleaseGroup,
ReleaseHash = parsedAlbumInfo.ReleaseHash,
Title = releaseInfo.Title,
//FullSeason = parsedEpisodeInfo.FullSeason,
//SeasonNumber = parsedEpisodeInfo.SeasonNumber,
Language = parsedEpisodeInfo.Language,
Language = parsedAlbumInfo.Language,
//AirDate = parsedEpisodeInfo.AirDate,
ArtistName = parsedEpisodeInfo.ArtistName,
ArtistName = parsedAlbumInfo.ArtistName,
//EpisodeNumbers = parsedEpisodeInfo.EpisodeNumbers,
//AbsoluteEpisodeNumbers = parsedEpisodeInfo.AbsoluteEpisodeNumbers,

View File

@ -1,27 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Queue;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.IndexerSearch
{
class AlbumSearchService : IExecute<AlbumSearchCommand>
//IExecute<MissingAlbumSearchCommand>,
class AlbumSearchService : IExecute<AlbumSearchCommand>,
IExecute<MissingAlbumSearchCommand>
//IExecute<CutoffUnmetAlbumSearchCommand>
{
private readonly ISearchForNzb _nzbSearchService;
private readonly IAlbumService _albumService;
private readonly IQueueService _queueService;
private readonly IProcessDownloadDecisions _processDownloadDecisions;
private readonly Logger _logger;
public AlbumSearchService(ISearchForNzb nzbSearchService,
IAlbumService albumService,
IQueueService queueService,
IProcessDownloadDecisions processDownloadDecisions,
Logger logger)
{
_nzbSearchService = nzbSearchService;
_albumService = albumService;
_queueService = queueService;
_processDownloadDecisions = processDownloadDecisions;
_logger = logger;
}
private void SearchForMissingAlbums(List<Album> albums, bool userInvokedSearch)
{
_logger.ProgressInfo("Performing missing search for {0} albums", albums.Count);
var downloadedCount = 0;
foreach (var album in albums)
{
List<DownloadDecision> decisions;
decisions = _nzbSearchService.AlbumSearch(album.Id, false, userInvokedSearch);
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
downloadedCount += processed.Grabbed.Count;
}
_logger.ProgressInfo("Completed missing search for {0} albums. {1} reports downloaded.", albums.Count, downloadedCount);
}
public void Execute(AlbumSearchCommand message)
{
foreach (var albumId in message.AlbumIds)
@ -33,5 +65,47 @@ namespace NzbDrone.Core.IndexerSearch
_logger.ProgressInfo("Album search completed. {0} reports downloaded.", processed.Grabbed.Count);
}
}
public void Execute(MissingAlbumSearchCommand message)
{
List<Album> albums;
if (message.ArtistId.HasValue)
{
int artistId = message.ArtistId.Value;
albums = _albumService.AlbumsWithoutFiles(new PagingSpec<Album>
{
Page = 1,
PageSize = 100000,
SortDirection = SortDirection.Ascending,
SortKey = "Id",
FilterExpression =
v =>
v.Monitored == true &&
v.Artist.Monitored == true
}).Records.Where(e => e.ArtistId.Equals(artistId)).ToList();
}
else
{
albums = _albumService.AlbumsWithoutFiles(new PagingSpec<Album>
{
Page = 1,
PageSize = 100000,
SortDirection = SortDirection.Ascending,
SortKey = "Id",
FilterExpression =
v =>
v.Monitored == true &&
v.Artist.Monitored == true
}).Records.ToList();
}
var queue = _queueService.GetQueue().Select(q => q.Album.Id);
var missing = albums.Where(e => !queue.Contains(e.Id)).ToList();
SearchForMissingAlbums(missing, message.Trigger == CommandTrigger.Manual);
}
}
}

View File

@ -0,0 +1,20 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.IndexerSearch
{
public class MissingAlbumSearchCommand : Command
{
public int? ArtistId { get; set; }
public override bool SendUpdatesToClient => true;
public MissingAlbumSearchCommand()
{
}
public MissingAlbumSearchCommand(int artistId)
{
ArtistId = artistId;
}
}
}

View File

@ -1,20 +0,0 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.IndexerSearch
{
public class MissingEpisodeSearchCommand : Command
{
public int? SeriesId { get; set; }
public override bool SendUpdatesToClient => true;
public MissingEpisodeSearchCommand()
{
}
public MissingEpisodeSearchCommand(int seriesId)
{
SeriesId = seriesId;
}
}
}

View File

@ -174,7 +174,7 @@ namespace NzbDrone.Core.Music
return Query.Where(s => s.CleanTitle == title)
.AndWhere(s => s.ArtistId == artistId)
.SingleOrDefault();
.FirstOrDefault();
}
public Album FindByArtistAndName(string artistName, string cleanTitle)

View File

@ -0,0 +1,62 @@
using NLog;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Music
{
public class ArtistScannedHandler : IHandle<ArtistScannedEvent>,
IHandle<ArtistScanSkippedEvent>
{
private readonly IAlbumMonitoredService _albumMonitoredService;
private readonly IArtistService _artistService;
private readonly IManageCommandQueue _commandQueueManager;
//private readonly IEpisodeAddedService _episodeAddedService;
private readonly Logger _logger;
public ArtistScannedHandler(IAlbumMonitoredService albumMonitoredService,
IArtistService artistService,
IManageCommandQueue commandQueueManager,
//IEpisodeAddedService episodeAddedService,
Logger logger)
{
_albumMonitoredService = albumMonitoredService;
_artistService = artistService;
_commandQueueManager = commandQueueManager;
//_episodeAddedService = episodeAddedService;
_logger = logger;
}
private void HandleScanEvents(Artist artist)
{
if (artist.AddOptions == null)
{
//_episodeAddedService.SearchForRecentlyAdded(series.Id);
return;
}
_logger.Info("[{0}] was recently added, performing post-add actions", artist.Name);
_albumMonitoredService.SetAlbumMonitoredStatus(artist, artist.AddOptions);
if (artist.AddOptions.SearchForMissingTracks)
{
_commandQueueManager.Push(new MissingAlbumSearchCommand(artist.Id));
}
artist.AddOptions = null;
_artistService.RemoveAddOptions(artist);
}
public void Handle(ArtistScannedEvent message)
{
HandleScanEvents(message.Artist);
}
public void Handle(ArtistScanSkippedEvent message)
{
HandleScanEvents(message.Artist);
}
}
}

View File

@ -697,7 +697,7 @@
<Compile Include="Indexers\Torznab\TorznabSettings.cs" />
<Compile Include="Indexers\XElementExtensions.cs" />
<Compile Include="IndexerSearch\Definitions\SearchCriteriaBase.cs" />
<Compile Include="IndexerSearch\MissingEpisodeSearchCommand.cs" />
<Compile Include="IndexerSearch\MissingAlbumSearchCommand.cs" />
<Compile Include="IndexerSearch\NzbSearchService.cs" />
<Compile Include="Instrumentation\Commands\ClearLogCommand.cs" />
<Compile Include="Instrumentation\Commands\DeleteLogFilesCommand.cs" />
@ -865,6 +865,7 @@
<Compile Include="Music\MonitoringOptions.cs" />
<Compile Include="Music\AlbumMonitoredService.cs" />
<Compile Include="Music\MoveArtistService.cs" />
<Compile Include="Music\ArtistScannedHandler.cs" />
<Compile Include="Music\TrackMonitoredService.cs" />
<Compile Include="Music\Member.cs" />
<Compile Include="Music\AddArtistOptions.cs" />

View File

@ -338,7 +338,7 @@ namespace NzbDrone.Core.Parser
var artist = file.Tag.FirstAlbumArtist;
if (artist.IsNotNullOrWhiteSpace())
if (artist.IsNullOrWhiteSpace())
{
artist = file.Tag.FirstPerformer;
}

View File

@ -38,8 +38,6 @@ namespace NzbDrone.Core.Parser
{
private readonly IEpisodeService _episodeService;
private readonly ISeriesService _seriesService;
private readonly IAlbumRepository _albumRepository;
private readonly IArtistService _artistService;
private readonly IAlbumService _albumService;
private readonly ITrackService _trackService;
@ -49,14 +47,12 @@ namespace NzbDrone.Core.Parser
ISeriesService seriesService,
ITrackService trackService,
IArtistService artistService,
IAlbumRepository albumRepository,
IAlbumService albumService,
// ISceneMappingService sceneMappingService,
Logger logger)
{
_episodeService = episodeService;
_seriesService = seriesService;
_albumRepository = albumRepository;
_albumService = albumService;
_artistService = artistService;
// _sceneMappingService = sceneMappingService;
@ -694,11 +690,6 @@ namespace NzbDrone.Core.Parser
parsedTrackInfo = Parser.ParseMusicPath(filename);
}
//if (parsedTrackInfo == null)
//{
// var title = Path.GetFileNameWithoutExtension(filename);
//}
if (parsedTrackInfo == null)
{
if (MediaFileExtensions.Extensions.Contains(Path.GetExtension(filename)))
@ -734,6 +725,28 @@ namespace NzbDrone.Core.Parser
{
var result = new List<Track>();
if (parsedTrackInfo.AlbumTitle.IsNullOrWhiteSpace())
{
return new List<Track>();
}
var album = _albumService.FindByTitle(artist.Id, parsedTrackInfo.AlbumTitle);
if (album == null)
{
return new List<Track>();
}
Track trackInfo = null;
trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.Title);
if (trackInfo !=null)
{
result.Add(trackInfo);
return result;
}
if (parsedTrackInfo.TrackNumbers == null)
{
return new List<Track>();
@ -741,26 +754,13 @@ namespace NzbDrone.Core.Parser
foreach (var trackNumber in parsedTrackInfo.TrackNumbers)
{
Track trackInfo = null;
Track trackInfoByNumber = null;
//if (searchCriteria != null)
//{
// trackInfo = searchCriteria.Episodes.SingleOrDefault(e => e.SeasonNumber == seasonNumber && e.EpisodeNumber == trackNumber);
//}
trackInfoByNumber = _trackService.FindTrack(artist.Id, album.Id, trackNumber);
if (trackInfo == null)
if (trackInfoByNumber != null)
{
var album = _albumRepository.FindByArtistAndName(parsedTrackInfo.ArtistTitle, Parser.CleanArtistTitle(parsedTrackInfo.AlbumTitle));
if (album == null)
{
return new List<Track>();
}
trackInfo = _trackService.FindTrack(artist.Id, album.Id, trackNumber);
}
if (trackInfo != null)
{
result.Add(trackInfo);
result.Add(trackInfoByNumber);
}
else

View File

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Tv
if (series.AddOptions.SearchForMissingEpisodes)
{
_commandQueueManager.Push(new MissingEpisodeSearchCommand(series.Id));
_commandQueueManager.Push(new MissingAlbumSearchCommand(series.Id));
}
series.AddOptions = null;