예제 #1
0
        public static void PopulateArtFromAniDBAnime(NancyContext ctx, SVR_AniDB_Anime anime, Serie sr, bool allpics, int pic)
        {
            Random rand    = new Random();
            var    tvdbIDs = RepoFactory.CrossRef_AniDB_TvDB.GetByAnimeID(anime.AnimeID).ToList();
            var    fanarts = tvdbIDs
                             .SelectMany(a => RepoFactory.TvDB_ImageFanart.GetBySeriesID(a.TvDBID)).ToList();
            var banners = tvdbIDs
                          .SelectMany(a => RepoFactory.TvDB_ImageWideBanner.GetBySeriesID(a.TvDBID)).ToList();

            if (allpics || pic > 1)
            {
                if (allpics)
                {
                    pic = 999;
                }

                int pic_index = 0;
                var posters   = anime.AllPosters;
                if (posters != null)
                {
                    foreach (var cont_image in posters)
                    {
                        if (pic_index < pic)
                        {
                            sr.art.thumb.Add(new Art()
                            {
                                url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                cont_image.AniDB_Anime_DefaultImageID),
                                index = pic_index
                            });
                            pic_index++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                pic_index = 0;
                foreach (var cont_image in fanarts)
                {
                    if (pic_index < pic)
                    {
                        sr.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_FanArt,
                                                                            cont_image.TvDB_ImageFanartID),
                            index = pic_index
                        });
                        pic_index++;
                    }
                    else
                    {
                        break;
                    }
                }

                pic_index = 0;
                foreach (var cont_image in banners)
                {
                    if (pic_index < pic)
                    {
                        sr.art.banner.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Banner,
                                                                            cont_image.TvDB_ImageWideBannerID),
                            index = pic_index
                        });
                        pic_index++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (pic > 0)
            {
                var poster = anime.GetDefaultPosterDetailsNoBlanks();
                sr.art.thumb.Add(new Art()
                {
                    url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)poster.ImageType, poster.ImageID),
                    index = 0
                });

                if (fanarts.Count > 0)
                {
                    var default_fanart = anime.GetDefaultFanart();

                    if (default_fanart != null)
                    {
                        sr.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, default_fanart.ImageType,
                                                                            default_fanart.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                    else
                    {
                        var tvdbart = fanarts[rand.Next(fanarts.Count)];
                        sr.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_FanArt,
                                                                            tvdbart.TvDB_ImageFanartID),
                            index = 0
                        });
                    }
                }

                if (banners.Count > 0)
                {
                    var default_fanart = anime.GetDefaultWideBanner();

                    if (default_fanart != null)
                    {
                        sr.art.banner.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, default_fanart.ImageType,
                                                                            default_fanart.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                    else
                    {
                        var tvdbart = banners[rand.Next(banners.Count)];
                        sr.art.banner.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Banner,
                                                                            tvdbart.TvDB_ImageWideBannerID),
                            index = 0
                        });
                    }
                }
            }
        }