|
|
|
@ -1,4 +1,9 @@
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
|
|
|
|
using NzbDrone.Core.Music.Events;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -12,12 +17,12 @@ namespace NzbDrone.Core.Music
|
|
|
|
|
List<Track> GetTracks(IEnumerable<int> ids);
|
|
|
|
|
Track FindTrack(string artistId, string albumId, int trackNumber);
|
|
|
|
|
Track FindTrackByTitle(string artistId, string albumId, string releaseTitle);
|
|
|
|
|
List<Track> GetTrackByArtist(string artistId);
|
|
|
|
|
List<Track> GetTracksByAlbum(string artistId, string albumId);
|
|
|
|
|
List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
|
|
|
|
|
List<Track> GetTracksByArtist(string artistId);
|
|
|
|
|
//List<Track> GetTracksByAlbum(string artistId, string albumId);
|
|
|
|
|
//List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
|
|
|
|
|
List<Track> TracksWithFiles(string artistId);
|
|
|
|
|
PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
|
|
|
|
List<Track> GeTracksByFileId(int trackFileId);
|
|
|
|
|
//PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
|
|
|
|
List<Track> GetTracksByFileId(int trackFileId);
|
|
|
|
|
void UpdateTrack(Track track);
|
|
|
|
|
void SetTrackMonitored(int trackId, bool monitored);
|
|
|
|
|
void UpdateTracks(List<Track> tracks);
|
|
|
|
@ -29,89 +34,158 @@ namespace NzbDrone.Core.Music
|
|
|
|
|
|
|
|
|
|
public class TrackService : ITrackService
|
|
|
|
|
{
|
|
|
|
|
public void DeleteMany(List<Track> tracks)
|
|
|
|
|
private readonly ITrackRepository _trackRepository;
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public TrackService(ITrackRepository trackRepository, IConfigService configService, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository = trackRepository;
|
|
|
|
|
_configService = configService;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Track FindTrack(string artistId, string albumId, int trackNumber)
|
|
|
|
|
public Track GetTrack(int id)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.Get(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Track FindTrackByTitle(string artistId, string albumId, string releaseTitle)
|
|
|
|
|
public List<Track> GetTracks(IEnumerable<int> ids)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.Get(ids).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> GeTracksByFileId(int trackFileId)
|
|
|
|
|
public Track FindTrack(string artistId, string albumId, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.Find(artistId, albumId, episodeNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Track GetTrack(int id)
|
|
|
|
|
public List<Track> GetTracksByArtist(string artistId)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.GetTracks(artistId).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> GetTrackByArtist(string artistId)
|
|
|
|
|
public List<Track> GetTracksByAlbum(string artistId, string albumId)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.GetTracks(artistId, albumId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> GetTracks(IEnumerable<int> ids)
|
|
|
|
|
public Track FindTrackByTitle(string artistId, string albumId, string releaseTitle)
|
|
|
|
|
{
|
|
|
|
|
// TODO: can replace this search mechanism with something smarter/faster/better
|
|
|
|
|
var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle).Replace(".", " ");
|
|
|
|
|
var tracks = _trackRepository.GetTracks(artistId, albumId);
|
|
|
|
|
|
|
|
|
|
var matches = tracks.Select(
|
|
|
|
|
track => new
|
|
|
|
|
{
|
|
|
|
|
Position = normalizedReleaseTitle.IndexOf(Parser.Parser.NormalizeEpisodeTitle(track.Title), StringComparison.CurrentCultureIgnoreCase),
|
|
|
|
|
Length = Parser.Parser.NormalizeEpisodeTitle(track.Title).Length,
|
|
|
|
|
Track = track
|
|
|
|
|
})
|
|
|
|
|
.Where(e => e.Track.Title.Length > 0 && e.Position >= 0)
|
|
|
|
|
.OrderBy(e => e.Position)
|
|
|
|
|
.ThenByDescending(e => e.Length)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (matches.Any())
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return matches.First().Track;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> GetTracksByAlbum(string artistId, string albumId)
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> TracksWithFiles(string artistId)
|
|
|
|
|
{
|
|
|
|
|
return _trackRepository.TracksWithFiles(artistId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
var episodeResult = _trackRepository.TracksWithoutFiles(pagingSpec);
|
|
|
|
|
|
|
|
|
|
return episodeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle)
|
|
|
|
|
public List<Track> GetTracksByFileId(int trackFileId)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return _trackRepository.GetTracksByFileId(trackFileId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InsertMany(List<Track> tracks)
|
|
|
|
|
public void UpdateTrack(Track track)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.Update(track);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetTrackMonitored(int trackId, bool monitored)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
var track = _trackRepository.Get(trackId);
|
|
|
|
|
_trackRepository.SetMonitoredFlat(track, monitored);
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Monitored flag for Track:{0} was set to {1}", trackId, monitored);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetTrackMonitoredByAlbum(string artistId, string albumId, bool monitored)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.SetMonitoredByAlbum(artistId, albumId, monitored);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Track> TracksWithFiles(string artistId)
|
|
|
|
|
public void UpdateEpisodes(List<Track> tracks)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.UpdateMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec)
|
|
|
|
|
public void InsertMany(List<Track> tracks)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.InsertMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateMany(List<Track> tracks)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.UpdateMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateTrack(Track track)
|
|
|
|
|
public void DeleteMany(List<Track> tracks)
|
|
|
|
|
{
|
|
|
|
|
_trackRepository.DeleteMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(ArtistDeletedEvent message)
|
|
|
|
|
{
|
|
|
|
|
var tracks = GetTracksByArtist(message.Artist.SpotifyId);
|
|
|
|
|
_trackRepository.DeleteMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(TrackFileDeletedEvent message)
|
|
|
|
|
{
|
|
|
|
|
foreach (var track in GetTracksByFileId(message.TrackFile.Id))
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Detaching track {0} from file.", track.Id);
|
|
|
|
|
track.TrackFileId = 0;
|
|
|
|
|
|
|
|
|
|
if (message.Reason != DeleteMediaFileReason.Upgrade && _configService.AutoUnmonitorPreviouslyDownloadedEpisodes)
|
|
|
|
|
{
|
|
|
|
|
track.Monitored = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateTrack(track);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(TrackFileAddedEvent message)
|
|
|
|
|
{
|
|
|
|
|
foreach (var track in message.TrackFile.Tracks.Value)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.SetFileId(track.Id, message.TrackFile.Id);
|
|
|
|
|
_logger.Debug("Linking [{0}] > [{1}]", message.TrackFile.RelativePath, track);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateTracks(List<Track> tracks)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
_trackRepository.UpdateMany(tracks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|