public override void ProcessCommand() { try { //if (string.IsNullOrEmpty(ServerSettings.WebCacheAuthKey)) return; CrossRef_AniDB_TvDB xref = RepoFactory.CrossRef_AniDB_TvDB.GetByID(CrossRef_AniDB_TvDBID); if (xref == null) { return; } SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(xref.AniDBID); if (anime == null) { return; } AzureWebAPI.Send_CrossRefAniDBTvDB(xref.ToV2Model(), anime.MainTitle); } catch (Exception ex) { logger.Error(ex, "Error processing CommandRequest_WebCacheSendXRefAniDBTvDB: {0}" + ex); } }
public string LinkAniDBTvDB(CrossRef_AniDB_TvDBV2 link) { try { CrossRef_AniDB_TvDB xref = RepoFactory.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(link.AnimeID, link.TvDBID); if (xref != null && link.IsAdditive) { string msg = $"You have already linked Anime ID {xref.AniDBID} to this TvDB show/season/ep"; SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(xref.AniDBID); if (anime != null) { msg = $"You have already linked Anime {anime.MainTitle} ({xref.AniDBID}) to this TvDB show/season/ep"; } return(msg); } // we don't need to proactively remove the link here anymore, as all links are removed when it is not marked as additive CommandRequest_LinkAniDBTvDB cmdRequest = new CommandRequest_LinkAniDBTvDB(link.AnimeID, link.TvDBID, link.IsAdditive); cmdRequest.Save(); return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public CrossRef_AniDB_TvDBResult(CrossRef_AniDB_TvDB xref) { this.AnimeID = xref.AnimeID; this.TvDBID = xref.TvDBID; this.TvDBSeasonNumber = xref.TvDBSeasonNumber; this.AdminApproved = xref.AdminApproved; this.SeriesName = xref.SeriesName; }
public CrossRef_AniDB_TvDB GetByAnimeID(ISession session, int id) { CrossRef_AniDB_TvDB cr = session .CreateCriteria(typeof(CrossRef_AniDB_TvDB)) .Add(Restrictions.Eq("AnimeID", id)) .UniqueResult <CrossRef_AniDB_TvDB>(); return(cr); }
public static CrossRef_AniDB_TvDBV2 ToV2Model(this CrossRef_AniDB_TvDB xref) { return(new CrossRef_AniDB_TvDBV2 { AnimeID = xref.AniDBID, CrossRefSource = (int)xref.CrossRefSource, TvDBID = xref.TvDBID }); }
public static void LinkAniDBTvDB(int animeID, int tvDBID, bool additiveLink = false) { if (!additiveLink) { // remove all current links logger.Info($"Removing All TvDB Links for: {animeID}"); RemoveAllAniDBTvDBLinks(animeID, false); } // check if we have this information locally // if not download it now TvDB_Series tvSeries = RepoFactory.TvDB_Series.GetByTvDBID(tvDBID); if (tvSeries != null) { // download and update series info, episode info and episode images // will also download fanart, posters and wide banners CommandRequest_TvDBUpdateSeries cmdSeriesEps = new CommandRequest_TvDBUpdateSeries(tvDBID, false); cmdSeriesEps.Save(); } else { var unused = GetSeriesInfoOnlineAsync(tvDBID, true).Result; } CrossRef_AniDB_TvDB xref = RepoFactory.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(animeID, tvDBID) ?? new CrossRef_AniDB_TvDB(); xref.AniDBID = animeID; xref.TvDBID = tvDBID; xref.CrossRefSource = CrossRefSource.User; RepoFactory.CrossRef_AniDB_TvDB.Save(xref); logger.Info( $"Adding TvDB Link: AniDB(ID:{animeID}) -> TvDB(ID:{tvDBID})"); if (ServerSettings.Instance.TraktTv.Enabled && !string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { // check for Trakt associations List <CrossRef_AniDB_TraktV2> trakt = RepoFactory.CrossRef_AniDB_TraktV2.GetByAnimeID(animeID); if (trakt.Count != 0) { foreach (CrossRef_AniDB_TraktV2 a in trakt) { RepoFactory.CrossRef_AniDB_TraktV2.Delete(a); } } var cmd2 = new CommandRequest_TraktSearchAnime(animeID, false); cmd2.Save(); } }
public CrossRef_AniDB_TvDB GetByTvDBID(int id, int season) { using (var session = JMMService.SessionFactory.OpenSession()) { CrossRef_AniDB_TvDB cr = session .CreateCriteria(typeof(CrossRef_AniDB_TvDB)) .Add(Restrictions.Eq("TvDBID", id)) .Add(Restrictions.Eq("TvDBSeasonNumber", season)) .UniqueResult <CrossRef_AniDB_TvDB>(); return(cr); } }
public void Save(CrossRef_AniDB_TvDB obj) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }
// Removes all TVDB information from a series, bringing it back to a blank state. public static void RemoveLinkAniDBTvDB(int animeID, int tvDBID) { CrossRef_AniDB_TvDB xref = RepoFactory.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(animeID, tvDBID); if (xref == null) { return; } RepoFactory.CrossRef_AniDB_TvDB.Delete(xref); SVR_AniDB_Anime.UpdateStatsByAnimeID(animeID); }
// default constructor public AddCrossRef_AniDB_TvDBRequest(CrossRef_AniDB_TvDB data, string seriesName) { this.AnimeID = data.AnimeID; this.TvDBID = data.TvDBID; this.TvDBSeason = data.TvDBSeasonNumber; string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } this.Username = username; this.SeriesName = seriesName; }
public void Delete(int id) { using (var session = JMMService.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { CrossRef_AniDB_TvDB cr = GetByID(id); if (cr != null) { session.Delete(cr); transaction.Commit(); } } } }
// Removes all TVDB information from a series, bringing it back to a blank state. public static void RemoveLinkAniDBTvDB(int animeID, int tvDBID) { CrossRef_AniDB_TvDB xref = Repo.Instance.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(animeID, tvDBID); if (xref == null) { return; } Repo.Instance.CrossRef_AniDB_TvDB.Delete(xref); Repo.Instance.CrossRef_AniDB_TvDB_Episode.Delete( Repo.Instance.CrossRef_AniDB_TvDB_Episode.GetByAnimeID(animeID)); Repo.Instance.CrossRef_AniDB_TvDB_Episode_Override.Delete( Repo.Instance.CrossRef_AniDB_TvDB_Episode_Override.GetByAnimeID(animeID)); SVR_AniDB_Anime.UpdateStatsByAnimeID(animeID); }
private static void AddCrossRef_AniDB_TvDBV2(int animeID, int tvdbID, CrossRefSource source) { CrossRef_AniDB_TvDB xref = RepoFactory.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(animeID, tvdbID); if (xref != null) { return; } xref = new CrossRef_AniDB_TvDB { AniDBID = animeID, TvDBID = tvdbID, CrossRefSource = source }; RepoFactory.CrossRef_AniDB_TvDB.Save(xref); }
private static void AddCrossRef_AniDB_TvDBV2(int animeID, int tvdbID, CrossRefSource source) { CrossRef_AniDB_TvDB xref = Repo.Instance.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID(animeID, tvdbID); if (xref != null) { return; } xref = new CrossRef_AniDB_TvDB { AniDBID = animeID, TvDBID = tvdbID, CrossRefSource = source }; Repo.Instance.CrossRef_AniDB_TvDB.BeginAdd(xref).Commit(); }
public static void MigrateTvDBLinks_v2_to_V3() { using (var session = DatabaseFactory.SessionFactory.OpenSession()) { // Clean up possibly failed migration RepoFactory.CrossRef_AniDB_TvDB_Episode.DeleteAllUnverifiedLinks(); // This method doesn't need mappings, and it's simple enough to work on all DB types // Migrate Special's overrides var specials = session .CreateSQLQuery( @"SELECT DISTINCT AnimeID, AniDBStartEpisodeType, AniDBStartEpisodeNumber, TvDBID, TvDBSeasonNumber, TvDBStartEpisodeNumber FROM CrossRef_AniDB_TvDBV2 WHERE TvDBSeasonNumber = 0") .AddScalar("AnimeID", NHibernateUtil.Int32) .AddScalar("AniDBStartEpisodeType", NHibernateUtil.Int32) .AddScalar("AniDBStartEpisodeNumber", NHibernateUtil.Int32) .AddScalar("TvDBID", NHibernateUtil.Int32) .AddScalar("TvDBSeasonNumber", NHibernateUtil.Int32) .AddScalar("TvDBStartEpisodeNumber", NHibernateUtil.Int32) .List <object[]>().Select(a => new CrossRef_AniDB_TvDBV2 { AnimeID = (int)a[0], AniDBStartEpisodeType = (int)a[1], AniDBStartEpisodeNumber = (int)a[2], TvDBID = (int)a[3], TvDBSeasonNumber = (int)a[4], TvDBStartEpisodeNumber = (int)a[5] }).ToLookup(a => a.AnimeID); // Split them by series so that we can escape on error more easily foreach (var special in specials) { var overrides = TvDBLinkingHelper.GetSpecialsOverridesFromLegacy(special.ToList()); foreach (var episodeOverride in overrides) { var exists = RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.GetByAniDBAndTvDBEpisodeIDs( episodeOverride.AniDBEpisodeID, episodeOverride.TvDBEpisodeID); if (exists != null) { continue; } RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.Save(episodeOverride); } } // override OVAs if they don't have default links var ovas = session .CreateSQLQuery( @"SELECT DISTINCT AniDB_Anime.AnimeID, AniDBStartEpisodeType, AniDBStartEpisodeNumber, TvDBID, TvDBSeasonNumber, TvDBStartEpisodeNumber FROM CrossRef_AniDB_TvDBV2 INNER JOIN AniDB_Anime on AniDB_Anime.AnimeID = CrossRef_AniDB_TvDBV2.AnimeID WHERE AnimeType = 1 OR AnimeType = 3") .AddScalar("AnimeID", NHibernateUtil.Int32) .AddScalar("AniDBStartEpisodeType", NHibernateUtil.Int32) .AddScalar("AniDBStartEpisodeNumber", NHibernateUtil.Int32) .AddScalar("TvDBID", NHibernateUtil.Int32) .AddScalar("TvDBSeasonNumber", NHibernateUtil.Int32) .AddScalar("TvDBStartEpisodeNumber", NHibernateUtil.Int32) .List <object[]>().Select(a => new CrossRef_AniDB_TvDBV2 { AnimeID = (int)a[0], AniDBStartEpisodeType = (int)a[1], AniDBStartEpisodeNumber = (int)a[2], TvDBID = (int)a[3], TvDBSeasonNumber = (int)a[4], TvDBStartEpisodeNumber = (int)a[5] }).ToLookup(a => a.AnimeID); // Split them by series so that we can escape on error more easily foreach (var special in ovas) { var overrides = TvDBLinkingHelper.GetSpecialsOverridesFromLegacy(special.ToList()); foreach (var episodeOverride in overrides) { var exists = RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.GetByAniDBAndTvDBEpisodeIDs( episodeOverride.AniDBEpisodeID, episodeOverride.TvDBEpisodeID); if (exists != null) { continue; } RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.Save(episodeOverride); } } // Series Links var links = session .CreateSQLQuery( @"SELECT AnimeID, TvDBID, CrossRefSource FROM CrossRef_AniDB_TvDBV2") .AddScalar("AnimeID", NHibernateUtil.Int32) .AddScalar("TvDBID", NHibernateUtil.Int32) .AddScalar("CrossRefSource", NHibernateUtil.Int32) .List <object[]>().Select(a => new CrossRef_AniDB_TvDB { AniDBID = (int)a[0], TvDBID = (int)a[1], CrossRefSource = (CrossRefSource)a[2] }).DistinctBy(a => new[] { a.AniDBID, a.TvDBID }).ToList(); foreach (var link in links) { var exists = RepoFactory.CrossRef_AniDB_TvDB.GetByAniDBAndTvDBID( link.AniDBID, link.TvDBID); if (exists != null) { continue; } RepoFactory.CrossRef_AniDB_TvDB.Save(link); } // Scan Series Without links for prequel/sequel links var list = RepoFactory.CrossRef_AniDB_TvDB.GetSeriesWithoutLinks(); // AniDB_Anime_Relation is a direct repository, so GetFullLinearRelationTree will be slow // Using a visited node set to skip processed nodes should be faster HashSet <int> visitedNodes = new HashSet <int>(); var seriesWithoutLinksLookup = list.ToDictionary(a => a.AniDB_ID); foreach (var animeseries in list) { if (visitedNodes.Contains(animeseries.AniDB_ID)) { continue; } var relations = RepoFactory.AniDB_Anime_Relation.GetFullLinearRelationTree(animeseries.AniDB_ID); int?tvDBID = relations.SelectMany(a => RepoFactory.CrossRef_AniDB_TvDB.GetByAnimeID(a)) .FirstOrDefault(a => a != null)?.TvDBID; // No link was found in the entire relation tree if (tvDBID == null) { relations.ForEach(a => visitedNodes.Add(a)); continue; } var seriesToUpdate = relations.Where(a => seriesWithoutLinksLookup.ContainsKey(a)) .Select(a => seriesWithoutLinksLookup[a]).ToList(); foreach (var series in seriesToUpdate) { CrossRef_AniDB_TvDB link = new CrossRef_AniDB_TvDB { AniDBID = series.AniDB_ID, TvDBID = tvDBID.Value, CrossRefSource = CrossRefSource.Automatic }; // No need to check for existence RepoFactory.CrossRef_AniDB_TvDB.Save(link); visitedNodes.Add(series.AniDB_ID); } } list = RepoFactory.AnimeSeries.GetAll().ToList(); int count = 0; list.AsParallel().ForAll(animeseries => { Interlocked.Increment(ref count); if (count % 50 == 0) { ServerState.Instance.CurrentSetupStatus = string.Format( Commons.Properties.Resources.Database_Validating, "Generating TvDB Episode Matchings", $" {count}/{list.Count}"); } TvDBLinkingHelper.GenerateTvDBEpisodeMatches(animeseries.AniDB_ID, true); }); string dropV2 = "DROP TABLE CrossRef_AniDB_TvDBV2"; session.CreateSQLQuery(dropV2).ExecuteUpdate(); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { string aid = Utils.GetParam("AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } string uname = Utils.GetParam("uname"); if (uname.Trim().Length == 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository(); CrossRef_AniDB_TvDB xref = null; // check for admin approved List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDApproved(animeid); if (recs.Count > 0) { xref = recs[0]; // should only be one } // check for user specific if (xref == null) { recs = repCrossRef.GetByAnimeIDUser(animeid, uname); if (recs.Count > 0) { xref = recs[0]; // should only be one } } // check for other users (anonymous) if (xref == null) { // check for other users (anonymous) recs = repCrossRef.GetByAnimeID(animeid); if (recs.Count == 0) { Response.Write(Constants.ERROR_XML); return; } // find the most popular result List <CrossRefStat> results = new List <CrossRefStat>(); foreach (CrossRef_AniDB_TvDB xrefloc in recs) { bool found = false; foreach (CrossRefStat stat in results) { if (stat.TvDBID == xrefloc.TvDBID && stat.TvDBSeason == xrefloc.TvDBSeasonNumber) { found = true; stat.ResultCount++; } } if (!found) { CrossRefStat stat = new CrossRefStat(); stat.ResultCount = 1; stat.TvDBID = xrefloc.TvDBID; stat.TvDBSeason = xrefloc.TvDBSeasonNumber; stat.CrossRef = xrefloc; results.Add(stat); } } CrossRefStat mostPopular = null; foreach (CrossRefStat stat in results) { if (mostPopular == null) { mostPopular = stat; } else { if (stat.ResultCount > mostPopular.ResultCount) { mostPopular = stat; } } } xref = mostPopular.CrossRef; } CrossRef_AniDB_TvDBResult result = new CrossRef_AniDB_TvDBResult(xref); string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TvDBResult)); Response.Write(ret); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository(); StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docXRef = new XmlDocument(); docXRef.LoadXml(xmlData); string uname = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "Username"); string sname = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "SeriesName"); string aid = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); string tvid = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "TvDBID"); int tvDBID = 0; int.TryParse(tvid, out tvDBID); string tvseason = Utils.TryGetProperty("AddCrossRef_AniDB_TvDB_Request", docXRef, "TvDBSeason"); int tvDBSeason = 0; if (!int.TryParse(tvseason, out tvDBSeason)) { Response.Write(Constants.ERROR_XML); return; } if (string.IsNullOrEmpty(uname) || animeid <= 0 || tvDBID <= 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_TvDB xref = null; List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDUser(animeid, uname); if (recs.Count == 1) { xref = recs[0]; } if (recs.Count == 0) { xref = new CrossRef_AniDB_TvDB(); } else { xref = recs[0]; } xref.AnimeID = animeid; xref.AdminApproved = 0; xref.CrossRefSource = 1; xref.TvDBID = tvDBID; xref.TvDBSeasonNumber = tvDBSeason; xref.Username = uname; xref.SeriesName = sname; repCrossRef.Save(xref); // now send to mirror string uri = string.Format("http://{0}/AddCrossRef_AniDB_TvDB.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }
public static TvDB_Series GetTvDBSeries(this CrossRef_AniDB_TvDB cross) { return(Repo.Instance.TvDB_Series.GetByTvDBID(cross.TvDBID)); }