You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.6 KiB
69 lines
2.6 KiB
using System.Collections.Generic;
|
|
using Marr.Data.QGen;
|
|
using NzbDrone.Core.Datastore;
|
|
using NzbDrone.Core.Messaging.Events;
|
|
using NzbDrone.Core.Music;
|
|
|
|
namespace NzbDrone.Core.MediaFiles
|
|
{
|
|
public interface IMediaFileRepository : IBasicRepository<TrackFile>
|
|
{
|
|
List<TrackFile> GetFilesByArtist(int artistId);
|
|
List<TrackFile> GetFilesByAlbum(int albumId);
|
|
List<TrackFile> GetFilesByRelease(int releaseId);
|
|
List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath);
|
|
}
|
|
|
|
|
|
public class MediaFileRepository : BasicRepository<TrackFile>, IMediaFileRepository
|
|
{
|
|
public MediaFileRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
|
: base(database, eventAggregator)
|
|
{
|
|
}
|
|
|
|
// always join with all the other good stuff
|
|
// needed more often than not so better to load it all now
|
|
protected override QueryBuilder<TrackFile> Query =>
|
|
DataMapper.Query<TrackFile>()
|
|
.Join<TrackFile, Track>(JoinType.Left, t => t.Tracks, (t, x) => t.Id == x.TrackFileId)
|
|
.Join<TrackFile, Album>(JoinType.Left, t => t.Album, (t, a) => t.AlbumId == a.Id)
|
|
.Join<TrackFile, Artist>(JoinType.Left, t => t.Artist, (t, a) => t.Album.Value.ArtistMetadataId == a.ArtistMetadataId)
|
|
.Join<Artist, ArtistMetadata>(JoinType.Left, a => a.Metadata, (a, m) => a.ArtistMetadataId == m.Id);
|
|
|
|
public List<TrackFile> GetFilesByArtist(int artistId)
|
|
{
|
|
return Query
|
|
.Join<Album, AlbumRelease>(JoinType.Inner, a => a.AlbumReleases, (a, r) => a.Id == r.AlbumId)
|
|
.Where<AlbumRelease>(r => r.Monitored == true)
|
|
.AndWhere(t => t.Artist.Value.Id == artistId)
|
|
.ToList();
|
|
}
|
|
|
|
public List<TrackFile> GetFilesByAlbum(int albumId)
|
|
{
|
|
return Query
|
|
.Where(f => f.AlbumId == albumId)
|
|
.ToList();
|
|
}
|
|
|
|
public List<TrackFile> GetFilesByRelease(int releaseId)
|
|
{
|
|
return Query
|
|
.Where<Track>(x => x.AlbumReleaseId == releaseId)
|
|
.ToList();
|
|
}
|
|
|
|
|
|
public List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath)
|
|
{
|
|
return Query
|
|
.Join<Album, AlbumRelease>(JoinType.Inner, a => a.AlbumReleases, (a, r) => a.Id == r.AlbumId)
|
|
.Where<AlbumRelease>(r => r.Monitored == true)
|
|
.AndWhere(t => t.Artist.Value.Id == artistId)
|
|
.AndWhere(t => t.RelativePath == relativePath)
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|