2012-02-21 03:25:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2012-02-21 03:25:19 +00:00
|
|
|
|
|
2013-02-19 06:01:03 +00:00
|
|
|
|
namespace NzbDrone.Core.Tv
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public interface IEpisodeRepository : IBasicRepository<Episode>
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Episode Get(int seriesId, int season, int episodeNumber);
|
|
|
|
|
Episode Get(int seriesId, DateTime date);
|
|
|
|
|
IList<Episode> GetEpisodes(int seriesId);
|
|
|
|
|
IList<Episode> GetEpisodes(int seriesId, int seasonNumber);
|
|
|
|
|
IList<Episode> GetEpisodeByFileId(int fileId);
|
|
|
|
|
IList<Episode> EpisodesWithoutFiles(bool includeSpecials);
|
|
|
|
|
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
|
|
|
|
|
IList<Episode> EpisodesWithFiles();
|
|
|
|
|
}
|
2012-02-21 03:25:19 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
|
|
|
|
{
|
|
|
|
|
public EpisodeRepository(IObjectDatabase objectDatabase)
|
|
|
|
|
: base(objectDatabase)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public Episode Get(int seriesId, int season, int episodeNumber)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public Episode Get(int seriesId, DateTime date)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public IList<Episode> GetEpisodes(int seriesId)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
return Queryable.Where(s => s.SeriesId == seriesId).ToList();
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public IList<Episode> GetEpisodes(int seriesId, int seasonNumber)
|
2012-02-21 03:25:19 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
return Queryable.Where(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).ToList();
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
2012-02-21 06:50:38 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public IList<Episode> GetEpisodeByFileId(int fileId)
|
2012-02-21 06:50:38 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
return Queryable.Where(s => s.EpisodeFile != null && s.EpisodeFile.EpisodeFileId == fileId).ToList();
|
2012-02-21 06:50:38 +00:00
|
|
|
|
}
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
public IList<Episode> EpisodesWithoutFiles(bool includeSpecials)
|
2012-02-28 05:50:56 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
var noFiles = Queryable.Where(s => s.EpisodeFile == null);
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
if (!includeSpecials)
|
2012-02-28 05:50:56 +00:00
|
|
|
|
{
|
2013-02-20 02:05:15 +00:00
|
|
|
|
noFiles = noFiles.Where(c => c.SeasonNumber != 0);
|
2012-02-28 05:50:56 +00:00
|
|
|
|
}
|
2013-02-20 02:05:15 +00:00
|
|
|
|
|
|
|
|
|
return noFiles.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<Episode> EpisodesWithFiles()
|
|
|
|
|
{
|
|
|
|
|
return Queryable.Where(s => s.EpisodeFile != null).ToList();
|
2012-02-28 05:50:56 +00:00
|
|
|
|
}
|
2012-02-21 03:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
} |