public override void ProcessCommand()
 {
     AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
     AnimeSeries ser = repSeries.GetByAnimeID(AnimeID);
     if (ser!=null)
         ser.UpdateStats(true, true, true);
 }
		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;
			}
		}
Beispiel #3
0
        public static void InitCache()
        {
            string t = "AnimeSeries";

            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, string.Empty);

            AnimeSeriesRepository repo = new AnimeSeriesRepository();

            Cache = new PocoCache <int, AnimeSeries>(repo.InternalGetAll(), a => a.AnimeSeriesID);
            Changes.AddOrUpdateRange(Cache.Keys);
            AniDBIds = Cache.CreateIndex(a => a.AniDB_ID);
            Groups   = Cache.CreateIndex(a => a.AnimeGroupID);
            int cnt = 0;
            List <AnimeSeries> sers =
                Cache.Values.Where(
                    a => a.ContractVersion < AnimeSeries.CONTRACT_VERSION || a.Contract?.AniDBAnime?.AniDBAnime == null)
                .ToList();
            int max = sers.Count;

            foreach (AnimeSeries s in sers)
            {
                repo.Save(s, false, false, true);
                cnt++;
                if (cnt % 10 == 0)
                {
                    ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                            " DbRegen - " + cnt + "/" + max);
                }
            }
            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                    " DbRegen - " + max + "/" + max);
        }
Beispiel #4
0
		private List<string> GetPosterFilenames(ISession session)
		{
			List<string> allPosters = new List<string>();

			// check if user has specied a fanart to always be used
			if (DefaultAnimeSeriesID.HasValue)
			{
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				AnimeSeries defaultSeries = repSeries.GetByID(session, DefaultAnimeSeriesID.Value);
				if (defaultSeries != null)
				{
					AniDB_Anime anime = defaultSeries.GetAnime(session);
					string defPosterPathNoBlanks = anime.GetDefaultPosterPathNoBlanks(session);

					if (!string.IsNullOrEmpty(defPosterPathNoBlanks) && File.Exists(defPosterPathNoBlanks))
					{
						allPosters.Add(defPosterPathNoBlanks);
						return allPosters;
					}
				}
			}

			foreach (AnimeSeries ser in GetAllSeries(session))
			{
				AniDB_Anime anime = ser.GetAnime(session);
				string defPosterPathNoBlanks = anime.GetDefaultPosterPathNoBlanks(session);

				if (!string.IsNullOrEmpty(defPosterPathNoBlanks) && File.Exists(defPosterPathNoBlanks))
					allPosters.Add(defPosterPathNoBlanks);
			}

			return allPosters;
		}
 private void UpdatePlexKodiContracts(AnimeSeries_User ugrp)
 {
     using (var session = JMMService.SessionFactory.OpenSession())
     {
         AnimeSeriesRepository repo = new AnimeSeriesRepository();
         AnimeSeries           ser  = repo.GetByID(ugrp.AnimeSeriesID);
         Contract_AnimeSeries  con  = ser?.GetUserContract(ugrp.JMMUserID);
         if (con == null)
         {
             return;
         }
         ugrp.PlexContract = Helper.GenerateFromSeries(con, ser, ser.GetAnime(session), ugrp.JMMUserID);
     }
 }
		public override void ProcessCommand()
		{
            logger.Info("Get AniDB episode info: {0}", EpisodeID);

			
			try
			{
                // we don't use this command to update episode info
                // we actually use it to update the cross ref info instead
                // and we only use it for the "Other Episodes" section of the FILE command
                // because that field doesn't tell you what anime it belongs to

                CrossRef_File_EpisodeRepository repCrossRefs = new CrossRef_File_EpisodeRepository();
                List<CrossRef_File_Episode> xrefs = repCrossRefs.GetByEpisodeID(EpisodeID);
                if (xrefs.Count == 0) return;

                Raw_AniDB_Episode epInfo = JMMService.AnidbProcessor.GetEpisodeInfo(EpisodeID);
                if (epInfo != null)
				{
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                    foreach (CrossRef_File_Episode xref in xrefs)
                    {
                        int oldAnimeID = xref.AnimeID;
                        xref.AnimeID = epInfo.AnimeID;
                        repCrossRefs.Save(xref);


                        AnimeSeries ser = repSeries.GetByAnimeID(oldAnimeID);
                        if (ser != null)
                            ser.UpdateStats(true, true, true);
                        StatsCache.Instance.UpdateUsingAnime(oldAnimeID);

                        ser = repSeries.GetByAnimeID(epInfo.AnimeID);
                        if (ser != null)
                            ser.UpdateStats(true, true, true);
                        StatsCache.Instance.UpdateUsingAnime(epInfo.AnimeID);
                    }
				}
				
			}
			catch (Exception ex)
			{
                logger.Error("Error processing CommandRequest_GetEpisode: {0} - {1}", EpisodeID, ex.ToString());
				return;
			}
		}
		public override void ProcessCommand()
		{
			logger.Info("Processing CommandRequest_TraktSyncCollectionSeries");

			try
			{
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				AnimeSeries series = repSeries.GetByID(AnimeSeriesID);
				if (series == null)
				{
					logger.Error("Could not find anime series: {0}", AnimeSeriesID);
					return;
				}

				TraktTVHelper.SyncCollectionToTrakt_Series(series);
			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_TraktSyncCollectionSeries: {0}", ex.ToString());
				return;
			}
		}
Beispiel #8
0
        public Contract_AnimeSeries_SaveResponse SaveSeries(Contract_AnimeSeries_Save contract, int userID)
        {
            Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse();
            contractout.ErrorMessage = "";
            contractout.AnimeSeries = null;
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = null;

                int? oldGroupID = null;
                if (contract.AnimeSeriesID.HasValue)
                {
                    ser = repSeries.GetByID(contract.AnimeSeriesID.Value);
                    if (ser == null)
                    {
                        contractout.ErrorMessage = "Could not find existing series with ID: " + contract.AnimeSeriesID.Value.ToString();
                        return contractout;
                    }

                    // check if we are moving a series
                    oldGroupID = ser.AnimeGroupID;
                }
                else
                {
                    ser = new AnimeSeries();
                    ser.DateTimeCreated = DateTime.Now;
                    ser.DefaultAudioLanguage = "";
                    ser.DefaultSubtitleLanguage = "";
                    ser.MissingEpisodeCount = 0;
                    ser.MissingEpisodeCountGroups = 0;
                    ser.LatestLocalEpisodeNumber = 0;
                    ser.SeriesNameOverride = "";
                }

                ser.AnimeGroupID = contract.AnimeGroupID;
                ser.AniDB_ID = contract.AniDB_ID;
                ser.DefaultAudioLanguage = contract.DefaultAudioLanguage;
                ser.DefaultSubtitleLanguage = contract.DefaultSubtitleLanguage;
                ser.DateTimeUpdated = DateTime.Now;
                ser.SeriesNameOverride = contract.SeriesNameOverride;
                ser.DefaultFolder = contract.DefaultFolder;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(ser.AniDB_ID);
                if (anime == null)
                {
                    contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID);
                    return contractout;
                }

                repSeries.Save(ser);

                // update stats for groups
                //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true ,true, true);
                ser.QueueUpdateStats();

                if (oldGroupID.HasValue)
                {
                    AnimeGroupRepository repGroups = new AnimeGroupRepository();
                    AnimeGroup grp = repGroups.GetByID(oldGroupID.Value);
                    if (grp != null)
                    {
                        grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
                    }
                }
                List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2();
                List<CrossRef_AniDB_MAL> xrefMAL = ser.CrossRefMAL;

                List<TvDB_Series> sers = new List<TvDB_Series>();
                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                    sers.Add(xref.GetTvDBSeries());
                CrossRef_AniDB_Other xrefMovie = ser.CrossRefMovieDB;
                MovieDB_Movie movie = null;
                if (xrefMovie != null)
                    movie = xrefMovie.GetMovieDB_Movie();
                contractout.AnimeSeries = ser.ToContract(anime, xrefs, ser.CrossRefMovieDB, ser.GetUserRecord(userID),
                    sers, xrefMAL, false, null, null, null, null,movie);

                return contractout;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                contractout.ErrorMessage = ex.Message;
                return contractout;
            }
        }
Beispiel #9
0
        public static void SyncCollectionToTrakt()
        {
            try
            {
                if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return;

                // check that we have at least one user nominated for Trakt
                JMMUserRepository repUsers = new JMMUserRepository();
                List<JMMUser> traktUsers = repUsers.GetTraktUsers();
                if (traktUsers.Count == 0) return;

                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                List<AnimeSeries> allSeries = repSeries.GetAll();

                // now get the full users collection from Trakt
                List<TraktV2ShowCollectedResult> collected = new List<TraktV2ShowCollectedResult>();
                List<TraktV2ShowWatchedResult> watched = new List<TraktV2ShowWatchedResult>();

                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                TraktV2SyncCollectionEpisodesByNumber syncCollectionAdd = new TraktV2SyncCollectionEpisodesByNumber();
                TraktV2SyncCollectionEpisodesByNumber syncCollectionRemove = new TraktV2SyncCollectionEpisodesByNumber();
                TraktV2SyncWatchedEpisodesByNumber syncHistoryAdd = new TraktV2SyncWatchedEpisodesByNumber();
                TraktV2SyncWatchedEpisodesByNumber syncHistoryRemove = new TraktV2SyncWatchedEpisodesByNumber();

                #region Local Collection Sync

                ///////////////////////////////////////////////////////////////////////////////////////
                // First take a look at our local collection and update on Trakt
                ///////////////////////////////////////////////////////////////////////////////////////

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                int counter = 0;
                foreach (AnimeSeries series in allSeries)
                {
                    counter++;
                    logger.Trace("Syncing check -  local collection: {0} / {1} - {2}", counter, allSeries.Count, series.GetSeriesName());

                    AniDB_Anime anime = repAnime.GetByAnimeID(series.AniDB_ID);
                    if (anime == null) continue;

                    //if (anime.AnimeID != 3427) continue;

                    TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                    traktSummary.Populate(series.AniDB_ID);
                    if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                    // get the current watched records for this series on Trakt

                    foreach (AnimeEpisode ep in series.GetAnimeEpisodes())
                    {
                        if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                        {
                            EpisodeSyncDetails epsync = ReconSyncTraktEpisode(series, ep, traktSummary, traktUsers, collected, watched, false);
                            if (epsync != null)
                            {
                                switch (epsync.SyncType)
                                {
                                    case TraktSyncType.CollectionAdd:
                                        syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.CollectionRemove:
                                        syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.HistoryAdd:
                                        syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.HistoryRemove:
                                        syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                }
                            }
                        }
                    }
                }
                #endregion

                // refresh online info, just in case it was chnaged by the last operations
                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                #region Online Collection Sync
                ///////////////////////////////////////////////////////////////////////////////////////
                // Now look at the collection according to Trakt, and remove it if we don't have it locally
                ///////////////////////////////////////////////////////////////////////////////////////

                CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository();

                counter = 0;
                foreach (TraktV2ShowCollectedResult col in collected)
                {
                    counter++;
                    logger.Trace("Syncing check - Online collection: {0} / {1} - {2}", counter, collected.Count, col.show.Title);
                    //continue;

                    // check if we have this series locally
                    List<CrossRef_AniDB_TraktV2> xrefs = repCrossRef.GetByTraktID(col.show.ids.slug);

                    if (xrefs.Count > 0)
                    {
                        foreach (CrossRef_AniDB_TraktV2 xref in xrefs)
                        {
                            AnimeSeries locSeries = repSeries.GetByAnimeID(xref.AnimeID);
                            if (locSeries == null) continue;

                            TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                            traktSummary.Populate(locSeries.AniDB_ID);
                            if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                            // if we have this series locSeries, let's sync the whole series
                            foreach (AnimeEpisode ep in locSeries.GetAnimeEpisodes())
                            {
                                if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                                {
                                    EpisodeSyncDetails epsync = ReconSyncTraktEpisode(locSeries, ep, traktSummary, traktUsers, collected, watched, false);
                                    if (epsync != null)
                                    {
                                        switch (epsync.SyncType)
                                        {
                                            case TraktSyncType.CollectionAdd:
                                                syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.CollectionRemove:
                                                syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryAdd:
                                                syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryRemove:
                                                syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                    else
                    {
                        // Actually we can't do this, because the user may have other non Anime series and Movies
                        /*
                        // series doesn't exist locally at all, so let's completely remove it from Trakt
                        foreach (TraktV2CollectedSeason colSeason in col.seasons)
                        {
                            foreach (TraktV2CollectedEpisode colEp in colSeason.episodes)
                            {
                                string msg = string.Format("SYNC ONLINE: Removing from Trakt Collection:  Slug: {0} - S:{1} - EP:{2}", col.show.ids.slug, colSeason.number, colEp.number);
                                logger.Trace(msg);

                                SyncEpisodeToTrakt(TraktSyncType.CollectionRemove, col.show.ids.slug, colSeason.number, colEp.number, DateTime.Now, false);
                            }
                        }*/
                    }

                }

                #endregion

                // refresh online info, just in case it was chnaged by the last operations
                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                #region Online History (Watched/Unwatched) Sync
                ///////////////////////////////////////////////////////////////////////////////////////
                // Now look at the history according to Trakt, and remove it if we don't have it locally
                ///////////////////////////////////////////////////////////////////////////////////////

                counter = 0;

                foreach (TraktV2ShowWatchedResult wtch in watched)
                {
                    counter++;
                    logger.Trace("Syncing check - Online History: {0} / {1} - {2}", counter, watched.Count, wtch.show.Title);
                    //continue;

                    // check if we have this series locally
                    List<CrossRef_AniDB_TraktV2> xrefs = repCrossRef.GetByTraktID(wtch.show.ids.slug);

                    if (xrefs.Count > 0)
                    {
                        foreach (CrossRef_AniDB_TraktV2 xref in xrefs)
                        {
                            AnimeSeries locSeries = repSeries.GetByAnimeID(xref.AnimeID);
                            if (locSeries == null) continue;

                            TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                            traktSummary.Populate(locSeries.AniDB_ID);
                            if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                            // if we have this series locSeries, let's sync the whole series
                            foreach (AnimeEpisode ep in locSeries.GetAnimeEpisodes())
                            {
                                if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                                {
                                    EpisodeSyncDetails epsync = ReconSyncTraktEpisode(locSeries, ep, traktSummary, traktUsers, collected, watched, false);
                                    if (epsync != null)
                                    {
                                        switch (epsync.SyncType)
                                        {
                                            case TraktSyncType.CollectionAdd:
                                                syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.CollectionRemove:
                                                syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryAdd:
                                                syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryRemove:
                                                syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                    else
                    {
                        // Actually we can't do this, because the user may have other non Anime series and Movies
                        /*
                        // series doesn't exist locally at all, so let's completely remove it from Trakt
                        foreach (TraktV2WatchedSeason wtchSeason in wtch.seasons)
                        {
                            foreach (TraktV2WatchedEpisode wtchEp in wtchSeason.episodes)
                            {
                                string msg = string.Format("SYNC ONLINE: Removing from Trakt History:  Slug: {0} - S:{1} - EP:{2}", wtch.show.ids.slug, wtchSeason.number, wtchEp.number);
                                logger.Trace(msg);

                                SyncEpisodeToTrakt(TraktSyncType.HistoryRemove, wtch.show.ids.slug, wtchSeason.number, wtchEp.number, DateTime.Now, false);
                            }
                        }*/
                    }

                }

                #endregion

                // send the data to Trakt
                string json = string.Empty;
                string url = TraktURIs.SyncCollectionAdd;
                string retData = string.Empty;

                if (syncCollectionAdd.shows != null && syncCollectionAdd.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodesByNumber>(syncCollectionAdd);
                    url = TraktURIs.SyncCollectionAdd;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncCollectionRemove.shows != null && syncCollectionRemove.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodesByNumber>(syncCollectionRemove);
                    url = TraktURIs.SyncCollectionRemove;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncHistoryAdd.shows != null && syncHistoryAdd.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncWatchedEpisodesByNumber>(syncHistoryAdd);
                    url = TraktURIs.SyncHistoryAdd;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncHistoryRemove.shows != null && syncHistoryRemove.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncWatchedEpisodesByNumber>(syncHistoryRemove);
                    url = TraktURIs.SyncHistoryRemove;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                logger.Trace("Test");

            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.SyncCollectionToTrakt: " + ex.ToString(), ex);
            }
        }
Beispiel #10
0
		/// <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 "";
			}
		}
Beispiel #11
0
        public string SyncTraktSeries(int animeID)
        {
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByAnimeID(animeID);
                if (ser == null) return "Could not find Anime Series";

                CommandRequest_TraktSyncCollectionSeries cmd = new CommandRequest_TraktSyncCollectionSeries(ser.AnimeSeriesID, ser.GetSeriesName());
                cmd.Save();

                return string.Empty;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #12
0
        public Contract_AnimeSeries_SaveResponse MoveSeries(int animeSeriesID, int newAnimeGroupID, int userID)
        {
            Contract_AnimeSeries_SaveResponse contractout = new Contract_AnimeSeries_SaveResponse();
            contractout.ErrorMessage = "";
            contractout.AnimeSeries = null;
            try
            {

                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = null;

                ser = repSeries.GetByID(animeSeriesID);
                if (ser == null)
                {
                    contractout.ErrorMessage = "Could not find existing series with ID: " + animeSeriesID.ToString();
                    return contractout;
                }

                // make sure the group exists
                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeGroup grpTemp = repGroups.GetByID(newAnimeGroupID);
                if (grpTemp == null)
                {
                    contractout.ErrorMessage = "Could not find existing group with ID: " + newAnimeGroupID.ToString();
                    return contractout;
                }

                int oldGroupID = ser.AnimeGroupID;
                ser.AnimeGroupID = newAnimeGroupID;
                ser.DateTimeUpdated = DateTime.Now;

                repSeries.Save(ser);

                // update stats for new groups
                //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
                ser.QueueUpdateStats();

                // update stats for old groups
                AnimeGroup grp = repGroups.GetByID(oldGroupID);
                if (grp != null)
                {
                    grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
                }

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(ser.AniDB_ID);
                if (anime == null)
                {
                    contractout.ErrorMessage = string.Format("Could not find anime record with ID: {0}", ser.AniDB_ID);
                    return contractout;
                }
                List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2();
                List<CrossRef_AniDB_MAL> xrefMAL = ser.CrossRefMAL;

                List<TvDB_Series> sers = new List<TvDB_Series>();
                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                    sers.Add(xref.GetTvDBSeries());
                CrossRef_AniDB_Other xrefMovie = ser.CrossRefMovieDB;
                MovieDB_Movie movie=null;
                if (xrefMovie != null)
                    movie = xrefMovie.GetMovieDB_Movie();
                contractout.AnimeSeries = ser.ToContract(anime, xrefs, xrefMovie,
                ser.GetUserRecord(userID), sers, xrefMAL, false, null, null, null, null,movie);

                return contractout;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                contractout.ErrorMessage = ex.Message;
                return contractout;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Delete a series, and everything underneath it (episodes, files)
        /// </summary>
        /// <param name="animeSeriesID"></param>
        /// <param name="deleteFiles">also delete the physical files</param>
        /// <returns></returns>
        public string DeleteAnimeSeries(int animeSeriesID, bool deleteFiles, bool deleteParentGroup)
        {
            try
            {
                AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository();
                VideoLocalRepository repVids = new VideoLocalRepository();
                AnimeGroupRepository repGroups = new AnimeGroupRepository();

                AnimeSeries ser = repAnimeSer.GetByID(animeSeriesID);
                if (ser == null) return "Series does not exist";

                int animeGroupID = ser.AnimeGroupID;

                foreach (AnimeEpisode ep in ser.GetAnimeEpisodes())
                {
                    foreach (VideoLocal vid in ep.GetVideoLocals())
                    {
                        if (deleteFiles)
                        {
                            logger.Info("Deleting video local record and file: {0}", vid.FullServerPath);
                            if (!File.Exists(vid.FullServerPath)) return "File could not be found";
                            File.Delete(vid.FullServerPath);
                        }
                        CommandRequest_DeleteFileFromMyList cmdDel = new CommandRequest_DeleteFileFromMyList(vid.Hash, vid.FileSize);
                        cmdDel.Save();

                        repVids.Delete(vid.VideoLocalID);
                    }

                    repEps.Delete(ep.AnimeEpisodeID);
                }
                repAnimeSer.Delete(ser.AnimeSeriesID);

                // finally update stats
                AnimeGroup grp = repGroups.GetByID(animeGroupID);
                if (grp != null)
                {
                    if (grp.GetAllSeries().Count == 0)
                    {
                        DeleteAnimeGroup(grp.AnimeGroupID, false);
                    }
                    else
                    {
                        grp.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
                        StatsCache.Instance.UpdateUsingGroup(grp.TopLevelAnimeGroup.AnimeGroupID);
                    }
                }

                return "";

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #14
0
        public Contract_AnimeGroup GetTopLevelGroupForSeries(int animeSeriesID, int userID)
        {
            try
            {
                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                AnimeSeries ser = repSeries.GetByID(animeSeriesID);
                if (ser == null) return null;

                AnimeGroup grp = ser.TopLevelAnimeGroup;
                if (grp == null) return null;

                return grp.ToContract(grp.GetUserRecord(userID));

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return null;
        }
Beispiel #15
0
        public List<Contract_AniDB_Anime_Similar> GetSimilarAnimeLinks(int animeID, int userID)
        {
            List<Contract_AniDB_Anime_Similar> links = new List<Contract_AniDB_Anime_Similar>();
            try
            {
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return links;

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser juser = repUsers.GetByID(userID);
                if (juser == null) return links;

                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                foreach (AniDB_Anime_Similar link in anime.GetSimilarAnime())
                {
                    AniDB_Anime animeLink = repAnime.GetByAnimeID(link.SimilarAnimeID);
                    if (animeLink != null)
                    {
                        if (!juser.AllowedAnime(animeLink)) continue;
                    }

                    // check if this anime has a series
                    AnimeSeries ser = repSeries.GetByAnimeID(link.SimilarAnimeID);

                    links.Add(link.ToContract(animeLink, ser, userID));
                }

                return links;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return links;
            }
        }
Beispiel #16
0
        public List<Contract_AnimeSeries> GetSeriesWithoutAnyFiles(int userID)
        {
            List<Contract_AnimeSeries> contracts = new List<Contract_AnimeSeries>();

            VideoLocalRepository repVids = new VideoLocalRepository();
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

            try
            {
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    if (repVids.GetByAniDBAnimeID(ser.AniDB_ID).Count == 0)
                    {
                        contracts.Add(ser.ToContract(ser.GetUserRecord(userID)));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Beispiel #17
0
        public string DeleteAnimeGroup(int animeGroupID, bool deleteFiles)
        {
            try
            {
                AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository();
                AnimeGroupRepository repGroups = new AnimeGroupRepository();

                AnimeGroup grp = repGroups.GetByID(animeGroupID);
                if (grp == null) return "Group does not exist";

                int? parentGroupID = grp.AnimeGroupParentID;

                foreach (AnimeSeries ser in grp.GetAllSeries())
                {
                    DeleteAnimeSeries(ser.AnimeSeriesID, deleteFiles, false);
                }

                // delete all sub groups
                foreach (AnimeGroup subGroup in grp.GetAllChildGroups())
                {
                    DeleteAnimeGroup(subGroup.AnimeGroupID, deleteFiles);
                }

                GroupFilterConditionRepository repConditions = new GroupFilterConditionRepository();
                // delete any group filter conditions which reference these groups
                foreach (GroupFilterCondition gfc in repConditions.GetByConditionType(GroupFilterConditionType.AnimeGroup))
                {
                    int thisGrpID = 0;
                    int.TryParse(gfc.ConditionParameter, out thisGrpID);
                    if (thisGrpID == animeGroupID)
                        repConditions.Delete(gfc.GroupFilterConditionID);
                }

                repGroups.Delete(grp.AnimeGroupID);

                // finally update stats

                if (parentGroupID.HasValue)
                {
                    AnimeGroup grpParent = repGroups.GetByID(parentGroupID.Value);

                    if (grpParent != null)
                    {
                        grpParent.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
                        StatsCache.Instance.UpdateUsingGroup(grpParent.TopLevelAnimeGroup.AnimeGroupID);
                    }
                }

                return "";

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #18
0
        public string SaveUser(Contract_JMMUser user)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                bool existingUser = false;
                bool updateStats = false;
                JMMUser jmmUser = null;
                if (user.JMMUserID.HasValue)
                {
                    jmmUser = repUsers.GetByID(user.JMMUserID.Value);
                    if (jmmUser == null) return "User not found";
                    existingUser = true;
                }
                else
                {
                    jmmUser = new JMMUser();
                    updateStats = true;
                }

                if (existingUser && jmmUser.IsAniDBUser != user.IsAniDBUser)
                    updateStats = true;

                jmmUser.HideCategories = user.HideCategories;
                jmmUser.IsAniDBUser = user.IsAniDBUser;
                jmmUser.IsTraktUser = user.IsTraktUser;
                jmmUser.IsAdmin = user.IsAdmin;
                jmmUser.Username = user.Username;
                jmmUser.CanEditServerSettings = user.CanEditServerSettings;
                jmmUser.PlexUsers = user.PlexUsers;
                if (string.IsNullOrEmpty(user.Password))
                    jmmUser.Password = "";

                // make sure that at least one user is an admin
                if (jmmUser.IsAdmin == 0)
                {
                    bool adminExists = false;
                    List<JMMUser> users = repUsers.GetAll();
                    foreach (JMMUser userOld in users)
                    {
                        if (userOld.IsAdmin == 1)
                        {
                            if (existingUser)
                            {
                                if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true;
                            }
                            else
                                adminExists = true;

                        }
                    }

                    if (!adminExists) return "At least one user must be an administrator";
                }

                repUsers.Save(jmmUser);

                // update stats
                if (updateStats)
                {
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    foreach (AnimeSeries ser in repSeries.GetAll())
                        ser.QueueUpdateStats();
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }

            return "";
        }
Beispiel #19
0
        public void SetDefaultSeriesForGroup(int animeGroupID, int animeSeriesID)
        {
            try
            {
                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                AnimeGroup grp = repGroups.GetByID(animeGroupID);
                if (grp == null) return;

                AnimeSeries ser = repSeries.GetByID(animeSeriesID);
                if (ser == null) return;

                grp.DefaultAnimeSeriesID = animeSeriesID;
                repGroups.Save(grp);

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Beispiel #20
0
		public static void ScanForMatches()
		{
			AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
			List<AnimeSeries> allSeries = repSeries.GetAll();

			CrossRef_AniDB_OtherRepository repCrossRef = new CrossRef_AniDB_OtherRepository();
			foreach (AnimeSeries ser in allSeries)
			{
				AniDB_Anime anime = ser.GetAnime();
				if (anime == null) continue;

				if (anime.IsMovieDBLinkDisabled) continue;

				// don't scan if it is associated on the TvDB
				if (anime.GetCrossRefTvDBV2().Count > 0) continue;

				// don't scan if it is associated on the MovieDB
				if (anime.GetCrossRefMovieDB() != null) continue;

				// don't scan if it is not a movie
				if (!anime.SearchOnMovieDB)
					continue;

				logger.Trace("Found anime movie without MovieDB association: " + anime.MainTitle);

				CommandRequest_MovieDBSearchAnime cmd = new CommandRequest_MovieDBSearchAnime(ser.AniDB_ID, false);
				cmd.Save();
			}

		}
Beispiel #21
0
        public List<Contract_AnimeSearch> OnlineAnimeTitleSearch(string titleQuery)
        {
            List<Contract_AnimeSearch> retTitles = new List<Contract_AnimeSearch>();

            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

            try
            {
                // check if it is a title search or an ID search
                int aid = 0;
                if (int.TryParse(titleQuery, out aid))
                {
                    // user is direct entering the anime id

                    // try the local database first
                    // if not download the data from AniDB now
                    AniDB_Anime anime = anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(aid, false, ServerSettings.AniDB_DownloadRelatedAnime);
                    if (anime != null)
                    {
                        Contract_AnimeSearch res = new Contract_AnimeSearch();
                        res.AnimeID = anime.AnimeID;
                        res.MainTitle = anime.MainTitle;
                        res.Titles = anime.AllTitles;

                        // check for existing series and group details
                        AnimeSeries ser = repSeries.GetByAnimeID(anime.AnimeID);
                        if (ser != null)
                        {
                            res.SeriesExists = true;
                            res.AnimeSeriesID = ser.AnimeSeriesID;
                            res.AnimeSeriesName = anime.GetFormattedTitle();
                        }
                        else
                        {
                            res.SeriesExists = false;
                        }
                        retTitles.Add(res);
                    }
                }
                else
                {
                    // title search so look at the web cache
                    List<JMMServer.Providers.Azure.AnimeIDTitle> titles = JMMServer.Providers.Azure.AzureWebAPI.Get_AnimeTitle(titleQuery);

                    using (var session = JMMService.SessionFactory.OpenSession())
                    {
                        foreach (JMMServer.Providers.Azure.AnimeIDTitle tit in titles)
                        {
                            Contract_AnimeSearch res = new Contract_AnimeSearch();
                            res.AnimeID = tit.AnimeID;
                            res.MainTitle = tit.MainTitle;
                            res.Titles = tit.Titles;

                            // check for existing series and group details
                            AnimeSeries ser = repSeries.GetByAnimeID(tit.AnimeID);
                            if (ser != null)
                            {
                                res.SeriesExists = true;
                                res.AnimeSeriesID = ser.AnimeSeriesID;
                                res.AnimeSeriesName = ser.GetAnime(session).GetFormattedTitle(session);
                            }
                            else
                            {
                                res.SeriesExists = false;
                            }

                            retTitles.Add(res);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retTitles;
        }
Beispiel #22
0
        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 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);
								session.SaveOrUpdate(cmdRelgrp);
							}

							transaction.Commit();
						}
					}

					
				}

				//}

			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_GetReleaseGroupStatus: {0} - {1}", AnimeID, ex.ToString());
				return;
			}
		}
Beispiel #24
0
        public void RecreateAllGroups()
        {
            try
            {
                // pause queues
                JMMService.CmdProcessorGeneral.Paused = true;
                JMMService.CmdProcessorHasher.Paused = true;
                JMMService.CmdProcessorImages.Paused = true;

                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeGroup_UserRepository repGroupUser = new AnimeGroup_UserRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                // get all the old groups
                List<AnimeGroup> oldGroups = repGroups.GetAll();
                List<AnimeGroup_User> oldGroupUsers = repGroupUser.GetAll();

                // create a new group, where we will place all the series temporarily
                AnimeGroup tempGroup = new AnimeGroup();
                tempGroup.GroupName = "AAA Migrating Groups AAA";
                tempGroup.Description = "AAA Migrating Groups AAA";
                tempGroup.SortName = "AAA Migrating Groups AAA";
                tempGroup.DateTimeUpdated = DateTime.Now;
                tempGroup.DateTimeCreated = DateTime.Now;
                repGroups.Save(tempGroup);

                // move all series to the new group
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    ser.AnimeGroupID = tempGroup.AnimeGroupID;
                    repSeries.Save(ser, false);
                }

                // delete all the old groups
                foreach (AnimeGroup grp in oldGroups)
                    repGroups.Delete(grp.AnimeGroupID);

                // delete all the old group user records
                foreach (AnimeGroup_User grpUser in oldGroupUsers)
                    repGroupUser.Delete(grpUser.AnimeGroupID);

                // recreate groups
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    bool createNewGroup = true;

                    if (ServerSettings.AutoGroupSeries)
                    {
                        List<AnimeGroup> grps = AnimeGroup.GetRelatedGroupsFromAnimeID(ser.AniDB_ID);

                        // only use if there is just one result
                        if (grps != null && grps.Count > 0 && !grps[0].GroupName.Equals("AAA Migrating Groups AAA"))
                        {
                            ser.AnimeGroupID = grps[0].AnimeGroupID;
                            createNewGroup = false;
                        }
                    }

                    if (createNewGroup)
                    {
                        AnimeGroup anGroup = new AnimeGroup();
                        anGroup.Populate(ser);
                        repGroups.Save(anGroup);

                        ser.AnimeGroupID = anGroup.AnimeGroupID;
                    }

                    repSeries.Save(ser, false);
                }

                // delete the temp group
                if (tempGroup.GetAllSeries().Count == 0)
                    repGroups.Delete(tempGroup.AnimeGroupID);

                // create group user records and update group stats
                foreach (AnimeGroup grp in repGroups.GetAll())
                    grp.UpdateStatsFromTopLevel(true, true);

                // un-pause queues
                JMMService.CmdProcessorGeneral.Paused = false;
                JMMService.CmdProcessorHasher.Paused = false;
                JMMService.CmdProcessorImages.Paused = false;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
Beispiel #25
0
		void workerMyAnime2_DoWork(object sender, DoWorkEventArgs e)
		{
			MA2Progress ma2Progress = new MA2Progress();
			ma2Progress.CurrentFile = 0;
			ma2Progress.ErrorMessage = "";
			ma2Progress.MigratedFiles = 0;
			ma2Progress.TotalFiles = 0;

			try
			{
				string databasePath = e.Argument as string;

				string connString = string.Format(@"data source={0};useutf16encoding=True", databasePath);
				SQLiteConnection myConn = new SQLiteConnection(connString);
				myConn.Open();

				// get a list of unlinked files
				VideoLocalRepository repVids = new VideoLocalRepository();
				AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository();
				AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository();
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
				AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();

				List<VideoLocal> vids = repVids.GetVideosWithoutEpisode();
				ma2Progress.TotalFiles = vids.Count;

				foreach (VideoLocal vid in vids)
				{
					ma2Progress.CurrentFile = ma2Progress.CurrentFile + 1;
					workerMyAnime2.ReportProgress(0, ma2Progress);

					// search for this file in the XrossRef table in MA2
					string sql = string.Format("SELECT AniDB_EpisodeID from CrossRef_Episode_FileHash WHERE Hash = '{0}' AND FileSize = {1}", vid.ED2KHash, vid.FileSize);
					SQLiteCommand sqCommand = new SQLiteCommand(sql);
					sqCommand.Connection = myConn;

					SQLiteDataReader myReader = sqCommand.ExecuteReader();
					while (myReader.Read())
					{
						int episodeID = 0;
						if (!int.TryParse(myReader.GetValue(0).ToString(), out episodeID)) continue;
						if (episodeID <= 0) continue;

						sql = string.Format("SELECT AnimeID from AniDB_Episode WHERE EpisodeID = {0}", episodeID);
						sqCommand = new SQLiteCommand(sql);
						sqCommand.Connection = myConn;

						SQLiteDataReader myReader2 = sqCommand.ExecuteReader();
						while (myReader2.Read())
						{
							int animeID = myReader2.GetInt32(0);

							// so now we have all the needed details we can link the file to the episode
							// as long as wehave the details in JMM
							AniDB_Anime anime = null;
							AniDB_Episode ep = repAniEps.GetByEpisodeID(episodeID);
							if (ep == null)
							{
								logger.Debug("Getting Anime record from AniDB....");
								anime = JMMService.AnidbProcessor.GetAnimeInfoHTTP(animeID, true, ServerSettings.AutoGroupSeries);
							}
							else
								anime = repAniAnime.GetByAnimeID(animeID);

							// create the group/series/episode records if needed
							AnimeSeries ser = null;
							if (anime == null) continue;

							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);
							}


							AnimeEpisode epAnime = repEps.GetByAniDBEpisodeID(episodeID);
							if (epAnime == null)
								continue;

							CrossRef_File_EpisodeRepository repXRefs = new CrossRef_File_EpisodeRepository();
							CrossRef_File_Episode xref = new CrossRef_File_Episode();

							try
							{
								xref.PopulateManually(vid, epAnime);
							}
							catch (Exception ex)
							{
								string msg = string.Format("Error populating XREF: {0} - {1}", vid.ToStringDetailed(), ex.ToString());
								throw;
							}

							repXRefs.Save(xref);

							vid.RenameIfRequired();
							vid.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(vid.ED2KHash);
								cmd.Save();
							}

							ma2Progress.MigratedFiles = ma2Progress.MigratedFiles + 1;
							workerMyAnime2.ReportProgress(0, ma2Progress);

						}
						myReader2.Close();


						//Console.WriteLine(myReader.GetString(0));
					}
					myReader.Close();
				}


				myConn.Close();

				ma2Progress.CurrentFile = ma2Progress.CurrentFile + 1;
				workerMyAnime2.ReportProgress(0, ma2Progress);

			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
				ma2Progress.ErrorMessage = ex.Message;
				workerMyAnime2.ReportProgress(0, ma2Progress);
			}
		}
Beispiel #26
0
        public string RemoveAssociationOnFile(int videoLocalID, int aniDBEpisodeID)
        {
            try
            {
                VideoLocalRepository repVids = new VideoLocalRepository();
                CrossRef_File_EpisodeRepository repXRefs = new CrossRef_File_EpisodeRepository();

                VideoLocal vid = repVids.GetByID(videoLocalID);
                if (vid == null)
                    return "Could not find video record";

                int? animeSeriesID = null;
                foreach (AnimeEpisode ep in vid.GetAnimeEpisodes())
                {
                    if (ep.AniDB_EpisodeID != aniDBEpisodeID) continue;

                    animeSeriesID = ep.AnimeSeriesID;
                    CrossRef_File_Episode xref = repXRefs.GetByHashAndEpisodeID(vid.Hash, ep.AniDB_EpisodeID);
                    if (xref != null)
                    {
                        if (xref.CrossRefSource == (int)CrossRefSource.AniDB)
                            return "Cannot remove associations created from AniDB data";

                        // delete cross ref from web cache
                        CommandRequest_WebCacheDeleteXRefFileEpisode cr = new CommandRequest_WebCacheDeleteXRefFileEpisode(vid.Hash, ep.AniDB_EpisodeID);
                        cr.Save();

                        repXRefs.Delete(xref.CrossRef_File_EpisodeID);
                    }
                }

                if (animeSeriesID.HasValue)
                {
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    AnimeSeries ser = repSeries.GetByID(animeSeriesID.Value);
                    if (ser != null)
                        ser.QueueUpdateStats();
                }

                return "";

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #27
0
		public static void ScanForMatches()
		{
			AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
			List<AnimeSeries> allSeries = repSeries.GetAll();

			CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
			List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
			List<int> alreadyLinked = new List<int>();
			foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
			{
				alreadyLinked.Add(xref.AnimeID);
			}

			foreach (AnimeSeries ser in allSeries)
			{
				if (alreadyLinked.Contains(ser.AniDB_ID)) continue;

				AniDB_Anime anime = ser.GetAnime();

				if (anime!= null)
				{
					logger.Trace("Found anime without tvDB association: " + anime.MainTitle);
					if (!anime.SearchOnTvDB) continue;
					if (anime.IsTvDBLinkDisabled)
					{
						logger.Trace("Skipping scan tvDB link because it is disabled: " + anime.MainTitle);
						continue;
					}
				}

				CommandRequest_TvDBSearchAnime cmd = new CommandRequest_TvDBSearchAnime(ser.AniDB_ID, false);
				cmd.Save();
			}

		}
Beispiel #28
0
        public string RemoveLinkAniDBTraktForAnime(int animeID)
        {
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByAnimeID(animeID);

                if (ser == null) return "Could not find Series for Anime!";

                // check if there are default images used associated
                AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();
                List<AniDB_Anime_DefaultImage> images = repDefaults.GetByAnimeID(animeID);
                foreach (AniDB_Anime_DefaultImage image in images)
                {
                    if (image.ImageParentType == (int)JMMImageType.Trakt_Fanart ||
                        image.ImageParentType == (int)JMMImageType.Trakt_Poster)
                    {
                        repDefaults.Delete(image.AniDB_Anime_DefaultImageID);
                    }
                }

                CrossRef_AniDB_TraktV2Repository repXrefTrakt = new CrossRef_AniDB_TraktV2Repository();
                foreach (CrossRef_AniDB_TraktV2 xref in repXrefTrakt.GetByAnimeID(animeID))
                {
                    TraktTVHelper.RemoveLinkAniDBTrakt(animeID, (enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber,
                        xref.TraktID, xref.TraktSeasonNumber, xref.TraktStartEpisodeNumber);
                }

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
		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)
					{
						crossRefs = XMLService.Get_CrossRef_File_Episode(vidLocal);
						if (crossRefs == null || crossRefs.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 (CrossRef_File_Episode xref in crossRefs)
							{
								// in this case we need to save the cross refs manually as AniDB did not provide them
								repXrefFE.Save(xref);
							}
						}
					}
					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....");

				// try using the cache first
				using (var session = JMMService.SessionFactory.OpenSession())
				{
					anime = JMMService.AnidbProcessor.GetAnimeInfoHTTPFromCache(session, animeID, ServerSettings.AutoGroupSeries);
				}

				// if not in cache try from AniDB
				if (anime == null)
					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)
			{
				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();
			}
		}
Beispiel #30
0
        public string RemoveLinkAniDBTvDB(int animeID, int aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber)
        {
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByAnimeID(animeID);

                if (ser == null) return "Could not find Series for Anime!";

                // check if there are default images used associated
                AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();
                List<AniDB_Anime_DefaultImage> images = repDefaults.GetByAnimeID(animeID);
                foreach (AniDB_Anime_DefaultImage image in images)
                {
                    if (image.ImageParentType == (int)JMMImageType.TvDB_Banner ||
                        image.ImageParentType == (int)JMMImageType.TvDB_Cover ||
                        image.ImageParentType == (int)JMMImageType.TvDB_FanArt)
                    {
                        if (image.ImageParentID == tvDBID)
                            repDefaults.Delete(image.AniDB_Anime_DefaultImageID);
                    }
                }

                TvDBHelper.RemoveLinkAniDBTvDB(animeID, (enEpisodeType)aniEpType, aniEpNumber, tvDBID, tvSeasonNumber, tvEpNumber);

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #31
0
        public static void ScanForMatches()
        {
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            List<AnimeSeries> allSeries = repSeries.GetAll();

            CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository();
            List<CrossRef_AniDB_TraktV2> allCrossRefs = repCrossRef.GetAll();
            List<int> alreadyLinked = new List<int>();
            foreach (CrossRef_AniDB_TraktV2 xref in allCrossRefs)
            {
                alreadyLinked.Add(xref.AnimeID);
            }

            foreach (AnimeSeries ser in allSeries)
            {
                if (alreadyLinked.Contains(ser.AniDB_ID)) continue;

                AniDB_Anime anime = ser.GetAnime();

                if (anime != null)
                    logger.Trace("Found anime without Trakt association: " + anime.MainTitle);

                if (anime.IsTraktLinkDisabled) continue;

                CommandRequest_TraktSearchAnime cmd = new CommandRequest_TraktSearchAnime(ser.AniDB_ID, false);
                cmd.Save();
            }
        }
Beispiel #32
0
        /// <summary>
        /// Removes all tvdb links for one anime
        /// </summary>
        /// <param name="animeID"></param>
        /// <returns></returns>
        public string RemoveLinkAniDBTvDBForAnime(int animeID)
        {
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByAnimeID(animeID);

                if (ser == null) return "Could not find Series for Anime!";

                CrossRef_AniDB_TvDBV2Repository repCrossRef= new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> xrefs = repCrossRef.GetByAnimeID(animeID);
                if (xrefs == null) return "";

                AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();
                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                {
                    // check if there are default images used associated
                    List<AniDB_Anime_DefaultImage> images = repDefaults.GetByAnimeID(animeID);
                    foreach (AniDB_Anime_DefaultImage image in images)
                    {
                        if (image.ImageParentType == (int)JMMImageType.TvDB_Banner ||
                            image.ImageParentType == (int)JMMImageType.TvDB_Cover ||
                            image.ImageParentType == (int)JMMImageType.TvDB_FanArt)
                        {
                            if (image.ImageParentID == xref.TvDBID)
                                repDefaults.Delete(image.AniDB_Anime_DefaultImageID);
                        }
                    }

                    TvDBHelper.RemoveLinkAniDBTvDB(xref.AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber,
                        xref.TvDBID, xref.TvDBSeasonNumber, xref.TvDBStartEpisodeNumber);
                }

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }