2012-02-21 04:25:19 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-02-20 03:05:15 +01:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2012-02-21 04:25:19 +01:00
|
|
|
|
|
2013-02-19 07:01:03 +01:00
|
|
|
|
namespace NzbDrone.Core.Tv
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
public interface IEpisodeRepository : IBasicRepository<Episode>
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
Episode Get(int seriesId, int season, int episodeNumber);
|
|
|
|
|
Episode Get(int seriesId, DateTime date);
|
2013-03-04 00:18:43 +01:00
|
|
|
|
List<Episode> GetEpisodes(int seriesId);
|
|
|
|
|
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
|
|
|
|
|
List<Episode> GetEpisodeByFileId(int fileId);
|
|
|
|
|
List<Episode> EpisodesWithoutFiles(bool includeSpecials);
|
2013-02-20 03:05:15 +01:00
|
|
|
|
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
|
2013-03-04 00:18:43 +01:00
|
|
|
|
List<Episode> EpisodesWithFiles();
|
2013-02-24 00:08:22 +01:00
|
|
|
|
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
|
2013-03-01 08:03:41 +01:00
|
|
|
|
void SetIgnoreFlat(Episode episode, bool ignoreFlag);
|
2013-02-20 03:05:15 +01:00
|
|
|
|
}
|
2012-02-21 04:25:19 +01:00
|
|
|
|
|
2013-02-20 03:05:15 +01:00
|
|
|
|
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
|
|
|
|
{
|
|
|
|
|
public EpisodeRepository(IObjectDatabase objectDatabase)
|
|
|
|
|
: base(objectDatabase)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 03:05:15 +01:00
|
|
|
|
public Episode Get(int seriesId, int season, int episodeNumber)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 03:05:15 +01:00
|
|
|
|
public Episode Get(int seriesId, DateTime date)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 00:18:43 +01:00
|
|
|
|
public List<Episode> GetEpisodes(int seriesId)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
return Queryable.Where(s => s.SeriesId == seriesId).ToList();
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 00:18:43 +01:00
|
|
|
|
public List<Episode> GetEpisodes(int seriesId, int seasonNumber)
|
2012-02-21 04:25:19 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
return Queryable.Where(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).ToList();
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
2012-02-21 07:50:38 +01:00
|
|
|
|
|
2013-03-04 00:18:43 +01:00
|
|
|
|
public List<Episode> GetEpisodeByFileId(int fileId)
|
2012-02-21 07:50:38 +01:00
|
|
|
|
{
|
2013-03-01 08:03:41 +01:00
|
|
|
|
return Queryable.Where(s => s.EpisodeFile != null && s.EpisodeFile.Id == fileId).ToList();
|
2012-02-21 07:50:38 +01:00
|
|
|
|
}
|
2012-02-28 06:50:56 +01:00
|
|
|
|
|
2013-03-04 00:18:43 +01:00
|
|
|
|
public List<Episode> EpisodesWithoutFiles(bool includeSpecials)
|
2012-02-28 06:50:56 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
if (!includeSpecials)
|
2012-02-28 06:50:56 +01:00
|
|
|
|
{
|
2013-03-21 04:02:57 +01:00
|
|
|
|
return Queryable.Where(s => s.EpisodeFile == null && s.SeasonNumber != 0).ToList();
|
2012-02-28 06:50:56 +01:00
|
|
|
|
}
|
2013-02-20 03:05:15 +01:00
|
|
|
|
|
2013-03-21 04:02:57 +01:00
|
|
|
|
return Queryable.Where(s => s.EpisodeFile == null).ToList();
|
2013-02-20 03:05:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
return Queryable.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 00:18:43 +01:00
|
|
|
|
public List<Episode> EpisodesWithFiles()
|
2013-02-20 03:05:15 +01:00
|
|
|
|
{
|
|
|
|
|
return Queryable.Where(s => s.EpisodeFile != null).ToList();
|
2012-02-28 06:50:56 +01:00
|
|
|
|
}
|
2013-02-24 00:08:22 +01:00
|
|
|
|
|
|
|
|
|
public List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate)
|
|
|
|
|
{
|
|
|
|
|
return Queryable.Where(s => s.AirDate >= startDate && s.AirDate <= endDate).ToList();
|
|
|
|
|
}
|
2013-03-01 08:03:41 +01:00
|
|
|
|
|
|
|
|
|
public void SetIgnoreFlat(Episode episode, bool ignoreFlag)
|
|
|
|
|
{
|
|
|
|
|
episode.Ignored = ignoreFlag;
|
|
|
|
|
ObjectDatabase.UpdateField(episode, "Ignored");
|
|
|
|
|
}
|
2012-02-21 04:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
} |