public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALUpdatedWatchedStatus: {0}", AnimeID); try { // find the latest eps to update SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID); if (anime == null) { return; } List <CrossRef_AniDB_MAL> crossRefs = anime.GetCrossRefMAL(); if (crossRefs == null || crossRefs.Count == 0) { return; } SVR_AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(AnimeID); if (ser == null) { return; } MALHelper.UpdateMALSeries(ser); } catch (Exception ex) { logger.Error("Error processing CommandRequest_MALUpdatedWatchedStatus: {0} - {1}", AnimeID, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALSearchAnime: {0}", AnimeID); try { // first check if the user wants to use the web cache if (ServerSettings.WebCache_MAL_Get) { try { Azure_CrossRef_AniDB_MAL crossRef = AzureWebAPI.Get_CrossRefAniDBMAL(AnimeID); if (crossRef != null) { logger.Trace("Found MAL match on web cache for {0} - id = {1} ({2}/{3})", AnimeID, crossRef.MALID, crossRef.StartEpisodeType, crossRef.StartEpisodeNumber); MALHelper.LinkAniDBMAL(AnimeID, crossRef.MALID, crossRef.MALTitle, crossRef.StartEpisodeType, crossRef.StartEpisodeNumber, true); return; } } catch (Exception) { } } if (!ServerSettings.MAL_AutoLink) { return; } string searchCriteria = ""; SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID); if (anime == null) { return; } searchCriteria = anime.MainTitle; // if not wanting to use web cache, or no match found on the web cache go to TvDB directly anime malResults = MALHelper.SearchAnimesByTitle(searchCriteria); if (malResults.entry.Length == 1) { logger.Trace("Using MAL search result for search on {0} : {1} ({2})", searchCriteria, malResults.entry[0].id, malResults.entry[0].title); MALHelper.LinkAniDBMAL(AnimeID, malResults.entry[0].id, malResults.entry[0].title, (int)enEpisodeType.Episode, 1, false); } else if (malResults.entry.Length == 0) { logger.Trace("ZERO MAL search result results for: {0}", searchCriteria); } else { // if the title's match exactly and they have the same amount of episodes, we will use it foreach (animeEntry res in malResults.entry) { if (res.title.Equals(anime.MainTitle, StringComparison.InvariantCultureIgnoreCase) && res.episodes == anime.EpisodeCountNormal) { logger.Trace("Using MAL search result for search on {0} : {1} ({2})", searchCriteria, res.id, res.title); MALHelper.LinkAniDBMAL(AnimeID, res.id, res.title, (int)enEpisodeType.Episode, 1, false); } } logger.Trace("Too many MAL search result results for, skipping: {0}", searchCriteria); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_MALSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALDownloadStatusFromMAL"); try { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { return; } // find the latest eps to update AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); myanimelist mal = MALHelper.GetMALAnimeList(); if (mal == null) { return; } if (mal.anime == null) { return; } CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); AnimeEpisodeRepository repEp = new AnimeEpisodeRepository(); // find the anidb user JMMUserRepository repUsers = new JMMUserRepository(); List <JMMUser> aniDBUsers = repUsers.GetAniDBUsers(); if (aniDBUsers.Count == 0) { return; } JMMUser user = aniDBUsers[0]; foreach (myanimelistAnime malAnime in mal.anime) { // look up the anime CrossRef_AniDB_MAL xref = repCrossRef.GetByMALID(malAnime.series_animedb_id); if (xref == null) { continue; } if (malAnime.series_animedb_id == 8107 || malAnime.series_animedb_id == 10737) { Console.Write(""); } // check if this anime has any other links List <CrossRef_AniDB_MAL> allXrefs = repCrossRef.GetByAnimeID(xref.AnimeID); if (allXrefs.Count == 0) { continue; } // find the range of watched episodes that this applies to int startEpNumber = xref.StartEpisodeNumber; int endEpNumber = GetUpperEpisodeLimit(allXrefs, xref); List <AniDB_Episode> aniEps = repAniEps.GetByAnimeID(xref.AnimeID); foreach (AniDB_Episode aniep in aniEps) { if (aniep.EpisodeType != xref.StartEpisodeType) { continue; } AnimeEpisode ep = repEp.GetByAniDBEpisodeID(aniep.EpisodeID); if (ep == null) { continue; } int adjustedWatchedEps = malAnime.my_watched_episodes + xref.StartEpisodeNumber - 1; int epNum = aniep.EpisodeNumber; if (epNum < startEpNumber || epNum > endEpNumber) { continue; } AnimeEpisode_User usrRec = ep.GetUserRecord(user.JMMUserID); if (epNum <= adjustedWatchedEps) { // update if the user doesn't have a record (means not watched) // or it is currently un-watched bool update = false; if (usrRec == null) { update = true; } else { if (!usrRec.WatchedDate.HasValue) { update = true; } } if (update) { ep.ToggleWatchedStatus(true, true, DateTime.Now, user.JMMUserID, false); } } else { bool update = false; if (usrRec != null) { if (usrRec.WatchedDate.HasValue) { update = true; } } if (update) { ep.ToggleWatchedStatus(false, true, DateTime.Now, user.JMMUserID, false); } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_MALDownloadStatusFromMAL: {0}", ex.ToString()); return; } }
/// <summary> /// Test MAL Creditionals against MAL /// </summary> /// <returns></returns> private object TestMAL() { return(MALHelper.VerifyCredentials() ? APIStatus.OK() : APIStatus.Unauthorized()); }
public static void RunImport_ScanMAL() { MALHelper.ScanForMatches(); }