Beispiel #1
0
        public static void SaveExtendedShowInfoV2(TraktV2ShowExtended tvshow, List<TraktV2Season> seasons)
        {
            try
            {
                // save this data to the DB for use later
                Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Trakt_Show show = repShows.GetByTraktSlug(tvshow.ids.slug);
                if (show == null)
                    show = new Trakt_Show();

                show.Populate(tvshow);
                repShows.Save(show);

                if (tvshow.images != null && tvshow.images.fanart != null)
                {
                    if (!string.IsNullOrEmpty(tvshow.images.fanart.full))
                    {
                        Trakt_ImageFanart fanart = repFanart.GetByShowIDAndSeason(show.Trakt_ShowID, 1);
                        if (fanart == null)
                        {
                            fanart = new Trakt_ImageFanart();
                            fanart.Enabled = 0;
                        }

                        fanart.ImageURL = tvshow.images.fanart.full;
                        fanart.Season = 1;
                        fanart.Trakt_ShowID = show.Trakt_ShowID;
                        repFanart.Save(fanart);
                    }
                }

                // save the seasons
                Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
                Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
                Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();

                // delete episodes if they no longer exist on Trakt
                if (seasons.Count > 0)
                {
                    foreach (Trakt_Episode epTemp in repEpisodes.GetByShowID(show.Trakt_ShowID))
                    {
                        TraktV2Episode ep = null;
                        TraktV2Season sea = seasons.FirstOrDefault(x => x.number == epTemp.Season);
                        if (sea != null)
                            ep = sea.episodes.FirstOrDefault(x => x.number == epTemp.EpisodeNumber);

                        // if the episode is null, it means it doesn't exist on Trakt, so we should delete it
                        if (ep == null)
                            repEpisodes.Delete(epTemp.Trakt_EpisodeID);
                    }
                }

                foreach (TraktV2Season sea in seasons)
                {
                    Trakt_Season season = repSeasons.GetByShowIDAndSeason(show.Trakt_ShowID, sea.number);
                    if (season == null)
                        season = new Trakt_Season();

                    season.Season = sea.number;
                    season.URL = string.Format(TraktURIs.WebsiteSeason, show.TraktID, sea.number);
                    season.Trakt_ShowID = show.Trakt_ShowID;
                    repSeasons.Save(season);

                    if (sea.images != null && sea.images.poster != null)
                    {
                        if (!string.IsNullOrEmpty(sea.images.poster.full))
                        {
                            Trakt_ImagePoster poster = repPosters.GetByShowIDAndSeason(show.Trakt_ShowID, season.Season);
                            if (poster == null)
                            {
                                poster = new Trakt_ImagePoster();
                                poster.Enabled = 0;
                            }

                            poster.ImageURL = sea.images.poster.full;
                            poster.Season = season.Season;
                            poster.Trakt_ShowID = show.Trakt_ShowID;
                            repPosters.Save(poster);
                        }
                    }

                    if (sea.episodes != null)
                    {
                        foreach (TraktV2Episode ep in sea.episodes)
                        {
                            Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, ep.season, ep.number);
                            if (episode == null)
                                episode = new Trakt_Episode();

                            Console.Write(ep.ids.trakt);

                            if (ep.images.screenshot != null)
                                episode.EpisodeImage = ep.images.screenshot.full;
                            else
                                episode.EpisodeImage = string.Empty;

                            episode.TraktID = ep.ids.TraktID;
                            episode.EpisodeNumber = ep.number;
                            episode.Overview = string.Empty; // this is now part of a separate API call for V2, we get this info from TvDB anyway
                            episode.Season = ep.season;
                            episode.Title = ep.title;
                            episode.URL = string.Format(TraktURIs.WebsiteEpisode, show.TraktID, ep.season, ep.number);
                            episode.Trakt_ShowID = show.Trakt_ShowID;
                            repEpisodes.Save(episode);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.SaveExtendedShowInfo: " + ex.ToString(), ex);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public static void RemoveTraktDBEntries(Trakt_Show show)
        {
            Trakt_ShowRepository repShows = new Trakt_ShowRepository();
            CrossRef_AniDB_TraktV2Repository repXRefs = new CrossRef_AniDB_TraktV2Repository();
            Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
            Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
            Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
            Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();

            // this means Trakt has no record of this slug.
            // 1. Delete any cross ref links
            foreach (CrossRef_AniDB_TraktV2 xref in repXRefs.GetByTraktID(show.TraktID))
                repXRefs.Delete(xref.CrossRef_AniDB_TraktV2ID);

            // 2. Delete default image links

            // 3. Delete episodes
            foreach (Trakt_Episode epTemp in repEpisodes.GetByShowID(show.Trakt_ShowID))
                repEpisodes.Delete(epTemp.Trakt_EpisodeID);

            // 4. Delete fanart and posters
            foreach (Trakt_ImageFanart fanart in repFanart.GetByShowID(show.Trakt_ShowID))
                repFanart.Delete(fanart.Trakt_ImageFanartID);

            foreach (Trakt_ImagePoster poster in repPosters.GetByShowID(show.Trakt_ShowID))
                repPosters.Delete(poster.Trakt_ImagePosterID);

            // 5. Delete seasons
            foreach (Trakt_Season season in repSeasons.GetByShowID(show.Trakt_ShowID))
                repSeasons.Delete(season.Trakt_SeasonID);

            // 6. Delete the show
            repShows.Delete(show.Trakt_ShowID);
        }
Beispiel #4
0
        public Contract_AniDB_AnimeCrossRefs GetCrossRefDetails(int animeID)
        {
            Contract_AniDB_AnimeCrossRefs result = new Contract_AniDB_AnimeCrossRefs();
            result.AnimeID = animeID;

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                    if (anime == null) return result;

                    TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                    TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
                    TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();

                    // TvDB
                    foreach (CrossRef_AniDB_TvDBV2 xref in anime.GetCrossRefTvDBV2())
                    {
                        result.CrossRef_AniDB_TvDB.Add(xref.ToContract());

                        TvDB_Series ser = repSeries.GetByTvDBID(session, xref.TvDBID);
                        if (ser != null)
                            result.TvDBSeries.Add(ser.ToContract());

                        foreach (TvDB_Episode ep in anime.GetTvDBEpisodes())
                            result.TvDBEpisodes.Add(ep.ToContract());

                        foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImageFanarts.Add(fanart.ToContract());

                        foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImagePosters.Add(poster.ToContract());

                        foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(xref.TvDBID))
                            result.TvDBImageWideBanners.Add(banner.ToContract());

                    }

                    // Trakt

                    Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
                    Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                    Trakt_ShowRepository repTrakt = new Trakt_ShowRepository();

                    foreach (CrossRef_AniDB_TraktV2 xref in anime.GetCrossRefTraktV2())
                    {
                        result.CrossRef_AniDB_Trakt.Add(xref.ToContract());

                        Trakt_Show show = repTrakt.GetByTraktSlug(session, xref.TraktID);
                        if (show != null)
                        {
                            result.TraktShows.Add(show.ToContract());

                            foreach (Trakt_ImageFanart fanart in repTraktFanart.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImageFanarts.Add(fanart.ToContract());

                            foreach (Trakt_ImagePoster poster in repTraktPosters.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImagePosters.Add(poster.ToContract());
                        }
                    }

                    // MovieDB
                    CrossRef_AniDB_Other xrefMovie = anime.GetCrossRefMovieDB();
                    if (xrefMovie == null)
                        result.CrossRef_AniDB_MovieDB = null;
                    else
                        result.CrossRef_AniDB_MovieDB = xrefMovie.ToContract();

                    MovieDB_Movie movie = anime.GetMovieDBMovie();
                    if (movie == null)
                        result.MovieDBMovie = null;
                    else
                        result.MovieDBMovie = movie.ToContract();

                    foreach (MovieDB_Fanart fanart in anime.GetMovieDBFanarts())
                    {
                        if (fanart.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBFanarts.Add(fanart.ToContract());
                    }

                    foreach (MovieDB_Poster poster in anime.GetMovieDBPosters())
                    {
                        if (poster.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBPosters.Add(poster.ToContract());
                    }

                    // MAL
                    List<CrossRef_AniDB_MAL> xrefMAL = anime.GetCrossRefMAL();
                    if (xrefMAL == null)
                        result.CrossRef_AniDB_MAL = null;
                    else
                    {
                        result.CrossRef_AniDB_MAL = new List<Contract_CrossRef_AniDB_MAL>();
                        foreach (CrossRef_AniDB_MAL xrefTemp in xrefMAL)
                            result.CrossRef_AniDB_MAL.Add(xrefTemp.ToContract());
                    }

                }
                return result;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return result;
            }
        }
		public System.IO.Stream GetImage(string ImageType, string ImageID)
		{
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
			TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository();
			TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
			TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository();

			MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
			MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();

			Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
			Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
			Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
			Trakt_FriendRepository repTraktFriends = new Trakt_FriendRepository();

			JMMImageType imageType = (JMMImageType)int.Parse(ImageType);

			switch (imageType)
			{
				case JMMImageType.AniDB_Cover:

					AniDB_Anime anime = repAnime.GetByAnimeID(int.Parse(ImageID));
					if (anime == null) return null;

					if (File.Exists(anime.PosterPath))
					{
						FileStream fs = File.OpenRead(anime.PosterPath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
						return null;
					}

				case JMMImageType.AniDB_Character:

					AniDB_CharacterRepository repChar = new AniDB_CharacterRepository();
					AniDB_Character chr = repChar.GetByID(int.Parse(ImageID));
					if (chr == null) return null;

					if (File.Exists(chr.PosterPath))
					{
						FileStream fs = File.OpenRead(chr.PosterPath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
						return null;
					}

				case JMMImageType.AniDB_Creator:

					AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
					AniDB_Seiyuu creator = repCreator.GetByID(int.Parse(ImageID));
					if (creator == null) return null;

					if (File.Exists(creator.PosterPath))
					{
						FileStream fs = File.OpenRead(creator.PosterPath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
						return null;
					}

				case JMMImageType.TvDB_Cover:

					TvDB_ImagePoster poster = repPosters.GetByID(int.Parse(ImageID));
					if (poster == null) return null;

					if (File.Exists(poster.FullImagePath))
					{
						FileStream fs = File.OpenRead(poster.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_Banner:

					TvDB_ImageWideBanner wideBanner = repWideBanners.GetByID(int.Parse(ImageID));
					if (wideBanner == null) return null;

					if (File.Exists(wideBanner.FullImagePath))
					{
						FileStream fs = File.OpenRead(wideBanner.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_Episode:

					TvDB_Episode ep = repEpisodes.GetByID(int.Parse(ImageID));
					if (ep == null) return null;

					if (File.Exists(ep.FullImagePath))
					{
						FileStream fs = File.OpenRead(ep.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_FanArt:

					TvDB_ImageFanart fanart = repFanart.GetByID(int.Parse(ImageID));
					if (fanart == null) return null;

					if (File.Exists(fanart.FullImagePath))
					{
						FileStream fs = File.OpenRead(fanart.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
						return null;
					}

				case JMMImageType.MovieDB_Poster:

					MovieDB_Poster mPoster = repMoviePosters.GetByID(int.Parse(ImageID));
					if (mPoster == null) return null;

					// now find only the original size
					mPoster = repMoviePosters.GetByOnlineID(mPoster.ImageID, Constants.MovieDBImageSize.Original);
					if (mPoster == null) return null;

					if (File.Exists(mPoster.FullImagePath))
					{
						FileStream fs = File.OpenRead(mPoster.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
						return null;
					}

				case JMMImageType.MovieDB_FanArt:

					MovieDB_Fanart mFanart = repMovieFanart.GetByID(int.Parse(ImageID));
					if (mFanart == null) return null;

					mFanart = repMovieFanart.GetByOnlineID(mFanart.ImageID, Constants.MovieDBImageSize.Original);
					if (mFanart == null) return null;

					if (File.Exists(mFanart.FullImagePath))
					{
						FileStream fs = File.OpenRead(mFanart.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Fanart:

					Trakt_ImageFanart tFanart = repTraktFanart.GetByID(int.Parse(ImageID));
					if (tFanart == null) return null;

					if (File.Exists(tFanart.FullImagePath))
					{
						FileStream fs = File.OpenRead(tFanart.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Friend:


					Trakt_Friend tFriend = repTraktFriends.GetByID(int.Parse(ImageID));
					if (tFriend == null) return null;

					if (File.Exists(tFriend.FullImagePath))
					{
						FileStream fs = File.OpenRead(tFriend.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find Trakt_Friend image: {0}", tFriend.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_ActivityScrobble:
				case JMMImageType.Trakt_ShoutUser:


					Trakt_Friend tFriendScrobble = repTraktFriends.GetByID(int.Parse(ImageID));
					if (tFriendScrobble == null) return null;

					if (File.Exists(tFriendScrobble.FullImagePath))
					{
						FileStream fs = File.OpenRead(tFriendScrobble.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find Trakt_ActivityScrobble image: {0}", tFriendScrobble.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Poster:

					Trakt_ImagePoster tPoster = repTraktPosters.GetByID(int.Parse(ImageID));
					if (tPoster == null) return null;

					if (File.Exists(tPoster.FullImagePath))
					{
						FileStream fs = File.OpenRead(tPoster.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Episode:
				case JMMImageType.Trakt_WatchedEpisode:

					Trakt_Episode tEpisode = repTraktEpisodes.GetByID(int.Parse(ImageID));
					if (tEpisode == null) return null;

					if (File.Exists(tEpisode.FullImagePath))
					{
						FileStream fs = File.OpenRead(tEpisode.FullImagePath);
						WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
						return fs;
					}
					else
					{
						logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
						return null;
					}

				default:

					return null;
			}



			
		}
Beispiel #6
0
        public string EnableDisableImage(bool enabled, int imageID, int imageType)
        {
            try
            {
                JMMImageType imgType = (JMMImageType)imageType;

                switch (imgType)
                {
                    case JMMImageType.AniDB_Cover:

                        AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                        AniDB_Anime anime = repAnime.GetByAnimeID(imageID);
                        if (anime == null) return "Could not find anime";

                        anime.ImageEnabled = enabled ? 1 : 0;
                        repAnime.Save(anime);

                        break;

                    case JMMImageType.TvDB_Banner:

                        TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();
                        TvDB_ImageWideBanner banner = repBanners.GetByID(imageID);

                        if (banner == null) return "Could not find image";

                        banner.Enabled = enabled ? 1 : 0;
                        repBanners.Save(banner);

                        break;

                    case JMMImageType.TvDB_Cover:

                        TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
                        TvDB_ImagePoster poster = repPosters.GetByID(imageID);

                        if (poster == null) return "Could not find image";

                        poster.Enabled = enabled ? 1 : 0;
                        repPosters.Save(poster);

                        break;

                    case JMMImageType.TvDB_FanArt:

                        TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                        TvDB_ImageFanart fanart = repFanart.GetByID(imageID);

                        if (fanart == null) return "Could not find image";

                        fanart.Enabled = enabled ? 1 : 0;
                        repFanart.Save(fanart);

                        break;

                    case JMMImageType.MovieDB_Poster:

                        MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                        MovieDB_Poster moviePoster = repMoviePosters.GetByID(imageID);

                        if (moviePoster == null) return "Could not find image";

                        moviePoster.Enabled = enabled ? 1 : 0;
                        repMoviePosters.Save(moviePoster);

                        break;

                    case JMMImageType.MovieDB_FanArt:

                        MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();
                        MovieDB_Fanart movieFanart = repMovieFanart.GetByID(imageID);

                        if (movieFanart == null) return "Could not find image";

                        movieFanart.Enabled = enabled ? 1 : 0;
                        repMovieFanart.Save(movieFanart);

                        break;

                    case JMMImageType.Trakt_Poster:

                        Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                        Trakt_ImagePoster traktPoster = repTraktPosters.GetByID(imageID);

                        if (traktPoster == null) return "Could not find image";

                        traktPoster.Enabled = enabled ? 1 : 0;
                        repTraktPosters.Save(traktPoster);

                        break;

                    case JMMImageType.Trakt_Fanart:

                        Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
                        Trakt_ImageFanart traktFanart = repTraktFanart.GetByID(imageID);

                        if (traktFanart == null) return "Could not find image";

                        traktFanart.Enabled = enabled ? 1 : 0;
                        repTraktFanart.Save(traktFanart);

                        break;
                }

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Beispiel #7
0
        public List<Contract_Trakt_ImagePoster> GetAllTraktPosters(int? traktShowID)
        {
            List<Contract_Trakt_ImagePoster> allImages = new List<Contract_Trakt_ImagePoster>();
            try
            {
                Trakt_ImagePosterRepository repImages = new Trakt_ImagePosterRepository();
                List<Trakt_ImagePoster> allPosters = null;
                if (traktShowID.HasValue)
                    allPosters = repImages.GetByShowID(traktShowID.Value);
                else
                    allPosters = repImages.GetAll();

                foreach (Trakt_ImagePoster img in allPosters)
                    allImages.Add(img.ToContract());

                return allImages;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return allImages;
            }
        }
Beispiel #8
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_DownloadImage: {0}", EntityID);
            string downloadURL = "";
            try
            {
                ImageDownloadRequest req = null;
                switch (EntityTypeEnum)
                {
                    case JMMImageType.AniDB_Cover:
                        AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                        AniDB_Anime anime = repAnime.GetByID(EntityID);
                        if (anime == null) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, anime, ForceDownload);
                        break;

                    case JMMImageType.TvDB_Episode:

                        TvDB_EpisodeRepository repTvEp = new TvDB_EpisodeRepository();
                        TvDB_Episode ep = repTvEp.GetByID(EntityID);
                        if (ep == null) return;
                        if (string.IsNullOrEmpty(ep.Filename)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, ep, ForceDownload);
                        break;

                    case JMMImageType.TvDB_FanArt:

                        TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                        TvDB_ImageFanart fanart = repFanart.GetByID(EntityID);
                        if (fanart == null) return;
                        if (string.IsNullOrEmpty(fanart.BannerPath)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, fanart, ForceDownload);
                        break;

                    case JMMImageType.TvDB_Cover:

                        TvDB_ImagePosterRepository repPoster = new TvDB_ImagePosterRepository();
                        TvDB_ImagePoster poster = repPoster.GetByID(EntityID);
                        if (poster == null) return;
                        if (string.IsNullOrEmpty(poster.BannerPath)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, poster, ForceDownload);
                        break;

                    case JMMImageType.TvDB_Banner:

                        TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();
                        TvDB_ImageWideBanner wideBanner = repBanners.GetByID(EntityID);
                        if (wideBanner == null) return;
                        if (string.IsNullOrEmpty(wideBanner.BannerPath)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, wideBanner, ForceDownload);
                        break;

                    case JMMImageType.MovieDB_Poster:

                        MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                        MovieDB_Poster moviePoster = repMoviePosters.GetByID(EntityID);
                        if (moviePoster == null) return;
                        if (string.IsNullOrEmpty(moviePoster.URL)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, moviePoster, ForceDownload);
                        break;

                    case JMMImageType.MovieDB_FanArt:

                        MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();
                        MovieDB_Fanart movieFanart = repMovieFanart.GetByID(EntityID);
                        if (movieFanart == null) return;
                        if (string.IsNullOrEmpty(movieFanart.URL)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, movieFanart, ForceDownload);
                        break;

                    case JMMImageType.Trakt_Poster:

                        Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                        Trakt_ImagePoster traktPoster = repTraktPosters.GetByID(EntityID);
                        if (traktPoster == null) return;
                        if (string.IsNullOrEmpty(traktPoster.ImageURL)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, traktPoster, ForceDownload);
                        break;

                    case JMMImageType.Trakt_Fanart:

                        Trakt_ImageFanartRepository repTraktFanarts = new Trakt_ImageFanartRepository();
                        Trakt_ImageFanart traktFanart = repTraktFanarts.GetByID(EntityID);
                        if (traktFanart == null) return;
                        if (string.IsNullOrEmpty(traktFanart.ImageURL)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, traktFanart, ForceDownload);
                        break;

                    case JMMImageType.Trakt_Friend:

                        Trakt_FriendRepository repFriends = new Trakt_FriendRepository();
                        Trakt_Friend friend = repFriends.GetByID(EntityID);
                        if (friend == null) return;
                        if (string.IsNullOrEmpty(friend.Avatar)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, friend, ForceDownload);
                        break;

                    case JMMImageType.Trakt_Episode:

                        Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
                        Trakt_Episode traktEp = repTraktEpisodes.GetByID(EntityID);
                        if (traktEp == null) return;
                        if (string.IsNullOrEmpty(traktEp.EpisodeImage)) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, traktEp, ForceDownload);
                        break;

                    case JMMImageType.AniDB_Character:
                        AniDB_CharacterRepository repChars = new AniDB_CharacterRepository();
                        AniDB_Character chr = repChars.GetByID(EntityID);
                        if (chr == null) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, chr, ForceDownload);
                        break;

                    case JMMImageType.AniDB_Creator:
                        AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
                        AniDB_Seiyuu creator = repCreator.GetByID(EntityID);
                        if (creator == null) return;

                        req = new ImageDownloadRequest(EntityTypeEnum, creator, ForceDownload);
                        break;
                }

                if (req == null) return;

                List<string> fileNames = new List<string>();
                List<string> downloadURLs = new List<string>();

                string fileNameTemp = GetFileName(req, false);
                string downloadURLTemp = GetFileURL(req, false);

                fileNames.Add(fileNameTemp);
                downloadURLs.Add(downloadURLTemp);

                if (req.ImageType == JMMImageType.TvDB_FanArt)
                {
                    fileNameTemp = GetFileName(req, true);
                    downloadURLTemp = GetFileURL(req, true);

                    fileNames.Add(fileNameTemp);
                    downloadURLs.Add(downloadURLTemp);
                }

                for (int i = 0; i < fileNames.Count; i++)
                {
                    string fileName = fileNames[i];
                    downloadURL = downloadURLs[i];

                    bool downloadImage = true;
                    bool fileExists = File.Exists(fileName);

                    if (fileExists)
                    {
                        if (!req.ForceDownload)
                            downloadImage = false;
                        else
                            downloadImage = true;
                    }
                    else
                        downloadImage = true;

                    if (downloadImage)
                    {
                        string tempName = Path.Combine(ImageUtils.GetImagesTempFolder(), Path.GetFileName(fileName));
                        if (File.Exists(tempName)) File.Delete(tempName);

                        try
                        {
                            if (fileExists) File.Delete(fileName);
                        }
                        catch (Exception ex)
                        {
                            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                            string msg = string.Format(JMMServer.Properties.Resources.Command_DeleteError, fileName, ex.Message);
                            logger.Warn(msg);
                            return;
                        }

                        // download image
                        using (WebClient client = new WebClient())
                        {
                            client.Headers.Add("user-agent", "JMM");
                            //OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                            //BaseConfig.MyAnimeLog.Write("ProcessImages: Download: {0}  *** to ***  {1}", req.URL, fullName);
                            if (downloadURL.Length > 0)
                            {
                                client.DownloadFile(downloadURL, tempName);

                                string extension = "";
                                string contentType = client.ResponseHeaders["Content-type"].ToLower();
                                if (contentType.IndexOf("gif") >= 0) extension = ".gif";
                                if (contentType.IndexOf("jpg") >= 0) extension = ".jpg";
                                if (contentType.IndexOf("jpeg") >= 0) extension = ".jpg";
                                if (contentType.IndexOf("bmp") >= 0) extension = ".bmp";
                                if (contentType.IndexOf("png") >= 0) extension = ".png";
                                if (extension.Length > 0)
                                {
                                    string newFile = Path.ChangeExtension(tempName, extension);
                                    if (!newFile.ToLower().Equals(tempName.ToLower()))
                                    {
                                        try
                                        {
                                            System.IO.File.Delete(newFile);
                                        }
                                        catch
                                        {
                                            //BaseConfig.MyAnimeLog.Write("DownloadedImage:Download() Delete failed:{0}", newFile);
                                        }
                                        System.IO.File.Move(tempName, newFile);
                                        tempName = newFile;
                                    }
                                }
                            }
                        }

                        // move the file to it's final location
                        // check that the final folder exists
                        string fullPath = Path.GetDirectoryName(fileName);
                        if (!Directory.Exists(fullPath))
                            Directory.CreateDirectory(fullPath);

                        System.IO.File.Move(tempName, fileName);
                        logger.Info("Image downloaded: {0}", fileName);
                    }
                }

            }
            catch (Exception ex)
            {
                logger.Warn("Error processing CommandRequest_DownloadImage: {0} ({1}) - {2}", downloadURL, EntityID, ex.Message);
                return;
            }
        }
		public byte[] GetImage(string entityID, int entityType, bool thumnbnailOnly)
		{
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
			TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository();
			TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
			TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository();

			MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
			MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();

			Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
			Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
			Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
			Trakt_FriendRepository repTraktFriends = new Trakt_FriendRepository();

			JMMImageType imageType = (JMMImageType)entityType;

			switch (imageType)
			{
				case JMMImageType.AniDB_Cover:

					AniDB_Anime anime = repAnime.GetByAnimeID(int.Parse(entityID));
					if (anime == null) return null;

					if (File.Exists(anime.PosterPath))
						return File.ReadAllBytes(anime.PosterPath);
					else
					{
						logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
						return null;
					}

				case JMMImageType.AniDB_Character:

					AniDB_CharacterRepository repChar = new AniDB_CharacterRepository();
					AniDB_Character chr = repChar.GetByID(int.Parse(entityID));
					if (chr == null) return null;

					if (File.Exists(chr.PosterPath))
						return File.ReadAllBytes(chr.PosterPath);
					else
					{
						logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
						return null;
					}

				case JMMImageType.AniDB_Creator:

					AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
					AniDB_Seiyuu creator = repCreator.GetByID(int.Parse(entityID));
					if (creator == null) return null;

					if (File.Exists(creator.PosterPath))
						return File.ReadAllBytes(creator.PosterPath);
					else
					{
						logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
						return null;
					}

				case JMMImageType.TvDB_Cover:

					TvDB_ImagePoster poster = repPosters.GetByID(int.Parse(entityID));
					if (poster == null) return null;

					if (File.Exists(poster.FullImagePath))
						return File.ReadAllBytes(poster.FullImagePath);
					else
					{
						logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_Banner:

					TvDB_ImageWideBanner wideBanner = repWideBanners.GetByID(int.Parse(entityID));
					if (wideBanner == null) return null;

					if (File.Exists(wideBanner.FullImagePath))
						return File.ReadAllBytes(wideBanner.FullImagePath);
					else
					{
						logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_Episode:

					TvDB_Episode ep = repEpisodes.GetByID(int.Parse(entityID));
					if (ep == null) return null;

					if (File.Exists(ep.FullImagePath))
						return File.ReadAllBytes(ep.FullImagePath);
					else
					{
						logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
						return null;
					}

				case JMMImageType.TvDB_FanArt:

					TvDB_ImageFanart fanart = repFanart.GetByID(int.Parse(entityID));
					if (fanart == null) return null;

					if (thumnbnailOnly)
					{
						if (File.Exists(fanart.FullThumbnailPath))
							return File.ReadAllBytes(fanart.FullThumbnailPath);
						else
						{
							logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullThumbnailPath);
							return null;
						}
					}
					else
					{
						if (File.Exists(fanart.FullImagePath))
							return File.ReadAllBytes(fanart.FullImagePath);
						else
						{
							logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
							return null;
						}
					}

				case JMMImageType.MovieDB_Poster:

					MovieDB_Poster mPoster = repMoviePosters.GetByID(int.Parse(entityID));
					if (mPoster == null) return null;

					// now find only the original size
                    mPoster = repMoviePosters.GetByOnlineID(mPoster.URL);
					if (mPoster == null) return null;

					if (File.Exists(mPoster.FullImagePath))
						return File.ReadAllBytes(mPoster.FullImagePath);
					else
					{
						logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
						return null;
					}

				case JMMImageType.MovieDB_FanArt:

					MovieDB_Fanart mFanart = repMovieFanart.GetByID(int.Parse(entityID));
					if (mFanart == null) return null;

					mFanart = repMovieFanart.GetByOnlineID(mFanart.URL);
					if (mFanart == null) return null;

					if (File.Exists(mFanart.FullImagePath))
						return File.ReadAllBytes(mFanart.FullImagePath);
					else
					{
						logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Fanart:

					Trakt_ImageFanart tFanart = repTraktFanart.GetByID(int.Parse(entityID));
					if (tFanart == null) return null;

					if (File.Exists(tFanart.FullImagePath))
						return File.ReadAllBytes(tFanart.FullImagePath);
					else
					{
						logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Poster:

					Trakt_ImagePoster tPoster = repTraktPosters.GetByID(int.Parse(entityID));
					if (tPoster == null) return null;

					if (File.Exists(tPoster.FullImagePath))
						return File.ReadAllBytes(tPoster.FullImagePath);
					else
					{
						logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
						return null;
					}

				case JMMImageType.Trakt_Episode:
				case JMMImageType.Trakt_WatchedEpisode:

					Trakt_Episode tEpisode = repTraktEpisodes.GetByID(int.Parse(entityID));
					if (tEpisode == null) return null;

					if (File.Exists(tEpisode.FullImagePath))
						return File.ReadAllBytes(tEpisode.FullImagePath);
					else
					{
						logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
						return null;
					}

				default:

					return null;
			}

			

		}
Beispiel #10
0
        public string GetDefaultPosterPathNoBlanks(ISession session)
        {
            AniDB_Anime_DefaultImage defaultPoster = GetDefaultPoster(session);
            if (defaultPoster == null)
                return PosterPathNoDefault;
            else
            {
                ImageEntityType imageType = (ImageEntityType)defaultPoster.ImageParentType;

                switch (imageType)
                {
                    case ImageEntityType.AniDB_Cover:
                        return this.PosterPath;

                    case ImageEntityType.TvDB_Cover:

                        TvDB_ImagePosterRepository repTvPosters = new TvDB_ImagePosterRepository();
                        TvDB_ImagePoster tvPoster = repTvPosters.GetByID(session, defaultPoster.ImageParentID);
                        if (tvPoster != null)
                            return tvPoster.FullImagePath;
                        else
                            return this.PosterPath;

                    case ImageEntityType.Trakt_Poster:

                        Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                        Trakt_ImagePoster traktPoster = repTraktPosters.GetByID(session, defaultPoster.ImageParentID);
                        if (traktPoster != null)
                            return traktPoster.FullImagePath;
                        else
                            return this.PosterPath;

                    case ImageEntityType.MovieDB_Poster:

                        MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                        MovieDB_Poster moviePoster = repMoviePosters.GetByID(session, defaultPoster.ImageParentID);
                        if (moviePoster != null)
                            return moviePoster.FullImagePath;
                        else
                            return this.PosterPath;

                }
            }

            return PosterPath;
        }
Beispiel #11
0
        public ImageDetails GetDefaultPosterDetailsNoBlanks(ISession session)
        {
            ImageDetails details = new ImageDetails() { ImageType = JMMImageType.AniDB_Cover, ImageID = this.AnimeID };
            AniDB_Anime_DefaultImage defaultPoster = GetDefaultPoster(session);

            if (defaultPoster == null)
                return details;
            else
            {
                ImageEntityType imageType = (ImageEntityType)defaultPoster.ImageParentType;

                switch (imageType)
                {
                    case ImageEntityType.AniDB_Cover:
                        return details;

                    case ImageEntityType.TvDB_Cover:

                        TvDB_ImagePosterRepository repTvPosters = new TvDB_ImagePosterRepository();
                        TvDB_ImagePoster tvPoster = repTvPosters.GetByID(session, defaultPoster.ImageParentID);
                        if (tvPoster != null)
                            details = new ImageDetails() { ImageType = JMMImageType.TvDB_Cover, ImageID = tvPoster.TvDB_ImagePosterID };

                        return details;

                    case ImageEntityType.Trakt_Poster:

                        Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                        Trakt_ImagePoster traktPoster = repTraktPosters.GetByID(session, defaultPoster.ImageParentID);
                        if (traktPoster != null)
                            details = new ImageDetails() { ImageType = JMMImageType.Trakt_Poster, ImageID = traktPoster.Trakt_ImagePosterID };

                        return details;

                    case ImageEntityType.MovieDB_Poster:

                        MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                        MovieDB_Poster moviePoster = repMoviePosters.GetByID(session, defaultPoster.ImageParentID);
                        if (moviePoster != null)
                            details = new ImageDetails() { ImageType = JMMImageType.MovieDB_Poster, ImageID = moviePoster.MovieDB_PosterID };

                        return details;

                }
            }

            return details;
        }
Beispiel #12
0
		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();
					}
				}
			}
		}
		public Contract_AniDB_Anime_DefaultImage ToContract(ISession session)
		{
			Contract_AniDB_Anime_DefaultImage contract = new Contract_AniDB_Anime_DefaultImage();

			contract.AniDB_Anime_DefaultImageID = this.AniDB_Anime_DefaultImageID;
			contract.AnimeID = this.AnimeID;
			contract.ImageParentID = this.ImageParentID;
			contract.ImageParentType = this.ImageParentType;
			contract.ImageType = this.ImageType;

			contract.MovieFanart = null;
			contract.MoviePoster = null;
			contract.TVPoster = null;
			contract.TVFanart = null;
			contract.TVWideBanner = null;
			contract.TraktFanart = null;
			contract.TraktPoster = null;

			JMMImageType imgType = (JMMImageType)ImageParentType;

			switch (imgType)
			{
				case JMMImageType.TvDB_Banner:

					TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();
					TvDB_ImageWideBanner banner = repBanners.GetByID(session, ImageParentID);
					if (banner != null) contract.TVWideBanner = banner.ToContract();

					break;

				case JMMImageType.TvDB_Cover:

					TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
					TvDB_ImagePoster poster = repPosters.GetByID(session, ImageParentID);
					if (poster != null) contract.TVPoster = poster.ToContract();

					break;

				case JMMImageType.TvDB_FanArt:

					TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
					TvDB_ImageFanart fanart = repFanart.GetByID(session, ImageParentID);
					if (fanart != null) contract.TVFanart = fanart.ToContract();

					break;

				case JMMImageType.MovieDB_Poster:

					MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
					MovieDB_Poster moviePoster = repMoviePosters.GetByID(session, ImageParentID);
					if (moviePoster != null) contract.MoviePoster = moviePoster.ToContract();

					break;

				case JMMImageType.MovieDB_FanArt:

					MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();
					MovieDB_Fanart movieFanart = repMovieFanart.GetByID(session, ImageParentID);
					if (movieFanart != null) contract.MovieFanart = movieFanart.ToContract();

					break;

				case JMMImageType.Trakt_Fanart:

					Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
					Trakt_ImageFanart traktFanart = repTraktFanart.GetByID(session, ImageParentID);
					if (traktFanart != null) contract.TraktFanart = traktFanart.ToContract();

					break;

				case JMMImageType.Trakt_Poster:

					Trakt_ImagePosterRepository repTraktPoster = new Trakt_ImagePosterRepository();
					Trakt_ImagePoster traktPoster = repTraktPoster.GetByID(session, ImageParentID);
					if (traktPoster != null) contract.TraktPoster = traktPoster.ToContract();

					break;
			}

			return contract;
		}
Beispiel #14
0
		public static void SaveExtendedShowInfo(TraktTVShow tvshow)
		{ 
			try
			{
				// save this data to the DB for use later
				Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
				Trakt_ShowRepository repShows = new Trakt_ShowRepository();
				Trakt_Show show = repShows.GetByTraktID(tvshow.TraktID);
				if (show == null)
					show = new Trakt_Show();

				show.Populate(tvshow);
				repShows.Save(show);


				if (tvshow.images != null)
				{
					if (!string.IsNullOrEmpty(tvshow.images.fanart))
					{
						Trakt_ImageFanart fanart = repFanart.GetByShowIDAndSeason(show.Trakt_ShowID, 1);
						if (fanart == null)
						{
							fanart = new Trakt_ImageFanart();
							fanart.Enabled = 0;
						}

						fanart.ImageURL = tvshow.images.fanart;
						fanart.Season = 1;
						fanart.Trakt_ShowID = show.Trakt_ShowID;
						repFanart.Save(fanart);
					}
				}


				// save the seasons
				Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
				Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
				Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();

				foreach (TraktTVSeason sea in tvshow.seasons)
				{
					Trakt_Season season = repSeasons.GetByShowIDAndSeason(show.Trakt_ShowID, int.Parse(sea.season));
					if (season == null)
						season = new Trakt_Season();

					season.Season = int.Parse(sea.season);
					season.URL = sea.url;
					season.Trakt_ShowID = show.Trakt_ShowID;
					repSeasons.Save(season);

					if (sea.images != null)
					{
						if (!string.IsNullOrEmpty(sea.images.poster))
						{
							Trakt_ImagePoster poster = repPosters.GetByShowIDAndSeason(show.Trakt_ShowID, season.Season);
							if (poster == null)
							{
								poster = new Trakt_ImagePoster();
								poster.Enabled = 0;
							}

							poster.ImageURL = sea.images.poster;
							poster.Season = season.Season;
							poster.Trakt_ShowID = show.Trakt_ShowID;
							repPosters.Save(poster);
						}
					}

					foreach (TraktTVEpisode ep in sea.episodes)
					{
						Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, int.Parse(ep.season), int.Parse(ep.episode));
						if (episode == null)
							episode = new Trakt_Episode();

						episode.EpisodeImage = ep.screen;
						episode.EpisodeNumber = int.Parse(ep.episode);
						episode.Overview = ep.overview;
						episode.Season = int.Parse(ep.season);
						episode.Title = ep.title;
						episode.URL = ep.url;
						episode.Trakt_ShowID = show.Trakt_ShowID;
						repEpisodes.Save(episode);
					}
				}


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