public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_GetCharacter: {0}", CharID);

            try
            {
                AniDB_CharacterRepo.Instance.itory repChar = new AniDB_CharacterRepo.Instance.itory();
                AniDB_Character chr = repChar.GetByCharID(CharID);

                if (ForceRefresh || chr == null)
                {
                    // redownload anime details from http ap so we can get an update character list
                    chr = JMMService.AnidbProcessor.GetCharacterInfoUDP(CharID);
                }

                if (chr != null || !string.IsNullOrEmpty(chr.PosterPath) && !File.Exists(chr.PosterPath))
                {
                    CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, ImageEntityType.AniDB_Character, false);
                    cmd.Save();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_GetCharacter: {0} - {1}", CharID, ex.ToString());
                return;
            }
        }
		public override void ProcessCommand()
		{
			logger.Info("Processing CommandRequest_GetCharacter: {0}", CharID);

			try
			{
				AniDB_CharacterRepository repChar = new AniDB_CharacterRepository();
				AniDB_Character chr = repChar.GetByCharID(CharID);

				if (ForceRefresh || chr == null)
				{
					// redownload anime details from http ap so we can get an update character list
					chr = JMMService.AnidbProcessor.GetCharacterInfoUDP(CharID);
				}

				if (chr != null || !string.IsNullOrEmpty(chr.PosterPath) && !File.Exists(chr.PosterPath))
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character, false);
					cmd.Save();
				}

			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_GetCharacter: {0} - {1}", CharID, ex.ToString());
				return;
			}
		}
示例#3
0
		private static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages)
		{
			MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository();
			MovieDB_FanartRepository repFanart = new MovieDB_FanartRepository();
			MovieDB_PosterRepository repPosters = new MovieDB_PosterRepository();

			// save to the DB
			MovieDB_Movie movie = repMovies.GetByOnlineID(searchResult.MovieID);
			if (movie == null) movie = new MovieDB_Movie();
			movie.Populate(searchResult);
			repMovies.Save(session, movie);

			if (!saveImages) return;

			int numFanartDownloaded = 0;
			int numPostersDownloaded = 0;

			foreach (MovieDB_Image_Result img in searchResult.Images)
			{
				if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase))
				{
					MovieDB_Poster poster = repPosters.GetByOnlineID(session, img.ImageID, img.ImageSize);
					if (poster == null) poster = new MovieDB_Poster();
					poster.Populate(img, movie.MovieId);
					repPosters.Save(session, poster);

					if (ServerSettings.MovieDB_AutoPosters && numPostersDownloaded < ServerSettings.MovieDB_AutoPostersAmount)
					{
						// download the image
						if (!string.IsNullOrEmpty(poster.FullImagePath) && !File.Exists(poster.FullImagePath))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false);
							cmd.Save(session);
							numPostersDownloaded++;
						}
					}
				}
				else
				{
					// fanart (backdrop)
					MovieDB_Fanart fanart = repFanart.GetByOnlineID(session, img.ImageID, img.ImageSize);
					if (fanart == null) fanart = new MovieDB_Fanart();
					fanart.Populate(img, movie.MovieId);
					repFanart.Save(session, fanart);

					if (ServerSettings.MovieDB_AutoFanart && numFanartDownloaded < ServerSettings.MovieDB_AutoPostersAmount)
					{
						// download the image
						if (!string.IsNullOrEmpty(fanart.FullImagePath) && !File.Exists(fanart.FullImagePath))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false);
							cmd.Save(session);
							numFanartDownloaded++;
						}
					}
				}
			}
		}
示例#4
0
		public void DownloadAutomaticImages(XmlDocument doc, int seriesID, bool forceDownload)
		{
			List<object> banners = ParseBanners(seriesID, doc);

			int numFanartDownloaded = 0;
			int numPostersDownloaded = 0;
			int numBannersDownloaded = 0;

            // find out how many images we already have locally
            TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
            TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
            TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath))
                        numFanartDownloaded++;
                }

                foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath))
                        numPostersDownloaded++;
                }

                foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(banner.FullImagePath) && File.Exists(banner.FullImagePath))
                        numBannersDownloaded++;
                }
            }
            


			foreach (object obj in banners)
			{
				if (obj.GetType() == typeof(TvDB_ImageFanart))
				{
					TvDB_ImageFanart img = obj as TvDB_ImageFanart;
					if (ServerSettings.TvDB_AutoFanart && numFanartDownloaded < ServerSettings.TvDB_AutoFanartAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, forceDownload);
							cmd.Save();
							numFanartDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImagePoster))
				{
					TvDB_ImagePoster img = obj as TvDB_ImagePoster;
					if (ServerSettings.TvDB_AutoPosters && numPostersDownloaded < ServerSettings.TvDB_AutoPostersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, forceDownload);
							cmd.Save();
							numPostersDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImageWideBanner))
				{
					TvDB_ImageWideBanner img = obj as TvDB_ImageWideBanner;
					if (ServerSettings.TvDB_AutoWideBanners && numBannersDownloaded < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, forceDownload);
							cmd.Save();
							numBannersDownloaded++;
						}
					}
				}
			}
		}
示例#5
0
		public void DownloadAutomaticImages(XmlDocument doc, int seriesID, bool forceDownload)
		{
			List<object> banners = ParseBanners(seriesID, doc);

			int numFanartDownloaded = 0;
			int numPostersDownloaded = 0;
			int numBannersDownloaded = 0;

			foreach (object obj in banners)
			{
				if (obj.GetType() == typeof(TvDB_ImageFanart))
				{
					TvDB_ImageFanart img = obj as TvDB_ImageFanart;
					if (ServerSettings.TvDB_AutoFanart && numFanartDownloaded < ServerSettings.TvDB_AutoFanartAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, forceDownload);
							cmd.Save();
							numFanartDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImagePoster))
				{
					TvDB_ImagePoster img = obj as TvDB_ImagePoster;
					if (ServerSettings.TvDB_AutoPosters && numPostersDownloaded < ServerSettings.TvDB_AutoPostersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, forceDownload);
							cmd.Save();
							numPostersDownloaded++;
						}
					}
				}

				if (obj.GetType() == typeof(TvDB_ImageWideBanner))
				{
					TvDB_ImageWideBanner img = obj as TvDB_ImageWideBanner;
					if (ServerSettings.TvDB_AutoWideBanners && numBannersDownloaded < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						bool fileExists = File.Exists(img.FullImagePath);
						if (!fileExists || (fileExists && forceDownload))
						{
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, forceDownload);
							cmd.Save();
							numBannersDownloaded++;
						}
					}
				}
			}
		}
示例#6
0
        // List of Default priorities for commands
        // Pri 1
        //------
        // Reserved for commands user manually initiates from UI
        //------
        // Pri 2
        //------
        // CommandRequest_GetAnimeHTTP
        //------
        // Pri 3
        //------
        // CommandRequest_ProcessFile
        // CommandRequest_GetFile
        //------
        // Pri 4
        //------
        // CommandRequest_GetUpdated
        // CommandRequest_ReadMediaInfo
        // CommandRequest_GetEpsode
        //------
        // Pri 5
        //------
        // CommandRequest_GetReleaseGroupStatus
        //------
        // Pri 6
        //------
        // CommandRequest_SyncMyList
        // CommandRequest_SyncMyVotes
        //------
        // Pri 7
        //------
        // CommandRequest_GetCalendar
        //------
        // Pri 8
        //------
        // CommandRequest_UpdateMyListFileStatus
        // CommandRequest_GetCharactersCreators
        // CommandRequest_TraktSyncCollection
        // CommandRequest_TvDBUpdateSeriesAndEpisodes
        // CommandRequest_TvDBDownloadImages
        // CommandRequest_TvDBSearchAnime
        // CommandRequest_MovieDBSearchAnime
        // CommandRequest_TraktSearchAnime
        // CommandRequest_MALSearchAnime
        //------
        // Pri 9
        //------
        // CommandRequest_WebCacheSendFileHash
        // CommandRequest_GetReviews
        // CommandRequest_GetReleaseGroup
        // CommandRequest_WebCacheSendXRefFileEpisode
        // CommandRequest_WebCacheDeleteXRefFileEpisode
        // CommandRequest_AddFileToMyList
        // CommandRequest_DeleteFileFromMyList
        // CommandRequest_VoteAnime
        // CommandRequest_WebCacheDeleteXRefAniDBTvDB
        // CommandRequest_WebCacheDeleteXRefAniDBTvDBAll
        // CommandRequest_WebCacheSendXRefAniDBTvDB
        // CommandRequest_WebCacheSendXRefAniDBOther
        // CommandRequest_WebCacheDeleteXRefAniDBOther
        // CommandRequest_WebCacheDeleteXRefAniDBTrakt
        // CommandRequest_WebCacheSendXRefAniDBTrakt
        // CommandRequest_TraktUpdateInfoAndImages
        // CommandRequest_TraktSyncCollectionSeries
        // CommandRequest_TraktShowEpisodeUnseen
        // CommandRequest_DownloadImage
        // CommandRequest_TraktUpdateAllSeries
        // CommandRequest_MALUpdatedWatchedStatus
        // CommandRequest_MALUploadStatusToMAL
        // CommandRequest_MALDownloadStatusFromMAL
        // CommandRequest_WebCacheSendAniDB_File
        // CommandRequest_Azure_SendAnimeFull
        //------
        // Pri 10
        //------
        // CommandRequest_UpdateMylistStats
        // CommandRequest_Azure_SendAnimeXML
        //------
        // Pri 11
        //------
        // CommandRequest_Azure_SendAnimeTitle

        public static ICommandRequest GetCommand(CommandRequest crdb)
        {
            CommandRequestType crt = (CommandRequestType)crdb.CommandType;

            switch (crt)
            {
            case CommandRequestType.Trakt_SyncCollectionSeries:
                CommandRequest_TraktSyncCollectionSeries cr_CommandRequest_TraktSyncCollectionSeries =
                    new CommandRequest_TraktSyncCollectionSeries();
                cr_CommandRequest_TraktSyncCollectionSeries.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_TraktSyncCollectionSeries);

            case CommandRequestType.AniDB_GetEpisodeUDP:
                CommandRequest_GetEpisode cr_CommandRequest_GetEpisode = new CommandRequest_GetEpisode();
                cr_CommandRequest_GetEpisode.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_GetEpisode);

            case CommandRequestType.Azure_SendAnimeTitle:
                CommandRequest_Azure_SendAnimeTitle cr_CommandRequest_Azure_SendAnimeTitle =
                    new CommandRequest_Azure_SendAnimeTitle();
                cr_CommandRequest_Azure_SendAnimeTitle.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_Azure_SendAnimeTitle);

            case CommandRequestType.AniDB_GetTitles:
                CommandRequest_GetAniDBTitles cr_CommandRequest_GetAniDBTitles = new CommandRequest_GetAniDBTitles();
                cr_CommandRequest_GetAniDBTitles.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_GetAniDBTitles);

            case CommandRequestType.Azure_SendAnimeXML:
                CommandRequest_Azure_SendAnimeXML cr_CommandRequest_Azure_SendAnimeXML =
                    new CommandRequest_Azure_SendAnimeXML();
                cr_CommandRequest_Azure_SendAnimeXML.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_Azure_SendAnimeXML);

            case CommandRequestType.Azure_SendAnimeFull:
                CommandRequest_Azure_SendAnimeFull cr_CommandRequest_Azure_SendAnimeFull =
                    new CommandRequest_Azure_SendAnimeFull();
                cr_CommandRequest_Azure_SendAnimeFull.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_Azure_SendAnimeFull);

            case CommandRequestType.Azure_SendUserInfo:
                CommandRequest_Azure_SendUserInfo cr_CommandRequest_Azure_SendUserInfo =
                    new CommandRequest_Azure_SendUserInfo();
                cr_CommandRequest_Azure_SendUserInfo.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_CommandRequest_Azure_SendUserInfo);

            case CommandRequestType.AniDB_UpdateMylistStats:
                CommandRequest_UpdateMylistStats cr_AniDB_UpdateMylistStats = new CommandRequest_UpdateMylistStats();
                cr_AniDB_UpdateMylistStats.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_AniDB_UpdateMylistStats);

            case CommandRequestType.MAL_DownloadWatchedStates:
                CommandRequest_MALDownloadStatusFromMAL cr_MAL_DownloadWatchedStates =
                    new CommandRequest_MALDownloadStatusFromMAL();
                cr_MAL_DownloadWatchedStates.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_MAL_DownloadWatchedStates);

            case CommandRequestType.MAL_UploadWatchedStates:
                CommandRequest_MALUploadStatusToMAL cr_MAL_UploadWatchedStates =
                    new CommandRequest_MALUploadStatusToMAL();
                cr_MAL_UploadWatchedStates.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_MAL_UploadWatchedStates);

            case CommandRequestType.MAL_UpdateStatus:
                CommandRequest_MALUpdatedWatchedStatus cr_MAL_UpdateStatus =
                    new CommandRequest_MALUpdatedWatchedStatus();
                cr_MAL_UpdateStatus.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_MAL_UpdateStatus);

            case CommandRequestType.MAL_SearchAnime:
                CommandRequest_MALSearchAnime cr_MAL_SearchAnime = new CommandRequest_MALSearchAnime();
                cr_MAL_SearchAnime.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_MAL_SearchAnime);

            case CommandRequestType.WebCache_SendXRefAniDBMAL:
                CommandRequest_WebCacheSendXRefAniDBMAL cr_WebCacheSendXRefAniDBMAL =
                    new CommandRequest_WebCacheSendXRefAniDBMAL();
                cr_WebCacheSendXRefAniDBMAL.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_WebCacheSendXRefAniDBMAL);

            case CommandRequestType.WebCache_DeleteXRefAniDBMAL:
                CommandRequest_WebCacheDeleteXRefAniDBMAL cr_WebCacheDeleteXRefAniDBMAL =
                    new CommandRequest_WebCacheDeleteXRefAniDBMAL();
                cr_WebCacheDeleteXRefAniDBMAL.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_WebCacheDeleteXRefAniDBMAL);

            case CommandRequestType.AniDB_GetFileUDP:
                CommandRequest_GetFile cr_AniDB_GetFileUDP = new CommandRequest_GetFile();
                cr_AniDB_GetFileUDP.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_AniDB_GetFileUDP);

            case CommandRequestType.ReadMediaInfo:
                CommandRequest_ReadMediaInfo cr_ReadMediaInfo = new CommandRequest_ReadMediaInfo();
                cr_ReadMediaInfo.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_ReadMediaInfo);

            case CommandRequestType.Trakt_UpdateAllSeries:
                CommandRequest_TraktUpdateAllSeries cr_Trakt_UpdateAllSeries =
                    new CommandRequest_TraktUpdateAllSeries();
                cr_Trakt_UpdateAllSeries.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_Trakt_UpdateAllSeries);

            case CommandRequestType.Trakt_EpisodeCollection:
                CommandRequest_TraktCollectionEpisode cr_TraktCollectionEpisode =
                    new CommandRequest_TraktCollectionEpisode();
                cr_TraktCollectionEpisode.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_TraktCollectionEpisode);

            case CommandRequestType.Trakt_SyncCollection:
                CommandRequest_TraktSyncCollection cr_Trakt_SyncCollection =
                    new CommandRequest_TraktSyncCollection();
                cr_Trakt_SyncCollection.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_Trakt_SyncCollection);

            case CommandRequestType.Trakt_EpisodeHistory:
                CommandRequest_TraktHistoryEpisode cr_Trakt_EpisodeHistory =
                    new CommandRequest_TraktHistoryEpisode();
                cr_Trakt_EpisodeHistory.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_Trakt_EpisodeHistory);

            case CommandRequestType.Trakt_UpdateInfoImages:
                CommandRequest_TraktUpdateInfoAndImages cr_Trakt_UpdateInfoImages =
                    new CommandRequest_TraktUpdateInfoAndImages();
                cr_Trakt_UpdateInfoImages.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_Trakt_UpdateInfoImages);

            case CommandRequestType.WebCache_SendXRefAniDBTrakt:
                CommandRequest_WebCacheSendXRefAniDBTrakt cr_WebCache_SendXRefAniDBTrakt =
                    new CommandRequest_WebCacheSendXRefAniDBTrakt();
                cr_WebCache_SendXRefAniDBTrakt.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_WebCache_SendXRefAniDBTrakt);

            case CommandRequestType.WebCache_DeleteXRefAniDBTrakt:
                CommandRequest_WebCacheDeleteXRefAniDBTrakt cr_WebCache_DeleteXRefAniDBTrakt =
                    new CommandRequest_WebCacheDeleteXRefAniDBTrakt();
                cr_WebCache_DeleteXRefAniDBTrakt.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_WebCache_DeleteXRefAniDBTrakt);

            case CommandRequestType.Trakt_SearchAnime:
                CommandRequest_TraktSearchAnime cr_Trakt_SearchAnime = new CommandRequest_TraktSearchAnime();
                cr_Trakt_SearchAnime.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_Trakt_SearchAnime);

            case CommandRequestType.MovieDB_SearchAnime:
                CommandRequest_MovieDBSearchAnime cr_MovieDB_SearchAnime = new CommandRequest_MovieDBSearchAnime();
                cr_MovieDB_SearchAnime.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_MovieDB_SearchAnime);

            case CommandRequestType.WebCache_DeleteXRefAniDBOther:
                CommandRequest_WebCacheDeleteXRefAniDBOther cr_SendXRefAniDBOther =
                    new CommandRequest_WebCacheDeleteXRefAniDBOther();
                cr_SendXRefAniDBOther.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_SendXRefAniDBOther);

            case CommandRequestType.WebCache_SendXRefAniDBOther:
                CommandRequest_WebCacheSendXRefAniDBOther cr_WebCacheSendXRefAniDBOther =
                    new CommandRequest_WebCacheSendXRefAniDBOther();
                cr_WebCacheSendXRefAniDBOther.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_WebCacheSendXRefAniDBOther);

            case CommandRequestType.AniDB_DeleteFileUDP:
                CommandRequest_DeleteFileFromMyList cr_AniDB_DeleteFileUDP =
                    new CommandRequest_DeleteFileFromMyList();
                cr_AniDB_DeleteFileUDP.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_AniDB_DeleteFileUDP);

            case CommandRequestType.ImageDownload:
                CommandRequest_DownloadImage cr_ImageDownload = new CommandRequest_DownloadImage();
                cr_ImageDownload.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_ImageDownload);

            case CommandRequestType.WebCache_DeleteXRefAniDBTvDB:
                CommandRequest_WebCacheDeleteXRefAniDBTvDB cr_DeleteXRefAniDBTvDB =
                    new CommandRequest_WebCacheDeleteXRefAniDBTvDB();
                cr_DeleteXRefAniDBTvDB.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_DeleteXRefAniDBTvDB);

            case CommandRequestType.WebCache_SendXRefAniDBTvDB:
                CommandRequest_WebCacheSendXRefAniDBTvDB cr_SendXRefAniDBTvDB =
                    new CommandRequest_WebCacheSendXRefAniDBTvDB();
                cr_SendXRefAniDBTvDB.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_SendXRefAniDBTvDB);


            case CommandRequestType.TvDB_SearchAnime:
                CommandRequest_TvDBSearchAnime cr_TvDB_SearchAnime = new CommandRequest_TvDBSearchAnime();
                cr_TvDB_SearchAnime.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_TvDB_SearchAnime);

            case CommandRequestType.TvDB_DownloadImages:
                CommandRequest_TvDBDownloadImages cr_TvDB_DownloadImages = new CommandRequest_TvDBDownloadImages();
                cr_TvDB_DownloadImages.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_TvDB_DownloadImages);

            case CommandRequestType.TvDB_SeriesEpisodes:
                CommandRequest_TvDBUpdateSeriesAndEpisodes cr_TvDB_Episodes =
                    new CommandRequest_TvDBUpdateSeriesAndEpisodes();
                cr_TvDB_Episodes.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_TvDB_Episodes);

            case CommandRequestType.AniDB_SyncVotes:
                CommandRequest_SyncMyVotes cr_SyncVotes = new CommandRequest_SyncMyVotes();
                cr_SyncVotes.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_SyncVotes);

            case CommandRequestType.AniDB_VoteAnime:
                CommandRequest_VoteAnime cr_VoteAnime = new CommandRequest_VoteAnime();
                cr_VoteAnime.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_VoteAnime);

            case CommandRequestType.AniDB_GetCalendar:
                CommandRequest_GetCalendar cr_GetCalendar = new CommandRequest_GetCalendar();
                cr_GetCalendar.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_GetCalendar);

            case CommandRequestType.AniDB_GetReleaseGroup:
                CommandRequest_GetReleaseGroup cr_GetReleaseGroup = new CommandRequest_GetReleaseGroup();
                cr_GetReleaseGroup.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_GetReleaseGroup);

            case CommandRequestType.AniDB_GetAnimeHTTP:
                CommandRequest_GetAnimeHTTP cr_geth = new CommandRequest_GetAnimeHTTP();
                cr_geth.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_geth);

            case CommandRequestType.AniDB_GetReleaseGroupStatus:
                CommandRequest_GetReleaseGroupStatus cr_GetReleaseGroupStatus =
                    new CommandRequest_GetReleaseGroupStatus();
                cr_GetReleaseGroupStatus.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_GetReleaseGroupStatus);

            case CommandRequestType.HashFile:
                CommandRequest_HashFile cr_HashFile = new CommandRequest_HashFile();
                cr_HashFile.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_HashFile);

            case CommandRequestType.ProcessFile:
                CommandRequest_ProcessFile cr_pf = new CommandRequest_ProcessFile();
                cr_pf.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_pf);

            case CommandRequestType.AniDB_AddFileUDP:
                CommandRequest_AddFileToMyList cr_af = new CommandRequest_AddFileToMyList();
                cr_af.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_af);

            case CommandRequestType.AniDB_UpdateWatchedUDP:
                CommandRequest_UpdateMyListFileStatus cr_umlf = new CommandRequest_UpdateMyListFileStatus();
                cr_umlf.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_umlf);

            case CommandRequestType.WebCache_DeleteXRefFileEpisode:
                CommandRequest_WebCacheDeleteXRefFileEpisode cr_DeleteXRefFileEpisode =
                    new CommandRequest_WebCacheDeleteXRefFileEpisode();
                cr_DeleteXRefFileEpisode.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_DeleteXRefFileEpisode);

            case CommandRequestType.WebCache_SendXRefFileEpisode:
                CommandRequest_WebCacheSendXRefFileEpisode cr_SendXRefFileEpisode =
                    new CommandRequest_WebCacheSendXRefFileEpisode();
                cr_SendXRefFileEpisode.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_SendXRefFileEpisode);

            case CommandRequestType.AniDB_GetReviews:
                CommandRequest_GetReviews cr_GetReviews = new CommandRequest_GetReviews();
                cr_GetReviews.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_GetReviews);

            case CommandRequestType.AniDB_GetUpdated:
                CommandRequest_GetUpdated cr_GetUpdated = new CommandRequest_GetUpdated();
                cr_GetUpdated.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_GetUpdated);

            case CommandRequestType.AniDB_SyncMyList:
                CommandRequest_SyncMyList cr_SyncMyList = new CommandRequest_SyncMyList();
                cr_SyncMyList.LoadFromDBCommand(crdb);
                return((ICommandRequest)cr_SyncMyList);

            case CommandRequestType.Refresh_AnimeStats:
                CommandRequest_RefreshAnime cr_refreshAnime = new CommandRequest_RefreshAnime();
                cr_refreshAnime.LoadFromDBCommand(crdb);
                return(cr_refreshAnime);

            case CommandRequestType.LinkAniDBTvDB:
                CommandRequest_LinkAniDBTvDB cr_linkAniDBTvDB = new CommandRequest_LinkAniDBTvDB();
                cr_linkAniDBTvDB.LoadFromDBCommand(crdb);
                return(cr_linkAniDBTvDB);
            }

            return(null);
        }
        public static void SaveMovieToDatabase(ISession session, MovieDB_Movie_Result searchResult, bool saveImages,
            bool isTrakt)
        {
            ISessionWrapper sessionWrapper = session.Wrap();

            // save to the DB
            MovieDB_Movie movie = RepoFactory.MovieDb_Movie.GetByOnlineID(searchResult.MovieID);
            if (movie == null) movie = new MovieDB_Movie();
            movie.Populate(searchResult);

            // Only save movie info if source is not trakt, this presents adding tv shows as movies
            // Needs better fix later on

            if (!isTrakt)
            {
                RepoFactory.MovieDb_Movie.Save(movie);
            }

            if (!saveImages) return;

            int numFanartDownloaded = 0;
            int numPostersDownloaded = 0;

            // save data to the DB and determine the number of images we already have
            foreach (MovieDB_Image_Result img in searchResult.Images)
            {
                if (img.ImageType.Equals("poster", StringComparison.InvariantCultureIgnoreCase))
                {
                    MovieDB_Poster poster = RepoFactory.MovieDB_Poster.GetByOnlineID(session, img.URL);
                    if (poster == null) poster = new MovieDB_Poster();
                    poster.Populate(img, movie.MovieId);
                    RepoFactory.MovieDB_Poster.Save(poster);

                    if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath))
                        numPostersDownloaded++;
                }
                else
                {
                    // fanart (backdrop)
                    MovieDB_Fanart fanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(session, img.URL);
                    if (fanart == null) fanart = new MovieDB_Fanart();
                    fanart.Populate(img, movie.MovieId);
                    RepoFactory.MovieDB_Fanart.Save(fanart);

                    if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath))
                        numFanartDownloaded++;
                }
            }

            // download the posters
            if (ServerSettings.MovieDB_AutoPosters || isTrakt)
            {
                foreach (MovieDB_Poster poster in RepoFactory.MovieDB_Poster.GetByMovieID(sessionWrapper, movie.MovieId)
                    )
                {
                    if (numPostersDownloaded < ServerSettings.MovieDB_AutoPostersAmount)
                    {
                        // download the image
                        if (!string.IsNullOrEmpty(poster.FullImagePath) && !File.Exists(poster.FullImagePath))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.MovieDB_PosterID,
                                JMMImageType.MovieDB_Poster, false);
                            cmd.Save(session);
                            numPostersDownloaded++;
                        }
                    }
                    else
                    {
                        //The MovieDB_AutoPostersAmount should prevent from saving image info without image
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(poster.FullImagePath))
                        {
                            RepoFactory.MovieDB_Poster.Delete(poster.MovieDB_PosterID);
                        }
                    }
                }
            }

            // download the fanart
            if (ServerSettings.MovieDB_AutoFanart || isTrakt)
            {
                foreach (MovieDB_Fanart fanart in RepoFactory.MovieDB_Fanart.GetByMovieID(sessionWrapper, movie.MovieId)
                    )
                {
                    if (numFanartDownloaded < ServerSettings.MovieDB_AutoFanartAmount)
                    {
                        // download the image
                        if (!string.IsNullOrEmpty(fanart.FullImagePath) && !File.Exists(fanart.FullImagePath))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.MovieDB_FanartID,
                                JMMImageType.MovieDB_FanArt, false);
                            cmd.Save(session);
                            numFanartDownloaded++;
                        }
                    }
                    else
                    {
                        //The MovieDB_AutoFanartAmount should prevent from saving image info without image
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(fanart.FullImagePath))
                        {
                            RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID);
                        }
                    }
                }
            }
        }
示例#8
0
		public static TraktTV_ActivitySummary GetActivityFriends(bool shoutsOnly)
		{
			TraktTV_ActivitySummary summ = null;
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
					return null;

				string url = string.Format(Constants.TraktTvURLs.URLGetActivityFriends, Constants.TraktTvURLs.APIKey);
				if (shoutsOnly)
					url = string.Format(Constants.TraktTvURLs.URLGetActivityFriendsShoutsOnly, Constants.TraktTvURLs.APIKey);
				logger.Trace("GetActivityFriends: {0}", url);

				TraktTVPost_GetFriends cmdFriends = new TraktTVPost_GetFriends();
				cmdFriends.Init();

				string json = JSONHelper.Serialize<TraktTVPost_GetFriends>(cmdFriends); // TraktTVPost_GetFriends is really just an auth method
				string jsonResponse = SendData(url, json);
				if (jsonResponse.Trim().Length == 0) return null;

				summ = JSONHelper.Deserialize<TraktTV_ActivitySummary>(jsonResponse);
				if (summ == null) return null;


				// save any trakt data that we don't have already
				Trakt_ShowRepository repShows = new Trakt_ShowRepository();
				Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
				Trakt_FriendRepository repFriends = new Trakt_FriendRepository();

				foreach (TraktTV_Activity act in summ.activity)
				{
					if (act.user == null) continue;
					TraktTV_UserActivity friend = act.user;

					Trakt_Friend traktFriend = repFriends.GetByUsername(friend.username);
					if (traktFriend == null)
					{
						traktFriend = new Trakt_Friend();
						traktFriend.LastAvatarUpdate = DateTime.Now;
					}

					traktFriend.Populate(friend);
					repFriends.Save(traktFriend);

					if (!string.IsNullOrEmpty(traktFriend.FullImagePath))
					{
						bool fileExists = File.Exists(traktFriend.FullImagePath);
						TimeSpan ts = DateTime.Now - traktFriend.LastAvatarUpdate;

						if (!fileExists || ts.TotalHours > 8)
						{
							traktFriend.LastAvatarUpdate = DateTime.Now;
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFriend.Trakt_FriendID, JMMImageType.Trakt_Friend, true);
							cmd.Save();
						}
					}

					if (act.episode != null && act.show != null)
					{
						Trakt_Show show = repShows.GetByTraktID(act.show.TraktID);
						if (show == null)
						{
							show = new Trakt_Show();
							show.Populate(act.show);
							repShows.Save(show);
						}

						Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, int.Parse(act.episode.season), int.Parse(act.episode.number));
						if (episode == null)
							episode = new Trakt_Episode();

						episode.Populate(act.episode, show.Trakt_ShowID);
						repEpisodes.Save(episode);

						if (!string.IsNullOrEmpty(episode.FullImagePath))
						{
							bool fileExists = File.Exists(episode.FullImagePath);
							if (!fileExists)
							{
								CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(episode.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
								cmd.Save();
							}
						}
					}

					// a shout on just the show
					if (act.episode == null && act.show != null)
					{
						Trakt_Show show = repShows.GetByTraktID(act.show.TraktID);
						if (show == null)
						{
							show = new Trakt_Show();
							show.Populate(act.show);
							repShows.Save(show);
						}
					}
				}

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.GetActivityFriends: " + ex.ToString(), ex);
			}

			return summ;
		}
示例#9
0
文件: Importer.cs 项目: dizzydezz/jmm
		public static void RunImport_GetImages()
		{
			// AniDB posters
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			foreach (AniDB_Anime anime in repAnime.GetAll())
			{
				if (anime.AnimeID == 8580)
					Console.Write("");

				if (string.IsNullOrEmpty(anime.PosterPath)) continue;

				bool fileExists = File.Exists(anime.PosterPath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID, JMMImageType.AniDB_Cover, false);
					cmd.Save();
				}
			}

			// TvDB Posters
			if (ServerSettings.TvDB_AutoPosters)
			{
				TvDB_ImagePosterRepository repTvPosters = new TvDB_ImagePosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImagePoster> allPosters = repTvPosters.GetAll();
				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(tvPoster.SeriesID))
							postersCount[tvPoster.SeriesID] = postersCount[tvPoster.SeriesID] + 1;
						else
							postersCount[tvPoster.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImagePoster tvPoster in allPosters)
				{
					if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(tvPoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(tvPoster.SeriesID))
						postersAvailable = postersCount[tvPoster.SeriesID];

					if (!fileExists && postersAvailable < ServerSettings.TvDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvPoster.TvDB_ImagePosterID, JMMImageType.TvDB_Cover, false);
						cmd.Save();
					}
				}
			}

			// TvDB Fanart
			if (ServerSettings.TvDB_AutoFanart)
			{
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();
				TvDB_ImageFanartRepository repTvFanart = new TvDB_ImageFanartRepository();

				List<TvDB_ImageFanart> allFanart = repTvFanart.GetAll();
				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					// build a dictionary of series and how many images exist
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvFanart.SeriesID))
							fanartCount[tvFanart.SeriesID] = fanartCount[tvFanart.SeriesID] + 1;
						else
							fanartCount[tvFanart.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageFanart tvFanart in allFanart)
				{
					if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(tvFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(tvFanart.SeriesID))
						fanartAvailable = fanartCount[tvFanart.SeriesID];

					if (!fileExists && fanartAvailable < ServerSettings.TvDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvFanart.TvDB_ImageFanartID, JMMImageType.TvDB_FanArt, false);
						cmd.Save();
						fanartCount[tvFanart.SeriesID] = fanartAvailable + 1;
					}
				}
			}

			// TvDB Wide Banners
			if (ServerSettings.TvDB_AutoWideBanners)
			{
				TvDB_ImageWideBannerRepository repTvBanners = new TvDB_ImageWideBannerRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<TvDB_ImageWideBanner> allBanners = repTvBanners.GetAll();
				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(tvBanner.SeriesID))
							fanartCount[tvBanner.SeriesID] = fanartCount[tvBanner.SeriesID] + 1;
						else
							fanartCount[tvBanner.SeriesID] = 1;
					}
				}

				foreach (TvDB_ImageWideBanner tvBanner in allBanners)
				{
					if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
					bool fileExists = File.Exists(tvBanner.FullImagePath);

					int bannersAvailable = 0;
					if (fanartCount.ContainsKey(tvBanner.SeriesID))
						bannersAvailable = fanartCount[tvBanner.SeriesID];

					if (!fileExists && bannersAvailable < ServerSettings.TvDB_AutoWideBannersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvBanner.TvDB_ImageWideBannerID, JMMImageType.TvDB_Banner, false);
						cmd.Save();
					}
				}
			}

			// TvDB Episodes
			TvDB_EpisodeRepository repTvEpisodes = new TvDB_EpisodeRepository();
			foreach (TvDB_Episode tvEpisode in repTvEpisodes.GetAll())
			{
				if (string.IsNullOrEmpty(tvEpisode.FullImagePath)) continue;
				bool fileExists = File.Exists(tvEpisode.FullImagePath);
				if (!fileExists)
				{
					CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvEpisode.TvDB_EpisodeID, JMMImageType.TvDB_Episode, false);
					cmd.Save();
				}
			}

			// MovieDB Posters
			if (ServerSettings.MovieDB_AutoPosters)
			{
				MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
				Dictionary<int, int> postersCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Poster> allPosters = repMoviePosters.GetAll();
				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					if (fileExists)
					{
						if (postersCount.ContainsKey(moviePoster.MovieId))
							postersCount[moviePoster.MovieId] = postersCount[moviePoster.MovieId] + 1;
						else
							postersCount[moviePoster.MovieId] = 1;
					}
				}

				foreach (MovieDB_Poster moviePoster in allPosters)
				{
					if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
					bool fileExists = File.Exists(moviePoster.FullImagePath);

					int postersAvailable = 0;
					if (postersCount.ContainsKey(moviePoster.MovieId))
						postersAvailable = postersCount[moviePoster.MovieId];

					if (!fileExists && postersAvailable < ServerSettings.MovieDB_AutoPostersAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(moviePoster.MovieDB_PosterID, JMMImageType.MovieDB_Poster, false);
						cmd.Save();
					}
				}
			}

			// MovieDB Fanart
			if (ServerSettings.MovieDB_AutoFanart)
			{
				MovieDB_FanartRepository repMovieFanarts = new MovieDB_FanartRepository();
				Dictionary<int, int> fanartCount = new Dictionary<int, int>();

				// build a dictionary of series and how many images exist
				List<MovieDB_Fanart> allFanarts = repMovieFanarts.GetAll();
				foreach (MovieDB_Fanart movieFanart in allFanarts)
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					if (fileExists)
					{
						if (fanartCount.ContainsKey(movieFanart.MovieId))
							fanartCount[movieFanart.MovieId] = fanartCount[movieFanart.MovieId] + 1;
						else
							fanartCount[movieFanart.MovieId] = 1;
					}
				}

				foreach (MovieDB_Fanart movieFanart in repMovieFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(movieFanart.FullImagePath);

					int fanartAvailable = 0;
					if (fanartCount.ContainsKey(movieFanart.MovieId))
						fanartAvailable = fanartCount[movieFanart.MovieId];

					if (!fileExists && fanartAvailable < ServerSettings.MovieDB_AutoFanartAmount)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(movieFanart.MovieDB_FanartID, JMMImageType.MovieDB_FanArt, false);
						cmd.Save();
					}
				}
			}

			// Trakt Posters
			if (ServerSettings.Trakt_DownloadPosters)
			{
				Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
				foreach (Trakt_ImagePoster traktPoster in repTraktPosters.GetAll())
				{
					if (string.IsNullOrEmpty(traktPoster.FullImagePath)) continue;
					bool fileExists = File.Exists(traktPoster.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktPoster.Trakt_ImagePosterID, JMMImageType.Trakt_Poster, false);
						cmd.Save();
					}
				}
			}

			// Trakt Fanart
			if (ServerSettings.Trakt_DownloadFanart)
			{
				Trakt_ImageFanartRepository repTraktFanarts = new Trakt_ImageFanartRepository();
				foreach (Trakt_ImageFanart traktFanart in repTraktFanarts.GetAll())
				{
					if (string.IsNullOrEmpty(traktFanart.FullImagePath)) continue;
					bool fileExists = File.Exists(traktFanart.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFanart.Trakt_ImageFanartID, JMMImageType.Trakt_Fanart, false);
						cmd.Save();
					}
				}
			}

			// Trakt Episode
			if (ServerSettings.Trakt_DownloadEpisodes)
			{
				Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
				foreach (Trakt_Episode traktEp in repTraktEpisodes.GetAll())
				{
					if (string.IsNullOrEmpty(traktEp.FullImagePath)) continue;
					bool fileExists = File.Exists(traktEp.FullImagePath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktEp.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
						cmd.Save();
					}
				}
			}

			// AniDB Characters
			if (ServerSettings.AniDB_DownloadCharacters)
			{
				AniDB_CharacterRepository repChars = new AniDB_CharacterRepository();
				foreach (AniDB_Character chr in repChars.GetAll())
				{
					if (string.IsNullOrEmpty(chr.PosterPath)) continue;
					bool fileExists = File.Exists(chr.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID, JMMImageType.AniDB_Character, false);
						cmd.Save();
					}
				}
			}

			// AniDB Creators
			if (ServerSettings.AniDB_DownloadCreators)
			{
				AniDB_SeiyuuRepository repSeiyuu = new AniDB_SeiyuuRepository();
				foreach (AniDB_Seiyuu seiyuu in repSeiyuu.GetAll())
				{
					if (string.IsNullOrEmpty(seiyuu.PosterPath)) continue;
					bool fileExists = File.Exists(seiyuu.PosterPath);
					if (!fileExists)
					{
						CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID, JMMImageType.AniDB_Creator, false);
						cmd.Save();
					}
				}
			}
		}
示例#10
0
		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;
		}
示例#11
0
        public static void RunImport_GetImages()
        {
            // AniDB posters
            foreach (AniDB_Anime anime in RepoFactory.AniDB_Anime.GetAll())
            {
                if (anime.AnimeID == 8580)
                    Console.Write("");

                if (string.IsNullOrEmpty(anime.PosterPath)) continue;

                bool fileExists = File.Exists(anime.PosterPath);
                if (!fileExists)
                {
                    CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(anime.AniDB_AnimeID,
                        JMMImageType.AniDB_Cover,
                        false);
                    cmd.Save();
                }
            }

            // TvDB Posters
            if (ServerSettings.TvDB_AutoPosters)
            {
                Dictionary<int, int> postersCount = new Dictionary<int, int>();

                // build a dictionary of series and how many images exist
                IReadOnlyList<TvDB_ImagePoster> allPosters = RepoFactory.TvDB_ImagePoster.GetAll();
                foreach (TvDB_ImagePoster tvPoster in allPosters)
                {
                    if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvPoster.FullImagePath);

                    if (fileExists)
                    {
                        if (postersCount.ContainsKey(tvPoster.SeriesID))
                            postersCount[tvPoster.SeriesID] = postersCount[tvPoster.SeriesID] + 1;
                        else
                            postersCount[tvPoster.SeriesID] = 1;
                    }
                }

                foreach (TvDB_ImagePoster tvPoster in allPosters)
                {
                    if (string.IsNullOrEmpty(tvPoster.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvPoster.FullImagePath);

                    int postersAvailable = 0;
                    if (postersCount.ContainsKey(tvPoster.SeriesID))
                        postersAvailable = postersCount[tvPoster.SeriesID];

                    if (!fileExists && postersAvailable < ServerSettings.TvDB_AutoPostersAmount)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvPoster.TvDB_ImagePosterID,
                            JMMImageType.TvDB_Cover, false);
                        cmd.Save();

                        if (postersCount.ContainsKey(tvPoster.SeriesID))
                            postersCount[tvPoster.SeriesID] = postersCount[tvPoster.SeriesID] + 1;
                        else
                            postersCount[tvPoster.SeriesID] = 1;
                    }
                }
            }

            // TvDB Fanart
            if (ServerSettings.TvDB_AutoFanart)
            {
                Dictionary<int, int> fanartCount = new Dictionary<int, int>();
                IReadOnlyList<TvDB_ImageFanart> allFanart = RepoFactory.TvDB_ImageFanart.GetAll();
                foreach (TvDB_ImageFanart tvFanart in allFanart)
                {
                    // build a dictionary of series and how many images exist
                    if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvFanart.FullImagePath);

                    if (fileExists)
                    {
                        if (fanartCount.ContainsKey(tvFanart.SeriesID))
                            fanartCount[tvFanart.SeriesID] = fanartCount[tvFanart.SeriesID] + 1;
                        else
                            fanartCount[tvFanart.SeriesID] = 1;
                    }
                }

                foreach (TvDB_ImageFanart tvFanart in allFanart)
                {
                    if (string.IsNullOrEmpty(tvFanart.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvFanart.FullImagePath);

                    int fanartAvailable = 0;
                    if (fanartCount.ContainsKey(tvFanart.SeriesID))
                        fanartAvailable = fanartCount[tvFanart.SeriesID];

                    if (!fileExists && fanartAvailable < ServerSettings.TvDB_AutoFanartAmount)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvFanart.TvDB_ImageFanartID,
                            JMMImageType.TvDB_FanArt, false);
                        cmd.Save();

                        if (fanartCount.ContainsKey(tvFanart.SeriesID))
                            fanartCount[tvFanart.SeriesID] = fanartCount[tvFanart.SeriesID] + 1;
                        else
                            fanartCount[tvFanart.SeriesID] = 1;
                    }
                }
            }

            // TvDB Wide Banners
            if (ServerSettings.TvDB_AutoWideBanners)
            {
                Dictionary<int, int> fanartCount = new Dictionary<int, int>();

                // build a dictionary of series and how many images exist
                IReadOnlyList<TvDB_ImageWideBanner> allBanners = RepoFactory.TvDB_ImageWideBanner.GetAll();
                foreach (TvDB_ImageWideBanner tvBanner in allBanners)
                {
                    if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvBanner.FullImagePath);

                    if (fileExists)
                    {
                        if (fanartCount.ContainsKey(tvBanner.SeriesID))
                            fanartCount[tvBanner.SeriesID] = fanartCount[tvBanner.SeriesID] + 1;
                        else
                            fanartCount[tvBanner.SeriesID] = 1;
                    }
                }

                foreach (TvDB_ImageWideBanner tvBanner in allBanners)
                {
                    if (string.IsNullOrEmpty(tvBanner.FullImagePath)) continue;
                    bool fileExists = File.Exists(tvBanner.FullImagePath);

                    int bannersAvailable = 0;
                    if (fanartCount.ContainsKey(tvBanner.SeriesID))
                        bannersAvailable = fanartCount[tvBanner.SeriesID];

                    if (!fileExists && bannersAvailable < ServerSettings.TvDB_AutoWideBannersAmount)
                    {
                        CommandRequest_DownloadImage cmd =
                            new CommandRequest_DownloadImage(tvBanner.TvDB_ImageWideBannerID,
                                JMMImageType.TvDB_Banner, false);
                        cmd.Save();

                        if (fanartCount.ContainsKey(tvBanner.SeriesID))
                            fanartCount[tvBanner.SeriesID] = fanartCount[tvBanner.SeriesID] + 1;
                        else
                            fanartCount[tvBanner.SeriesID] = 1;
                    }
                }
            }

            // TvDB Episodes

            foreach (TvDB_Episode tvEpisode in RepoFactory.TvDB_Episode.GetAll())
            {
                if (string.IsNullOrEmpty(tvEpisode.FullImagePath)) continue;
                bool fileExists = File.Exists(tvEpisode.FullImagePath);
                if (!fileExists)
                {
                    CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(tvEpisode.TvDB_EpisodeID,
                        JMMImageType.TvDB_Episode, false);
                    cmd.Save();
                }
            }

            // MovieDB Posters
            if (ServerSettings.MovieDB_AutoPosters)
            {
                Dictionary<int, int> postersCount = new Dictionary<int, int>();

                // build a dictionary of series and how many images exist
                IReadOnlyList<MovieDB_Poster> allPosters = RepoFactory.MovieDB_Poster.GetAll();
                foreach (MovieDB_Poster moviePoster in allPosters)
                {
                    if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
                    bool fileExists = File.Exists(moviePoster.FullImagePath);

                    if (fileExists)
                    {
                        if (postersCount.ContainsKey(moviePoster.MovieId))
                            postersCount[moviePoster.MovieId] = postersCount[moviePoster.MovieId] + 1;
                        else
                            postersCount[moviePoster.MovieId] = 1;
                    }
                }

                foreach (MovieDB_Poster moviePoster in allPosters)
                {
                    if (string.IsNullOrEmpty(moviePoster.FullImagePath)) continue;
                    bool fileExists = File.Exists(moviePoster.FullImagePath);

                    int postersAvailable = 0;
                    if (postersCount.ContainsKey(moviePoster.MovieId))
                        postersAvailable = postersCount[moviePoster.MovieId];

                    if (!fileExists && postersAvailable < ServerSettings.MovieDB_AutoPostersAmount)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(
                            moviePoster.MovieDB_PosterID,
                            JMMImageType.MovieDB_Poster, false);
                        cmd.Save();

                        if (postersCount.ContainsKey(moviePoster.MovieId))
                            postersCount[moviePoster.MovieId] = postersCount[moviePoster.MovieId] + 1;
                        else
                            postersCount[moviePoster.MovieId] = 1;
                    }
                }
            }

            // MovieDB Fanart
            if (ServerSettings.MovieDB_AutoFanart)
            {
                Dictionary<int, int> fanartCount = new Dictionary<int, int>();

                // build a dictionary of series and how many images exist
                IReadOnlyList<MovieDB_Fanart> allFanarts = RepoFactory.MovieDB_Fanart.GetAll();
                foreach (MovieDB_Fanart movieFanart in allFanarts)
                {
                    if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
                    bool fileExists = File.Exists(movieFanart.FullImagePath);

                    if (fileExists)
                    {
                        if (fanartCount.ContainsKey(movieFanart.MovieId))
                            fanartCount[movieFanart.MovieId] = fanartCount[movieFanart.MovieId] + 1;
                        else
                            fanartCount[movieFanart.MovieId] = 1;
                    }
                }

                foreach (MovieDB_Fanart movieFanart in RepoFactory.MovieDB_Fanart.GetAll())
                {
                    if (string.IsNullOrEmpty(movieFanart.FullImagePath)) continue;
                    bool fileExists = File.Exists(movieFanart.FullImagePath);

                    int fanartAvailable = 0;
                    if (fanartCount.ContainsKey(movieFanart.MovieId))
                        fanartAvailable = fanartCount[movieFanart.MovieId];

                    if (!fileExists && fanartAvailable < ServerSettings.MovieDB_AutoFanartAmount)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(
                            movieFanart.MovieDB_FanartID,
                            JMMImageType.MovieDB_FanArt, false);
                        cmd.Save();

                        if (fanartCount.ContainsKey(movieFanart.MovieId))
                            fanartCount[movieFanart.MovieId] = fanartCount[movieFanart.MovieId] + 1;
                        else
                            fanartCount[movieFanart.MovieId] = 1;
                    }
                }
            }

            /*
            // Trakt Posters
            if (ServerSettings.Trakt_DownloadPosters)
            {
                foreach (Trakt_ImagePoster traktPoster in RepoFactory.Trakt_ImagePoster.GetAll())
                {
                    if (string.IsNullOrEmpty(traktPoster.FullImagePath)) continue;
                    bool fileExists = File.Exists(traktPoster.FullImagePath);
                    if (!fileExists)
                    {
                        CommandRequest_DownloadImage cmd =
                            new CommandRequest_DownloadImage(traktPoster.Trakt_ImagePosterID,
                                JMMImageType.Trakt_Poster, false);
                        cmd.Save();
                    }
                }
            }

            // Trakt Fanart
            if (ServerSettings.Trakt_DownloadFanart)
            {
                foreach (Trakt_ImageFanart traktFanart in RepoFactory.Trakt_ImageFanart.GetAll())
                {
                    if (string.IsNullOrEmpty(traktFanart.FullImagePath)) continue;
                    bool fileExists = File.Exists(traktFanart.FullImagePath);
                    if (!fileExists)
                    {
                        CommandRequest_DownloadImage cmd =
                            new CommandRequest_DownloadImage(traktFanart.Trakt_ImageFanartID,
                                JMMImageType.Trakt_Fanart, false);
                        cmd.Save();
                    }
                }
            }

            // Trakt Episode
            if (ServerSettings.Trakt_DownloadEpisodes)
            {
                foreach (Trakt_Episode traktEp in RepoFactory.Trakt_Episode.GetAll())
                {
                    if (string.IsNullOrEmpty(traktEp.FullImagePath)) continue;
                    if (!traktEp.TraktID.HasValue) continue; // if it doesn't have a TraktID it means it is old data

                    bool fileExists = File.Exists(traktEp.FullImagePath);
                    if (!fileExists)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktEp.Trakt_EpisodeID,
                            JMMImageType.Trakt_Episode, false);
                        cmd.Save();
                    }
                }
            }
            */

            // AniDB Characters
            if (ServerSettings.AniDB_DownloadCharacters)
            {
                foreach (AniDB_Character chr in RepoFactory.AniDB_Character.GetAll())
                {
                    if (chr.CharID == 75250)
                    {
                        Console.WriteLine("test");
                    }

                    if (string.IsNullOrEmpty(chr.PosterPath)) continue;
                    bool fileExists = File.Exists(chr.PosterPath);
                    if (!fileExists)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(chr.AniDB_CharacterID,
                            JMMImageType.AniDB_Character, false);
                        cmd.Save();
                    }
                }
            }

            // AniDB Creators
            if (ServerSettings.AniDB_DownloadCreators)
            {
                foreach (AniDB_Seiyuu seiyuu in RepoFactory.AniDB_Seiyuu.GetAll())
                {
                    if (string.IsNullOrEmpty(seiyuu.PosterPath)) continue;
                    bool fileExists = File.Exists(seiyuu.PosterPath);
                    if (!fileExists)
                    {
                        CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(seiyuu.AniDB_SeiyuuID,
                            JMMImageType.AniDB_Creator, false);
                        cmd.Save();
                    }
                }
            }
        }
示例#12
0
        public void DownloadAutomaticImages(XmlDocument doc, int seriesID, bool forceDownload)
        {
            List<object> banners = ParseBanners(seriesID, doc);

            int numFanartDownloaded = 0;
            int numPostersDownloaded = 0;
            int numBannersDownloaded = 0;

            // find out how many images we already have locally

            using (var session = DatabaseFactory.SessionFactory.OpenSession())
            {
                ISessionWrapper sessionWrapper = session.Wrap();

                foreach (TvDB_ImageFanart fanart in RepoFactory.TvDB_ImageFanart.GetBySeriesID(sessionWrapper, seriesID))
                {
                    if (!string.IsNullOrEmpty(fanart.FullImagePath) && File.Exists(fanart.FullImagePath))
                        numFanartDownloaded++;
                }

                foreach (TvDB_ImagePoster poster in RepoFactory.TvDB_ImagePoster.GetBySeriesID(sessionWrapper, seriesID))
                {
                    if (!string.IsNullOrEmpty(poster.FullImagePath) && File.Exists(poster.FullImagePath))
                        numPostersDownloaded++;
                }

                foreach (TvDB_ImageWideBanner banner in RepoFactory.TvDB_ImageWideBanner.GetBySeriesID(session, seriesID))
                {
                    if (!string.IsNullOrEmpty(banner.FullImagePath) && File.Exists(banner.FullImagePath))
                        numBannersDownloaded++;
                }
            }

            foreach (object obj in banners)
            {
                if (obj.GetType() == typeof(TvDB_ImageFanart))
                {
                    TvDB_ImageFanart img = obj as TvDB_ImageFanart;
                    if (ServerSettings.TvDB_AutoFanart && numFanartDownloaded < ServerSettings.TvDB_AutoFanartAmount)
                    {
                        bool fileExists = File.Exists(img.FullImagePath);
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageFanartID,
                                JMMImageType.TvDB_FanArt, forceDownload);
                            cmd.Save();
                            numFanartDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoFanartAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.FullImagePath))
                        {
                            RepoFactory.TvDB_ImageFanart.Delete(img.TvDB_ImageFanartID);
                        }
                    }
                }

                if (obj.GetType() == typeof(TvDB_ImagePoster))
                {
                    TvDB_ImagePoster img = obj as TvDB_ImagePoster;
                    if (ServerSettings.TvDB_AutoPosters && numPostersDownloaded < ServerSettings.TvDB_AutoPostersAmount)
                    {
                        bool fileExists = File.Exists(img.FullImagePath);
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImagePosterID,
                                JMMImageType.TvDB_Cover, forceDownload);
                            cmd.Save();
                            numPostersDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoPostersAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.FullImagePath))
                        {
                            RepoFactory.TvDB_ImagePoster.Delete(img.TvDB_ImagePosterID);
                        }
                    }
                }

                if (obj.GetType() == typeof(TvDB_ImageWideBanner))
                {
                    TvDB_ImageWideBanner img = obj as TvDB_ImageWideBanner;
                    if (ServerSettings.TvDB_AutoWideBanners &&
                        numBannersDownloaded < ServerSettings.TvDB_AutoWideBannersAmount)
                    {
                        bool fileExists = File.Exists(img.FullImagePath);
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd =
                                new CommandRequest_DownloadImage(img.TvDB_ImageWideBannerID,
                                    JMMImageType.TvDB_Banner, forceDownload);
                            cmd.Save();
                            numBannersDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoWideBannersAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.FullImagePath))
                        {
                            RepoFactory.TvDB_ImageWideBanner.Delete(img.TvDB_ImageWideBannerID);
                        }
                    }
                }
            }
        }
示例#13
0
		public static List<TraktTVUser> GetFriends()
		{
			List<TraktTVUser> friends = new List<TraktTVUser>();

			try
			{
				string url = string.Format(Constants.TraktTvURLs.URLGetFriends, Constants.TraktTvURLs.APIKey, ServerSettings.Trakt_Username);
				//string url = string.Format(Constants.TraktTvURLs.URLGetFriends, Constants.TraktTvURLs.APIKey, "lwerndly");
				logger.Trace("GetFriends: {0}", url);

				TraktTVPost_GetFriends cmdFriends = new TraktTVPost_GetFriends();
				cmdFriends.Init();

				string json = JSONHelper.Serialize<TraktTVPost_GetFriends>(cmdFriends);
				string jsonResponse = SendData(url, json);
				if (jsonResponse.Trim().Length == 0) return friends;
				friends = JSONHelper.Deserialize<List<TraktTVUser>>(jsonResponse);

				/*string json = Utils.DownloadWebPage(url);

				if (json.Trim().Length == 0) return null;

				friends = JSONHelper.Deserialize<List<TraktTVUser>>(json);*/

				Trakt_ShowRepository repShows = new Trakt_ShowRepository();
				Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
				Trakt_FriendRepository repFriends = new Trakt_FriendRepository();

				foreach (TraktTVUser friend in friends)
				{
					Trakt_Friend traktFriend = repFriends.GetByUsername(friend.username);
					if (traktFriend == null)
					{
						traktFriend = new Trakt_Friend();
						traktFriend.LastAvatarUpdate = DateTime.Now;
					}

					traktFriend.Populate(friend);
					repFriends.Save(traktFriend);

					if (!string.IsNullOrEmpty(traktFriend.FullImagePath))
					{
						bool fileExists = File.Exists(traktFriend.FullImagePath);
						TimeSpan ts = DateTime.Now - traktFriend.LastAvatarUpdate;

						if (!fileExists || ts.TotalHours > 8)
						{
							traktFriend.LastAvatarUpdate = DateTime.Now;
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFriend.Trakt_FriendID, JMMImageType.Trakt_Friend, true);
							cmd.Save();
						}
					}

					foreach (TraktTVWatched wtch in friend.watched)
					{
						if (wtch.episode != null && wtch.show != null)
						{

							Trakt_Show show = repShows.GetByTraktID(wtch.show.TraktID);
							if (show == null)
							{
								show = new Trakt_Show();
								show.Populate(wtch.show);
								repShows.Save(show);
							}

							Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, int.Parse(wtch.episode.season), int.Parse(wtch.episode.number));
							if (episode == null)
								episode = new Trakt_Episode();

							episode.Populate(wtch.episode, show.Trakt_ShowID);
							repEpisodes.Save(episode);

							if (!string.IsNullOrEmpty(episode.FullImagePath))
							{
								bool fileExists = File.Exists(episode.FullImagePath);
								if (!fileExists)
								{
									CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(episode.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
									cmd.Save();
								}
							}
						}
					}
				}

				

				//Contract_Trakt_Friend fr = friends[0].ToContract();

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.GetFriends: " + ex.ToString(), ex);
				return friends;
			}

			return friends;
		}
示例#14
0
		/// <summary>
		/// Updates the followung
		/// 1. Series Info
		/// 2. Episode Info
		/// 3. Episode Images
		/// 4. Fanart, Poster and Wide Banner Images
		/// </summary>
		/// <param name="seriesID"></param>
		/// <param name="forceRefresh"></param>
		public void UpdateAllInfoAndImages(int seriesID, bool forceRefresh, bool downloadImages)
		{
			TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository();
			TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();

			string fileName = string.Format("{0}.xml", ServerSettings.TvDB_Language);

			Dictionary<string, XmlDocument> docSeries = GetFullSeriesInfo(seriesID);
			if (docSeries.ContainsKey(fileName))
			{
				try
				{
					// update the series info
					XmlDocument xmlDoc = docSeries[fileName];
					if (xmlDoc != null)
					{
						TvDB_Series tvSeries = repSeries.GetByTvDBID(seriesID);
						if (tvSeries == null)
							tvSeries = new TvDB_Series();

						tvSeries.PopulateFromSeriesInfo(xmlDoc);
						repSeries.Save(tvSeries);
					}

					if (downloadImages)
					{
						// get all fanart, posters and wide banners
						if (docSeries.ContainsKey("banners.xml"))
						{
							XmlDocument xmlDocBanners = docSeries["banners.xml"];
							if (xmlDocBanners != null)
								DownloadAutomaticImages(xmlDocBanners, seriesID, forceRefresh);
						}
					}

					// update all the episodes and download episode images
					XmlNodeList episodeItems = xmlDoc["Data"].GetElementsByTagName("Episode");
					logger.Trace("Found {0} Episode nodes", episodeItems.Count.ToString());

					List<int> existingEpIds = new List<int>();
					foreach (XmlNode node in episodeItems)
					{
						try
						{
							

							// the episode id
							int id = int.Parse(node["id"].InnerText.Trim());
							existingEpIds.Add(id);

							TvDB_Episode ep = repEpisodes.GetByTvDBID(id);
							if (ep == null)
								ep = new TvDB_Episode();
							ep.Populate(node);
							repEpisodes.Save(ep);

							//BaseConfig.MyAnimeLog.Write("Refreshing episode info for: {0}", ep.ToString());

							if (downloadImages)
							{
								// download the image for this episode
								if (!string.IsNullOrEmpty(ep.Filename))
								{
									bool fileExists = File.Exists(ep.FullImagePath);
									if (!fileExists || (fileExists && forceRefresh))
									{
										CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(ep.TvDB_EpisodeID, JMMImageType.TvDB_Episode, forceRefresh);
										cmd.Save();
									}
								}
							}
						}
						catch (Exception ex)
						{
							logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
						}
					}

					// get all the existing tvdb episodes, to see if any have been deleted
					List<TvDB_Episode> allEps = repEpisodes.GetBySeriesID(seriesID);
					foreach (TvDB_Episode oldEp in allEps)
					{
						if (!existingEpIds.Contains(oldEp.Id))
							repEpisodes.Delete(oldEp.TvDB_EpisodeID);
					}


				}
				catch (Exception ex)
				{
					logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
				}
			}
		}
示例#15
0
		// List of Default priorities for commands
		// Pri 1
		//------
		// Reserved for commands user manually initiates from UI
		//------
		// Pri 2
		//------
		// CommandRequest_GetAnimeHTTP
		//------
		// Pri 3
		//------
		// CommandRequest_ProcessFile
		// CommandRequest_GetFile
		//------
		// Pri 4
		//------
		// CommandRequest_GetUpdated
		// CommandRequest_ReadMediaInfo
        // CommandRequest_GetEpsode
		//------
		// Pri 5
		//------
		// CommandRequest_GetReleaseGroupStatus
		//------
		// Pri 6
		//------
		// CommandRequest_SyncMyList
		// CommandRequest_SyncMyVotes
		//------
		// Pri 7
		//------
		// CommandRequest_GetCalendar
		//------
		// Pri 8
		//------
		// CommandRequest_UpdateMyListFileStatus
		// CommandRequest_GetCharactersCreators
		// CommandRequest_TraktSyncCollection
		// CommandRequest_TvDBUpdateSeriesAndEpisodes
		// CommandRequest_TvDBDownloadImages
		// CommandRequest_TvDBSearchAnime
		// CommandRequest_MovieDBSearchAnime
		// CommandRequest_TraktSearchAnime
		// CommandRequest_MALSearchAnime
		//------
		// Pri 9
		//------
		// CommandRequest_WebCacheSendFileHash
		// CommandRequest_GetReviews
		// CommandRequest_GetReleaseGroup
		// CommandRequest_WebCacheSendXRefFileEpisode
		// CommandRequest_WebCacheDeleteXRefFileEpisode
		// CommandRequest_AddFileToMyList
		// CommandRequest_DeleteFileFromMyList
		// CommandRequest_VoteAnime
		// CommandRequest_WebCacheDeleteXRefAniDBTvDB
		// CommandRequest_WebCacheDeleteXRefAniDBTvDBAll
		// CommandRequest_WebCacheSendXRefAniDBTvDB
		// CommandRequest_WebCacheSendXRefAniDBOther
		// CommandRequest_WebCacheDeleteXRefAniDBOther
		// CommandRequest_WebCacheDeleteXRefAniDBTrakt
		// CommandRequest_WebCacheSendXRefAniDBTrakt
		// CommandRequest_TraktUpdateInfoAndImages
		// CommandRequest_TraktSyncCollectionSeries
		// CommandRequest_TraktShowEpisodeUnseen
		// CommandRequest_DownloadImage
		// CommandRequest_TraktUpdateAllSeries
		// CommandRequest_MALUpdatedWatchedStatus
		// CommandRequest_MALUploadStatusToMAL
		// CommandRequest_MALDownloadStatusFromMAL
		// CommandRequest_WebCacheSendAniDB_File
		// CommandRequest_Azure_SendAnimeFull
		//------
		// Pri 10
		//------
		// CommandRequest_UpdateMylistStats
		// CommandRequest_Azure_SendAnimeXML
		//------
		// Pri 11
		//------
		// CommandRequest_Azure_SendAnimeTitle

		public static ICommandRequest GetCommand(CommandRequest crdb)
		{
			CommandRequestType crt = (CommandRequestType)crdb.CommandType;
			switch (crt)
			{
                case CommandRequestType.Trakt_SyncCollectionSeries:
                    CommandRequest_TraktSyncCollectionSeries cr_CommandRequest_TraktSyncCollectionSeries = new CommandRequest_TraktSyncCollectionSeries();
                    cr_CommandRequest_TraktSyncCollectionSeries.LoadFromDBCommand(crdb);
                    return (ICommandRequest)cr_CommandRequest_TraktSyncCollectionSeries;

                case CommandRequestType.AniDB_GetEpisodeUDP:
                    CommandRequest_GetEpisode cr_CommandRequest_GetEpisode = new CommandRequest_GetEpisode();
                    cr_CommandRequest_GetEpisode.LoadFromDBCommand(crdb);
                    return (ICommandRequest)cr_CommandRequest_GetEpisode;

				case CommandRequestType.Azure_SendAnimeTitle:
					CommandRequest_Azure_SendAnimeTitle cr_CommandRequest_Azure_SendAnimeTitle = new CommandRequest_Azure_SendAnimeTitle();
					cr_CommandRequest_Azure_SendAnimeTitle.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_CommandRequest_Azure_SendAnimeTitle;

				case CommandRequestType.AniDB_GetTitles:
					CommandRequest_GetAniDBTitles cr_CommandRequest_GetAniDBTitles = new CommandRequest_GetAniDBTitles();
					cr_CommandRequest_GetAniDBTitles.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_CommandRequest_GetAniDBTitles;

				case CommandRequestType.Azure_SendAnimeXML:
					CommandRequest_Azure_SendAnimeXML cr_CommandRequest_Azure_SendAnimeXML = new CommandRequest_Azure_SendAnimeXML();
					cr_CommandRequest_Azure_SendAnimeXML.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_CommandRequest_Azure_SendAnimeXML;

				case CommandRequestType.Azure_SendAnimeFull:
					CommandRequest_Azure_SendAnimeFull cr_CommandRequest_Azure_SendAnimeFull = new CommandRequest_Azure_SendAnimeFull();
					cr_CommandRequest_Azure_SendAnimeFull.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_CommandRequest_Azure_SendAnimeFull;

                case CommandRequestType.Azure_SendUserInfo:
                    CommandRequest_Azure_SendUserInfo cr_CommandRequest_Azure_SendUserInfo = new CommandRequest_Azure_SendUserInfo();
                    cr_CommandRequest_Azure_SendUserInfo.LoadFromDBCommand(crdb);
                    return (ICommandRequest)cr_CommandRequest_Azure_SendUserInfo;

				case CommandRequestType.AniDB_UpdateMylistStats:
					CommandRequest_UpdateMylistStats cr_AniDB_UpdateMylistStats = new CommandRequest_UpdateMylistStats();
					cr_AniDB_UpdateMylistStats.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_AniDB_UpdateMylistStats;

				case CommandRequestType.MAL_DownloadWatchedStates:
					CommandRequest_MALDownloadStatusFromMAL cr_MAL_DownloadWatchedStates = new CommandRequest_MALDownloadStatusFromMAL();
					cr_MAL_DownloadWatchedStates.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_MAL_DownloadWatchedStates;

				case CommandRequestType.MAL_UploadWatchedStates:
					CommandRequest_MALUploadStatusToMAL cr_MAL_UploadWatchedStates = new CommandRequest_MALUploadStatusToMAL();
					cr_MAL_UploadWatchedStates.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_MAL_UploadWatchedStates;

				case CommandRequestType.MAL_UpdateStatus:
					CommandRequest_MALUpdatedWatchedStatus cr_MAL_UpdateStatus = new CommandRequest_MALUpdatedWatchedStatus();
					cr_MAL_UpdateStatus.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_MAL_UpdateStatus;

				case CommandRequestType.MAL_SearchAnime:
					CommandRequest_MALSearchAnime cr_MAL_SearchAnime = new CommandRequest_MALSearchAnime();
					cr_MAL_SearchAnime.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_MAL_SearchAnime;

				case CommandRequestType.WebCache_SendXRefAniDBMAL:
					CommandRequest_WebCacheSendXRefAniDBMAL cr_WebCacheSendXRefAniDBMAL = new CommandRequest_WebCacheSendXRefAniDBMAL();
					cr_WebCacheSendXRefAniDBMAL.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_WebCacheSendXRefAniDBMAL;

				case CommandRequestType.WebCache_DeleteXRefAniDBMAL:
					CommandRequest_WebCacheDeleteXRefAniDBMAL cr_WebCacheDeleteXRefAniDBMAL = new CommandRequest_WebCacheDeleteXRefAniDBMAL();
					cr_WebCacheDeleteXRefAniDBMAL.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_WebCacheDeleteXRefAniDBMAL;

				case CommandRequestType.AniDB_GetFileUDP:
					CommandRequest_GetFile cr_AniDB_GetFileUDP = new CommandRequest_GetFile();
					cr_AniDB_GetFileUDP.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_AniDB_GetFileUDP;

				case CommandRequestType.ReadMediaInfo:
					CommandRequest_ReadMediaInfo cr_ReadMediaInfo = new CommandRequest_ReadMediaInfo();
					cr_ReadMediaInfo.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_ReadMediaInfo;

				case CommandRequestType.Trakt_UpdateAllSeries:
					CommandRequest_TraktUpdateAllSeries cr_Trakt_UpdateAllSeries = new CommandRequest_TraktUpdateAllSeries();
					cr_Trakt_UpdateAllSeries.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_Trakt_UpdateAllSeries;

				case CommandRequestType.Trakt_EpisodeCollection:
                    CommandRequest_TraktCollectionEpisode cr_TraktCollectionEpisode = new CommandRequest_TraktCollectionEpisode();
                    cr_TraktCollectionEpisode.LoadFromDBCommand(crdb);
                    return (ICommandRequest)cr_TraktCollectionEpisode;

				case CommandRequestType.Trakt_SyncCollection:
					CommandRequest_TraktSyncCollection cr_Trakt_SyncCollection = new CommandRequest_TraktSyncCollection();
					cr_Trakt_SyncCollection.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_Trakt_SyncCollection;

				case CommandRequestType.Trakt_EpisodeHistory:
					CommandRequest_TraktHistoryEpisode cr_Trakt_EpisodeHistory = new CommandRequest_TraktHistoryEpisode();
					cr_Trakt_EpisodeHistory.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_Trakt_EpisodeHistory;

				case CommandRequestType.Trakt_UpdateInfoImages:
					CommandRequest_TraktUpdateInfoAndImages cr_Trakt_UpdateInfoImages = new CommandRequest_TraktUpdateInfoAndImages();
					cr_Trakt_UpdateInfoImages.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_Trakt_UpdateInfoImages;

				case CommandRequestType.WebCache_SendXRefAniDBTrakt:
					CommandRequest_WebCacheSendXRefAniDBTrakt cr_WebCache_SendXRefAniDBTrakt = new CommandRequest_WebCacheSendXRefAniDBTrakt();
					cr_WebCache_SendXRefAniDBTrakt.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_WebCache_SendXRefAniDBTrakt;

				case CommandRequestType.WebCache_DeleteXRefAniDBTrakt:
					CommandRequest_WebCacheDeleteXRefAniDBTrakt cr_WebCache_DeleteXRefAniDBTrakt = new CommandRequest_WebCacheDeleteXRefAniDBTrakt();
					cr_WebCache_DeleteXRefAniDBTrakt.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_WebCache_DeleteXRefAniDBTrakt;

				case CommandRequestType.Trakt_SearchAnime:
					CommandRequest_TraktSearchAnime cr_Trakt_SearchAnime = new CommandRequest_TraktSearchAnime();
					cr_Trakt_SearchAnime.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_Trakt_SearchAnime;

				case CommandRequestType.MovieDB_SearchAnime:
					CommandRequest_MovieDBSearchAnime cr_MovieDB_SearchAnime = new CommandRequest_MovieDBSearchAnime();
					cr_MovieDB_SearchAnime.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_MovieDB_SearchAnime;

				case CommandRequestType.WebCache_DeleteXRefAniDBOther:
					CommandRequest_WebCacheDeleteXRefAniDBOther cr_SendXRefAniDBOther = new CommandRequest_WebCacheDeleteXRefAniDBOther();
					cr_SendXRefAniDBOther.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_SendXRefAniDBOther;

				case CommandRequestType.WebCache_SendXRefAniDBOther:
					CommandRequest_WebCacheSendXRefAniDBOther cr_WebCacheSendXRefAniDBOther = new CommandRequest_WebCacheSendXRefAniDBOther();
					cr_WebCacheSendXRefAniDBOther.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_WebCacheSendXRefAniDBOther;

				case CommandRequestType.AniDB_DeleteFileUDP:
					CommandRequest_DeleteFileFromMyList cr_AniDB_DeleteFileUDP = new CommandRequest_DeleteFileFromMyList();
					cr_AniDB_DeleteFileUDP.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_AniDB_DeleteFileUDP;

				case CommandRequestType.ImageDownload:
					CommandRequest_DownloadImage cr_ImageDownload = new CommandRequest_DownloadImage();
					cr_ImageDownload.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_ImageDownload;

				case CommandRequestType.WebCache_DeleteXRefAniDBTvDB:
					CommandRequest_WebCacheDeleteXRefAniDBTvDB cr_DeleteXRefAniDBTvDB = new CommandRequest_WebCacheDeleteXRefAniDBTvDB();
					cr_DeleteXRefAniDBTvDB.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_DeleteXRefAniDBTvDB;

				case CommandRequestType.WebCache_SendXRefAniDBTvDB:
					CommandRequest_WebCacheSendXRefAniDBTvDB cr_SendXRefAniDBTvDB = new CommandRequest_WebCacheSendXRefAniDBTvDB();
					cr_SendXRefAniDBTvDB.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_SendXRefAniDBTvDB;


				case CommandRequestType.TvDB_SearchAnime:
					CommandRequest_TvDBSearchAnime cr_TvDB_SearchAnime = new CommandRequest_TvDBSearchAnime();
					cr_TvDB_SearchAnime.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_TvDB_SearchAnime;

				case CommandRequestType.TvDB_DownloadImages:
					CommandRequest_TvDBDownloadImages cr_TvDB_DownloadImages = new CommandRequest_TvDBDownloadImages();
					cr_TvDB_DownloadImages.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_TvDB_DownloadImages;

				case CommandRequestType.TvDB_SeriesEpisodes:
					CommandRequest_TvDBUpdateSeriesAndEpisodes cr_TvDB_Episodes = new CommandRequest_TvDBUpdateSeriesAndEpisodes();
					cr_TvDB_Episodes.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_TvDB_Episodes;

				case CommandRequestType.AniDB_SyncVotes:
					CommandRequest_SyncMyVotes cr_SyncVotes = new CommandRequest_SyncMyVotes();
					cr_SyncVotes.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_SyncVotes;

				case CommandRequestType.AniDB_VoteAnime:
					CommandRequest_VoteAnime cr_VoteAnime = new CommandRequest_VoteAnime();
					cr_VoteAnime.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_VoteAnime;

				case CommandRequestType.AniDB_GetCalendar:
					CommandRequest_GetCalendar cr_GetCalendar = new CommandRequest_GetCalendar();
					cr_GetCalendar.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_GetCalendar;

				case CommandRequestType.AniDB_GetReleaseGroup:
					CommandRequest_GetReleaseGroup cr_GetReleaseGroup = new CommandRequest_GetReleaseGroup();
					cr_GetReleaseGroup.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_GetReleaseGroup;

				case CommandRequestType.AniDB_GetAnimeHTTP:
					CommandRequest_GetAnimeHTTP cr_geth = new CommandRequest_GetAnimeHTTP();
					cr_geth.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_geth;

				case CommandRequestType.AniDB_GetReleaseGroupStatus:
					CommandRequest_GetReleaseGroupStatus cr_GetReleaseGroupStatus = new CommandRequest_GetReleaseGroupStatus();
					cr_GetReleaseGroupStatus.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_GetReleaseGroupStatus;

				case CommandRequestType.HashFile:
					CommandRequest_HashFile cr_HashFile = new CommandRequest_HashFile();
					cr_HashFile.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_HashFile;

				case CommandRequestType.ProcessFile:
					CommandRequest_ProcessFile cr_pf = new CommandRequest_ProcessFile();
					cr_pf.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_pf;

				case CommandRequestType.AniDB_AddFileUDP:
					CommandRequest_AddFileToMyList cr_af = new CommandRequest_AddFileToMyList();
					cr_af.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_af;

				case CommandRequestType.AniDB_UpdateWatchedUDP:
					CommandRequest_UpdateMyListFileStatus cr_umlf = new CommandRequest_UpdateMyListFileStatus();
					cr_umlf.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_umlf;

				case CommandRequestType.WebCache_DeleteXRefFileEpisode:
					CommandRequest_WebCacheDeleteXRefFileEpisode cr_DeleteXRefFileEpisode = new CommandRequest_WebCacheDeleteXRefFileEpisode();
					cr_DeleteXRefFileEpisode.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_DeleteXRefFileEpisode;

				case CommandRequestType.WebCache_SendXRefFileEpisode:
					CommandRequest_WebCacheSendXRefFileEpisode cr_SendXRefFileEpisode = new CommandRequest_WebCacheSendXRefFileEpisode();
					cr_SendXRefFileEpisode.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_SendXRefFileEpisode;
					
				case CommandRequestType.AniDB_GetReviews:
					CommandRequest_GetReviews cr_GetReviews = new CommandRequest_GetReviews();
					cr_GetReviews.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_GetReviews;

				case CommandRequestType.AniDB_GetUpdated:
					CommandRequest_GetUpdated cr_GetUpdated = new CommandRequest_GetUpdated();
					cr_GetUpdated.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_GetUpdated;

				case CommandRequestType.AniDB_SyncMyList:
					CommandRequest_SyncMyList cr_SyncMyList = new CommandRequest_SyncMyList();
					cr_SyncMyList.LoadFromDBCommand(crdb);
					return (ICommandRequest)cr_SyncMyList;

                case CommandRequestType.Refresh_AnimeStats:
                    CommandRequest_RefreshAnime cr_refreshAnime=new CommandRequest_RefreshAnime();
                    cr_refreshAnime.LoadFromDBCommand(crdb);
			        return cr_refreshAnime;
			}

			return null;
		}
示例#16
0
        public static void DownloadAllImages(string traktID)
        {
            try
            {
                //now download the images
                Trakt_ShowRepository repShow = new Trakt_ShowRepository();
                Trakt_Show show = repShow.GetByTraktSlug(traktID);
                if (show == null) return;

                if (ServerSettings.Trakt_DownloadFanart)
                {
                    //download the fanart image for the show
                    Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
                    Trakt_ImageFanart fanart = repFanart.GetByShowIDAndSeason(show.Trakt_ShowID, 1);
                    if (fanart != null)
                    {
                        if (!string.IsNullOrEmpty(fanart.FullImagePath))
                        {
                            if (!File.Exists(fanart.FullImagePath))
                            {
                                CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(fanart.Trakt_ImageFanartID, JMMImageType.Trakt_Fanart, false);
                                cmd.Save();
                            }
                        }
                    }
                }

                // download the posters for seasons
                Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();
                foreach (Trakt_Season season in show.Seasons)
                {
                    if (ServerSettings.Trakt_DownloadPosters)
                    {
                        Trakt_ImagePoster poster = repPosters.GetByShowIDAndSeason(season.Trakt_ShowID, season.Season);
                        if (poster != null)
                        {
                            if (!string.IsNullOrEmpty(poster.FullImagePath))
                            {
                                if (!File.Exists(poster.FullImagePath))
                                {
                                    CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(poster.Trakt_ImagePosterID, JMMImageType.Trakt_Poster, false);
                                    cmd.Save();
                                }
                            }
                        }
                    }

                    if (ServerSettings.Trakt_DownloadEpisodes)
                    {
                        // download the screenshots for episodes
                        foreach (Trakt_Episode ep in season.Episodes)
                        {
                            if (!string.IsNullOrEmpty(ep.FullImagePath))
                            {
                                if (!File.Exists(ep.FullImagePath))
                                {
                                    CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(ep.Trakt_EpisodeID, JMMImageType.Trakt_Episode, false);
                                    cmd.Save();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.UpdateAllInfoAndImages: " + ex.ToString(), ex);
            }
        }
示例#17
0
		public static List<TraktTV_ShoutGet> GetShowShouts(ISession session, int animeID)
		{
			List<TraktTV_ShoutGet> shouts = null;
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
					return null;

				CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository();
				CrossRef_AniDB_Trakt traktXRef = repXrefTrakt.GetByAnimeID(session, animeID);
				if (traktXRef == null) return null;

				string url = string.Format(Constants.TraktTvURLs.URLGetShowShouts, Constants.TraktTvURLs.APIKey, traktXRef.TraktID);
				logger.Trace("GetShowShouts: {0}", url);

				// Search for a series
				string json = Utils.DownloadWebPage(url);

				if (json.Trim().Length == 0) return new List<TraktTV_ShoutGet>();

				shouts = JSONHelper.Deserialize<List<TraktTV_ShoutGet>>(json);

				Trakt_FriendRepository repFriends = new Trakt_FriendRepository();
				foreach (TraktTV_ShoutGet shout in shouts)
				{
					Trakt_Friend traktFriend = repFriends.GetByUsername(session, shout.user.username);
					if (traktFriend == null)
					{
						traktFriend = new Trakt_Friend();
						traktFriend.LastAvatarUpdate = DateTime.Now;
					}

					traktFriend.Populate(shout.user);
					repFriends.Save(traktFriend);

					if (!string.IsNullOrEmpty(traktFriend.FullImagePath))
					{
						bool fileExists = File.Exists(traktFriend.FullImagePath);
						TimeSpan ts = DateTime.Now - traktFriend.LastAvatarUpdate;

						if (!fileExists || ts.TotalHours > 8)
						{
							traktFriend.LastAvatarUpdate = DateTime.Now;
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFriend.Trakt_FriendID, JMMImageType.Trakt_Friend, true);
							cmd.Save(session);
						}
					}
				}

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.GetShowShouts: " + ex.ToString(), ex);
			}

			return shouts;
		}