コード例 #1
0
        public static Group GenerateFromAnimeGroup(NancyContext ctx, SVR_AnimeGroup ag, int uid, bool nocast, bool notag, int level,
                                                   bool all, int filterid, bool allpic, int pic, TagFilter.Filter tagfilter)
        {
            Group g = new Group
            {
                name = ag.GroupName,
                id   = ag.AnimeGroupID,

                //g.videoqualities = ag.VideoQualities; <-- deadly trap
                added  = ag.DateTimeCreated,
                edited = ag.DateTimeUpdated
            };

            SVR_GroupFilter filter = null;

            if (filterid > 0)
            {
                filter = RepoFactory.GroupFilter.GetByID(filterid);
                if (filter?.ApplyToSeries == 0)
                {
                    filter = null;
                }
            }

            List <SVR_AniDB_Anime> animes;

            if (filter != null)
            {
                animes = filter.SeriesIds[uid].Select(id => RepoFactory.AnimeSeries.GetByID(id))
                         .Where(ser => ser?.AnimeGroupID == ag.AnimeGroupID).Select(ser => ser.GetAnime())
                         .Where(a => a != null).OrderBy(a => a.BeginYear).ThenBy(a => a.AirDate ?? DateTime.MaxValue)
                         .ToList();
            }
            else
            {
                animes = ag.Anime?.OrderBy(a => a.BeginYear).ThenBy(a => a.AirDate ?? DateTime.MaxValue).ToList();
            }

            if (animes != null && animes.Count > 0)
            {
                var    anime = animes.FirstOrDefault();
                Random rand  = new Random();
                if (allpic || pic > 1)
                {
                    if (allpic)
                    {
                        pic = 999;
                    }
                    int pic_index = 0;
                    foreach (var ani in animes)
                    {
                        foreach (var cont_image in ani.AllPosters)
                        {
                            if (pic_index < pic)
                            {
                                g.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 ani.Contract.AniDBAnime.Fanarts)
                        {
                            if (pic_index < pic)
                            {
                                g.art.fanart.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 ani.Contract.AniDBAnime.Banners)
                        {
                            if (pic_index < pic)
                            {
                                g.art.banner.Add(new Art
                                {
                                    url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                    cont_image.AniDB_Anime_DefaultImageID),
                                    index = pic_index
                                });
                                pic_index++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    g.art.thumb.Add(new Art
                    {
                        url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.AniDB_Cover,
                                                                        anime.AnimeID),
                        index = 0
                    });

                    var fanarts = anime.Contract.AniDBAnime.Fanarts;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        g.art.fanart.Add(new Art
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }

                    fanarts = anime.Contract.AniDBAnime.Banners;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        g.art.banner.Add(new Art
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                }

                List <SVR_AnimeEpisode> ael;
                if (filter != null)
                {
                    ael = filter.SeriesIds[uid].Select(id => RepoFactory.AnimeSeries.GetByID(id))
                          .Where(ser => ser?.AnimeGroupID == ag.AnimeGroupID).SelectMany(ser => ser.GetAnimeEpisodes())
                          .ToList();
                }
                else
                {
                    ael = ag.GetAllSeries().SelectMany(a => a.GetAnimeEpisodes()).ToList();
                }

                GenerateSizes(g, ael, uid);

                g.air = anime.AirDate?.ToPlexDate() ?? string.Empty;

                g.rating  = Math.Round(ag.AniDBRating / 100, 1).ToString(CultureInfo.InvariantCulture);
                g.summary = anime.Description ?? string.Empty;
                g.titles  = anime.GetTitles().ToAPIContract();
                g.year    = anime.BeginYear.ToString();

                if (!notag && ag.Contract.Stat_AllTags != null)
                {
                    g.tags = TagFilter.ProcessTags(tagfilter, ag.Contract.Stat_AllTags.ToList());
                }

                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 (g.roles == null)
                        {
                            g.roles = new List <Role>();
                        }
                        g.roles.Add(role);
                    }
                }
            }

            if (level > 0)
            {
                List <int> series = null;
                if (filter?.SeriesIds.ContainsKey(uid) == true)
                {
                    series = filter.SeriesIds[uid].ToList();
                }
                foreach (SVR_AnimeSeries ada in ag.GetSeries())
                {
                    if (series != null && series.Count > 0 && !series.Contains(ada.AnimeSeriesID))
                    {
                        continue;
                    }
                    g.series.Add(Serie.GenerateFromAnimeSeries(ctx, ada, uid, nocast, notag, (level - 1), all, allpic,
                                                               pic, (TagFilter.Filter)tagfilter));
                }
                // This should be faster
                g.series.Sort();
            }

            return(g);
        }
コード例 #2
0
ファイル: Group.cs プロジェクト: ShokoAnime/ShokoServer
        public static Group GenerateFromAnimeGroup(HttpContext ctx, SVR_AnimeGroup ag, int uid, bool nocast, bool notag, int level,
                                                   bool all, int filterid, bool allpic, int pic, TagFilter.Filter tagfilter)
        {
            Group g = new Group
            {
                name = ag.GroupName,
                id   = ag.AnimeGroupID,

                //g.videoqualities = ag.VideoQualities; <-- deadly trap
                added  = ag.DateTimeCreated,
                edited = ag.DateTimeUpdated
            };

            SVR_GroupFilter filter = null;

            if (filterid > 0)
            {
                filter = RepoFactory.GroupFilter.GetByID(filterid);
                if (filter?.ApplyToSeries == 0)
                {
                    filter = null;
                }
            }

            List <SVR_AniDB_Anime> animes;

            if (filter != null)
            {
                animes = filter.SeriesIds[uid].Select(id => RepoFactory.AnimeSeries.GetByID(id))
                         .Where(ser => ser?.AnimeGroupID == ag.AnimeGroupID).Select(ser => ser.GetAnime())
                         .Where(a => a != null).OrderBy(a => a.BeginYear).ThenBy(a => a.AirDate ?? DateTime.MaxValue)
                         .ToList();
            }
            else
            {
                animes = ag.Anime?.OrderBy(a => a.BeginYear).ThenBy(a => a.AirDate ?? DateTime.MaxValue).ToList();
            }

            if (animes != null && animes.Count > 0)
            {
                var anime = animes.FirstOrDefault(a => a != null);
                if (anime == null)
                {
                    return(g);
                }
                PopulateArtFromAniDBAnime(ctx, animes, g, allpic, pic);

                List <SVR_AnimeEpisode> ael;
                if (filter != null && filter.SeriesIds.ContainsKey(uid))
                {
                    var series = filter.SeriesIds[uid].Select(id => RepoFactory.AnimeSeries.GetByID(id))
                                 .Where(ser => (ser?.AnimeGroupID ?? 0) == ag.AnimeGroupID).ToList();
                    ael = series.SelectMany(ser => ser?.GetAnimeEpisodes()).Where(a => a != null)
                          .ToList();
                    g.size = series.Count;
                }
                else
                {
                    var series = ag.GetAllSeries();
                    ael    = series.SelectMany(a => a?.GetAnimeEpisodes()).Where(a => a != null).ToList();
                    g.size = series.Count;
                }

                GenerateSizes(g, ael, uid);

                g.air = anime.AirDate?.ToPlexDate() ?? string.Empty;

                g.rating  = Math.Round(ag.AniDBRating / 100, 1).ToString(CultureInfo.InvariantCulture);
                g.summary = anime.Description ?? string.Empty;
                g.titles  = anime.GetTitles().Select(s => new AnimeTitle
                {
                    Type     = s.TitleType,
                    Language = s.Language,
                    Title    = s.Title
                }).ToList();
                g.year = anime.BeginYear.ToString();

                if (!notag && ag.Contract.Stat_AllTags != null)
                {
                    g.tags = TagFilter.String.ProcessTags(tagfilter, ag.Contract.Stat_AllTags.ToList());
                }

                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 (g.roles == null)
                        {
                            g.roles = new List <Role>();
                        }
                        g.roles.Add(role);
                    }
                }

                if (level > 0)
                {
                    foreach (SVR_AnimeSeries ada in animes.Select(a => RepoFactory.AnimeSeries.GetByAnimeID(a.AnimeID)))
                    {
                        g.series.Add(Serie.GenerateFromAnimeSeries(ctx, ada, uid, nocast, notag, (level - 1), all, allpic,
                                                                   pic, tagfilter));
                    }
                    // we already sorted animes, so no need to sort
                }
            }

            return(g);
        }
コード例 #3
0
        public int CompareTo(object obj)
        {
            Serie a = obj as Serie;

            if (a == null)
            {
                return(1);
            }
            int s, s1;

            // try year first, as it is more likely to have relevannt data
            if (int.TryParse(a.year, out s1) && int.TryParse(year, out s))
            {
                if (s < s1)
                {
                    return(-1);
                }
                if (s > s1)
                {
                    return(1);
                }
            }
            // Does it have an air date? Sort by it
            if (!string.IsNullOrEmpty(a.air) && !a.air.Equals(DateTime.MinValue.ToString("dd-MM-yyyy")) &&
                !string.IsNullOrEmpty(air) && !air.Equals(DateTime.MinValue.ToString("dd-MM-yyyy")))
            {
                DateTime d, d1;
                if (DateTime.TryParseExact(a.air, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None,
                                           out d1) &&
                    DateTime.TryParseExact(air, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out d))
                {
                    if (d < d1)
                    {
                        return(-1);
                    }
                    if (d > d1)
                    {
                        return(1);
                    }
                }
            }
            // I don't trust TvDB well enough to sort by them. Bakamonogatari...
            // Does it have a Season? Sort by it
            if (int.TryParse(a.season, out s1) && int.TryParse(season, out s))
            {
                // Only try if the season is valid
                if (s >= 0 && s1 >= 0)
                {
                    // Specials
                    if (s == 0 && s1 > 0)
                    {
                        return(1);
                    }
                    if (s > 0 && s1 == 0)
                    {
                        return(-1);
                    }
                    // Normal
                    if (s < s1)
                    {
                        return(-1);
                    }
                    if (s > s1)
                    {
                        return(1);
                    }
                }
            }
            return(name.CompareTo(a.name));
        }
コード例 #4
0
        public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level,
                                                    bool all)
        {
            Serie sr = new Serie();

            Video nv = ser.GetPlexContract(uid);

            sr.id         = ser.AnimeSeriesID;
            sr.summary    = nv.Summary;
            sr.year       = nv.Year;
            sr.air        = nv.AirDate.ToString("dd-MM-yyyy");
            sr.size       = int.Parse(nv.LeafCount);
            sr.localsize  = int.Parse(nv.ChildCount);
            sr.viewed     = int.Parse(nv.ViewedLeafCount);
            sr.rating     = nv.Rating;
            sr.userrating = nv.UserRating;
            sr.titles     = nv.Titles;
            sr.name       = nv.Title;
            sr.season     = nv.Season;
            if (nv.IsMovie)
            {
                sr.ismovie = 1;
            }

            Random rand = new Random();
            Contract_ImageDetails art = new Contract_ImageDetails();

            if (nv.Fanarts != null && nv.Fanarts.Count > 0)
            {
                art = nv.Fanarts[rand.Next(nv.Fanarts.Count)];
                sr.art.fanart.Add(new Art()
                {
                    url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                    index = 0
                });
            }

            if (nv.Banner != null && nv.Fanarts.Count > 0)
            {
                art = nv.Banners[rand.Next(nv.Banners.Count)];

                sr.art.banner.Add(new Art()
                {
                    url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                    index = 0
                });
            }

            if (!string.IsNullOrEmpty(nv.Thumb))
            {
                sr.art.thumb.Add(new Art()
                {
                    url = APIHelper.ConstructImageLinkFromRest(ctx, nv.Thumb), index = 0
                });
            }

            if (!nocast)
            {
                if (nv.Roles != null)
                {
                    foreach (RoleTag rtg in nv.Roles)
                    {
                        Role new_role = new Role();
                        if (!String.IsNullOrEmpty(rtg.Value))
                        {
                            new_role.name = rtg.Value;
                        }
                        else
                        {
                            new_role.name = "";
                        }
                        if (!String.IsNullOrEmpty(rtg.TagPicture))
                        {
                            new_role.namepic = APIHelper.ConstructImageLinkFromRest(ctx, rtg.TagPicture);
                        }
                        else
                        {
                            new_role.namepic = "";
                        }
                        if (!String.IsNullOrEmpty(rtg.Role))
                        {
                            new_role.role = rtg.Role;
                        }
                        else
                        {
                            rtg.Role = "";
                        }
                        if (!String.IsNullOrEmpty(rtg.RoleDescription))
                        {
                            new_role.roledesc = rtg.RoleDescription;
                        }
                        else
                        {
                            new_role.roledesc = "";
                        }
                        if (!String.IsNullOrEmpty(rtg.RolePicture))
                        {
                            new_role.rolepic = APIHelper.ConstructImageLinkFromRest(ctx, rtg.RolePicture);
                        }
                        else
                        {
                            new_role.rolepic = "";
                        }
                        sr.roles.Add(new_role);
                    }
                }
            }

            if (!notag)
            {
                if (nv.Genres != null)
                {
                    foreach (Shoko.Models.PlexAndKodi.Tag otg in nv.Genres)
                    {
                        Tag new_tag = new Tag();
                        new_tag.tag = otg.Value;
                        sr.tags.Add(new_tag);
                    }
                }
            }

            if (level > 0)
            {
                List <SVR_AnimeEpisode> ael = ser.GetAnimeEpisodes();
                if (ael.Count > 0)
                {
                    sr.eps = new List <Episode>();
                    foreach (SVR_AnimeEpisode ae in ael)
                    {
                        if (!all && (ae?.GetVideoLocals()?.Count ?? 0) == 0)
                        {
                            continue;
                        }
                        Episode new_ep = Episode.GenerateFromAnimeEpisode(ctx, ae, uid, (level - 1));
                        if (new_ep != null)
                        {
                            sr.eps.Add(new_ep);
                        }
                    }
                    sr.eps = sr.eps.OrderBy(a => a.epnumber).ToList();
                }
            }

            return(sr);
        }
コード例 #5
0
        public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level, bool all, bool allpics, int pic, TagFilter.Filter tagfilter)
        {
            Serie sr = new Serie();

            List <SVR_AnimeEpisode> ael = ser.GetAnimeEpisodes();
            var contract = ser.Contract;

            if (contract == null)
            {
                ser.UpdateContract();
            }

            sr.id      = ser.AnimeSeriesID;
            sr.summary = contract.AniDBAnime.AniDBAnime.Description;
            sr.year    = contract.AniDBAnime.AniDBAnime.BeginYear.ToString();
            var airdate = ser.AirDate;

            if (airdate != DateTime.MinValue)
            {
                sr.air = airdate.ToPlexDate();
            }

            GenerateSizes(sr, ael, uid);

            sr.rating = Math.Round(contract.AniDBAnime.AniDBAnime.Rating / 100D, 1)
                        .ToString(CultureInfo.InvariantCulture);
            AniDB_Vote vote = RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.Anime) ??
                              RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.AnimeTemp);

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

            var ls = contract.CrossRefAniDBTvDBV2?.OrderBy(a => a.TvDBSeasonNumber).FirstOrDefault();

            if ((ls?.TvDBSeasonNumber ?? 0) != 0)
            {
                sr.season = ls.TvDBSeasonNumber.ToString();
            }

            if (contract.AniDBAnime.AniDBAnime.AnimeType == (int)AnimeType.Movie)
            {
                sr.ismovie = 1;
            }

            #region Images

            var anime = ser.GetAnime();
            if (anime != null)
            {
                Random rand = new Random();
                if (allpics || pic > 1)
                {
                    if (allpics)
                    {
                        pic = 999;
                    }
                    int pic_index = 0;
                    if (anime.AllPosters != null)
                    {
                        foreach (var cont_image in anime.AllPosters)
                        {
                            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;
                    if (anime.Contract.AniDBAnime.Fanarts != null)
                    {
                        foreach (var cont_image in anime.Contract.AniDBAnime.Fanarts)
                        {
                            if (pic_index < pic)
                            {
                                sr.art.fanart.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;
                    if (anime.Contract.AniDBAnime.Banners != null)
                    {
                        foreach (var cont_image in anime.Contract.AniDBAnime.Banners)
                        {
                            if (pic_index < pic)
                            {
                                sr.art.banner.Add(new Art()
                                {
                                    url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                    cont_image.AniDB_Anime_DefaultImageID),
                                    index = pic_index
                                });
                                pic_index++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    sr.art.thumb.Add(new Art()
                    {
                        url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.AniDB_Cover,
                                                                        anime.AnimeID),
                        index = 0
                    });

                    var fanarts = anime.Contract.AniDBAnime.Fanarts;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        sr.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }

                    fanarts = anime.Contract.AniDBAnime.Banners;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        sr.art.banner.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                }
            }

            #endregion

            if (!nocast)
            {
                var xref_animestaff = RepoFactory.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(ser.AniDB_ID,
                                                                                               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 = ser.Contract.AniDBAnime.AniDBAnime.GetAllTags();
                if (tags != null)
                {
                    sr.tags = TagFilter.ProcessTags(tagfilter, tags.ToList());
                }
            }

            if (level > 0)
            {
                if (ael.Count > 0)
                {
                    sr.eps = new List <Episode>();
                    foreach (SVR_AnimeEpisode ae in ael)
                    {
                        if (!all && (ae?.GetVideoLocals()?.Count ?? 0) == 0)
                        {
                            continue;
                        }
                        Episode new_ep = Episode.GenerateFromAnimeEpisode(ctx, ae, uid, (level - 1));
                        if (new_ep != null)
                        {
                            sr.eps.Add(new_ep);
                        }
                        if (level - 1 > 0)
                        {
                            foreach (RawFile file in new_ep.files)
                            {
                                sr.filesize += file.size;
                            }
                        }
                    }
                    sr.eps = sr.eps.OrderBy(a => a.epnumber).ToList();
                }
            }

            return(sr);
        }
コード例 #6
0
        private static void GenerateSizes(Serie sr, List <SVR_AnimeEpisode> ael, int uid)
        {
            int eps      = 0;
            int credits  = 0;
            int specials = 0;
            int trailers = 0;
            int parodies = 0;
            int others   = 0;

            int local_eps      = 0;
            int local_credits  = 0;
            int local_specials = 0;
            int local_trailers = 0;
            int local_parodies = 0;
            int local_others   = 0;

            int watched_eps      = 0;
            int watched_credits  = 0;
            int watched_specials = 0;
            int watched_trailers = 0;
            int watched_parodies = 0;
            int watched_others   = 0;

            // single loop. Will help on long shows
            foreach (SVR_AnimeEpisode ep in ael)
            {
                if (ep == null)
                {
                    continue;
                }
                var local = ep.GetVideoLocals().Any();
                switch (ep.EpisodeTypeEnum)
                {
                case EpisodeType.Episode:
                {
                    eps++;
                    if (local)
                    {
                        local_eps++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_eps++;
                    }
                    break;
                }

                case EpisodeType.Credits:
                {
                    credits++;
                    if (local)
                    {
                        local_credits++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_credits++;
                    }
                    break;
                }

                case EpisodeType.Special:
                {
                    specials++;
                    if (local)
                    {
                        local_specials++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_specials++;
                    }
                    break;
                }

                case EpisodeType.Trailer:
                {
                    trailers++;
                    if (local)
                    {
                        local_trailers++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_trailers++;
                    }
                    break;
                }

                case EpisodeType.Parody:
                {
                    parodies++;
                    if (local)
                    {
                        local_parodies++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_parodies++;
                    }
                    break;
                }

                case EpisodeType.Other:
                {
                    others++;
                    if (local)
                    {
                        local_others++;
                    }
                    if ((ep.GetUserRecord(uid)?.WatchedCount ?? 0) > 0)
                    {
                        watched_others++;
                    }
                    break;
                }
                }
            }

            sr.size      = eps + credits + specials + trailers + parodies + others;
            sr.localsize = local_eps + local_credits + local_specials + local_trailers + local_parodies + local_others;
            sr.viewed    = watched_eps + watched_credits + watched_specials + watched_trailers + watched_parodies + watched_others;

            sr.total_sizes = new Sizes()
            {
                Episodes = eps,
                Credits  = credits,
                Specials = specials,
                Trailers = trailers,
                Parodies = parodies,
                Others   = others
            };

            sr.local_sizes = new Sizes()
            {
                Episodes = local_eps,
                Credits  = local_credits,
                Specials = local_specials,
                Trailers = local_trailers,
                Parodies = local_parodies,
                Others   = local_others
            };

            sr.watched_sizes = new Sizes()
            {
                Episodes = watched_eps,
                Credits  = watched_credits,
                Specials = watched_specials,
                Trailers = watched_trailers,
                Parodies = watched_parodies,
                Others   = watched_others
            };
        }
コード例 #7
0
ファイル: Serie.cs プロジェクト: notnyt/ShokoServer
        public static void PopulateArtFromAniDBAnime(HttpContext ctx, SVR_AniDB_Anime anime, Serie sr, bool allpics, int pic)
        {
            Random rand    = (Random)ctx.Items["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
                        });
                    }
                }
            }
        }
コード例 #8
0
ファイル: Serie.cs プロジェクト: notnyt/ShokoServer
        public static Serie GenerateFromAnimeSeries(HttpContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level, bool all, bool allpics, int pic, TagFilter.Filter tagfilter)
        {
            Serie sr = GenerateFromAniDB_Anime(ctx, ser.GetAnime(), nocast, notag, allpics, pic, tagfilter);

            List <SVR_AnimeEpisode> ael = ser.GetAnimeEpisodes();
            var contract = ser.Contract;

            if (contract == null)
            {
                ser.UpdateContract();
            }

            sr.id   = ser.AnimeSeriesID;
            sr.name = ser.GetSeriesName();
            GenerateSizes(sr, ael, uid);

            int?season = ael.FirstOrDefault(a =>
                                            a.AniDB_Episode != null && (a.AniDB_Episode.EpisodeType == (int)EpisodeType.Episode && a.AniDB_Episode.EpisodeNumber == 1))
                         ?.TvDBEpisode?.SeasonNumber;

            if (season != null)
            {
                sr.season = season.Value.ToString();
            }

            var tvdbseriesID = ael.Select(a => a.TvDBEpisode).Where(a => a != null).GroupBy(a => a.SeriesID)
                               .MaxBy(a => a.Count()).FirstOrDefault()?.Key;

            if (tvdbseriesID != null)
            {
                var tvdbseries = RepoFactory.TvDB_Series.GetByTvDBID(tvdbseriesID.Value);
                if (tvdbseries != null)
                {
                    var title = new AnimeTitle {
                        Language = "EN", Title = tvdbseries.SeriesName, Type = "TvDB"
                    };
                    sr.titles.Add(title);
                }
            }

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

            if (level > 0)
            {
                if (ael.Count > 0)
                {
                    sr.eps = new List <Episode>();
                    foreach (SVR_AnimeEpisode ae in ael)
                    {
                        if (!all && (ae?.GetVideoLocals()?.Count ?? 0) == 0)
                        {
                            continue;
                        }
                        Episode new_ep = Episode.GenerateFromAnimeEpisode(ctx, ae, uid, (level - 1), pic);
                        if (new_ep == null)
                        {
                            continue;
                        }

                        sr.eps.Add(new_ep);

                        if (level - 1 <= 0)
                        {
                            continue;
                        }
                        foreach (RawFile file in new_ep.files)
                        {
                            sr.filesize += file.size;
                        }
                    }
                    sr.eps = sr.eps.OrderBy(a => a.epnumber).ToList();
                }
            }

            return(sr);
        }
コード例 #9
0
ファイル: Serie.cs プロジェクト: notnyt/ShokoServer
        public static Serie GenerateFromAniDB_Anime(HttpContext 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 (!nocast)
            {
                var tags = anime.GetAllTags();
                if (tags != null)
                {
                    sr.tags = TagFilter.ProcessTags(tagfilter, tags.ToList());
                }
            }

            return(sr);
        }