예제 #1
0
        public static Serie GenerateFromAniDB_Anime(NancyContext ctx, SVR_AniDB_Anime anime, bool nocast, bool notag, bool allpics, int pic, TagFilter.Filter tagfilter)
        {
            Serie sr = new Serie
            {
                // 0 will load all
                id      = -1,
                aid     = anime.AnimeID,
                summary = anime.Description,
                rating  = Math.Round(anime.Rating / 100D, 1)
                          .ToString(CultureInfo.InvariantCulture),
                votes   = anime.VoteCount.ToString(),
                name    = anime.MainTitle,
                ismovie = anime.AnimeType == (int)AnimeType.Movie ? 1 : 0
            };

            if (anime.AirDate != null)
            {
                sr.year = anime.AirDate.Value.Year.ToString();
                var airdate = anime.AirDate.Value;
                if (airdate != DateTime.MinValue)
                {
                    sr.air = airdate.ToPlexDate();
                }
            }

            AniDB_Vote vote = RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.Anime) ??
                              RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                sr.userrating = Math.Round(vote.VoteValue / 100D, 1).ToString(CultureInfo.InvariantCulture);
            }
            sr.titles = anime.GetTitles().Select(title =>
                                                 new AnimeTitle {
                Language = title.Language, Title = title.Title, Type = title.TitleType
            }).ToList();

            PopulateArtFromAniDBAnime(ctx, anime, sr, allpics, pic);

            if (!nocast)
            {
                var xref_animestaff = RepoFactory.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(anime.AnimeID,
                                                                                               StaffRoleType.Seiyuu);
                foreach (var xref in xref_animestaff)
                {
                    if (xref.RoleID == null)
                    {
                        continue;
                    }
                    var character = RepoFactory.AnimeCharacter.GetByID(xref.RoleID.Value);
                    if (character == null)
                    {
                        continue;
                    }
                    var staff = RepoFactory.AnimeStaff.GetByID(xref.StaffID);
                    if (staff == null)
                    {
                        continue;
                    }
                    var role = new Role
                    {
                        character       = character.Name,
                        character_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Character,
                                                                                    xref.RoleID.Value),
                        staff       = staff.Name,
                        staff_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Staff,
                                                                                xref.StaffID),
                        role = xref.Role,
                        type = ((StaffRoleType)xref.RoleType).ToString()
                    };
                    if (sr.roles == null)
                    {
                        sr.roles = new List <Role>();
                    }
                    sr.roles.Add(role);
                }
            }

            if (!notag)
            {
                var tags = anime.GetAllTags();
                if (tags != null)
                {
                    sr.tags = TagFilter.ProcessTags(tagfilter, tags.ToList());
                }
            }

            return(sr);
        }
예제 #2
0
        public void GenerateFromAniDB_Anime(HttpContext ctx, SVR_AniDB_Anime anime)
        {
            anidb_id   = anime.AnimeID;
            restricted = anime.Restricted == 1;
            if (ctx.Items.ContainsKey("description"))
            {
                description = new List <Description>
                {
                    new Description {
                        source = "AniDB", language = "en", description = anime.Description
                    }
                };
            }

            ratings = new List <Rating>
            {
                new Rating
                {
                    source     = "AniDB",
                    rating     = (decimal)anime.Rating / 10,
                    max_rating = 100,
                    votes      = anime.VoteCount
                }
            };
            name        = anime.MainTitle;
            series_type = anime.AnimeType.ToString();

            if (anime.AirDate != null)
            {
                var airdate = anime.AirDate.Value;
                if (airdate != DateTime.MinValue)
                {
                    air_date = airdate.ToString("yyyy-MM-dd");
                }
            }
            if (anime.EndDate != null)
            {
                var enddate = anime.EndDate.Value;
                if (enddate != DateTime.MinValue)
                {
                    end_date = enddate.ToString("yyyy-MM-dd");
                }
            }

            AniDB_Vote vote = Repo.Instance.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.Anime) ??
                              Repo.Instance.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                string voteType = (AniDBVoteType)vote.VoteType == AniDBVoteType.Anime ? "Permanent" : "Temporary";
                user_rating = new Rating
                {
                    rating = (decimal)Math.Round(vote.VoteValue / 100D, 1), max_rating = 10, type = voteType,
                    source = "User"
                };
            }

            if (ctx.Items.ContainsKey("titles"))
            {
                titles = anime.GetTitles().Select(title => new Title
                {
                    language = title.Language, title = title.Title, type = title.TitleType
                }).ToList();
            }

            PopulateArtFromAniDBAnime(ctx, anime);

            if (ctx.Items.ContainsKey("cast"))
            {
                var xref_animestaff = Repo.Instance.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(anime.AnimeID,
                                                                                                 StaffRoleType.Seiyuu);
                foreach (var xref in xref_animestaff)
                {
                    if (xref.RoleID == null)
                    {
                        continue;
                    }
                    AnimeCharacter character = Repo.Instance.AnimeCharacter.GetByID(xref.RoleID.Value);
                    if (character == null)
                    {
                        continue;
                    }
                    AnimeStaff staff = Repo.Instance.AnimeStaff.GetByID(xref.StaffID);
                    if (staff == null)
                    {
                        continue;
                    }
                    Role role = new Role
                    {
                        character = new Role.Person
                        {
                            name        = character.Name, alternate_name = character.AlternateName,
                            image       = new Image(ctx, xref.RoleID.Value, ImageEntityType.Character),
                            description = character.Description
                        },
                        staff = new Role.Person
                        {
                            name           = staff.Name,
                            alternate_name = staff.AlternateName,
                            description    = staff.Description,
                            image          = new Image(ctx, xref.StaffID, ImageEntityType.Staff),
                        },
                        role         = ((StaffRoleType)xref.RoleType).ToString(),
                        role_details = xref.Role
                    };
                    if (cast == null)
                    {
                        cast = new List <Role>();
                    }
                    cast.Add(role);
                }
            }

            if (ctx.Items.ContainsKey("tags"))
            {
                var animeTags = anime.GetAllTags();
                if (animeTags != null)
                {
                    if (!ctx.Items.TryGetValue("tagfilter", out object tagfilter))
                    {
                        tagfilter = 0;
                    }
                    tags = TagFilter.ProcessTags((TagFilter.Filter)tagfilter, animeTags.ToList());
                }
            }
        }