From 8e626269d1043e1c23c29b320fb67ff33760a673 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 15 Feb 2018 23:03:44 -0500 Subject: [PATCH] Misc Fixes and Better Logging/Rejection Messages for Track Import --- frontend/src/Components/SignalRConnector.js | 10 +++------- .../Tracks/TrackModuleWithSignalR.cs | 20 ------------------- .../TrackImport/ImportApprovedTracks.cs | 15 +++++++------- .../TrackImport/ImportDecisionMaker.cs | 3 ++- .../Music/Events/TrackInfoRefreshedEvent.cs | 4 +--- .../Music/RefreshTrackService.cs | 2 +- .../Parser/Model/ParsedTrackInfo.cs | 4 ++-- src/NzbDrone.Core/Parser/Parser.cs | 5 ++++- src/NzbDrone.Core/Parser/ParsingService.cs | 7 +++---- 9 files changed, 24 insertions(+), 46 deletions(-) diff --git a/frontend/src/Components/SignalRConnector.js b/frontend/src/Components/SignalRConnector.js index b78f61ef3..ee158a339 100644 --- a/frontend/src/Components/SignalRConnector.js +++ b/frontend/src/Components/SignalRConnector.js @@ -218,16 +218,12 @@ class SignalRConnector extends Component { } handleTrack = (body) => { - const action = body.action; - const section = 'tracks'; - - if (action === 'updated') { + if (body.action === 'updated') { this.props.updateItem({ - section, + section: 'tracks', + updateOnly: true, ...body.resource }); - } else if (action === 'deleted') { - this.props.removeItem({ section, id: body.resource.id }); } } diff --git a/src/Lidarr.Api.V1/Tracks/TrackModuleWithSignalR.cs b/src/Lidarr.Api.V1/Tracks/TrackModuleWithSignalR.cs index 5e482c773..1f28b2de3 100644 --- a/src/Lidarr.Api.V1/Tracks/TrackModuleWithSignalR.cs +++ b/src/Lidarr.Api.V1/Tracks/TrackModuleWithSignalR.cs @@ -5,7 +5,6 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Music; -using NzbDrone.Core.Music.Events; using NzbDrone.SignalR; using Lidarr.Api.V1.TrackFiles; using Lidarr.Api.V1.Artist; @@ -15,7 +14,6 @@ using NzbDrone.Core.MediaFiles.Events; namespace Lidarr.Api.V1.Tracks { public abstract class TrackModuleWithSignalR : LidarrRestModuleWithSignalR, - IHandle, IHandle, IHandle { @@ -107,24 +105,6 @@ namespace Lidarr.Api.V1.Tracks return result; } - public void Handle(TrackInfoRefreshedEvent message) - { - foreach (var track in message.Removed) - { - BroadcastResourceChange(ModelAction.Deleted, track.ToResource()); - } - - foreach (var track in message.Added) - { - BroadcastResourceChange(ModelAction.Updated, track.ToResource()); - } - - foreach (var track in message.Updated) - { - BroadcastResourceChange(ModelAction.Updated, track.Id); - } - } - public void Handle(TrackImportedEvent message) { foreach (var track in message.TrackInfo.Tracks) diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs index 275fd4e5a..d8698ab80 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using NzbDrone.Core.Extras; using NzbDrone.Core.Music; using NzbDrone.Core.Languages; @@ -25,7 +26,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport { private readonly IUpgradeMediaFiles _trackFileUpgrader; private readonly IMediaFileService _mediaFileService; - //private readonly IExtraService _extraService; + private readonly IExtraService _extraService; private readonly IDiskProvider _diskProvider; private readonly IEventAggregator _eventAggregator; private readonly IAlbumRepository _albumRepository; @@ -33,7 +34,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport public ImportApprovedTracks(IUpgradeMediaFiles episodeFileUpgrader, IMediaFileService mediaFileService, - //IExtraService extraService, + IExtraService extraService, IAlbumRepository albumRepository, IDiskProvider diskProvider, IEventAggregator eventAggregator, @@ -41,7 +42,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport { _trackFileUpgrader = episodeFileUpgrader; _mediaFileService = mediaFileService; - // _extraService = extraService; + _extraService = extraService; _albumRepository = albumRepository; _diskProvider = diskProvider; _eventAggregator = eventAggregator; @@ -129,10 +130,10 @@ namespace NzbDrone.Core.MediaFiles.TrackImport _mediaFileService.Add(trackFile); importResults.Add(new ImportResult(importDecision)); - //if (newDownload) - //{ - // _extraService.ImportExtraFiles(localTrack, trackFile, copyOnly); // TODO: Import Music Extras - //} + if (newDownload) + { + _extraService.ImportExtraFiles(localTrack, trackFile, copyOnly); + } _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, oldFiles, newDownload, downloadClientItem)); diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportDecisionMaker.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportDecisionMaker.cs index 7859f54f6..c68ab007f 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportDecisionMaker.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportDecisionMaker.cs @@ -94,7 +94,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport if (localTrack.Tracks.Empty()) { - decision = new ImportDecision(localTrack, new Rejection("Invalid album or track")); + decision = localTrack.Album != null ? new ImportDecision(localTrack, new Rejection($"Couldn't parse track from: {localTrack.ParsedTrackInfo}")) : + new ImportDecision(localTrack, new Rejection($"Couldn't parse album from: {localTrack.ParsedTrackInfo}")); } else { diff --git a/src/NzbDrone.Core/Music/Events/TrackInfoRefreshedEvent.cs b/src/NzbDrone.Core/Music/Events/TrackInfoRefreshedEvent.cs index a71afa345..02bf1148d 100644 --- a/src/NzbDrone.Core/Music/Events/TrackInfoRefreshedEvent.cs +++ b/src/NzbDrone.Core/Music/Events/TrackInfoRefreshedEvent.cs @@ -12,14 +12,12 @@ namespace NzbDrone.Core.Music.Events public Album Album { get; set; } public ReadOnlyCollection Added { get; private set; } public ReadOnlyCollection Updated { get; private set; } - public ReadOnlyCollection Removed { get; private set; } - public TrackInfoRefreshedEvent(Album album, IList added, IList updated, IList removed) + public TrackInfoRefreshedEvent(Album album, IList added, IList updated) { Album = album; Added = new ReadOnlyCollection(added); Updated = new ReadOnlyCollection(updated); - Removed = new ReadOnlyCollection(removed); } } } diff --git a/src/NzbDrone.Core/Music/RefreshTrackService.cs b/src/NzbDrone.Core/Music/RefreshTrackService.cs index feaf8c770..7c52cf907 100644 --- a/src/NzbDrone.Core/Music/RefreshTrackService.cs +++ b/src/NzbDrone.Core/Music/RefreshTrackService.cs @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Music _trackService.UpdateMany(updateList); _trackService.InsertMany(newList); - _eventAggregator.PublishEvent(new TrackInfoRefreshedEvent(album, newList, updateList, existingTracks)); + _eventAggregator.PublishEvent(new TrackInfoRefreshedEvent(album, newList, updateList)); if (failCount != 0) { diff --git a/src/NzbDrone.Core/Parser/Model/ParsedTrackInfo.cs b/src/NzbDrone.Core/Parser/Model/ParsedTrackInfo.cs index 2d5bf8471..54ea3cfd5 100644 --- a/src/NzbDrone.Core/Parser/Model/ParsedTrackInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ParsedTrackInfo.cs @@ -37,10 +37,10 @@ namespace NzbDrone.Core.Parser.Model if (TrackNumbers != null && TrackNumbers.Any()) { - trackString = string.Format("T{0}", string.Join("-", TrackNumbers.Select(c => c.ToString("00")))); + trackString = string.Format("{0}", string.Join("-", TrackNumbers.Select(c => c.ToString("00")))); } - return string.Format("{0} - {1} - {2}: {3}", ArtistTitle, AlbumTitle, trackString, Quality); + return string.Format("{0} - {1} - {2}:{3} {4}: {5}", ArtistTitle, AlbumTitle, DiscNumber, trackString, Title, Quality); } } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 2c2bbf5ef..adb7575ab 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Music; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Languages; using TagLib; +using TagLib.IFD.Tags; namespace NzbDrone.Core.Parser { @@ -604,7 +605,6 @@ namespace NzbDrone.Core.Parser private static ParsedTrackInfo ParseAudioTags(string path) { - var fileInfo = new FileInfo(path); var file = TagLib.File.Create(path); Logger.Debug("Starting Tag Parse for {0}", file.Name); @@ -627,6 +627,7 @@ namespace NzbDrone.Core.Parser var temp = new int[1]; temp[0] = (int)trackNumber; + var result = new ParsedTrackInfo { Language = Language.English, //TODO Parse from Tag/Mediainfo @@ -640,6 +641,8 @@ namespace NzbDrone.Core.Parser ArtistTitleInfo = artistTitleInfo, Title = trackTitle }; + + Logger.Trace("File Tags Parsed: Artist: {0}, Album: {1}, Disc: {2}, Track Numbers(s): {3}, TrackTitle: {4}", result.ArtistTitle, result.AlbumTitle, result.DiscNumber, trackNumber, result.Title); foreach (ICodec codec in file.Properties.Codecs) { diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index 484873a6f..b8a9bd11c 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -286,16 +286,15 @@ namespace NzbDrone.Core.Parser if (parsedTrackInfo.Title.IsNotNullOrWhiteSpace()) { trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, parsedTrackInfo.Title); - _logger.Debug("Track {0} selected for {1}", trackInfo, parsedTrackInfo); - + if (trackInfo != null) { + _logger.Debug("Track {0} selected for {1}", trackInfo, parsedTrackInfo); result.Add(trackInfo); - } else { - _logger.Debug("Unable to find {0}", parsedTrackInfo); + _logger.Debug("Unable to find track for {0}", parsedTrackInfo); } }