2017-09-04 02:20:56 +00:00
|
|
|
using System;
|
2017-06-28 02:25:51 +00:00
|
|
|
using System.Linq;
|
2018-10-20 22:09:12 +00:00
|
|
|
using NLog;
|
2017-06-28 02:25:51 +00:00
|
|
|
using Marr.Data.QGen;
|
2017-06-18 02:27:01 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
2017-07-02 00:21:39 +00:00
|
|
|
using NzbDrone.Core.Datastore.Extensions;
|
2017-06-18 02:27:01 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2017-10-17 04:05:03 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
|
|
|
using NzbDrone.Core.Qualities;
|
2019-03-12 22:37:59 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2017-06-18 02:27:01 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Music
|
|
|
|
{
|
|
|
|
public interface IAlbumRepository : IBasicRepository<Album>
|
|
|
|
{
|
|
|
|
List<Album> GetAlbums(int artistId);
|
2018-12-15 00:02:43 +00:00
|
|
|
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
|
2019-03-15 12:10:45 +00:00
|
|
|
List<Album> GetAlbumsForRefresh(int artistId, IEnumerable<string> foreignIds);
|
2018-12-15 00:02:43 +00:00
|
|
|
Album FindByTitle(int artistMetadataId, string title);
|
2019-01-12 16:56:13 +00:00
|
|
|
Album FindById(string foreignId);
|
2017-07-02 00:21:39 +00:00
|
|
|
PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec);
|
2017-10-17 04:05:03 +00:00
|
|
|
PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, List<LanguagesBelowCutoff> languagesBelowCutoff);
|
2017-06-28 02:25:51 +00:00
|
|
|
List<Album> AlbumsBetweenDates(DateTime startDate, DateTime endDate, bool includeUnmonitored);
|
2018-02-10 04:03:12 +00:00
|
|
|
List<Album> ArtistAlbumsBetweenDates(Artist artist, DateTime startDate, DateTime endDate, bool includeUnmonitored);
|
2017-06-25 13:17:49 +00:00
|
|
|
void SetMonitoredFlat(Album album, bool monitored);
|
2017-09-04 02:20:56 +00:00
|
|
|
void SetMonitored(IEnumerable<int> ids, bool monitored);
|
2018-12-15 00:02:43 +00:00
|
|
|
Album FindAlbumByRelease(string albumReleaseId);
|
|
|
|
Album FindAlbumByTrack(int trackId);
|
2018-04-08 06:25:34 +00:00
|
|
|
List<Album> GetArtistAlbumsWithFiles(Artist artist);
|
2017-06-18 02:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class AlbumRepository : BasicRepository<Album>, IAlbumRepository
|
|
|
|
{
|
2017-09-04 02:20:56 +00:00
|
|
|
private readonly IMainDatabase _database;
|
2018-10-20 22:09:12 +00:00
|
|
|
private readonly Logger _logger;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2018-10-20 22:09:12 +00:00
|
|
|
public AlbumRepository(IMainDatabase database, IEventAggregator eventAggregator, Logger logger)
|
2017-06-18 02:27:01 +00:00
|
|
|
: base(database, eventAggregator)
|
|
|
|
{
|
2017-09-04 02:20:56 +00:00
|
|
|
_database = database;
|
2018-10-20 22:09:12 +00:00
|
|
|
_logger = logger;
|
2017-06-18 02:27:01 +00:00
|
|
|
}
|
2017-10-08 03:01:49 +00:00
|
|
|
|
2017-06-18 02:27:01 +00:00
|
|
|
public List<Album> GetAlbums(int artistId)
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
return Query.Join<Album, Artist>(JoinType.Inner, album => album.Artist, (l, r) => l.ArtistMetadataId == r.ArtistMetadataId)
|
|
|
|
.Where<Artist>(a => a.Id == artistId).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId)
|
|
|
|
{
|
|
|
|
return Query.Where(s => s.ArtistMetadataId == artistMetadataId);
|
2017-06-18 02:27:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:10:45 +00:00
|
|
|
public List<Album> GetAlbumsForRefresh(int artistMetadataId, IEnumerable<string> foreignIds)
|
2017-06-18 02:27:01 +00:00
|
|
|
{
|
2019-03-15 12:10:45 +00:00
|
|
|
return Query
|
|
|
|
.Where(a => a.ArtistMetadataId == artistMetadataId)
|
|
|
|
.OrWhere($"[ForeignAlbumId] IN ('{string.Join("', '", foreignIds)}')")
|
|
|
|
.ToList();
|
2017-06-18 02:27:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:10:45 +00:00
|
|
|
public Album FindById(string foreignAlbumId)
|
2019-01-12 16:56:13 +00:00
|
|
|
{
|
2019-03-15 12:10:45 +00:00
|
|
|
return Query.Where(s => s.ForeignAlbumId == foreignAlbumId).SingleOrDefault();
|
2019-01-12 16:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 00:21:39 +00:00
|
|
|
public PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec)
|
|
|
|
{
|
|
|
|
var currentTime = DateTime.UtcNow;
|
|
|
|
|
2017-07-04 10:49:07 +00:00
|
|
|
//pagingSpec.TotalRecords = GetMissingAlbumsQuery(pagingSpec, currentTime).GetRowCount(); Cant Use GetRowCount with a Manual Query
|
|
|
|
|
|
|
|
pagingSpec.TotalRecords = GetMissingAlbumsQueryCount(pagingSpec, currentTime);
|
2017-07-02 00:21:39 +00:00
|
|
|
pagingSpec.Records = GetMissingAlbumsQuery(pagingSpec, currentTime).ToList();
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
}
|
|
|
|
|
2017-10-17 04:05:03 +00:00
|
|
|
public PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, List<LanguagesBelowCutoff> languagesBelowCutoff)
|
|
|
|
{
|
|
|
|
|
|
|
|
pagingSpec.TotalRecords = GetCutOffAlbumsQueryCount(pagingSpec, qualitiesBelowCutoff, languagesBelowCutoff);
|
|
|
|
pagingSpec.Records = GetCutOffAlbumsQuery(pagingSpec, qualitiesBelowCutoff, languagesBelowCutoff).ToList();
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
}
|
|
|
|
|
2017-06-28 02:25:51 +00:00
|
|
|
public List<Album> AlbumsBetweenDates(DateTime startDate, DateTime endDate, bool includeUnmonitored)
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
var query = Query.Join<Album, Artist>(JoinType.Inner, rg => rg.Artist, (rg, a) => rg.ArtistMetadataId == a.ArtistMetadataId)
|
|
|
|
.Where<Album>(rg => rg.ReleaseDate >= startDate)
|
|
|
|
.AndWhere(rg => rg.ReleaseDate <= endDate);
|
2017-06-28 02:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!includeUnmonitored)
|
|
|
|
{
|
|
|
|
query.AndWhere(e => e.Monitored)
|
2018-12-15 00:02:43 +00:00
|
|
|
.AndWhere(e => e.Artist.Value.Monitored);
|
2017-06-28 02:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return query.ToList();
|
|
|
|
}
|
|
|
|
|
2018-02-10 04:03:12 +00:00
|
|
|
public List<Album> ArtistAlbumsBetweenDates(Artist artist, DateTime startDate, DateTime endDate, bool includeUnmonitored)
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
var query = Query.Join<Album, Artist>(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistMetadataId == s.ArtistMetadataId)
|
2018-02-10 04:03:12 +00:00
|
|
|
.Where<Album>(e => e.ReleaseDate >= startDate)
|
|
|
|
.AndWhere(e => e.ReleaseDate <= endDate)
|
2018-12-15 00:02:43 +00:00
|
|
|
.AndWhere(e => e.ArtistMetadataId == artist.ArtistMetadataId);
|
2018-02-10 04:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!includeUnmonitored)
|
|
|
|
{
|
|
|
|
query.AndWhere(e => e.Monitored)
|
2018-12-15 00:02:43 +00:00
|
|
|
.AndWhere(e => e.Artist.Value.Monitored);
|
2018-02-10 04:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return query.ToList();
|
|
|
|
}
|
|
|
|
|
2017-07-04 10:49:07 +00:00
|
|
|
private QueryBuilder<Album> GetMissingAlbumsQuery(PagingSpec<Album> pagingSpec, DateTime currentTime)
|
2017-07-02 00:21:39 +00:00
|
|
|
{
|
2017-07-04 10:49:07 +00:00
|
|
|
string sortKey;
|
2017-10-08 03:01:49 +00:00
|
|
|
string monitored = "(Albums.[Monitored] = 0) OR (Artists.[Monitored] = 0)";
|
2017-07-04 10:49:07 +00:00
|
|
|
|
2018-03-15 01:28:46 +00:00
|
|
|
if (pagingSpec.FilterExpressions.FirstOrDefault().ToString().Contains("True"))
|
2017-07-04 10:49:07 +00:00
|
|
|
{
|
2017-10-08 03:01:49 +00:00
|
|
|
monitored = "(Albums.[Monitored] = 1) AND (Artists.[Monitored] = 1)";
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pagingSpec.SortKey == "releaseDate")
|
|
|
|
{
|
2017-10-08 03:01:49 +00:00
|
|
|
sortKey = "Albums." + pagingSpec.SortKey;
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
|
|
|
else if (pagingSpec.SortKey == "artist.sortName")
|
|
|
|
{
|
2017-10-08 03:01:49 +00:00
|
|
|
sortKey = "Artists." + pagingSpec.SortKey.Split('.').Last();
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
2018-03-25 02:20:13 +00:00
|
|
|
else if (pagingSpec.SortKey == "albumTitle")
|
|
|
|
{
|
|
|
|
sortKey = "Albums.title";
|
|
|
|
}
|
2017-07-04 10:49:07 +00:00
|
|
|
else
|
|
|
|
{
|
2017-10-08 03:01:49 +00:00
|
|
|
sortKey = "Albums.releaseDate";
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN Artists ON Albums.ArtistMetadataId = Artists.ArtistMetadataId " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId == Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId == AlbumReleases.Id " +
|
|
|
|
"LEFT OUTER JOIN TrackFiles ON TrackFiles.Id == Tracks.TrackFileId " +
|
|
|
|
"WHERE TrackFiles.Id IS NULL " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"AND ({0}) AND {1} " +
|
|
|
|
"GROUP BY Albums.Id " +
|
|
|
|
" ORDER BY {2} {3} LIMIT {4} OFFSET {5}",
|
|
|
|
monitored,
|
|
|
|
BuildReleaseDateCutoffWhereClause(currentTime),
|
|
|
|
sortKey,
|
|
|
|
pagingSpec.ToSortDirection(),
|
|
|
|
pagingSpec.PageSize,
|
|
|
|
pagingSpec.PagingOffset());
|
2017-07-04 10:49:07 +00:00
|
|
|
|
2017-10-08 03:01:49 +00:00
|
|
|
return Query.QueryText(query);
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int GetMissingAlbumsQueryCount(PagingSpec<Album> pagingSpec, DateTime currentTime)
|
|
|
|
{
|
2018-03-25 02:20:13 +00:00
|
|
|
var monitored = "(Albums.[Monitored] = 0) OR (Artists.[Monitored] = 0)";
|
2017-07-04 10:49:07 +00:00
|
|
|
|
2018-03-15 01:28:46 +00:00
|
|
|
if (pagingSpec.FilterExpressions.FirstOrDefault().ToString().Contains("True"))
|
2017-07-04 10:49:07 +00:00
|
|
|
{
|
2018-03-25 02:20:13 +00:00
|
|
|
monitored = "(Albums.[Monitored] = 1) AND (Artists.[Monitored] = 1)";
|
2017-07-04 10:49:07 +00:00
|
|
|
}
|
2017-10-08 03:01:49 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN Artists ON Albums.ArtistMetadataId = Artists.ArtistMetadataId " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId == Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId == AlbumReleases.Id " +
|
|
|
|
"LEFT OUTER JOIN TrackFiles ON TrackFiles.Id == Tracks.TrackFileId " +
|
|
|
|
"WHERE TrackFiles.Id IS NULL " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"AND ({0}) AND {1} " +
|
|
|
|
"GROUP BY Albums.Id ",
|
|
|
|
monitored,
|
|
|
|
BuildReleaseDateCutoffWhereClause(currentTime));
|
2017-07-04 10:49:07 +00:00
|
|
|
|
|
|
|
return Query.QueryText(query).Count();
|
2017-07-02 00:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private string BuildReleaseDateCutoffWhereClause(DateTime currentTime)
|
|
|
|
{
|
2017-10-08 03:01:49 +00:00
|
|
|
return string.Format("datetime(strftime('%s', Albums.[ReleaseDate]), 'unixepoch') <= '{0}'",
|
2017-07-02 00:21:39 +00:00
|
|
|
currentTime.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
}
|
|
|
|
|
2017-10-17 04:05:03 +00:00
|
|
|
private QueryBuilder<Album> GetCutOffAlbumsQuery(PagingSpec<Album> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, List<LanguagesBelowCutoff> languagesBelowCutoff)
|
|
|
|
{
|
|
|
|
string sortKey;
|
|
|
|
string monitored = "(Albums.[Monitored] = 0) OR (Artists.[Monitored] = 0)";
|
|
|
|
|
2018-03-15 01:28:46 +00:00
|
|
|
if (pagingSpec.FilterExpressions.FirstOrDefault().ToString().Contains("True"))
|
2017-10-17 04:05:03 +00:00
|
|
|
{
|
|
|
|
monitored = "(Albums.[Monitored] = 1) AND (Artists.[Monitored] = 1)";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pagingSpec.SortKey == "releaseDate")
|
|
|
|
{
|
|
|
|
sortKey = "Albums." + pagingSpec.SortKey;
|
|
|
|
}
|
|
|
|
else if (pagingSpec.SortKey == "artist.sortName")
|
|
|
|
{
|
|
|
|
sortKey = "Artists." + pagingSpec.SortKey.Split('.').Last();
|
|
|
|
}
|
2018-03-25 02:20:13 +00:00
|
|
|
else if (pagingSpec.SortKey == "albumTitle")
|
|
|
|
{
|
|
|
|
sortKey = "Albums.title";
|
|
|
|
}
|
2017-10-17 04:05:03 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sortKey = "Albums.releaseDate";
|
|
|
|
}
|
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN Artists 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 {0} " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"GROUP BY Albums.Id " +
|
|
|
|
"HAVING ({1} OR {2}) " +
|
|
|
|
"ORDER BY {3} {4} LIMIT {5} OFFSET {6}",
|
|
|
|
monitored,
|
|
|
|
BuildQualityCutoffWhereClause(qualitiesBelowCutoff),
|
|
|
|
BuildLanguageCutoffWhereClause(languagesBelowCutoff),
|
|
|
|
sortKey,
|
|
|
|
pagingSpec.ToSortDirection(),
|
|
|
|
pagingSpec.PageSize,
|
|
|
|
pagingSpec.PagingOffset());
|
2017-10-17 04:05:03 +00:00
|
|
|
|
|
|
|
return Query.QueryText(query);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetCutOffAlbumsQueryCount(PagingSpec<Album> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, List<LanguagesBelowCutoff> languagesBelowCutoff)
|
|
|
|
{
|
2018-04-15 04:49:16 +00:00
|
|
|
var monitored = "(Albums.[Monitored] = 0) OR (Artists.[Monitored] = 0)";
|
2017-10-17 04:05:03 +00:00
|
|
|
|
2018-03-15 01:28:46 +00:00
|
|
|
if (pagingSpec.FilterExpressions.FirstOrDefault().ToString().Contains("True"))
|
2017-10-17 04:05:03 +00:00
|
|
|
{
|
2018-04-15 04:49:16 +00:00
|
|
|
monitored = "(Albums.[Monitored] = 1) AND (Artists.[Monitored] = 1)";
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN Artists 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 {0} " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"GROUP BY Albums.Id " +
|
|
|
|
"HAVING ({1} OR {2}) ",
|
|
|
|
monitored,
|
|
|
|
BuildQualityCutoffWhereClause(qualitiesBelowCutoff),
|
|
|
|
BuildLanguageCutoffWhereClause(languagesBelowCutoff));
|
2017-10-17 04:05:03 +00:00
|
|
|
|
|
|
|
return Query.QueryText(query).Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string BuildLanguageCutoffWhereClause(List<LanguagesBelowCutoff> languagesBelowCutoff)
|
|
|
|
{
|
2018-02-10 04:03:12 +00:00
|
|
|
var clauses = new List<string>();
|
2017-10-17 04:05:03 +00:00
|
|
|
|
|
|
|
foreach (var language in languagesBelowCutoff)
|
|
|
|
{
|
|
|
|
foreach (var belowCutoff in language.LanguageIds)
|
|
|
|
{
|
2018-02-10 04:03:12 +00:00
|
|
|
clauses.Add(string.Format("(Artists.[LanguageProfileId] = {0} AND TrackFiles.[Language] = {1})", language.ProfileId, belowCutoff));
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-10 04:03:12 +00:00
|
|
|
return string.Format("({0})", string.Join(" OR ", clauses));
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private string BuildQualityCutoffWhereClause(List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
|
|
|
{
|
|
|
|
var clauses = new List<string>();
|
|
|
|
|
|
|
|
foreach (var profile in qualitiesBelowCutoff)
|
|
|
|
{
|
|
|
|
foreach (var belowCutoff in profile.QualityIds)
|
|
|
|
{
|
2019-02-23 22:39:11 +00:00
|
|
|
clauses.Add(string.Format("(Artists.[QualityProfileId] = {0} AND MIN(TrackFiles.Quality) LIKE '%_quality_: {1},%')", profile.ProfileId, belowCutoff));
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return string.Format("({0})", string.Join(" OR ", clauses));
|
|
|
|
}
|
|
|
|
|
2017-06-25 13:17:49 +00:00
|
|
|
public void SetMonitoredFlat(Album album, bool monitored)
|
|
|
|
{
|
|
|
|
album.Monitored = monitored;
|
|
|
|
SetFields(album, p => p.Monitored);
|
|
|
|
}
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
public void SetMonitored(IEnumerable<int> ids, bool monitored)
|
|
|
|
{
|
|
|
|
var mapper = _database.GetDataMapper();
|
|
|
|
|
|
|
|
mapper.AddParameter("monitored", monitored);
|
|
|
|
|
|
|
|
var sql = "UPDATE Albums " +
|
|
|
|
"SET Monitored = @monitored " +
|
|
|
|
$"WHERE Id IN ({string.Join(", ", ids)})";
|
|
|
|
|
|
|
|
mapper.ExecuteNonQuery(sql);
|
|
|
|
}
|
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
public Album FindByTitle(int artistMetadataId, string title)
|
2017-08-14 02:58:42 +00:00
|
|
|
{
|
2018-10-20 22:09:12 +00:00
|
|
|
var cleanTitle = Parser.Parser.CleanArtistName(title);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cleanTitle))
|
|
|
|
cleanTitle = title;
|
|
|
|
|
|
|
|
return Query.Where(s => s.CleanTitle == cleanTitle || s.Title == title)
|
2018-12-15 00:02:43 +00:00
|
|
|
.AndWhere(s => s.ArtistMetadataId == artistMetadataId)
|
2019-03-12 22:37:59 +00:00
|
|
|
.ExclusiveOrDefault();
|
2017-07-03 18:39:06 +00:00
|
|
|
}
|
2018-04-07 04:52:28 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
public Album FindAlbumByRelease(string albumReleaseId)
|
2018-04-07 04:52:28 +00:00
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId = Albums.Id " +
|
|
|
|
"WHERE AlbumReleases.ForeignReleaseId = '{0}'",
|
|
|
|
albumReleaseId);
|
|
|
|
return Query.QueryText(query).FirstOrDefault();
|
2018-04-07 04:52:28 +00:00
|
|
|
}
|
2018-04-08 06:25:34 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
public Album FindAlbumByTrack(int trackId)
|
2018-04-08 06:25:34 +00:00
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId = Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId = AlbumReleases.Id " +
|
|
|
|
"WHERE Tracks.Id = {0}",
|
|
|
|
trackId);
|
|
|
|
return Query.QueryText(query).FirstOrDefault();
|
|
|
|
}
|
2018-04-08 06:25:34 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
public List<Album> GetArtistAlbumsWithFiles(Artist artist)
|
|
|
|
{
|
|
|
|
string query = string.Format("SELECT Albums.* " +
|
|
|
|
"FROM Albums " +
|
|
|
|
"JOIN AlbumReleases ON AlbumReleases.AlbumId == Albums.Id " +
|
|
|
|
"JOIN Tracks ON Tracks.AlbumReleaseId == AlbumReleases.Id " +
|
|
|
|
"JOIN TrackFiles ON TrackFiles.Id == Tracks.TrackFileId " +
|
|
|
|
"WHERE Albums.ArtistMetadataId == {0} " +
|
|
|
|
"AND AlbumReleases.Monitored = 1 " +
|
|
|
|
"GROUP BY Albums.Id ",
|
|
|
|
artist.ArtistMetadataId);
|
|
|
|
|
|
|
|
return Query.QueryText(query).ToList();
|
2018-04-08 06:25:34 +00:00
|
|
|
}
|
2017-06-18 02:27:01 +00:00
|
|
|
}
|
|
|
|
}
|