sonarr-repo-only/NzbDrone.Core/Tv/EpisodeRepository.cs

87 lines
6.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Tv
{
public interface IEpisodeRepository : IBasicRepository<Episode>
{
Episode Get(int seriesId, int season, int episodeNumber);
Episode Get(int seriesId, DateTime date);
List<Episode> GetEpisodes(int seriesId);
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
List<Episode> GetEpisodeByFileId(int fileId);
List<Episode> EpisodesWithoutFiles(bool includeSpecials);
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> EpisodesWithFiles();
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
void SetIgnoreFlat(Episode episode, bool ignoreFlag);
}
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
{
public EpisodeRepository(IObjectDatabase objectDatabase)
: base(objectDatabase)
{
}
public Episode Get(int seriesId, int season, int episodeNumber)
{
return Queryable.Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
}
public Episode Get(int seriesId, DateTime date)
{
return Queryable.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
}
public List<Episode> GetEpisodes(int seriesId)
{
return Queryable.Where(s => s.SeriesId == seriesId).ToList();
}
public List<Episode> GetEpisodes(int seriesId, int seasonNumber)
{
return Queryable.Where(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).ToList();
}
public List<Episode> GetEpisodeByFileId(int fileId)
{
return Queryable.Where(s => s.EpisodeFile != null && s.EpisodeFile.Id == fileId).ToList();
}
public List<Episode> EpisodesWithoutFiles(bool includeSpecials)
{
var noFiles = Queryable.Where(s => s.EpisodeFile == null);
if (!includeSpecials)
{
noFiles = noFiles.Where(c => c.SeasonNumber != 0);
}
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 List<Episode> EpisodesWithFiles()
{
return Queryable.Where(s => s.EpisodeFile != null).ToList();
}
public List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate)
{
return Queryable.Where(s => s.AirDate >= startDate && s.AirDate <= endDate).ToList();
}
public void SetIgnoreFlat(Episode episode, bool ignoreFlag)
{
episode.Ignored = ignoreFlag;
ObjectDatabase.UpdateField(episode, "Ignored");
}
}
}