protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docXRef = new XmlDocument(); docXRef.LoadXml(xmlData); string sid = Utils.TryGetProperty("DeleteCrossRef_AniDBTvDBAll_Request", docXRef, "SeriesID"); int seriesID = 0; int.TryParse(sid, out seriesID); CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository(); List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByTvDBID(seriesID); foreach (CrossRef_AniDB_TvDB xref in recs) { repCrossRef.Delete(xref.CrossRef_AniDB_TvDBID); } // now send to mirror string uri = string.Format("http://{0}/DeleteCrossRef_AniDBTvDBAll.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }
public static void FixDuplicateTvDBLinks() { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); // delete all TvDB link duplicates CrossRef_AniDB_TvDBRepository repCrossRefTvDB = new CrossRef_AniDB_TvDBRepository(); List <CrossRef_AniDB_TvDB> xrefsTvDBProcessed = new List <CrossRef_AniDB_TvDB>(); List <CrossRef_AniDB_TvDB> xrefsTvDBToBeDeleted = new List <CrossRef_AniDB_TvDB>(); List <CrossRef_AniDB_TvDB> xrefsTvDB = repCrossRefTvDB.GetAll(); foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB) { bool deleteXref = false; foreach (CrossRef_AniDB_TvDB xref in xrefsTvDBProcessed) { if (xref.TvDBID == xrefTvDB.TvDBID && xref.TvDBSeasonNumber == xrefTvDB.TvDBSeasonNumber) { xrefsTvDBToBeDeleted.Add(xrefTvDB); deleteXref = true; } } if (!deleteXref) { xrefsTvDBProcessed.Add(xrefTvDB); } } foreach (CrossRef_AniDB_TvDB xref in xrefsTvDBToBeDeleted) { string msg = ""; AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID); if (anime != null) { msg = anime.MainTitle; } logger.Warn("Deleting TvDB Link because of a duplicate: {0} ({1}) - {2}/{3}", xref.AnimeID, msg, xref.TvDBID, xref.TvDBSeasonNumber); repCrossRefTvDB.Delete(xref.CrossRef_AniDB_TvDBID); } }
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("DeleteCrossRef_AniDB_TvDBRequest", docXRef, "Username"); string aid = Utils.TryGetProperty("DeleteCrossRef_AniDB_TvDBRequest", docXRef, "AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (string.IsNullOrEmpty(uname) || animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } List <CrossRef_AniDB_TvDB> recs = repCrossRef.GetByAnimeIDUser(animeid, uname); foreach (CrossRef_AniDB_TvDB xref in recs) { repCrossRef.Delete(xref.CrossRef_AniDB_TvDBID); } // now send to mirror string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_TvDB.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }
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); } }
/// <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(""); } }
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 Contract_Trakt_Friend ToContract() { CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_TvDBRepository repXrefTvDB = new CrossRef_AniDB_TvDBRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); Trakt_FriendRepository repFriends = new Trakt_FriendRepository(); Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository(); Trakt_Friend traktFriend = repFriends.GetByUsername(username); if (traktFriend == null) { return(null); } Contract_Trakt_Friend contract = new Contract_Trakt_Friend(); contract.Trakt_FriendID = traktFriend.Trakt_FriendID; contract.Username = username; contract.Full_name = full_name; contract.Gender = gender; contract.Age = age; contract.Location = location; contract.About = about; contract.Joined = joined; contract.Avatar = avatar; contract.Url = url; contract.JoinedDate = Utils.GetAniDBDateAsDate(joined); contract.WatchedEpisodes = new List <Contract_Trakt_WatchedEpisode>(); // we only care about the watched episodes foreach (TraktTVWatched wtch in watched) { if (wtch.episode != null) { Contract_Trakt_WatchedEpisode watchedEp = new Contract_Trakt_WatchedEpisode(); watchedEp.Watched = wtch.watched; watchedEp.WatchedDate = Utils.GetAniDBDateAsDate(wtch.watched); if (!contract.LastEpisodeWatched.HasValue) { contract.LastEpisodeWatched = watchedEp.WatchedDate; } if (watchedEp.WatchedDate.HasValue && watchedEp.WatchedDate > contract.LastEpisodeWatched) { contract.LastEpisodeWatched = watchedEp.WatchedDate; } watchedEp.AnimeSeriesID = null; watchedEp.Episode_Number = wtch.episode.number; watchedEp.Episode_Overview = wtch.episode.overview; watchedEp.Episode_Season = wtch.episode.season; watchedEp.Episode_Title = wtch.episode.title; watchedEp.Episode_Url = wtch.episode.url; if (wtch.episode.images != null) { watchedEp.Episode_Screenshot = wtch.episode.images.screen; } if (wtch.show != null) { watchedEp.TraktShow = wtch.show.ToContract(); // find the anime and series based on the trakt id int?animeID = null; CrossRef_AniDB_Trakt xref = repXrefTrakt.GetByTraktID(wtch.show.TraktID, int.Parse(wtch.episode.season)); if (xref != null) { animeID = xref.AnimeID; } else { // try the tvdb id instead //TODO /* * CrossRef_AniDB_TvDB xrefTvDB = repXrefTvDB.GetByTvDBID(int.Parse(wtch.show.tvdb_id), int.Parse(wtch.episode.season)); * if (xrefTvDB != null) * animeID = xrefTvDB.AnimeID;*/ } if (animeID.HasValue) { AnimeSeries ser = repSeries.GetByAnimeID(animeID.Value); if (ser != null) { watchedEp.AnimeSeriesID = ser.AnimeSeriesID; } AniDB_Anime anime = repAnime.GetByAnimeID(animeID.Value); if (anime != null) { watchedEp.Anime = anime.ToContract(true, null); } } } contract.WatchedEpisodes.Add(watchedEp); break; // only show the latest show } } List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>(); sortCriteria.Add(new SortPropOrFieldAndDirection("WatchedDate", true, SortType.eDateTime)); contract.WatchedEpisodes = Sorting.MultiSort <Contract_Trakt_WatchedEpisode>(contract.WatchedEpisodes, sortCriteria); return(contract); }