public override void ProcessCommand()
{
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
AnimeSeries ser = repSeries.GetByAnimeID(AnimeID);
if (ser!=null)
ser.UpdateStats(true, true, true);
}
public override void ProcessCommand()
{
logger.Info("Get AniDB episode info: {0}", EpisodeID);
try
{
// we don't use this command to update episode info
// we actually use it to update the cross ref info instead
// and we only use it for the "Other Episodes" section of the FILE command
// because that field doesn't tell you what anime it belongs to
CrossRef_File_EpisodeRepository repCrossRefs = new CrossRef_File_EpisodeRepository();
List<CrossRef_File_Episode> xrefs = repCrossRefs.GetByEpisodeID(EpisodeID);
if (xrefs.Count == 0) return;
Raw_AniDB_Episode epInfo = JMMService.AnidbProcessor.GetEpisodeInfo(EpisodeID);
if (epInfo != null)
{
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
foreach (CrossRef_File_Episode xref in xrefs)
{
int oldAnimeID = xref.AnimeID;
xref.AnimeID = epInfo.AnimeID;
repCrossRefs.Save(xref);
AnimeSeries ser = repSeries.GetByAnimeID(oldAnimeID);
if (ser != null)
ser.UpdateStats(true, true, true);
StatsCache.Instance.UpdateUsingAnime(oldAnimeID);
ser = repSeries.GetByAnimeID(epInfo.AnimeID);
if (ser != null)
ser.UpdateStats(true, true, true);
StatsCache.Instance.UpdateUsingAnime(epInfo.AnimeID);
}
}
}
catch (Exception ex)
{
logger.Error("Error processing CommandRequest_GetEpisode: {0} - {1}", EpisodeID, ex.ToString());
return;
}
}
public static void SyncCollectionToTrakt()
{
try
{
if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return;
// check that we have at least one user nominated for Trakt
JMMUserRepository repUsers = new JMMUserRepository();
List<JMMUser> traktUsers = repUsers.GetTraktUsers();
if (traktUsers.Count == 0) return;
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
List<AnimeSeries> allSeries = repSeries.GetAll();
// now get the full users collection from Trakt
List<TraktV2ShowCollectedResult> collected = new List<TraktV2ShowCollectedResult>();
List<TraktV2ShowWatchedResult> watched = new List<TraktV2ShowWatchedResult>();
if (!GetTraktCollectionInfo(ref collected, ref watched)) return;
TraktV2SyncCollectionEpisodesByNumber syncCollectionAdd = new TraktV2SyncCollectionEpisodesByNumber();
TraktV2SyncCollectionEpisodesByNumber syncCollectionRemove = new TraktV2SyncCollectionEpisodesByNumber();
TraktV2SyncWatchedEpisodesByNumber syncHistoryAdd = new TraktV2SyncWatchedEpisodesByNumber();
TraktV2SyncWatchedEpisodesByNumber syncHistoryRemove = new TraktV2SyncWatchedEpisodesByNumber();
#region Local Collection Sync
///////////////////////////////////////////////////////////////////////////////////////
// First take a look at our local collection and update on Trakt
///////////////////////////////////////////////////////////////////////////////////////
AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
int counter = 0;
foreach (AnimeSeries series in allSeries)
{
counter++;
logger.Trace("Syncing check - local collection: {0} / {1} - {2}", counter, allSeries.Count, series.GetSeriesName());
AniDB_Anime anime = repAnime.GetByAnimeID(series.AniDB_ID);
if (anime == null) continue;
//if (anime.AnimeID != 3427) continue;
TraktSummaryContainer traktSummary = new TraktSummaryContainer();
traktSummary.Populate(series.AniDB_ID);
if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;
// get the current watched records for this series on Trakt
foreach (AnimeEpisode ep in series.GetAnimeEpisodes())
{
if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
{
EpisodeSyncDetails epsync = ReconSyncTraktEpisode(series, ep, traktSummary, traktUsers, collected, watched, false);
if (epsync != null)
{
switch (epsync.SyncType)
{
case TraktSyncType.CollectionAdd:
syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
case TraktSyncType.CollectionRemove:
syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
case TraktSyncType.HistoryAdd:
syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
case TraktSyncType.HistoryRemove:
syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
}
}
}
}
}
#endregion
// refresh online info, just in case it was chnaged by the last operations
if (!GetTraktCollectionInfo(ref collected, ref watched)) return;
#region Online Collection Sync
///////////////////////////////////////////////////////////////////////////////////////
// Now look at the collection according to Trakt, and remove it if we don't have it locally
///////////////////////////////////////////////////////////////////////////////////////
CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository();
counter = 0;
foreach (TraktV2ShowCollectedResult col in collected)
{
counter++;
logger.Trace("Syncing check - Online collection: {0} / {1} - {2}", counter, collected.Count, col.show.Title);
//continue;
// check if we have this series locally
List<CrossRef_AniDB_TraktV2> xrefs = repCrossRef.GetByTraktID(col.show.ids.slug);
if (xrefs.Count > 0)
{
foreach (CrossRef_AniDB_TraktV2 xref in xrefs)
{
AnimeSeries locSeries = repSeries.GetByAnimeID(xref.AnimeID);
if (locSeries == null) continue;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:
示例7: IncrementalTvDBUpdate
/// <summary>
/// Used to get a list of TvDB Series ID's that require updating
/// </summary>
/// <param name="tvDBIDs">The list Of Series ID's that need to be updated. Pass in an empty list</param>
/// <returns>The current server time before the update started</returns>
public string IncrementalTvDBUpdate(ref List<int> tvDBIDs, ref bool tvDBOnline)
{
// check if we have record of doing an automated update for the TvDB previously
// if we have then we have kept a record of the server time and can do a delta update
// otherwise we need to do a full update and keep a record of the time
List<int> allTvDBIDs = new List<int>();
tvDBIDs = new List<int>();
tvDBOnline = true;
try
{
CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
// record the tvdb server time when we started
// we record the time now instead of after we finish, to include any possible misses
string currentTvDBServerTime = CurrentServerTime;
if (currentTvDBServerTime.Length == 0)
{
tvDBOnline = false;
return currentTvDBServerTime;
}
foreach (AnimeSeries ser in repSeries.GetAll())
{
List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2();
if (xrefs == null) continue;
foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
{
if (!allTvDBIDs.Contains(xref.TvDBID)) allTvDBIDs.Add(xref.TvDBID);
}
}
// get the time we last did a TvDB update
// if this is the first time it will be null
// update the anidb info ever 24 hours
ScheduledUpdateRepository repSched = new ScheduledUpdateRepository();
ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.TvDBInfo);
string lastServerTime = "";
if (sched != null)
{
TimeSpan ts = DateTime.Now - sched.LastUpdate;
logger.Trace("Last tvdb info update was {0} hours ago", ts.TotalHours.ToString());
if (!string.IsNullOrEmpty(sched.UpdateDetails))
lastServerTime = sched.UpdateDetails;
// the UpdateDetails field for this type will actually contain the last server time from
// TheTvDB that a full update was performed
}
// get a list of updates from TvDB since that time
if (lastServerTime.Length > 0)
{
List<int> seriesList = GetUpdatedSeriesList(lastServerTime);
logger.Trace("{0} series have been updated since last download", seriesList.Count.ToString());
logger.Trace("{0} TvDB series locally", allTvDBIDs.Count.ToString());
foreach (int id in seriesList)
{
if (allTvDBIDs.Contains(id)) tvDBIDs.Add(id);
}
logger.Trace("{0} TvDB local series have been updated since last download", tvDBIDs.Count.ToString());
}
else
{
// use the full list
tvDBIDs = allTvDBIDs;
}
return currentTvDBServerTime;
}
catch (Exception ex)
{
logger.ErrorException("IncrementalTvDBUpdate: "+ ex.ToString(), ex);
return "";
}
}
void workerMyAnime2_DoWork(object sender, DoWorkEventArgs e)
{
MA2Progress ma2Progress = new MA2Progress();
ma2Progress.CurrentFile = 0;
ma2Progress.ErrorMessage = "";
ma2Progress.MigratedFiles = 0;
ma2Progress.TotalFiles = 0;
try
{
string databasePath = e.Argument as string;
string connString = string.Format(@"data source={0};useutf16encoding=True", databasePath);
SQLiteConnection myConn = new SQLiteConnection(connString);
myConn.Open();
// get a list of unlinked files
VideoLocalRepository repVids = new VideoLocalRepository();
AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository();
AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository();
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
List<VideoLocal> vids = repVids.GetVideosWithoutEpisode();
ma2Progress.TotalFiles = vids.Count;
foreach (VideoLocal vid in vids)
{
ma2Progress.CurrentFile = ma2Progress.CurrentFile + 1;
workerMyAnime2.ReportProgress(0, ma2Progress);
// search for this file in the XrossRef table in MA2
string sql = string.Format("SELECT AniDB_EpisodeID from CrossRef_Episode_FileHash WHERE Hash = '{0}' AND FileSize = {1}", vid.ED2KHash, vid.FileSize);
SQLiteCommand sqCommand = new SQLiteCommand(sql);
sqCommand.Connection = myConn;
SQLiteDataReader myReader = sqCommand.ExecuteReader();
while (myReader.Read())
{
int episodeID = 0;
if (!int.TryParse(myReader.GetValue(0).ToString(), out episodeID)) continue;
if (episodeID <= 0) continue;
sql = string.Format("SELECT AnimeID from AniDB_Episode WHERE EpisodeID = {0}", episodeID);
sqCommand = new SQLiteCommand(sql);
sqCommand.Connection = myConn;
SQLiteDataReader myReader2 = sqCommand.ExecuteReader();
while (myReader2.Read())
{
int animeID = myReader2.GetInt32(0);
// so now we have all the needed details we can link the file to the episode
// as long as wehave the details in JMM
AniDB_Anime anime = null;
AniDB_Episode ep = repAniEps.GetByEpisodeID(episodeID);
if (ep == null)
{
logger.Debug("Getting Anime record from AniDB....");
anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(animeID, true, ServerSettings.AutoGroupSeries);
}
else
anime = repAniAnime.GetByAnimeID(animeID);
// create the group/series/episode records if needed
AnimeSeries ser = null;
if (anime == null) continue;
logger.Debug("Creating groups, series and episodes....");
// check if there is an AnimeSeries Record associated with this AnimeID
ser = repSeries.GetByAnimeID(animeID);
if (ser == null)
{
// create a new AnimeSeries record
ser = anime.CreateAnimeSeriesAndGroup();
}
ser.CreateAnimeEpisodes();
// check if we have any group status data for this associated anime
// if not we will download it now
AniDB_GroupStatusRepository repStatus = new AniDB_GroupStatusRepository();
if (repStatus.GetByAnimeID(anime.AnimeID).Count == 0)
{
CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(anime.AnimeID, false);
cmdStatus.Save();
}
// update stats
ser.EpisodeAddedDate = DateTime.Now;
repSeries.Save(ser);
AnimeGroupRepository repGroups = new AnimeGroupRepository();
foreach (AnimeGroup grp in ser.AllGroupsAbove)
{
grp.EpisodeAddedDate = DateTime.Now;
repGroups.Save(grp);
}
//.........这里部分代码省略.........
public override void ProcessCommand()
{
logger.Info("Processing CommandRequest_GetReleaseGroupStatus: {0}", AnimeID);
try
{
// only get group status if we have an associated series
AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
AnimeSeries series = repSeries.GetByAnimeID(AnimeID);
if (series == null) return;
AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID);
if (anime == null) return;
// don't get group status if the anime has already ended more than 50 days ago
bool skip = false;
if (!ForceRefresh)
{
if (anime.EndDate.HasValue)
{
if (anime.EndDate.Value < DateTime.Now)
{
TimeSpan ts = DateTime.Now - anime.EndDate.Value;
if (ts.TotalDays > 50)
{
// don't skip if we have never downloaded this info before
AniDB_GroupStatusRepository repGrpStatus = new AniDB_GroupStatusRepository();
List<AniDB_GroupStatus> grpStatuses = repGrpStatus.GetByAnimeID(AnimeID);
if (grpStatuses != null && grpStatuses.Count > 0)
{
skip = true;
}
}
}
}
}
if (skip)
{
logger.Info("Skipping group status command because anime has already ended: {0}", anime.ToString());
return;
}
GroupStatusCollection grpCol = JMMService.AnidbProcessor.GetReleaseGroupStatusUDP(AnimeID);
if (ServerSettings.AniDB_DownloadReleaseGroups)
{
// save in bulk to improve performance
using (var session = JMMService.SessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
foreach (Raw_AniDB_GroupStatus grpStatus in grpCol.Groups)
{
CommandRequest_GetReleaseGroup cmdRelgrp = new CommandRequest_GetReleaseGroup(grpStatus.GroupID, false);
session.SaveOrUpdate(cmdRelgrp);
}
transaction.Commit();
}
}
}
//}
}
catch (Exception ex)
{
logger.Error("Error processing CommandRequest_GetReleaseGroupStatus: {0} - {1}", AnimeID, ex.ToString());
return;
}
}
请发表评论