public static void Send_CrossRefAniDBTvDB(CrossRef_AniDB_TvDBV2 data, string animeName) { //if (!ServerSettings.WebCache_XRefFileEpisode_Send) return; string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_TvDB", azureHostBaseAddress); CrossRef_AniDB_TvDBInput input = new CrossRef_AniDB_TvDBInput(data, animeName); string json = JSONHelper.Serialize<CrossRef_AniDB_TvDBInput>(input); SendData(uri, json, "POST"); }
public void Save(CrossRef_AniDB_TvDBV2 obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
public CrossRef_AniDB_TvDBInput(CrossRef_AniDB_TvDBV2 xref, string animeName) { this.AnimeID = xref.AnimeID; this.AnimeName = animeName; this.AniDBStartEpisodeType = xref.AniDBStartEpisodeType; this.AniDBStartEpisodeNumber = xref.AniDBStartEpisodeNumber; this.TvDBID = xref.TvDBID; this.TvDBSeasonNumber = xref.TvDBSeasonNumber; this.TvDBStartEpisodeNumber = xref.TvDBStartEpisodeNumber; this.TvDBTitle = xref.TvDBTitle; this.CrossRefSource = xref.CrossRefSource; this.Username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) this.Username = Constants.AnonWebCacheUsername; this.AuthGUID = string.Empty; }
public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache) { using (var session = JMMService.SessionFactory.OpenSession()) { CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); List<CrossRef_AniDB_TvDBV2> xrefTemps = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID, (int)aniEpType, aniEpNumber); if (xrefTemps != null && xrefTemps.Count > 0) { foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps) { // delete the existing one if we are updating TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber, xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber); } } // check if we have this information locally // if not download it now TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository(); TvDB_Series tvSeries = repSeries.GetByTvDBID(tvDBID); if (tvSeries == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later tvSeries = GetSeriesInfoOnline(tvDBID); } // download and update series info, episode info and episode images // will also download fanart, posters and wide banners CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false); cmdSeriesEps.Save(); CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber); if (xref == null) xref = new CrossRef_AniDB_TvDBV2(); xref.AnimeID = animeID; xref.AniDBStartEpisodeType = (int)aniEpType; xref.AniDBStartEpisodeNumber = aniEpNumber; xref.TvDBID = tvDBID; xref.TvDBSeasonNumber = tvSeasonNumber; xref.TvDBStartEpisodeNumber = tvEpNumber; if (tvSeries != null) xref.TvDBTitle = tvSeries.SeriesName; if (excludeFromWebCache) xref.CrossRefSource = (int)CrossRefSource.WebCache; else xref.CrossRefSource = (int)CrossRefSource.User; repCrossRef.Save(xref); StatsCache.Instance.UpdateUsingAnime(animeID); logger.Trace("Changed tvdb association: {0}", animeID); if (!excludeFromWebCache) { CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID); req.Save(); } if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { CrossRef_AniDB_TraktV2Repository repTraktXrefs = new CrossRef_AniDB_TraktV2Repository(); if (repTraktXrefs.GetByAnimeID(animeID).Count == 0) { // check for Trakt associations CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false); cmd2.Save(session); } } } return ""; }
public static void MigrateTvDBLinks_V1_to_V2() { try { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); TvDB_EpisodeRepository repEps = new TvDB_EpisodeRepository(); CrossRef_AniDB_TvDBRepository repCrossRefTvDB = new CrossRef_AniDB_TvDBRepository(); CrossRef_AniDB_TvDBV2Repository repCrossRefTvDBNew = new CrossRef_AniDB_TvDBV2Repository(); using (var session = JMMService.SessionFactory.OpenSession()) { List<CrossRef_AniDB_TvDB> xrefsTvDB = repCrossRefTvDB.GetAll(); foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2(); xrefNew.AnimeID = xrefTvDB.AnimeID; xrefNew.CrossRefSource = xrefTvDB.CrossRefSource; xrefNew.TvDBID = xrefTvDB.TvDBID; xrefNew.TvDBSeasonNumber = xrefTvDB.TvDBSeasonNumber; TvDB_Series ser = xrefTvDB.GetTvDBSeries(session); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; // determine start ep type if (xrefTvDB.TvDBSeasonNumber == 0) xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; else xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode; xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TvDBStartEpisodeNumber = 1; repCrossRefTvDBNew.Save(xrefNew); } // create cross ref's for specials foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { AniDB_Anime anime = repAnime.GetByAnimeID(xrefTvDB.AnimeID); if (anime == null) continue; // this anime has specials if (anime.EpisodeCountSpecial <= 0) continue; // this tvdb series has a season 0 (specials) List<int> seasons = repEps.GetSeasonNumbersForSeries(xrefTvDB.TvDBID); if (!seasons.Contains(0)) continue; //make sure we are not doubling up CrossRef_AniDB_TvDBV2 temp = repCrossRefTvDBNew.GetByTvDBID(xrefTvDB.TvDBID, 0, 1, xrefTvDB.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1); if (temp != null) continue; CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2(); xrefNew.AnimeID = xrefTvDB.AnimeID; xrefNew.CrossRefSource = xrefTvDB.CrossRefSource; xrefNew.TvDBID = xrefTvDB.TvDBID; xrefNew.TvDBSeasonNumber = 0; xrefNew.TvDBStartEpisodeNumber = 1; xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; xrefNew.AniDBStartEpisodeNumber = 1; TvDB_Series ser = xrefTvDB.GetTvDBSeries(session); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; repCrossRefTvDBNew.Save(xrefNew); } } } catch (Exception ex) { logger.ErrorException("Could not MigrateTvDBLinks_V1_to_V2: " + ex.ToString(), ex); } }
public static void MigrateTvDBLinks_V1_to_V2() { try { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { ISessionWrapper sessionWrapper = session.Wrap(); IReadOnlyList<CrossRef_AniDB_TvDB> xrefsTvDB = RepoFactory.CrossRef_AniDB_TvDB.GetAll(); foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2(); xrefNew.AnimeID = xrefTvDB.AnimeID; xrefNew.CrossRefSource = xrefTvDB.CrossRefSource; xrefNew.TvDBID = xrefTvDB.TvDBID; xrefNew.TvDBSeasonNumber = xrefTvDB.TvDBSeasonNumber; TvDB_Series ser = xrefTvDB.GetTvDBSeries(sessionWrapper); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; // determine start ep type if (xrefTvDB.TvDBSeasonNumber == 0) xrefNew.AniDBStartEpisodeType = (int) enEpisodeType.Special; else xrefNew.AniDBStartEpisodeType = (int) enEpisodeType.Episode; xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TvDBStartEpisodeNumber = 1; RepoFactory.CrossRef_AniDB_TvDBV2.Save(xrefNew); } // create cross ref's for specials foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(xrefTvDB.AnimeID); if (anime == null) continue; // this anime has specials if (anime.EpisodeCountSpecial <= 0) continue; // this tvdb series has a season 0 (specials) List<int> seasons = RepoFactory.TvDB_Episode.GetSeasonNumbersForSeries(xrefTvDB.TvDBID); if (!seasons.Contains(0)) continue; //make sure we are not doubling up CrossRef_AniDB_TvDBV2 temp = RepoFactory.CrossRef_AniDB_TvDBV2.GetByTvDBID(xrefTvDB.TvDBID, 0, 1, xrefTvDB.AnimeID, (int) enEpisodeType.Special, 1); if (temp != null) continue; CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2(); xrefNew.AnimeID = xrefTvDB.AnimeID; xrefNew.CrossRefSource = xrefTvDB.CrossRefSource; xrefNew.TvDBID = xrefTvDB.TvDBID; xrefNew.TvDBSeasonNumber = 0; xrefNew.TvDBStartEpisodeNumber = 1; xrefNew.AniDBStartEpisodeType = (int) enEpisodeType.Special; xrefNew.AniDBStartEpisodeNumber = 1; TvDB_Series ser = xrefTvDB.GetTvDBSeries(sessionWrapper); if (ser != null) xrefNew.TvDBTitle = ser.SeriesName; RepoFactory.CrossRef_AniDB_TvDBV2.Save(xrefNew); } } } catch (Exception ex) { logger.Error( ex,"Could not MigrateTvDBLinks_V1_to_V2: " + ex.ToString()); } }
public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache, bool additiveLink=false) { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { if(!additiveLink) // remove all current links RemoveAllAniDBTvDBLinks(session.Wrap(), animeID); // check if we have this information locally // if not download it now TvDB_Series tvSeries = RepoFactory.TvDB_Series.GetByTvDBID(tvDBID); if (tvSeries == null) { // we download the series info here just so that we have the basic info in the // database before the queued task runs later tvSeries = GetSeriesInfoOnline(tvDBID); } // download and update series info, episode info and episode images // will also download fanart, posters and wide banners CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false); //Optimize for batch updates, if there are a lot of LinkAniDBTvDB commands queued //this will cause only one updateSeriesAndEpisodes command to be created if (RepoFactory.CommandRequest.GetByCommandID(cmdSeriesEps.CommandID) == null) { cmdSeriesEps.Save(); } CrossRef_AniDB_TvDBV2 xref = RepoFactory.CrossRef_AniDB_TvDBV2.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int) aniEpType, aniEpNumber); if (xref == null) xref = new CrossRef_AniDB_TvDBV2(); xref.AnimeID = animeID; xref.AniDBStartEpisodeType = (int) aniEpType; xref.AniDBStartEpisodeNumber = aniEpNumber; xref.TvDBID = tvDBID; xref.TvDBSeasonNumber = tvSeasonNumber; xref.TvDBStartEpisodeNumber = tvEpNumber; if (tvSeries != null) xref.TvDBTitle = tvSeries.SeriesName; if (excludeFromWebCache) xref.CrossRefSource = (int) CrossRefSource.WebCache; else xref.CrossRefSource = (int) CrossRefSource.User; RepoFactory.CrossRef_AniDB_TvDBV2.Save(xref); AniDB_Anime.UpdateStatsByAnimeID(animeID); logger.Trace("Changed tvdb association: {0}", animeID); if (!excludeFromWebCache) { CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID); req.Save(); } if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { if (RepoFactory.CrossRef_AniDB_TraktV2.GetByAnimeID(animeID).Count == 0) { // check for Trakt associations CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false); cmd2.Save(session); } } } return ""; }