Add TvDbEpisodeId to Episode. now we can index episodes before they showup in thetvdb

pull/4/head
kay.one 14 years ago
parent be74c67df8
commit 3beeff4e18

@ -1,15 +0,0 @@
using System;
namespace NzbDrone.Core.Model
{
public class NzbInfoModel
{
public string Title { get; set; }
public Uri Link { get; set; }
public bool IsPassworded()
{
return Title.EndsWith("(Passworded)", StringComparison.InvariantCultureIgnoreCase);
}
}
}

@ -180,7 +180,6 @@
<Compile Include="Model\EpisodeRenameModel.cs" />
<Compile Include="Model\EpisodeSortingType.cs" />
<Compile Include="Model\EpisodeStatusType.cs" />
<Compile Include="Model\NzbInfoModel.cs" />
<Compile Include="Model\SabnzbdPriorityType.cs" />
<Compile Include="Model\SceneNameModel.cs" />
<Compile Include="Model\SeasonParseResult.cs" />

@ -178,7 +178,7 @@ namespace NzbDrone.Core.Providers
var newEpisode = new Episode
{
AirDate = episode.FirstAired,
EpisodeId = episode.Id,
TvDbEpisodeId = episode.Id,
EpisodeNumber = episode.EpisodeNumber,
Language = episode.Language.Abbriviation,
Overview = episode.Overview,
@ -188,73 +188,11 @@ namespace NzbDrone.Core.Providers
Title = episode.EpisodeName
};
if (_sonicRepo.Exists<Episode>(e => e.EpisodeId == newEpisode.EpisodeId))
{
updateList.Add(newEpisode);
}
else
{
newList.Add(newEpisode);
}
successCount++;
}
catch (Exception e)
{
Logger.FatalException(
String.Format("An error has occurred while updating episode info for series {0}", seriesId), e);
failCount++;
}
}
_sonicRepo.AddMany(newList);
_sonicRepo.UpdateMany(updateList);
Logger.Debug("Finished episode refresh for series:{0}. Successful:{1} - Failed:{2} ",
targetSeries.SeriesName, successCount, failCount);
}
public virtual void RefreshEpisodeInfo(Season season)
{
Logger.Info("Starting episode info refresh for season {0} of series:{1}", season.SeasonNumber,
season.SeriesId);
int successCount = 0;
int failCount = 0;
var targetSeries = _tvDb.GetSeries(season.SeriesId, true);
var updateList = new List<Episode>();
var newList = new List<Episode>();
foreach (var episode in targetSeries.Episodes.Where(e => e.SeasonId == season.SeasonId))
{
try
{
//DateTime throws an error in SQLServer per message below:
//SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
//So lets hack it so it works for SQLServer (as well as SQLite), perhaps we can find a better solution
//Todo: Fix this hack
if (episode.FirstAired < new DateTime(1753, 1, 1))
episode.FirstAired = new DateTime(1753, 1, 1);
var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
Logger.Trace("Updating info for series:{0} - episode:{1}", targetSeries.SeriesName,
episode.EpisodeNumber);
var newEpisode = new Episode
{
AirDate = episode.FirstAired,
EpisodeId = episode.Id,
EpisodeNumber = episode.EpisodeNumber,
Language = episode.Language.Abbriviation,
Overview = episode.Overview,
SeasonId = episode.SeasonId,
SeasonNumber = episode.SeasonNumber,
SeriesId = season.SeriesId,
Title = episode.EpisodeName
};
//TODO: Replace this db check with a local check. Should make things even faster
if (_sonicRepo.Exists<Episode>(e => e.EpisodeId == newEpisode.EpisodeId))
if (existingEpisode != null)
{
newEpisode.EpisodeId = existingEpisode.EpisodeId;
updateList.Add(newEpisode);
}
else
@ -267,8 +205,7 @@ namespace NzbDrone.Core.Providers
catch (Exception e)
{
Logger.FatalException(
String.Format("An error has occurred while updating episode info for season {0} of series {1}",
season.SeasonNumber, season.SeriesId), e);
String.Format("An error has occurred while updating episode info for series {0}", seriesId), e);
failCount++;
}
}

@ -7,9 +7,11 @@ namespace NzbDrone.Core.Repository
{
public class Episode
{
[SubSonicPrimaryKey(false)]
[SubSonicPrimaryKey]
public virtual int EpisodeId { get; set; }
public int? TvDbEpisodeId { get; set; }
public virtual int SeriesId { get; set; }
public virtual int EpisodeFileId { get; set; }
public virtual int SeasonId { get; set; }

Loading…
Cancel
Save