2018-01-26 03:01:53 +00:00
|
|
|
using System;
|
2013-03-01 07:03:41 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-09-14 06:36:07 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.MediaFiles
|
|
|
|
{
|
2017-05-11 18:43:05 +00:00
|
|
|
public interface IMediaFileRepository : IBasicRepository<TrackFile>
|
2013-03-01 07:03:41 +00:00
|
|
|
{
|
2017-06-20 00:57:07 +00:00
|
|
|
List<TrackFile> GetFilesByArtist(int artistId);
|
2017-08-26 02:00:14 +00:00
|
|
|
List<TrackFile> GetFilesByAlbum(int albumId);
|
2017-05-11 18:43:05 +00:00
|
|
|
List<TrackFile> GetFilesWithoutMediaInfo();
|
2018-01-26 03:01:53 +00:00
|
|
|
List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath);
|
2013-03-01 07:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-11 18:43:05 +00:00
|
|
|
public class MediaFileRepository : BasicRepository<TrackFile>, IMediaFileRepository
|
2013-03-01 07:03:41 +00:00
|
|
|
{
|
2015-05-03 19:46:21 +00:00
|
|
|
public MediaFileRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
2013-09-14 06:36:07 +00:00
|
|
|
: base(database, eventAggregator)
|
2013-03-01 07:03:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:43:05 +00:00
|
|
|
public List<TrackFile> GetFilesWithoutMediaInfo()
|
2013-06-02 19:29:00 +00:00
|
|
|
{
|
2017-05-11 18:43:05 +00:00
|
|
|
return Query.Where(c => c.MediaInfo == null).ToList();
|
2013-03-01 07:03:41 +00:00
|
|
|
}
|
2014-04-10 17:58:50 +00:00
|
|
|
|
2017-06-20 00:57:07 +00:00
|
|
|
public List<TrackFile> GetFilesByArtist(int artistId)
|
2014-04-10 17:58:50 +00:00
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT TrackFiles.* " +
|
|
|
|
"FROM Artists " +
|
|
|
|
"JOIN Albums ON Albums.ArtistMetadataId = Artists.ArtistMetadataId " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId == Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId == AlbumReleases.Id " +
|
|
|
|
"JOIN TrackFiles ON TrackFiles.Id == Tracks.TrackFileId " +
|
|
|
|
"WHERE Artists.Id == {0} " +
|
|
|
|
"AND AlbumReleases.Monitored = 1",
|
|
|
|
artistId);
|
|
|
|
|
|
|
|
return Query.QueryText(query).ToList();
|
2014-04-10 17:58:50 +00:00
|
|
|
}
|
2017-08-26 02:00:14 +00:00
|
|
|
|
|
|
|
public List<TrackFile> GetFilesByAlbum(int albumId)
|
|
|
|
{
|
|
|
|
return Query.Where(c => c.AlbumId == albumId).ToList();
|
|
|
|
}
|
2018-01-26 03:01:53 +00:00
|
|
|
|
|
|
|
public List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath)
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
var mapper = DataMapper;
|
|
|
|
mapper.AddParameter("artistId", artistId);
|
|
|
|
mapper.AddParameter("relativePath", relativePath);
|
|
|
|
string query = "SELECT TrackFiles.* " +
|
|
|
|
"FROM Artists " +
|
|
|
|
"JOIN Albums ON Albums.ArtistMetadataId = Artists.ArtistMetadataId " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId == Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId == AlbumReleases.Id " +
|
|
|
|
"JOIN TrackFiles ON TrackFiles.Id == Tracks.TrackFileId " +
|
|
|
|
"WHERE Artists.Id == @artistId " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"AND TrackFiles.RelativePath == @relativePath";
|
|
|
|
|
|
|
|
return mapper.Query<TrackFile>(query);
|
2018-01-26 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 07:03:41 +00:00
|
|
|
}
|
2018-01-26 03:01:53 +00:00
|
|
|
}
|