public AniDB_Anime GetAnimeInfoHTTP(ISession session, int animeID, bool forceRefresh, bool downloadRelations) { //if (!Login()) return null; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = null; bool skip = true; if (forceRefresh) { skip = false; } else { anime = repAnime.GetByAnimeID(session, animeID); if (anime == null) { skip = false; } } if (skip) { if (anime == null) { anime = repAnime.GetByAnimeID(session, animeID); } return(anime); } AniDBHTTPCommand_GetFullAnime getAnimeCmd = null; lock (lockAniDBConnections) { Pause(); getAnimeCmd = new AniDBHTTPCommand_GetFullAnime(); getAnimeCmd.Init(animeID, false, forceRefresh, false); getAnimeCmd.Process(); } if (getAnimeCmd.Anime != null) { anime = SaveResultsForAnimeXML(session, animeID, downloadRelations, getAnimeCmd); if (forceRefresh) { CommandRequest_Azure_SendAnimeFull cmdAzure = new CommandRequest_Azure_SendAnimeFull(anime.AnimeID); cmdAzure.Save(session); } } return(anime); }
public override void ProcessCommand() { try { //if (string.IsNullOrEmpty(ServerSettings.WebCacheAuthKey)) return; CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByID(CrossRef_AniDB_TvDBID); if (xref == null) { return; } AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID); if (anime == null) { return; } AzureWebAPI.Send_CrossRefAniDBTvDB(xref, anime.MainTitle); } catch (Exception ex) { logger.ErrorException("Error processing CommandRequest_WebCacheSendXRefAniDBTvDB: {0}" + ex.ToString(), ex); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetReviews: {0}", AnimeID); try { return; // we will always assume that an anime was downloaded via http first AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID); if (anime != null) { // reviews count will be 0 when the anime is only downloaded via HTTP if (ForceRefresh || anime.AnimeReviews.Count == 0) { anime = JMMService.AnidbProcessor.GetAnimeInfoUDP(AnimeID, true); } foreach (AniDB_Anime_Review animeRev in anime.AnimeReviews) { JMMService.AnidbProcessor.GetReviewUDP(animeRev.ReviewID); } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetReviews: {0} - {1}", AnimeID, ex.ToString()); return; } }
/// <summary> /// Creates an <see cref="SVR_AnimeGroup"/> instance. /// </summary> /// <remarks> /// This method only creates an <see cref="SVR_AnimeGroup"/> instance. It does NOT save it to the database. /// </remarks> /// <param name="session">The NHibernate session.</param> /// <param name="mainSeries">The <see cref="SVR_AnimeSeries"/> whose name will represent the group (Optional. Pass <c>null</c> if not available).</param> /// <param name="mainAnimeId">The ID of the anime whose name will represent the group if <paramref name="mainSeries"/> is <c>null</c>.</param> /// <param name="now">The current date/time.</param> /// <returns>The created <see cref="SVR_AnimeGroup"/>.</returns> private SVR_AnimeGroup CreateAnimeGroup(SVR_AnimeSeries mainSeries, int mainAnimeId, DateTime now) { SVR_AnimeGroup animeGroup = new SVR_AnimeGroup(); string groupName = null; if (mainSeries != null) { animeGroup.Populate(mainSeries, now); groupName = mainSeries.GetSeriesName(); } else // The anime chosen as the group's main anime doesn't actually have a series { SVR_AniDB_Anime mainAnime = _aniDbAnimeRepo.GetByAnimeID(mainAnimeId); animeGroup.Populate(mainAnime, now); groupName = mainAnime.GetFormattedTitle(); } groupName = _truncateYearRegex.Replace(groupName, String.Empty); // If the title appears to end with a year suffix, then remove it animeGroup.GroupName = groupName; animeGroup.SortName = groupName; return(animeGroup); }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALUpdatedWatchedStatus: {0}", AnimeID); try { // find the latest eps to update AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID); if (anime == null) { return; } List <CrossRef_AniDB_MAL> crossRefs = anime.GetCrossRefMAL(); if (crossRefs == null || crossRefs.Count == 0) { return; } AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = repSeries.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 AniDB_Anime GetAnime(ISession session) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anidb_anime = repAnime.GetByAnimeID(session, this.AniDB_ID); return(anidb_anime); }
public override void ProcessCommand() { try { bool process = (ServerSettings.AniDB_Username.Equals("jonbaby", StringComparison.InvariantCultureIgnoreCase) || ServerSettings.AniDB_Username.Equals("jmediamanager", StringComparison.InvariantCultureIgnoreCase)); if (!process) { return; } AniDB_AnimeRepository rep = new AniDB_AnimeRepository(); AniDB_Anime anime = rep.GetByAnimeID(AnimeID); if (anime == null) { return; } if (anime.AllCategories.ToUpper().Contains("18 RESTRICTED")) { return; } AzureWebAPI.Send_AnimeFull(anime); } catch (Exception ex) { logger.Error("Error processing CommandRequest_Azure_SendAnimeFull: {0} - {1}", AnimeID, ex.ToString()); return; } }
public override void ProcessCommand() { try { bool process = ServerSettings.AniDB_Username.Equals("jonbaby", StringComparison.InvariantCultureIgnoreCase) || ServerSettings.AniDB_Username.Equals("jmediamanager", StringComparison.InvariantCultureIgnoreCase); if (!process) { return; } AniDB_AnimeRepository rep = new AniDB_AnimeRepository(); AniDB_Anime anime = rep.GetByAnimeID(AnimeID); if (anime == null) { return; } string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string filePath = Path.Combine(appPath, "Anime_HTTP"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string fileName = string.Format("AnimeDoc_{0}.xml", AnimeID); string fileNameWithPath = Path.Combine(filePath, fileName); string rawXML = ""; if (File.Exists(fileNameWithPath)) { StreamReader re = File.OpenText(fileNameWithPath); rawXML = re.ReadToEnd(); re.Close(); } AnimeXML xml = new AnimeXML(); xml.AnimeID = AnimeID; xml.AnimeName = anime.MainTitle; xml.DateDownloaded = 0; xml.Username = ServerSettings.AniDB_Username; xml.XMLContent = rawXML; AzureWebAPI.Send_AnimeXML(xml); } catch (Exception ex) { logger.Error("Error processing CommandRequest_Azure_SendAnimeXML: {0} - {1}", AnimeID, ex.ToString()); return; } }
public Contract_DuplicateFile ToContract() { Contract_DuplicateFile contract = new Contract_DuplicateFile(); contract.DateTimeUpdated = this.DateTimeUpdated; contract.DuplicateFileID = this.DuplicateFileID; contract.FilePathFile1 = this.FilePathFile1; contract.FilePathFile2 = this.FilePathFile2; contract.Hash = this.Hash; contract.ImportFolderIDFile1 = this.ImportFolderIDFile1; contract.ImportFolderIDFile2 = this.ImportFolderIDFile2; if (this.ImportFolder1 != null) { contract.ImportFolder1 = this.ImportFolder1.ToContract(); } else { contract.ImportFolder1 = null; } if (this.ImportFolder2 != null) { contract.ImportFolder2 = this.ImportFolder2.ToContract(); } else { contract.ImportFolder2 = null; } if (AniDBFile != null) { List <AniDB_Episode> eps = AniDBFile.Episodes; if (eps.Count > 0) { contract.EpisodeNumber = eps[0].EpisodeNumber; contract.EpisodeType = eps[0].EpisodeType; contract.EpisodeName = eps[0].RomajiName; contract.AnimeID = eps[0].AnimeID; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(eps[0].AnimeID); if (anime != null) { contract.AnimeName = anime.MainTitle; } } } return(contract); }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetCharactersCreators: {0}", AnimeID); try { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Character_CreatorRepository repCharCreators = new AniDB_Character_CreatorRepository(); AniDB_Anime anime = null; if (ForceRefresh) { // redownload anime details from http ap so we can get an update character list anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(AnimeID, false, false); } else { anime = repAnime.GetByAnimeID(AnimeID); } if (anime == null) { return; } foreach (AniDB_Anime_Character animeChar in anime.AnimeCharacters) { //MainWindow.anidbProcessor.UpdateCharacterInfo(charref.CharID, false); //logger.Trace("Downloading char info: {0}", animeChar.CharID); CommandRequest_GetCharacter cmdChar = new CommandRequest_GetCharacter(animeChar.CharID, ForceRefresh); cmdChar.Save(); // for each of the creators for this character foreach (AniDB_Character_Seiyuu aac in repCharCreators.GetByCharID(animeChar.CharID)) { CommandRequest_GetCreator cmdCreators = new CommandRequest_GetCreator(aac.SeiyuuID, ForceRefresh); cmdCreators.Save(); } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetCharactersCreators: {0} - {1}", AnimeID, 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); } }
public Contract_IgnoreAnime ToContract() { Contract_IgnoreAnime contract = new Contract_IgnoreAnime(); contract.IgnoreAnimeID = this.IgnoreAnimeID; contract.JMMUserID = this.JMMUserID; contract.AnimeID = this.AnimeID; contract.IgnoreType = this.IgnoreType; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID); if (anime != null) { contract.Anime = anime.ToContract(); } return(contract); }
public Contract_BookmarkedAnime ToContract() { Contract_BookmarkedAnime contract = new Contract_BookmarkedAnime(); contract.BookmarkedAnimeID = BookmarkedAnimeID; contract.AnimeID = AnimeID; contract.Priority = Priority; contract.Notes = Notes; contract.Downloading = Downloading; contract.Anime = null; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime an = repAnime.GetByAnimeID(AnimeID); if (an != null) { contract.Anime = an.Contract.AniDBAnime; } return(contract); }
public override void ProcessCommand() { try { CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository(); CrossRef_AniDB_TraktV2 xref = repCrossRef.GetByID(CrossRef_AniDB_TraktID); if (xref == null) { return; } Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show tvShow = repShow.GetByTraktSlug(xref.TraktID); if (tvShow == null) { return; } AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID); if (anime == null) { return; } string showName = ""; if (tvShow != null) { showName = tvShow.Title; } AzureWebAPI.Send_CrossRefAniDBTrakt(xref, anime.MainTitle); } catch (Exception ex) { logger.ErrorException( "Error processing CommandRequest_WebCacheSendXRefAniDBTrakt: {0}" + ex.ToString(), ex); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository(); JMMServer.Providers.Azure.CrossRef_AniDB_Other crossRef = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBOther(AnimeID, CrossRefType.MovieDB); if (crossRef != null) { int movieID = int.Parse(crossRef.CrossRefID); MovieDB_Movie movie = repMovies.GetByOnlineID(session, movieID); if (movie == null) { // update the info from online MovieDBHelper.UpdateMovieInfo(session, movieID, true); movie = repMovies.GetByOnlineID(movieID); } if (movie != null) { // since we are using the web cache result, let's save it MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, true); return; } } } catch (Exception) { } } string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, 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 List <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria); logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = MovieDBHelper.Search(title.Title); logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {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 { List <CrossRef_AniDB_MALResult> crossRefs = XMLService.Get_CrossRef_AniDB_MAL(AnimeID); if (crossRefs != null) { foreach (CrossRef_AniDB_MALResult crossRef in crossRefs) { 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) { } } string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.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_GetUpdated"); try { List <int> animeIDsToUpdate = new List <int>(); ScheduledUpdateRepository repSched = new ScheduledUpdateRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); // check the automated update table to see when the last time we ran this command ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.AniDBUpdates); if (sched != null) { int freqHours = Utils.GetScheduledHours(ServerSettings.AniDB_Anime_UpdateFrequency); // if we have run this in the last 12 hours and are not forcing it, then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!ForceRefresh) { return; } } } long webUpdateTime = 0; long webUpdateTimeNew = 0; if (sched == null) { // if this is the first time, lets ask for last 3 days DateTime localTime = DateTime.Now.AddDays(-3); DateTime utcTime = localTime.ToUniversalTime(); webUpdateTime = long.Parse(Utils.AniDBDate(utcTime)); webUpdateTimeNew = long.Parse(Utils.AniDBDate(DateTime.Now.ToUniversalTime())); sched = new ScheduledUpdate(); sched.UpdateType = (int)ScheduledUpdateType.AniDBUpdates; } else { logger.Trace("Last anidb info update was : {0}", sched.UpdateDetails); webUpdateTime = long.Parse(sched.UpdateDetails); webUpdateTimeNew = long.Parse(Utils.AniDBDate(DateTime.Now.ToUniversalTime())); DateTime timeNow = DateTime.Now.ToUniversalTime(); logger.Info(string.Format("{0} since last UPDATED command", Utils.FormatSecondsToDisplayTime(int.Parse((webUpdateTimeNew - webUpdateTime).ToString())))); } // get a list of updates from AniDB // startTime will contain the date/time from which the updates apply to JMMService.AnidbProcessor.GetUpdated(ref animeIDsToUpdate, ref webUpdateTime); // now save the update time from AniDB // we will use this next time as a starting point when querying the web cache sched.LastUpdate = DateTime.Now; sched.UpdateDetails = webUpdateTimeNew.ToString(); repSched.Save(sched); if (animeIDsToUpdate.Count == 0) { logger.Info("No anime to be updated"); return; } int countAnime = 0; int countSeries = 0; foreach (int animeID in animeIDsToUpdate) { // update the anime from HTTP AniDB_Anime anime = repAnime.GetByAnimeID(animeID); if (anime == null) { logger.Trace("No local record found for Anime ID: {0}, so skipping...", animeID); continue; } logger.Info("Updating CommandRequest_GetUpdated: {0} ", animeID); // but only if it hasn't been recently updated TimeSpan ts = DateTime.Now - anime.DateTimeUpdated; if (ts.TotalHours > 4) { CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(animeID, true, false); cmdAnime.Save(); countAnime++; } // update the group status // this will allow us to determine which anime has missing episodes // so we wonly get by an amime where we also have an associated series AnimeSeries ser = repSeries.GetByAnimeID(animeID); if (ser != null) { CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(animeID, true); cmdStatus.Save(); countSeries++; } } logger.Info("Updating {0} anime records, and {1} group status records", countAnime, countSeries); } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetUpdated: {0}", ex.ToString()); return; } }
public static void MigrateTraktLinks_V1_to_V2() { try { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); Trakt_EpisodeRepository repEps = new Trakt_EpisodeRepository(); Trakt_ShowRepository repShows = new Trakt_ShowRepository(); CrossRef_AniDB_TraktRepository repCrossRefTrakt = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_TraktV2Repository repCrossRefTraktNew = new CrossRef_AniDB_TraktV2Repository(); using (var session = JMMService.SessionFactory.OpenSession()) { List <CrossRef_AniDB_Trakt> xrefsTrakt = repCrossRefTrakt.GetAll(); foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2(); xrefNew.AnimeID = xrefTrakt.AnimeID; xrefNew.CrossRefSource = xrefTrakt.CrossRefSource; xrefNew.TraktID = xrefTrakt.TraktID; xrefNew.TraktSeasonNumber = xrefTrakt.TraktSeasonNumber; Trakt_Show show = xrefTrakt.GetByTraktShow(session); if (show != null) { xrefNew.TraktTitle = show.Title; } // determine start ep type if (xrefTrakt.TraktSeasonNumber == 0) { xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; } else { xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode; } xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TraktStartEpisodeNumber = 1; repCrossRefTraktNew.Save(xrefNew); } // create cross ref's for specials foreach (CrossRef_AniDB_Trakt xrefTrakt in xrefsTrakt) { AniDB_Anime anime = repAnime.GetByAnimeID(xrefTrakt.AnimeID); if (anime == null) { continue; } Trakt_Show show = xrefTrakt.GetByTraktShow(session); if (show == null) { continue; } // this anime has specials if (anime.EpisodeCountSpecial <= 0) { continue; } // this Trakt series has a season 0 (specials) List <int> seasons = repEps.GetSeasonNumbersForSeries(show.Trakt_ShowID); if (!seasons.Contains(0)) { continue; } //make sure we are not doubling up CrossRef_AniDB_TraktV2 temp = repCrossRefTraktNew.GetByTraktID(xrefTrakt.TraktID, 0, 1, xrefTrakt.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1); if (temp != null) { continue; } CrossRef_AniDB_TraktV2 xrefNew = new CrossRef_AniDB_TraktV2(); xrefNew.AnimeID = xrefTrakt.AnimeID; xrefNew.CrossRefSource = xrefTrakt.CrossRefSource; xrefNew.TraktID = xrefTrakt.TraktID; xrefNew.TraktSeasonNumber = 0; xrefNew.TraktStartEpisodeNumber = 1; xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special; xrefNew.AniDBStartEpisodeNumber = 1; xrefNew.TraktTitle = show.Title; repCrossRefTraktNew.Save(xrefNew); } } } catch (Exception ex) { logger.ErrorException("Could not MigrateTraktLinks_V1_to_V2: " + ex.ToString(), ex); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { CrossRef_AniDB_TraktResult crossRef = XMLService.Get_CrossRef_AniDB_Trakt(AnimeID); if (crossRef != null) { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(crossRef.TraktID); if (showInfo != null) { logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, crossRef.TraktID, crossRef.TraktSeasonNumber, true); return; } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } } // lets try to see locally if we have a tvDB link for this anime // Trakt allows the use of TvDB ID's or their own Trakt ID's CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID); if (xrefTvDBs != null && xrefTvDBs.Count == 1) //TODO this is temporary code, until trakt also allows multiple links { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(xrefTvDBs[0].TvDBID); if (showInfo != null) { // make sure the season specified by TvDB also exists on Trakt Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID); if (traktShow != null) { Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository(); Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber); if (traktSeason != null) { logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true); return; } } } } // if not lets try the tvdb web cache based on the same reasoning if (ServerSettings.WebCache_TvDB_Get) { List <JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID); if (cacheResults != null && cacheResults.Count > 0) { TraktTVShow showInfo = TraktTVHelper.GetShowInfo(cacheResults[0].TvDBID); if (showInfo != null) { // make sure the season specified by TvDB also exists on Trakt Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID); if (traktShow != null) { Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository(); Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, cacheResults[0].TvDBSeasonNumber); if (traktSeason != null) { logger.Trace("Found trakt match on web cache by using TvDBID {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true); return; } } } } } // finally lets try searching Trakt directly string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, 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 List <TraktTVShow> results = TraktTVHelper.SearchShow(searchCriteria); logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = TraktTVHelper.SearchShow(searchCriteria); logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }
public AniDB_Anime GetAnimeInfoUDP(int animeID, bool forceRefresh) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = null; bool skip = true; if (forceRefresh) { skip = false; } else { anime = repAnime.GetByAnimeID(animeID); if (anime == null) { skip = false; } } if (skip) { if (anime == null) { anime = repAnime.GetByAnimeID(animeID); } return(anime); } if (!Login()) { return(null); } enHelperActivityType ev = enHelperActivityType.NoSuchAnime; AniDBCommand_GetAnimeInfo getAnimeCmd = null; lock (lockAniDBConnections) { Pause(); getAnimeCmd = new AniDBCommand_GetAnimeInfo(); getAnimeCmd.Init(animeID, forceRefresh); SetWaitingOnResponse(true); ev = getAnimeCmd.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false)); SetWaitingOnResponse(false); } if (ev == enHelperActivityType.GotAnimeInfo && getAnimeCmd.AnimeInfo != null) { // check for an existing record so we don't over write the description anime = repAnime.GetByAnimeID(getAnimeCmd.AnimeInfo.AnimeID); if (anime == null) { anime = new AniDB_Anime(); } anime.PopulateAndSaveFromUDP(getAnimeCmd.AnimeInfo); } return(anime); }
public GroupStatusCollection GetReleaseGroupStatusUDP(int animeID) { if (!Login()) { return(null); } enHelperActivityType ev = enHelperActivityType.NoSuchCreator; AniDBCommand_GetGroupStatus getCmd = null; lock (lockAniDBConnections) { Pause(); getCmd = new AniDBCommand_GetGroupStatus(); getCmd.Init(animeID); SetWaitingOnResponse(true); ev = getCmd.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false)); SetWaitingOnResponse(false); } if (ev == enHelperActivityType.GotGroupStatus && getCmd.GrpStatusCollection != null) { // delete existing records AniDB_GroupStatusRepository repGrpStat = new AniDB_GroupStatusRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_EpisodeRepository repAniEp = new AniDB_EpisodeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); repGrpStat.DeleteForAnime(animeID); // save the records foreach (Raw_AniDB_GroupStatus raw in getCmd.GrpStatusCollection.Groups) { AniDB_GroupStatus grpstat = new AniDB_GroupStatus(raw); repGrpStat.Save(grpstat); } // updated cached stats // we don't do it in the save method as it would be too many unecessary updates logger.Trace("Updating group stats by anime from GetReleaseGroupStatusUDP: {0}", animeID); StatsCache.Instance.UpdateUsingAnime(animeID); if (getCmd.GrpStatusCollection.LatestEpisodeNumber > 0) { // update the anime with a record of the latest subbed episode AniDB_Anime anime = repAnime.GetByAnimeID(animeID); if (anime != null) { anime.LatestEpisodeNumber = getCmd.GrpStatusCollection.LatestEpisodeNumber; repAnime.Save(anime); // check if we have this episode in the database // if not get it now by updating the anime record List <AniDB_Episode> eps = repAniEp.GetByAnimeIDAndEpisodeNumber(animeID, getCmd.GrpStatusCollection.LatestEpisodeNumber); if (eps.Count == 0) { CommandRequest_GetAnimeHTTP cr_anime = new CommandRequest_GetAnimeHTTP(animeID, true, false); cr_anime.Save(); } // update the missing episode stats on groups and children AnimeSeries series = repSeries.GetByAnimeID(animeID); if (series != null) { series.UpdateStats(true, true, true); //series.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true); } } } } return(getCmd.GrpStatusCollection); }
private AniDB_Anime SaveResultsForAnimeXML(ISession session, int animeID, bool downloadRelations, AniDBHTTPCommand_GetFullAnime getAnimeCmd) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = null; logger.Trace("cmdResult.Anime: {0}", getAnimeCmd.Anime); anime = repAnime.GetByAnimeID(session, animeID); if (anime == null) { anime = new AniDB_Anime(); } anime.PopulateAndSaveFromHTTP(session, getAnimeCmd.Anime, getAnimeCmd.Episodes, getAnimeCmd.Titles, getAnimeCmd.Categories, getAnimeCmd.Tags, getAnimeCmd.Characters, getAnimeCmd.Relations, getAnimeCmd.SimilarAnime, getAnimeCmd.Recommendations, downloadRelations); // Request an image download CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID, JMMImageType.AniDB_Cover, false); cmd.Save(session); // create AnimeEpisode records for all episodes in this anime // only if we have a series AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries ser = repSeries.GetByAnimeID(session, animeID); if (ser != null) { ser.CreateAnimeEpisodes(session); } // update any files, that may have been linked /*CrossRef_File_EpisodeRepository repCrossRefs = new CrossRef_File_EpisodeRepository(); * repCrossRefs.GetByAnimeID(*/ // update cached stats StatsCache.Instance.UpdateUsingAnime(session, anime.AnimeID); StatsCache.Instance.UpdateAnimeContract(session, anime.AnimeID); // download character images foreach (AniDB_Anime_Character animeChar in anime.GetAnimeCharacters(session)) { AniDB_Character chr = animeChar.GetCharacter(session); if (chr == null) { continue; } if (ServerSettings.AniDB_DownloadCharacters) { if (!string.IsNullOrEmpty(chr.PosterPath) && !File.Exists(chr.PosterPath)) { logger.Debug("Downloading character image: {0} - {1}({2}) - {3}", anime.MainTitle, chr.CharName, chr.CharID, chr.PosterPath); cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character, false); cmd.Save(); } } if (ServerSettings.AniDB_DownloadCreators) { AniDB_Seiyuu seiyuu = chr.GetSeiyuu(session); if (seiyuu == null || string.IsNullOrEmpty(seiyuu.PosterPath)) { continue; } if (!File.Exists(seiyuu.PosterPath)) { logger.Debug("Downloading seiyuu image: {0} - {1}({2}) - {3}", anime.MainTitle, seiyuu.SeiyuuName, seiyuu.SeiyuuID, seiyuu.PosterPath); cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID, JMMImageType.AniDB_Creator, false); cmd.Save(); } } } return(anime); }
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)enEpisodeType.Special; } else { xrefNew.AniDBStartEpisodeType = (int)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)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(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); } }
private void ProcessFile_AniDB(VideoLocal vidLocal) { logger.Trace("Checking for AniDB_File record for: {0} --- {1}", vidLocal.Hash, vidLocal.FilePath); // check if we already have this AniDB_File info in the database AniDB_FileRepository repAniFile = new AniDB_FileRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); VideoLocalRepository repVidLocals = new VideoLocalRepository(); AnimeEpisodeRepository repEps = new AnimeEpisodeRepository(); CrossRef_File_EpisodeRepository repXrefFE = new CrossRef_File_EpisodeRepository(); AniDB_File aniFile = null; if (!ForceAniDB) { aniFile = repAniFile.GetByHashAndFileSize(vidLocal.Hash, vlocal.FileSize); if (aniFile == null) { logger.Trace("AniDB_File record not found"); } } int animeID = 0; if (aniFile == null) { // get info from AniDB logger.Debug("Getting AniDB_File record from AniDB...."); Raw_AniDB_File fileInfo = JMMService.AnidbProcessor.GetFileInfo(vidLocal); if (fileInfo != null) { // check if we already have a record aniFile = repAniFile.GetByHashAndFileSize(vidLocal.Hash, vlocal.FileSize); if (aniFile == null) { aniFile = new AniDB_File(); } aniFile.Populate(fileInfo); //overwrite with local file name string localFileName = Path.GetFileName(vidLocal.FilePath); aniFile.FileName = localFileName; repAniFile.Save(aniFile, false); aniFile.CreateLanguages(); aniFile.CreateCrossEpisodes(localFileName); if (!string.IsNullOrEmpty(fileInfo.OtherEpisodesRAW)) { string[] epIDs = fileInfo.OtherEpisodesRAW.Split(','); foreach (string epid in epIDs) { int id = 0; if (int.TryParse(epid, out id)) { CommandRequest_GetEpisode cmdEp = new CommandRequest_GetEpisode(id); cmdEp.Save(); } } } animeID = aniFile.AnimeID; } } bool missingEpisodes = false; // if we still haven't got the AniDB_File Info we try the web cache or local records if (aniFile == null) { // check if we have any records from previous imports List <CrossRef_File_Episode> crossRefs = repXrefFE.GetByHash(vidLocal.Hash); if (crossRefs == null || crossRefs.Count == 0) { // lets see if we can find the episode/anime info from the web cache if (ServerSettings.WebCache_XRefFileEpisode_Get) { List <JMMServer.Providers.Azure.CrossRef_File_Episode> xrefs = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefFileEpisode(vidLocal); crossRefs = new List <CrossRef_File_Episode>(); if (xrefs == null || xrefs.Count == 0) { logger.Debug("Cannot find AniDB_File record or get cross ref from web cache record so exiting: {0}", vidLocal.ED2KHash); return; } else { foreach (JMMServer.Providers.Azure.CrossRef_File_Episode xref in xrefs) { CrossRef_File_Episode xrefEnt = new CrossRef_File_Episode(); xrefEnt.Hash = vidLocal.ED2KHash; xrefEnt.FileName = Path.GetFileName(vidLocal.FullServerPath); xrefEnt.FileSize = vidLocal.FileSize; xrefEnt.CrossRefSource = (int)JMMServer.CrossRefSource.WebCache; xrefEnt.AnimeID = animeID; xrefEnt.EpisodeID = xref.EpisodeID; xrefEnt.Percentage = xref.Percentage; xrefEnt.EpisodeOrder = xref.EpisodeOrder; crossRefs.Add(xrefEnt); // in this case we need to save the cross refs manually as AniDB did not provide them repXrefFE.Save(xrefEnt); } } } else { logger.Debug("Cannot get AniDB_File record so exiting: {0}", vidLocal.ED2KHash); return; } } // we assume that all episodes belong to the same anime foreach (CrossRef_File_Episode xref in crossRefs) { animeID = xref.AnimeID; AniDB_Episode ep = repAniEps.GetByEpisodeID(xref.EpisodeID); if (ep == null) { missingEpisodes = true; } } } else { // check if we have the episode info // if we don't, we will need to re-download the anime info (which also has episode info) if (aniFile.EpisodeCrossRefs.Count == 0) { animeID = aniFile.AnimeID; // if we have the anidb file, but no cross refs it means something has been broken logger.Debug("Could not find any cross ref records for: {0}", vidLocal.ED2KHash); missingEpisodes = true; } else { foreach (CrossRef_File_Episode xref in aniFile.EpisodeCrossRefs) { AniDB_Episode ep = repAniEps.GetByEpisodeID(xref.EpisodeID); if (ep == null) { missingEpisodes = true; } animeID = xref.AnimeID; } } } // get from DB AniDB_Anime anime = repAniAnime.GetByAnimeID(animeID); bool animeRecentlyUpdated = false; if (anime != null) { TimeSpan ts = DateTime.Now - anime.DateTimeUpdated; if (ts.TotalHours < 4) { animeRecentlyUpdated = true; } } // even if we are missing episode info, don't get data more than once every 4 hours // this is to prevent banning if (missingEpisodes && !animeRecentlyUpdated) { logger.Debug("Getting Anime record from AniDB...."); anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(animeID, true, ServerSettings.AutoGroupSeries); } // create the group/series/episode records if needed AnimeSeries ser = null; if (anime != null) { logger.Debug("Creating groups, series and episodes...."); // check if there is an AnimeSeries Record associated with this AnimeID ser = repSeries.GetByAnimeID(animeID); if (ser == null) { // create a new AnimeSeries record ser = anime.CreateAnimeSeriesAndGroup(); } ser.CreateAnimeEpisodes(); // check if we have any group status data for this associated anime // if not we will download it now AniDB_GroupStatusRepository repStatus = new AniDB_GroupStatusRepository(); if (repStatus.GetByAnimeID(anime.AnimeID).Count == 0) { CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(anime.AnimeID, false); cmdStatus.Save(); } // update stats ser.EpisodeAddedDate = DateTime.Now; repSeries.Save(ser); AnimeGroupRepository repGroups = new AnimeGroupRepository(); foreach (AnimeGroup grp in ser.AllGroupsAbove) { grp.EpisodeAddedDate = DateTime.Now; repGroups.Save(grp); } } vidLocal.RenameIfRequired(); vidLocal.MoveFileIfRequired(); // update stats for groups and series if (ser != null) { // update all the groups above this series in the heirarchy ser.UpdateStats(true, true, true); StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID); } // Add this file to the users list if (ServerSettings.AniDB_MyList_AddFiles) { CommandRequest_AddFileToMyList cmd = new CommandRequest_AddFileToMyList(vidLocal.ED2KHash); cmd.Save(); } // lets also try adding to the users trakt collecion by sync'ing the series if (ser != null) { if (ServerSettings.WebCache_Trakt_Send && !string.IsNullOrEmpty(ServerSettings.Trakt_Username)) { CommandRequest_TraktSyncCollectionSeries cmdTrakt = new CommandRequest_TraktSyncCollectionSeries(ser.AnimeSeriesID, ser.GetAnime().MainTitle); cmdTrakt.Save(); } } // sync the series on MAL if (ser != null) { CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID); cmdMAL.Save(); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetCalendar"); try { // we will always assume that an anime was downloaded via http first ScheduledUpdateRepository repSched = new ScheduledUpdateRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.AniDBCalendar); if (sched == null) { sched = new ScheduledUpdate(); sched.UpdateType = (int)ScheduledUpdateType.AniDBCalendar; sched.UpdateDetails = ""; } else { int freqHours = Utils.GetScheduledHours(ServerSettings.AniDB_Calendar_UpdateFrequency); // if we have run this in the last 12 hours and are not forcing it, then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!ForceRefresh) { return; } } } sched.LastUpdate = DateTime.Now; repSched.Save(sched); CalendarCollection colCalendars = JMMService.AnidbProcessor.GetCalendarUDP(); if (colCalendars == null || colCalendars.Calendars == null) { logger.Error("Could not get calendar from AniDB"); return; } foreach (AniDBAPI.Calendar cal in colCalendars.Calendars) { AniDB_Anime anime = repAnime.GetByAnimeID(cal.AnimeID); if (anime != null) { // don't update if the local data is less 2 days old TimeSpan ts = DateTime.Now - anime.DateTimeUpdated; if (ts.TotalDays >= 2) { CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(cal.AnimeID, true, false); cmdAnime.Save(); } else { // update the release date even if we don't update the anime record if (anime.AirDate != cal.ReleaseDate) { anime.AirDate = cal.ReleaseDate; repAnime.Save(anime); AnimeSeriesRepository srepo = new AnimeSeriesRepository(); AnimeSeries ser = srepo.GetByAnimeID(anime.AnimeID); if (ser != null) { srepo.Save(ser, true, false); } } } } else { CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(cal.AnimeID, true, false); cmdAnime.Save(); } } } catch (Exception ex) { logger.ErrorException("Error processing CommandRequest_GetCalendar: " + ex.ToString(), ex); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetReleaseGroupStatus: {0}", AnimeID); try { // only get group status if we have an associated series AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeSeries series = repSeries.GetByAnimeID(AnimeID); if (series == null) { return; } AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID); if (anime == null) { return; } // don't get group status if the anime has already ended more than 50 days ago bool skip = false; if (!ForceRefresh) { if (anime.EndDate.HasValue) { if (anime.EndDate.Value < DateTime.Now) { TimeSpan ts = DateTime.Now - anime.EndDate.Value; if (ts.TotalDays > 50) { // don't skip if we have never downloaded this info before AniDB_GroupStatusRepository repGrpStatus = new AniDB_GroupStatusRepository(); List <AniDB_GroupStatus> grpStatuses = repGrpStatus.GetByAnimeID(AnimeID); if (grpStatuses != null && grpStatuses.Count > 0) { skip = true; } } } } } if (skip) { logger.Info("Skipping group status command because anime has already ended: {0}", anime.ToString()); return; } GroupStatusCollection grpCol = JMMService.AnidbProcessor.GetReleaseGroupStatusUDP(AnimeID); if (ServerSettings.AniDB_DownloadReleaseGroups) { // save in bulk to improve performance using (var session = JMMService.SessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { foreach (Raw_AniDB_GroupStatus grpStatus in grpCol.Groups) { CommandRequest_GetReleaseGroup cmdRelgrp = new CommandRequest_GetReleaseGroup(grpStatus.GroupID, false); cmdRelgrp.Save(session); } transaction.Commit(); } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetReleaseGroupStatus: {0} - {1}", AnimeID, ex.ToString()); return; } }
public System.IO.Stream GetImage(string ImageType, string ImageID) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository(); TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository(); TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository(); TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository(); MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository(); MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository(); Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository(); Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository(); Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository(); Trakt_FriendRepository repTraktFriends = new Trakt_FriendRepository(); JMMImageType imageType = (JMMImageType)int.Parse(ImageType); switch (imageType) { case JMMImageType.AniDB_Cover: AniDB_Anime anime = repAnime.GetByAnimeID(int.Parse(ImageID)); if (anime == null) { return(null); } if (File.Exists(anime.PosterPath)) { FileStream fs = File.OpenRead(anime.PosterPath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); return(BlankImage()); } case JMMImageType.AniDB_Character: AniDB_CharacterRepository repChar = new AniDB_CharacterRepository(); AniDB_Character chr = repChar.GetByID(int.Parse(ImageID)); if (chr == null) { return(null); } if (File.Exists(chr.PosterPath)) { FileStream fs = File.OpenRead(chr.PosterPath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath); return(BlankImage()); } case JMMImageType.AniDB_Creator: AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository(); AniDB_Seiyuu creator = repCreator.GetByID(int.Parse(ImageID)); if (creator == null) { return(null); } if (File.Exists(creator.PosterPath)) { FileStream fs = File.OpenRead(creator.PosterPath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath); return(BlankImage()); } case JMMImageType.TvDB_Cover: TvDB_ImagePoster poster = repPosters.GetByID(int.Parse(ImageID)); if (poster == null) { return(null); } if (File.Exists(poster.FullImagePath)) { FileStream fs = File.OpenRead(poster.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath); return(BlankImage()); } case JMMImageType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = repWideBanners.GetByID(int.Parse(ImageID)); if (wideBanner == null) { return(null); } if (File.Exists(wideBanner.FullImagePath)) { FileStream fs = File.OpenRead(wideBanner.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath); return(BlankImage()); } case JMMImageType.TvDB_Episode: TvDB_Episode ep = repEpisodes.GetByID(int.Parse(ImageID)); if (ep == null) { return(null); } if (File.Exists(ep.FullImagePath)) { FileStream fs = File.OpenRead(ep.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath); return(BlankImage()); } case JMMImageType.TvDB_FanArt: TvDB_ImageFanart fanart = repFanart.GetByID(int.Parse(ImageID)); if (fanart == null) { return(null); } if (File.Exists(fanart.FullImagePath)) { FileStream fs = File.OpenRead(fanart.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath); return(BlankImage()); } case JMMImageType.MovieDB_Poster: MovieDB_Poster mPoster = repMoviePosters.GetByID(int.Parse(ImageID)); if (mPoster == null) { return(null); } // now find only the original size mPoster = repMoviePosters.GetByOnlineID(mPoster.URL); if (mPoster == null) { return(null); } if (File.Exists(mPoster.FullImagePath)) { FileStream fs = File.OpenRead(mPoster.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath); return(BlankImage()); } case JMMImageType.MovieDB_FanArt: MovieDB_Fanart mFanart = repMovieFanart.GetByID(int.Parse(ImageID)); if (mFanart == null) { return(null); } mFanart = repMovieFanart.GetByOnlineID(mFanart.URL); if (mFanart == null) { return(null); } if (File.Exists(mFanart.FullImagePath)) { FileStream fs = File.OpenRead(mFanart.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath); return(BlankImage()); } case JMMImageType.Trakt_Fanart: Trakt_ImageFanart tFanart = repTraktFanart.GetByID(int.Parse(ImageID)); if (tFanart == null) { return(null); } if (File.Exists(tFanart.FullImagePath)) { FileStream fs = File.OpenRead(tFanart.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath); return(BlankImage()); } case JMMImageType.Trakt_Poster: Trakt_ImagePoster tPoster = repTraktPosters.GetByID(int.Parse(ImageID)); if (tPoster == null) { return(null); } if (File.Exists(tPoster.FullImagePath)) { FileStream fs = File.OpenRead(tPoster.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath); return(BlankImage()); } case JMMImageType.Trakt_Episode: case JMMImageType.Trakt_WatchedEpisode: Trakt_Episode tEpisode = repTraktEpisodes.GetByID(int.Parse(ImageID)); if (tEpisode == null) { return(null); } if (File.Exists(tEpisode.FullImagePath)) { FileStream fs = File.OpenRead(tEpisode.FullImagePath); WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; return(fs); } else { logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath); return(BlankImage()); } default: return(BlankImage()); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TvDBSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_TvDB_Get) { try { List <JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID); if (cacheResults != null && cacheResults.Count > 0) { // check again to see if there are any links, user may have manually added links while // this command was in the queue CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTemp = repCrossRef.GetByAnimeID(AnimeID); if (xrefTemp != null && xrefTemp.Count > 0) { return; } foreach (JMMServer.Providers.Azure.CrossRef_AniDB_TvDB xref in cacheResults) { TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(xref.TvDBID); if (tvser != null) { logger.Trace("Found tvdb match on web cache for {0}", AnimeID); TvDBHelper.LinkAniDBTvDB(AnimeID, (AniDBAPI.enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber, xref.TvDBID, xref.TvDBSeasonNumber, xref.TvDBStartEpisodeNumber, true); } else { //if we got a TvDB ID from the web cache, but couldn't find it on TheTvDB.com, it could mean 2 things //1. thetvdb.com is offline //2. the id is no longer valid // if the id is no longer valid we should remove it from the web cache /*if (TvDBHelper.ConfirmTvDBOnline()) * { * * }*/ } } return; } } catch (Exception) { } } string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.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 List <TVDBSeriesSearchResult> results = JMMService.TvdbHelper.SearchSeries(searchCriteria); logger.Trace("Found {0} tvdb results for {1} on TheTvDB", results.Count, searchCriteria); if (ProcessSearchResults(results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles()) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = JMMService.TvdbHelper.SearchSeries(title.Title); logger.Trace("Found {0} tvdb results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID); try { using (var session = JMMService.SessionFactory.OpenSession()) { // first check if the user wants to use the web cache if (ServerSettings.WebCache_Trakt_Get) { try { List <Contract_Azure_CrossRef_AniDB_Trakt> contracts = new List <Contract_Azure_CrossRef_AniDB_Trakt>(); List <JMMServer.Providers.Azure.CrossRef_AniDB_Trakt> resultsCache = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTrakt(AnimeID); if (resultsCache != null && resultsCache.Count > 0) { foreach (JMMServer.Providers.Azure.CrossRef_AniDB_Trakt xref in resultsCache) { TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(xref.TraktID); if (showInfo != null) { logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber, xref.TraktID, xref.TraktSeasonNumber, xref.TraktStartEpisodeNumber, true); return; } } } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } } // lets try to see locally if we have a tvDB link for this anime // Trakt allows the use of TvDB ID's or their own Trakt ID's CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository(); List <CrossRef_AniDB_TvDBV2> xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID); if (xrefTvDBs != null && xrefTvDBs.Count > 0) { foreach (CrossRef_AniDB_TvDBV2 tvXRef in xrefTvDBs) { // first search for this show by the TvDB ID List <TraktV2SearchTvDBIDShowResult> searchResults = TraktTVHelper.SearchShowByIDV2(TraktSearchIDType.tvdb, tvXRef.TvDBID.ToString()); if (searchResults != null && searchResults.Count > 0) { // since we are searching by ID, there will only be one 'show' result TraktV2Show resShow = null; foreach (TraktV2SearchTvDBIDShowResult res in searchResults) { if (res.ResultType == SearchIDType.Show) { resShow = res.show; break; } } if (resShow != null) { TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(resShow.ids.slug); if (showInfo != null && showInfo.ids != null) { // make sure the season specified by TvDB also exists on Trakt Trakt_ShowRepository repShow = new Trakt_ShowRepository(); Trakt_Show traktShow = repShow.GetByTraktSlug(session, showInfo.ids.slug); if (traktShow != null) { Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository(); Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber); if (traktSeason != null) { logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title); TraktTVHelper.LinkAniDBTrakt(AnimeID, (AniDBAPI.enEpisodeType)tvXRef.AniDBStartEpisodeType, tvXRef.AniDBStartEpisodeNumber, showInfo.ids.slug, tvXRef.TvDBSeasonNumber, tvXRef.TvDBStartEpisodeNumber, true); return; } } } } } } } // finally lets try searching Trakt directly string searchCriteria = ""; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AniDB_Anime anime = repAnime.GetByAnimeID(session, 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 List <TraktV2SearchShowResult> results = TraktTVHelper.SearchShowV2(searchCriteria); logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria); if (ProcessSearchResults(session, results, searchCriteria)) { return; } if (results.Count == 0) { foreach (AniDB_Anime_Title title in anime.GetTitles(session)) { if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) { continue; } if (searchCriteria.ToUpper() == title.Title.ToUpper()) { continue; } results = TraktTVHelper.SearchShowV2(searchCriteria); logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title); if (ProcessSearchResults(session, results, title.Title)) { return; } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString()); return; } }
public override void ProcessCommand() { logger.Info("Get AniDB file info: {0}", VideoLocalID); try { AniDB_FileRepository repAniFile = new AniDB_FileRepository(); VideoLocalRepository repVids = new VideoLocalRepository(); vlocal = repVids.GetByID(VideoLocalID); if (vlocal == null) { return; } AniDB_File aniFile = repAniFile.GetByHashAndFileSize(vlocal.Hash, vlocal.FileSize); /*// get anidb file info from web cache * if (aniFile == null && ServerSettings.WebCache_AniDB_File_Get) * { * AniDB_FileRequest fr = XMLService.Get_AniDB_File(vlocal.Hash, vlocal.FileSize); * if (fr != null) * { * aniFile = new AniDB_File(); * aniFile.Populate(fr); * * //overwrite with local file name * string localFileName = Path.GetFileName(vlocal.FilePath); * aniFile.FileName = localFileName; * * repAniFile.Save(aniFile, false); * aniFile.CreateLanguages(); * aniFile.CreateCrossEpisodes(localFileName); * * StatsCache.Instance.UpdateUsingAniDBFile(vlocal.Hash); * } * }*/ Raw_AniDB_File fileInfo = null; if (aniFile == null || ForceAniDB) { fileInfo = JMMService.AnidbProcessor.GetFileInfo(vlocal); } if (fileInfo != null) { // save to the database if (aniFile == null) { aniFile = new AniDB_File(); } aniFile.Populate(fileInfo); //overwrite with local file name string localFileName = Path.GetFileName(vlocal.FilePath); aniFile.FileName = localFileName; repAniFile.Save(aniFile, false); aniFile.CreateLanguages(); aniFile.CreateCrossEpisodes(localFileName); if (!string.IsNullOrEmpty(fileInfo.OtherEpisodesRAW)) { string[] epIDs = fileInfo.OtherEpisodesRAW.Split(','); foreach (string epid in epIDs) { int id = 0; if (int.TryParse(epid, out id)) { CommandRequest_GetEpisode cmdEp = new CommandRequest_GetEpisode(id); cmdEp.Save(); } } } AnimeSeriesRepository repo = new AnimeSeriesRepository(); AniDB_AnimeRepository animerepo = new AniDB_AnimeRepository(); AniDB_Anime anime = animerepo.GetByAnimeID(aniFile.AnimeID); if (anime != null) { using (var session = JMMService.SessionFactory.OpenSession()) { anime.UpdateContractDetailed(session); } } AnimeSeries series = repo.GetByAnimeID(aniFile.AnimeID); series.UpdateStats(false, true, true); // StatsCache.Instance.UpdateUsingAniDBFile(vlocal.Hash); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetFile: {0} - {1}", VideoLocalID, ex.ToString()); return; } }