public static Azure_CrossRef_AniDB_Other Get_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_TvDB_Get) { return(null); } string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_Other/{1}?p={2}&p2={3}", azureHostBaseAddress, animeID, username, (int)xrefType); string msg = string.Format("Getting AniDB/Other Cross Ref From Cache: {0}", animeID); DateTime start = DateTime.Now; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); string json = GetDataJson(uri); TimeSpan ts = DateTime.Now - start; msg = string.Format("Got AniDB/MAL Cross Ref From Cache: {0} - {1}", animeID, ts.TotalMilliseconds); ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); Azure_CrossRef_AniDB_Other xref = JSONHelper.Deserialize <Azure_CrossRef_AniDB_Other>(json); return(xref); }
public bool DeleteCrossRef_AniDB_Provider(int animeId, CrossRefType type) { return(WrapAuthentication((token) => { cclient.DeleteProvider(token, animeId, (int)type); })); }
public static void Delete_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { // id = animeid // p = username // p2 = AniDBStartEpisodeType // p3 = AniDBStartEpisodeNumber if (!ServerSettings.WebCache_TvDB_Send) { return; } string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_Other/{1}?p={2}&p2={3}", azureHostBaseAddress, animeID, username, (int)xrefType); string json = DeleteDataJson(uri); }
public string RemoveLinkAniDBForAnime(int animeID, int crossRefType) { try { SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(animeID); if (anime == null) { return("Could not find Anime!"); } CrossRefType xrefType = (CrossRefType)crossRefType; switch (xrefType) { case CrossRefType.MovieDB: Repo.Instance.AniDB_Anime_DefaultImage.FindAndDelete(() => Repo.Instance.AniDB_Anime_DefaultImage.GetByAnimeID(animeID).Where(a => a.ImageParentType == (int)ImageEntityType.MovieDB_FanArt || a.ImageParentType == (int)ImageEntityType.MovieDB_Poster).ToList()); MovieDBHelper.RemoveLinkAniDBMovieDB(animeID); break; case CrossRefType.TraktTV: return(RemoveLinkAniDBTraktForAnime(animeID)); case CrossRefType.TvDB: return(RemoveLinkAniDBTvDBForAnime(animeID)); } return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public CrossRef_AniDB_Other GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (var session = JMMService.SessionFactory.OpenSession()) { return GetByAnimeIDAndType(session, animeID, xrefType); } }
public CrossRef_AniDB_Other GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (var session = JMMService.SessionFactory.OpenSession()) { return(GetByAnimeIDAndType(session.Wrap(), animeID, xrefType)); } }
public static void Delete_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { // id = animeid // p = username // p2 = AniDBStartEpisodeType // p3 = AniDBStartEpisodeNumber if (!ServerSettings.Instance.WebCache.TvDB_Send) { return; } string username = ServerSettings.Instance.AniDb.Username; if (ServerSettings.Instance.WebCache.Anonymous) { username = Constants.AnonWebCacheUsername; } string uri = $@"http://{azureHostBaseAddress}/api/CrossRef_AniDB_Other/{animeID}?p={username}&p2={(int) xrefType}"; DeleteDataJson(uri); }
public static Azure_CrossRef_AniDB_Other Get_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { try { if (!ServerSettings.Instance.WebCache.TvDB_Get) { return(null); } string username = Constants.AnonWebCacheUsername; string uri = $@"http://{azureHostBaseAddress}/api/CrossRef_AniDB_Other/{animeID}?p={username}&p2={ (int) xrefType }"; string msg = $"Getting AniDB/Other Cross Ref From Cache: {animeID}"; DateTime start = DateTime.Now; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); string json = GetDataJson(uri); TimeSpan ts = DateTime.Now - start; msg = $"Got AniDB/MAL Cross Ref From Cache: {animeID} - {ts.TotalMilliseconds}"; ShokoService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); Azure_CrossRef_AniDB_Other xref = JSONHelper.Deserialize <Azure_CrossRef_AniDB_Other>(json); return(xref); } catch { return(null); } }
public CommandRequest_WebCacheDeleteXRefAniDBOther(int animeID, CrossRefType xrefType) { AnimeID = animeID; CrossRefType = (int)xrefType; Priority = (int)DefaultPriority; GenerateCommandID(); }
public CrossRef_AniDB_Other GetByAnimeIDAndType(ISession session, int animeID, CrossRefType xrefType) { CrossRef_AniDB_Other cr = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("AnimeID", animeID)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .UniqueResult<CrossRef_AniDB_Other>(); return cr; }
public CommandRequest_WebCacheDeleteXRefAniDBOther(int animeID, CrossRefType xrefType) { this.AnimeID = animeID; this.CommandType = (int)CommandRequestType.WebCache_DeleteXRefAniDBOther; this.CrossRefType = (int)xrefType; this.Priority = (int)DefaultPriority; GenerateCommandID(); }
// default constructor public DeleteCrossRef_AniDB_OtherRequest(int animeID, CrossRefType xrefType) { this.AnimeID = animeID; this.CrossRefType = (int)xrefType; string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) username = Constants.AnonWebCacheUsername; this.Username = username; }
public List <SVR_CrossRef_AniDB_Provider> GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (RepoLock.ReaderLock()) { if (IsCached) { return(Animes.GetMultiple(animeID).Where(a => a.CrossRefType == xrefType).ToList()); } return(Table.Where(a => a.AnimeID == animeID && a.CrossRefType == xrefType).ToList()); } }
public List <SVR_CrossRef_AniDB_Provider> GetByProvider(CrossRefType type, string providerid) { using (RepoLock.ReaderLock()) { if (IsCached) { return(CrossRefs.GetMultiple(type, providerid)); } return(Table.Where(a => a.CrossRefType == type && a.CrossRefID == providerid).ToList()); } }
public SVR_CrossRef_AniDB_Provider GetByAnimeIdAndProvider(CrossRefType type, int animeid, string providerid) { using (RepoLock.ReaderLock()) { if (IsCached) { return(CrossRefs.GetMultiple(type, providerid).FirstOrDefault(a => a.AnimeID == animeid)); } return(Table.FirstOrDefault(a => a.CrossRefType == type && a.CrossRefID == providerid && a.AnimeID == animeid)); } }
public List <CrossRef_AniDB_Other> GetByType(CrossRefType xrefType) { using (RepoLock.ReaderLock()) { if (IsCached) { return(CrossTypes.GetMultiple((int)xrefType)); } return(Table.Where(a => a.CrossRefType == (int)xrefType).ToList()); } }
public CrossRef_AniDB_Other GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (RepoLock.ReaderLock()) { if (IsCached) { return(Animes.GetMultiple(animeID).FirstOrDefault(a => a.CrossRefType == (int)xrefType)); } return(Table.FirstOrDefault(a => a.AnimeID == animeID && a.CrossRefType == (int)xrefType)); } }
public List<CrossRef_AniDB_Other> GetByType(CrossRefType xrefType) { using (var session = JMMService.SessionFactory.OpenSession()) { var xrefs = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .List<CrossRef_AniDB_Other>(); return new List<CrossRef_AniDB_Other>(xrefs); } }
public List <CrossRef_AniDB_Other> GetByType(CrossRefType xrefType) { using (var session = JMMService.SessionFactory.OpenSession()) { var xrefs = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .List <CrossRef_AniDB_Other>(); return(new List <CrossRef_AniDB_Other>(xrefs)); } }
public List<CrossRef_AniDB_Other> GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (var session = WebCache.SessionFactory.OpenSession()) { var xrefs = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("AnimeID", animeID)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .List<CrossRef_AniDB_Other>(); return new List<CrossRef_AniDB_Other>(xrefs); } }
public List <CrossRef_AniDB_Other> GetByAnimeIDAndType(int animeID, CrossRefType xrefType) { using (var session = WebCache.SessionFactory.OpenSession()) { var xrefs = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("AnimeID", animeID)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .List <CrossRef_AniDB_Other>(); return(new List <CrossRef_AniDB_Other>(xrefs)); } }
// default constructor public DeleteCrossRef_AniDB_OtherRequest(int animeID, CrossRefType xrefType) { this.AnimeID = animeID; this.CrossRefType = (int)xrefType; string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } this.Username = username; }
public LinkingProvider(CrossRefType cr) { if (cr == CrossRefType.TvDB) { GetAll = (ser) => Repo.Instance.TvDB_Episode.GetBySeriesID(int.Parse(ser)).Select(a => new LinkingEpisode(a, this)).ToList(); GetNumberOfEpisodesForSeason = (ser, season) => Repo.Instance.TvDB_Episode.GetNumberOfEpisodesForSeason(int.Parse(ser), season); GetLastSeasonForSeries = (ser) => Repo.Instance.TvDB_Episode.GetLastSeasonForSeries(int.Parse(ser)); } else if (cr == CrossRefType.TraktTV) { GetAll = (ser) => Repo.Instance.Trakt_Episode.GetByShowID(int.Parse(ser)).Select(a => new LinkingEpisode(a, this)).ToList(); GetNumberOfEpisodesForSeason = (ser, season) => Repo.Instance.Trakt_Episode.GetNumberOfEpisodesForSeason(int.Parse(ser), season); GetLastSeasonForSeries = (ser) => Repo.Instance.Trakt_Episode.GetLastSeasonForSeries(int.Parse(ser)); } }
public List <SVR_AnimeSeries> GetSeriesWithoutLinks(CrossRefType type) { return(Repo.Instance.AnimeSeries.GetAll().Where(a => { var anime = a.GetAnime(); if (anime == null) { return false; } if (anime.Restricted > 0) { return false; } return !GetByAnimeIDAndType(a.AniDB_ID, type).Any(); }).ToList()); }
public static void Delete_CrossRef_AniDB_Other(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_XRefFileEpisode_Send) { return; } if (ServerSettings.WebCache_Anonymous) { return; } string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_Other.aspx", ServerSettings.WebCache_Address); DeleteCrossRef_AniDB_OtherRequest req = new DeleteCrossRef_AniDB_OtherRequest(animeID, xrefType); string xml = req.ToXML(); SendData(uri, xml); }
public string LinkAniDBOther(int animeID, int id, int crossRefType) { try { CrossRefType xrefType = (CrossRefType)crossRefType; switch (xrefType) { case CrossRefType.MovieDB: MovieDBHelper.LinkAniDBMovieDB(animeID, id, false); break; } return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public string RemoveLinkAniDBOther(int animeID, int crossRefType) { try { SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID); if (anime == null) { return("Could not find Anime!"); } CrossRefType xrefType = (CrossRefType)crossRefType; switch (xrefType) { case CrossRefType.MovieDB: // check if there are default images used associated List <AniDB_Anime_DefaultImage> images = RepoFactory.AniDB_Anime_DefaultImage.GetByAnimeID(animeID); foreach (AniDB_Anime_DefaultImage image in images) { if (image.ImageParentType == (int)ImageEntityType.MovieDB_FanArt || image.ImageParentType == (int)ImageEntityType.MovieDB_Poster) { RepoFactory.AniDB_Anime_DefaultImage.Delete(image.AniDB_Anime_DefaultImageID); } } MovieDBHelper.RemoveLinkAniDBMovieDB(animeID); break; } return(string.Empty); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(ex.Message); } }
public static CrossRef_AniDB_OtherResult Get_CrossRef_AniDB_Other(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_TvDB_Get) { return(null); } try { string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) { username = Constants.AnonWebCacheUsername; } string uri = string.Format("http://{0}/GetCrossRef_AniDB_Other.aspx?uname={1}&AnimeID={2}&CrossRefType={3}", ServerSettings.WebCache_Address, username, animeID, (int)xrefType); string xml = GetData(uri); if (xml.Trim().Length == 0) { return(null); } XmlDocument docFile = new XmlDocument(); docFile.LoadXml(xml); string sOtherDBID = TryGetProperty(docFile, "CrossRef_AniDB_OtherResult", "CrossRefID"); if (string.IsNullOrEmpty(sOtherDBID)) { return(null); } CrossRef_AniDB_OtherResult result = new CrossRef_AniDB_OtherResult(); result.AnimeID = animeID; result.CrossRefID = sOtherDBID; return(result); } catch (Exception ex) { logger.ErrorException("Error in XMLService.Get_FileHash:: {0}", ex); return(null); } }
public static List <CrossRef_AniDB_ProviderEpisode> GetMatchPreview(int animeID, string crossSeriesID, CrossRefType tp) { var matches = GetEpisodeMatches(animeID, crossSeriesID, tp); return(matches.Where(a => a.AniDB != null && a.Cross != null).OrderBy(a => a.AniDB.EpisodeType) .ThenBy(a => a.AniDB.EpisodeNumber).Select(match => new CrossRef_AniDB_ProviderEpisode { AniDBEpisodeID = match.AniDB.EpisodeID, ProviderEpisodeID = match.Cross.Id, MatchRating = match.Rating, Season = match.Cross.Season, Number = match.AniDB.EpisodeNumber, Type = match.AniDB.GetEpisodeTypeEnum() }).ToList()); }
public CmdWebCacheDeleteAniDBXRef(int animeID, CrossRefType xrefType) { AnimeID = animeID; CrossRefType = (int)xrefType; }
public CrossRef_AniDB_Other GetByAnimeIDAndType(ISessionWrapper session, int animeID, CrossRefType xrefType) { CrossRef_AniDB_Other cr = session .CreateCriteria(typeof(CrossRef_AniDB_Other)) .Add(Restrictions.Eq("AnimeID", animeID)) .Add(Restrictions.Eq("CrossRefType", (int)xrefType)) .UniqueResult <CrossRef_AniDB_Other>(); return(cr); }
public static CrossRef_AniDB_OtherResult Get_CrossRef_AniDB_Other(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_TvDB_Get) return null; try { string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) username = Constants.AnonWebCacheUsername; string uri = string.Format("http://{0}/GetCrossRef_AniDB_Other.aspx?uname={1}&AnimeID={2}&CrossRefType={3}", ServerSettings.WebCache_Address, username, animeID, (int)xrefType); string xml = GetData(uri); if (xml.Trim().Length == 0) return null; XmlDocument docFile = new XmlDocument(); docFile.LoadXml(xml); string sOtherDBID = TryGetProperty(docFile, "CrossRef_AniDB_OtherResult", "CrossRefID"); if (string.IsNullOrEmpty(sOtherDBID)) return null; CrossRef_AniDB_OtherResult result = new CrossRef_AniDB_OtherResult(); result.AnimeID = animeID; result.CrossRefID = sOtherDBID; return result; } catch (Exception ex) { logger.ErrorException("Error in XMLService.Get_FileHash:: {0}", ex); return null; } }
private static void TryToMatchNormalEpisodesToCross(List <AniDB_Episode> aniepsNormal, List <LinkingEpisode> tvepsNormal, bool isAiring, CrossRefType crossType, ref List <(AniDB_Episode, LinkingEpisode, MatchRating)> matches)
public static void Delete_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { // id = animeid // p = username // p2 = AniDBStartEpisodeType // p3 = AniDBStartEpisodeNumber if (!ServerSettings.WebCache_TvDB_Send) return; string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) username = Constants.AnonWebCacheUsername; string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_Other/{1}?p={2}&p2={3}", azureHostBaseAddress, animeID, username, (int)xrefType); string json = DeleteDataJson(uri); }
public static List <(AniDB_Episode AniDB, LinkingEpisode Cross, MatchRating Rating)> GetEpisodeMatches(int animeID, string seriescrossId, CrossRefType crossType) { /* These all apply to normal episodes mainly. * It will fail for specials (BD will cause most to have the same air date). * * We will keep a running score to determine how accurate we believe the link is. Lower is better * Ideal score is 1 to 1 match with perfect air dates * * if the episodes are 1-1: * Try to match air date. * if no match: * match to the next episode after the previous match (starting at one) * if two episodes air on the same day: * match in order of episode, grouped by air date * * if the episodes are not 1-1: * try to match air date. * group episodes in order by air date * * if two episodes air on the same day on both sides: * split them as equally as possible, these will likely need manually overriden * if no match: * if all episodes belong to the same season: * split episodes equally and increment from previous match. these will almost definitely need overriden * else: * increment and hope for the best... */ // Get All AniDB and TvDB episodes for a series, normal and specials done separately // Due to fun season splitting on TvDB, // we need extra logic to determine if a series is one or more seasons // Get TvDB first, if we can't get the episodes, then there's no valid link if ((string.IsNullOrEmpty(seriescrossId)) || seriescrossId == "0") { return(new List <(AniDB_Episode AniDB, LinkingEpisode cross, MatchRating Rating)>()); } LinkingProvider provider = new LinkingProvider(crossType); List <LinkingEpisode> tveps = provider.GetAll(seriescrossId); List <LinkingEpisode> tvepsNormal = tveps.Where(a => a.Season != 0).OrderBy(a => a.Season) .ThenBy(a => a.Number).ToList(); List <LinkingEpisode> tvepsSpecial = tveps.Where(a => a.Season == 0).OrderBy(a => a.Number).ToList(); // Get AniDB List <AniDB_Episode> anieps = Repo.Instance.AniDB_Episode.GetByAnimeID(animeID); List <AniDB_Episode> aniepsNormal = anieps.Where(a => a.EpisodeType == (int)EpisodeType.Episode) .OrderBy(a => a.EpisodeNumber).ToList(); SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(animeID); List <(AniDB_Episode, LinkingEpisode, MatchRating)> matches = new List <(AniDB_Episode, LinkingEpisode, MatchRating)>(); // Try to match OVAs if ((anime?.AnimeType == (int)AnimeType.OVA || anime?.AnimeType == (int)AnimeType.Movie || anime?.AnimeType == (int)AnimeType.TVSpecial) && aniepsNormal.Count > 0 && tvepsSpecial.Count > 0) { TryToMatchSpeicalsToCross(aniepsNormal, tvepsSpecial, ref matches); } // Only try to match normal episodes if this is a series if (anime?.AnimeType != (int)AnimeType.Movie && aniepsNormal.Count > 0 && tvepsNormal.Count > 0) { TryToMatchNormalEpisodesToCross(aniepsNormal, tvepsNormal, anime?.EndDate == null, crossType, ref matches); } // Specials. We aren't going to try too hard here. // We'll try by titles and dates, but we'll rely mostly on overrides List <AniDB_Episode> aniepsSpecial = anieps.Where(a => a.EpisodeType == (int)EpisodeType.Special) .OrderBy(a => a.EpisodeNumber).ToList(); if (aniepsSpecial.Count > 0 && tvepsSpecial.Count > 0) { TryToMatchSpeicalsToCross(aniepsSpecial, tvepsSpecial, ref matches); } return(matches); }
public static CrossRef_AniDB_Other Get_CrossRefAniDBOther(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_TvDB_Get) return null; string username = ServerSettings.AniDB_Username; if (ServerSettings.WebCache_Anonymous) username = Constants.AnonWebCacheUsername; string uri = string.Format(@"http://{0}/api/CrossRef_AniDB_Other/{1}?p={2}&p2={3}", azureHostBaseAddress, animeID, username, (int)xrefType); string msg = string.Format("Getting AniDB/Other Cross Ref From Cache: {0}", animeID); DateTime start = DateTime.Now; JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); string json = GetDataJson(uri); TimeSpan ts = DateTime.Now - start; msg = string.Format("Got AniDB/MAL Cross Ref From Cache: {0} - {1}", animeID, ts.TotalMilliseconds); JMMService.LogToSystem(Constants.DBLogType.APIAzureHTTP, msg); CrossRef_AniDB_Other xref = JSONHelper.Deserialize<CrossRef_AniDB_Other>(json); return xref; }
public static void Delete_CrossRef_AniDB_Other(int animeID, CrossRefType xrefType) { if (!ServerSettings.WebCache_XRefFileEpisode_Send) return; if (ServerSettings.WebCache_Anonymous) return; string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_Other.aspx", ServerSettings.WebCache_Address); DeleteCrossRef_AniDB_OtherRequest req = new DeleteCrossRef_AniDB_OtherRequest(animeID, xrefType); string xml = req.ToXML(); SendData(uri, xml); }
private async Task <IActionResult> GetProviderInternal(SessionInfoWithError s, int animeId, CrossRefType crossRefType) { List <WebCache_CrossRef_AniDB_Provider> results = new List <WebCache_CrossRef_AniDB_Provider>(); //First check for admin approved link Models.Database.WebCache_CrossRef_AniDB_Provider r = await _db.CrossRef_AniDB_Providers.FirstOrDefaultAsync(a => a.Approved == WebCache_RoleType.Admin && a.AnimeID == animeId && a.CrossRefType == crossRefType); if (r != null) { results.Add(r.ToWebCache(WebCache_ReliabilityType.AdminVerified, 0)); if ((s.Role & WebCache_RoleType.Admin) == 0) { return(new JsonResult(results)); } //If not Admin, early exit, otherwise other admin might want to evaluate } //Second Check for Moderator Approved Link List <Models.Database.WebCache_CrossRef_AniDB_Provider> rl = await _db.CrossRef_AniDB_Providers.Where(a => a.Approved == WebCache_RoleType.Moderator && a.AnimeID == animeId && a.CrossRefType == crossRefType).ToListAsync(); if (rl.Count > 0) { results.AddRange(rl.Select(a => a.ToWebCache(WebCache_ReliabilityType.ModeratorVerified, 0))); } //Then The user link r = await _db.CrossRef_AniDB_Providers.FirstOrDefaultAsync(a => a.AniDBUserId == s.AniDBUserId && a.AnimeID == animeId && a.CrossRefType == crossRefType); if (r != null) { results.Add(r.ToWebCache(WebCache_ReliabilityType.User, 0)); } //And Now, the popular ones. var res = await _db.CrossRef_AniDB_Providers.Where(a => a.AnimeID == animeId && a.CrossRefType == crossRefType && a.Approved == WebCache_RoleType.None).GroupBy(a => new { a.CrossRefID, a.EpisodesOverrideData }).Select(a => new { Count = a.Count(), Result = a.First() }).OrderByDescending(a => a.Count).Take(5).ToListAsync(); foreach (var n in res) { results.Add(n.Result.ToWebCache(WebCache_ReliabilityType.Popular, n.Count)); } if (results.Count > 0) { return(new JsonResult(results)); } return(StatusCode(404, "CrossRef Not Found")); }
public static void GenerateEpisodeMatches(int animeID, CrossRefType reftype, bool skipMatchClearing = false) { if (reftype != CrossRefType.TvDB && reftype != CrossRefType.TraktTV) { return; } // wipe old links except User Verified if (!skipMatchClearing) { using (var upd = Repo.Instance.CrossRef_AniDB_Provider.BeginBatchUpdate(() => { List <SVR_CrossRef_AniDB_Provider> provs = new List <SVR_CrossRef_AniDB_Provider>(); Repo.Instance.CrossRef_AniDB_Provider.GetByAnimeIDAndType(animeID, reftype).ForEach(a => { a.EpisodesList.DeleteAllUnverifiedLinks(); if (a.EpisodesList.NeedPersitance) { provs.Add(a); } }); return(provs); })) { upd.ForEach(a => upd.Update(a)); upd.Commit(); } } Repo.Instance.CrossRef_AniDB_Provider.GetByAnimeIDAndType(animeID, reftype).ForEach(a => { a.EpisodesList.DeleteAllUnverifiedLinks(); }); using (var upd = Repo.Instance.CrossRef_AniDB_Provider.BeginBatchUpdate(() => Repo.Instance.CrossRef_AniDB_Provider.GetByAnimeIDAndType(animeID, reftype))) { foreach (SVR_CrossRef_AniDB_Provider cap in upd) { var matches = GetEpisodeMatches(animeID, cap.CrossRefID, reftype); foreach (var match in matches) { if (match.AniDB == null || match.Cross == null) { continue; } // Don't touch User Verified links if (cap.EpisodesList.GetByAnimeEpisodeId(match.AniDB.EpisodeID)?.MatchRating == MatchRating.UserVerified) { continue; } // check for duplicates only if we skip clearing the links Still needed? if ((cap.EpisodesList.GetByAnimeEpisodeId(match.AniDB.EpisodeID) != null) && skipMatchClearing) { cap.EpisodesList.AddOrUpdate(match.AniDB.EpisodeID, match.Cross.Id, match.Cross.Season, match.AniDB.EpisodeNumber, match.AniDB.GetEpisodeTypeEnum(), match.Rating); } if (cap.EpisodesList.GetByAnimeEpisodeId(match.AniDB.EpisodeID) == null && cap.EpisodesList.GetByProviderId(match.Cross.Id) == null) { cap.EpisodesList.AddOrUpdate(match.AniDB.EpisodeID, match.Cross.Id, match.Cross.Season, match.AniDB.EpisodeNumber, match.AniDB.GetEpisodeTypeEnum(), match.Rating); } } if (cap.EpisodesList.NeedPersitance) { upd.Commit(); } } } }