mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-07 21:42:16 -07:00
Log TrackImport and TrackFileDeleted to History
This commit is contained in:
parent
ab9a9232cf
commit
729d1142b0
12 changed files with 94 additions and 44 deletions
|
@ -18,11 +18,11 @@ function getHeaderTitle(eventType) {
|
|||
case 'downloadFailed':
|
||||
return 'Download Failed';
|
||||
case 'downloadFolderImported':
|
||||
return 'Episode Imported';
|
||||
return 'Track Imported';
|
||||
case 'trackFileDeleted':
|
||||
return 'Episode File Deleted';
|
||||
return 'Track File Deleted';
|
||||
case 'trackFileRenamed':
|
||||
return 'Episode File Renamed';
|
||||
return 'Track File Renamed';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ class HistoryRow extends Component {
|
|||
albumId,
|
||||
artist,
|
||||
album,
|
||||
track,
|
||||
language,
|
||||
quality,
|
||||
eventType,
|
||||
|
@ -121,6 +122,14 @@ class HistoryRow extends Component {
|
|||
);
|
||||
}
|
||||
|
||||
if (name === 'trackTitle') {
|
||||
return (
|
||||
<TableRowCell key={name}>
|
||||
{track.title}
|
||||
</TableRowCell>
|
||||
);
|
||||
}
|
||||
|
||||
if (name === 'language') {
|
||||
return (
|
||||
<TableRowCell key={name}>
|
||||
|
@ -220,6 +229,7 @@ HistoryRow.propTypes = {
|
|||
albumId: PropTypes.number,
|
||||
artist: PropTypes.object.isRequired,
|
||||
album: PropTypes.object,
|
||||
track: PropTypes.object,
|
||||
language: PropTypes.object.isRequired,
|
||||
quality: PropTypes.object.isRequired,
|
||||
eventType: PropTypes.string.isRequired,
|
||||
|
@ -234,4 +244,10 @@ HistoryRow.propTypes = {
|
|||
onMarkAsFailedPress: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
HistoryRow.defaultProps = {
|
||||
track: {
|
||||
title: ''
|
||||
}
|
||||
};
|
||||
|
||||
export default HistoryRow;
|
||||
|
|
|
@ -37,6 +37,11 @@ export const defaultState = {
|
|||
label: 'Album Title',
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'trackTitle',
|
||||
label: 'Track Title',
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
label: 'Language',
|
||||
|
|
|
@ -6,6 +6,7 @@ using NzbDrone.Core.Download;
|
|||
using NzbDrone.Core.History;
|
||||
using Lidarr.Api.V3.Albums;
|
||||
using Lidarr.Api.V3.Artist;
|
||||
using Lidarr.Api.V3.Tracks;
|
||||
using Lidarr.Http;
|
||||
using Lidarr.Http.Extensions;
|
||||
|
||||
|
@ -35,6 +36,7 @@ namespace Lidarr.Api.V3.History
|
|||
|
||||
resource.Artist = model.Artist.ToResource();
|
||||
resource.Album = model.Album.ToResource();
|
||||
resource.Track = model.Track.ToResource();
|
||||
|
||||
if (model.Artist != null)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ using NzbDrone.Core.Languages;
|
|||
using NzbDrone.Core.Qualities;
|
||||
using Lidarr.Api.V3.Albums;
|
||||
using Lidarr.Api.V3.Artist;
|
||||
using Lidarr.Api.V3.Tracks;
|
||||
using Lidarr.Http.REST;
|
||||
|
||||
namespace Lidarr.Api.V3.History
|
||||
|
@ -13,6 +14,7 @@ namespace Lidarr.Api.V3.History
|
|||
{
|
||||
public int AlbumId { get; set; }
|
||||
public int ArtistId { get; set; }
|
||||
public int TrackId { get; set; }
|
||||
public string SourceTitle { get; set; }
|
||||
public Language Language { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
|
@ -26,6 +28,7 @@ namespace Lidarr.Api.V3.History
|
|||
|
||||
public AlbumResource Album { get; set; }
|
||||
public ArtistResource Artist { get; set; }
|
||||
public TrackResource Track { get; set; }
|
||||
}
|
||||
|
||||
public static class HistoryResourceMapper
|
||||
|
@ -40,6 +43,7 @@ namespace Lidarr.Api.V3.History
|
|||
|
||||
AlbumId = model.AlbumId,
|
||||
ArtistId = model.ArtistId,
|
||||
TrackId = model.TrackId,
|
||||
SourceTitle = model.SourceTitle,
|
||||
Language = model.Language,
|
||||
Quality = model.Quality,
|
||||
|
|
|
@ -11,7 +11,7 @@ using NzbDrone.Core.Test.Framework;
|
|||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
|
||||
|
@ -54,23 +54,23 @@ namespace NzbDrone.Core.Test.HistoryTests
|
|||
[Test]
|
||||
public void should_use_file_name_for_source_title_if_scene_name_is_null()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew().Build();
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1).Build().ToList();
|
||||
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
var artist = Builder<Artist>.CreateNew().Build();
|
||||
var tracks = Builder<Track>.CreateListOfSize(1).Build().ToList();
|
||||
var trackFile = Builder<TrackFile>.CreateNew()
|
||||
.With(f => f.SceneName = null)
|
||||
.Build();
|
||||
|
||||
var localEpisode = new LocalEpisode
|
||||
var localTrack = new LocalTrack
|
||||
{
|
||||
Series = series,
|
||||
Episodes = episodes,
|
||||
Path = @"C:\Test\Unsorted\Series.s01e01.mkv"
|
||||
Artist = artist,
|
||||
Tracks = tracks,
|
||||
Path = @"C:\Test\Unsorted\Artist.01.Hymn.mp3"
|
||||
};
|
||||
|
||||
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true, "sab", "abcd"));
|
||||
Subject.Handle(new TrackImportedEvent(localTrack, trackFile, true, "sab", "abcd"));
|
||||
|
||||
Mocker.GetMock<IHistoryRepository>()
|
||||
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));
|
||||
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
src/NzbDrone.Core/Datastore/Migration/118_history_trackid.cs
Normal file
20
src/NzbDrone.Core/Datastore/Migration/118_history_trackid.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(118)]
|
||||
public class history_trackid : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("History")
|
||||
.AddColumn("TrackId").AsInt32().WithDefaultValue(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -113,7 +113,7 @@ namespace NzbDrone.Core.Datastore
|
|||
.Relationships.AutoMapICollectionOrComplexProperties()
|
||||
.For("Tracks")
|
||||
.LazyLoad(condition: parent => parent.Id > 0,
|
||||
query: (db, parent) => db.Query<Track>().Where(c => c.ArtistId == parent.Id).ToList()) // TODO: Figure what the hell to do here
|
||||
query: (db, parent) => db.Query<Track>().Where(c => c.TrackFileId == parent.Id).ToList()) // TODO: Figure what the hell to do here
|
||||
.HasOne(file => file.Artist, file => file.ArtistId);
|
||||
|
||||
Mapper.Entity<Track>().RegisterModel("Tracks")
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace NzbDrone.Core.History
|
|||
Data = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public int TrackId { get; set; }
|
||||
public int AlbumId { get; set; }
|
||||
public int ArtistId { get; set; }
|
||||
public string SourceTitle { get; set; }
|
||||
|
@ -23,6 +24,7 @@ namespace NzbDrone.Core.History
|
|||
public DateTime Date { get; set; }
|
||||
public Album Album { get; set; }
|
||||
public Artist Artist { get; set; }
|
||||
public Track Track { get; set; }
|
||||
public HistoryEventType EventType { get; set; }
|
||||
public Dictionary<string, string> Data { get; set; }
|
||||
public Language Language { get; set; }
|
||||
|
@ -38,6 +40,6 @@ namespace NzbDrone.Core.History
|
|||
SeriesFolderImported = 2,
|
||||
DownloadFolderImported = 3,
|
||||
DownloadFailed = 4,
|
||||
EpisodeFileDeleted = 5
|
||||
TrackFileDeleted = 5
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace NzbDrone.Core.History
|
|||
protected override SortBuilder<History> GetPagedQuery(QueryBuilder<History> query, PagingSpec<History> pagingSpec)
|
||||
{
|
||||
var baseQuery = query.Join<History, Artist>(JoinType.Inner, h => h.Artist, (h, s) => h.ArtistId == s.Id)
|
||||
.Join<History, Album>(JoinType.Inner, h => h.Album, (h, e) => h.AlbumId == e.Id);
|
||||
.Join<History, Album>(JoinType.Inner, h => h.Album, (h, e) => h.AlbumId == e.Id)
|
||||
.Join<History, Track>(JoinType.Left, h => h.Track, (h, e) => h.TrackId == e.Id);
|
||||
|
||||
return base.GetPagedQuery(baseQuery, pagingSpec);
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ namespace NzbDrone.Core.History
|
|||
|
||||
public class HistoryService : IHistoryService,
|
||||
IHandle<AlbumGrabbedEvent>,
|
||||
IHandle<EpisodeImportedEvent>,
|
||||
IHandle<TrackImportedEvent>,
|
||||
IHandle<DownloadFailedEvent>,
|
||||
IHandle<EpisodeFileDeletedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>,
|
||||
IHandle<ArtistDeletedEvent>
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
|
@ -74,14 +74,13 @@ namespace NzbDrone.Core.History
|
|||
return _historyRepository.FindByDownloadId(downloadId);
|
||||
}
|
||||
|
||||
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||
private string FindDownloadId(EpisodeImportedEvent trackedDownload)
|
||||
private string FindDownloadId(TrackImportedEvent trackedDownload)
|
||||
{
|
||||
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedEpisode.Path);
|
||||
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedTrack.Path);
|
||||
|
||||
var albumIds = trackedDownload.EpisodeInfo.Episodes.Select(c => c.Id).ToList();
|
||||
var albumIds = trackedDownload.TrackInfo.Tracks.Select(c => c.AlbumId).ToList();
|
||||
|
||||
var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.EpisodeInfo.Series.Id, trackedDownload.ImportedEpisode.Quality);
|
||||
var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.TrackInfo.Artist.Id, trackedDownload.ImportedTrack.Quality);
|
||||
|
||||
|
||||
//Find download related items for these episdoes
|
||||
|
@ -97,7 +96,7 @@ namespace NzbDrone.Core.History
|
|||
|
||||
if (stillDownloading.Any())
|
||||
{
|
||||
foreach (var matchingHistory in trackedDownload.EpisodeInfo.Episodes.Select(e => stillDownloading.Where(c => c.AlbumId == e.Id).ToList()))
|
||||
foreach (var matchingHistory in trackedDownload.TrackInfo.Tracks.Select(e => stillDownloading.Where(c => c.AlbumId == e.AlbumId).ToList()))
|
||||
{
|
||||
if (matchingHistory.Count != 1)
|
||||
{
|
||||
|
@ -165,8 +164,7 @@ namespace NzbDrone.Core.History
|
|||
}
|
||||
}
|
||||
|
||||
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||
public void Handle(EpisodeImportedEvent message)
|
||||
public void Handle(TrackImportedEvent message)
|
||||
{
|
||||
if (!message.NewDownload)
|
||||
{
|
||||
|
@ -180,24 +178,25 @@ namespace NzbDrone.Core.History
|
|||
downloadId = FindDownloadId(message);
|
||||
}
|
||||
|
||||
foreach (var episode in message.EpisodeInfo.Episodes)
|
||||
foreach (var track in message.TrackInfo.Tracks)
|
||||
{
|
||||
var history = new History
|
||||
{
|
||||
EventType = HistoryEventType.DownloadFolderImported,
|
||||
Date = DateTime.UtcNow,
|
||||
Quality = message.EpisodeInfo.Quality,
|
||||
SourceTitle = message.ImportedEpisode.SceneName ?? Path.GetFileNameWithoutExtension(message.EpisodeInfo.Path),
|
||||
ArtistId = message.ImportedEpisode.SeriesId,
|
||||
AlbumId = episode.Id,
|
||||
Quality = message.TrackInfo.Quality,
|
||||
SourceTitle = message.ImportedTrack.SceneName ?? Path.GetFileNameWithoutExtension(message.TrackInfo.Path),
|
||||
ArtistId = message.ImportedTrack.ArtistId,
|
||||
AlbumId = message.ImportedTrack.AlbumId,
|
||||
TrackId = track.Id,
|
||||
DownloadId = downloadId,
|
||||
Language = message.EpisodeInfo.Language
|
||||
Language = message.TrackInfo.Language
|
||||
};
|
||||
|
||||
//Won't have a value since we publish this event before saving to DB.
|
||||
//history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
|
||||
history.Data.Add("DroppedPath", message.EpisodeInfo.Path);
|
||||
history.Data.Add("ImportedPath", Path.Combine(message.EpisodeInfo.Series.Path, message.ImportedEpisode.RelativePath));
|
||||
history.Data.Add("DroppedPath", message.TrackInfo.Path);
|
||||
history.Data.Add("ImportedPath", Path.Combine(message.TrackInfo.Artist.Path, message.ImportedTrack.RelativePath));
|
||||
history.Data.Add("DownloadClient", message.DownloadClient);
|
||||
|
||||
_historyRepository.Insert(history);
|
||||
|
@ -227,25 +226,25 @@ namespace NzbDrone.Core.History
|
|||
}
|
||||
}
|
||||
|
||||
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||
public void Handle(EpisodeFileDeletedEvent message)
|
||||
public void Handle(TrackFileDeletedEvent message)
|
||||
{
|
||||
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)
|
||||
{
|
||||
_logger.Debug("Removing episode file from DB as part of cleanup routine, not creating history event.");
|
||||
_logger.Debug("Removing track file from DB as part of cleanup routine, not creating history event.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var episode in message.EpisodeFile.Episodes.Value)
|
||||
foreach (var track in message.TrackFile.Tracks.Value)
|
||||
{
|
||||
var history = new History
|
||||
{
|
||||
EventType = HistoryEventType.EpisodeFileDeleted,
|
||||
EventType = HistoryEventType.TrackFileDeleted,
|
||||
Date = DateTime.UtcNow,
|
||||
Quality = message.EpisodeFile.Quality,
|
||||
SourceTitle = message.EpisodeFile.Path,
|
||||
ArtistId = message.EpisodeFile.SeriesId,
|
||||
AlbumId = episode.Id,
|
||||
Quality = message.TrackFile.Quality,
|
||||
SourceTitle = message.TrackFile.Path,
|
||||
ArtistId = message.TrackFile.ArtistId,
|
||||
AlbumId = message.TrackFile.AlbumId,
|
||||
TrackId = track.Id,
|
||||
};
|
||||
|
||||
history.Data.Add("Reason", message.Reason.ToString());
|
||||
|
|
|
@ -293,6 +293,7 @@
|
|||
</Compile>
|
||||
<Compile Include="Datastore\Migration\105_rename_torrent_downloadstation.cs" />
|
||||
<Compile Include="Datastore\Migration\111_create_language_profiles.cs" />
|
||||
<Compile Include="Datastore\Migration\118_history_trackid.cs" />
|
||||
<Compile Include="Datastore\Migration\117_artist_links.cs" />
|
||||
<Compile Include="Datastore\Migration\116_change_drone_factory_variable_name.cs" />
|
||||
<Compile Include="Datastore\Migration\115_remove_tv_naming.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue