示例#1
0
        internal static Episode GenerateFromAnimeEpisode(HttpContext ctx, SVR_AnimeEpisode aep, int uid, int level, int pic = 1)
        {
            Episode ep = new Episode
            {
                id  = aep.AnimeEpisodeID,
                art = new ArtCollection()
            };

            if (aep.AniDB_Episode != null)
            {
                ep.eptype = aep.EpisodeTypeEnum.ToString();
            }

            var userrating = aep.UserRating;

            if (userrating > 0)
            {
                ep.userrating = userrating.ToString(CultureInfo.InvariantCulture);
            }
            if (double.TryParse(ep.rating, out double rating))
            {
                // 0.1 should be the absolute lowest rating
                if (rating > 10)
                {
                    ep.rating = (rating / 100).ToString(CultureInfo.InvariantCulture);
                }
            }

            CL_AnimeEpisode_User cae = aep.GetUserContract(uid);

            if (cae != null)
            {
                ep.name    = cae.AniDB_EnglishName;
                ep.summary = cae.Description;

                ep.year = cae.AniDB_AirDate?.Year.ToString(CultureInfo.InvariantCulture);
                ep.air  = cae.AniDB_AirDate?.ToPlexDate();

                ep.votes  = cae.AniDB_Votes;
                ep.rating = cae.AniDB_Rating;

                ep.view     = cae.IsWatched() ? 1 : 0;
                ep.epnumber = cae.EpisodeNumber;
            }

            TvDB_Episode tvep = aep.TvDBEpisode;

            if (tvep != null)
            {
                if (!string.IsNullOrEmpty(tvep.EpisodeName))
                {
                    ep.name = tvep.EpisodeName;
                }

                if (pic > 0)
                {
                    if (Misc.IsImageValid(tvep.GetFullImagePath()))
                    {
                        ep.art.thumb.Add(new Art
                        {
                            index = 0,
                            url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode,
                                                                              tvep.TvDB_EpisodeID)
                        });
                    }
                    var fanarts = aep.GetAnimeSeries()?.GetAnime()?.Contract?.AniDBAnime?.Fanarts;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var cont_image =
                            fanarts[new Random().Next(fanarts.Count)];
                        ep.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                            cont_image.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                    else
                    {
                        ep.art.fanart.Add(new Art
                        {
                            index = 0,
                            url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode,
                                                                              tvep.TvDB_EpisodeID)
                        });
                    }
                }

                if (!string.IsNullOrEmpty(tvep.Overview))
                {
                    ep.summary = tvep.Overview;
                }

                int    zeroPadding   = tvep.EpisodeNumber.ToString().Length;
                string episodeNumber = tvep.EpisodeNumber.ToString().PadLeft(zeroPadding, '0');
                zeroPadding = tvep.SeasonNumber.ToString().Length;
                string seasonNumber = tvep.SeasonNumber.ToString().PadLeft(zeroPadding, '0');

                ep.season = $"{seasonNumber}x{episodeNumber}";
                var airdate = tvep.AirDate;
                if (airdate != null)
                {
                    ep.air  = airdate.Value.ToPlexDate();
                    ep.year = airdate.Value.Year.ToString(CultureInfo.InvariantCulture);
                }
            }
            if (string.IsNullOrEmpty(ep.summary))
            {
                ep.summary = string.Intern("Episode Overview not Available");
            }
            if (pic > 0 && ep.art.thumb.Count == 0)
            {
                ep.art.thumb.Add(
                    new Art {
                    index = 0, url = APIV2Helper.ConstructSupportImageLink(ctx, "plex_404.png")
                });
                ep.art.fanart.Add(new Art
                {
                    index = 0,
                    url   = APIV2Helper.ConstructSupportImageLink(ctx, "plex_404.png")
                });
            }
            if (string.IsNullOrEmpty(ep.year))
            {
                ep.year = aep.GetAnimeSeries().AirDate.Year.ToString(CultureInfo.InvariantCulture);
            }

            if (level > 0)
            {
                List <SVR_VideoLocal> vls = aep.GetVideoLocals();
                if (vls.Count > 0)
                {
                    ep.files = new List <RawFile>();
                    foreach (SVR_VideoLocal vl in vls)
                    {
                        RawFile file = new RawFile(ctx, vl, (level - 1), uid, aep);
                        ep.files.Add(file);
                    }
                }
            }

            return(ep);
        }
示例#2
0
        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);
        }
示例#3
0
        internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level)
        {
            Episode ep = new Episode();

            if (aep != null)
            {
                CL_AnimeEpisode_User cae = aep.GetUserContract(uid);
                if (cae != null)
                {
                    ep.id         = aep.AnimeEpisodeID;
                    ep.art        = new ArtCollection();
                    ep.name       = aep.PlexContract?.Title;
                    ep.summary    = aep.PlexContract?.Summary;
                    ep.year       = aep.PlexContract?.Year;
                    ep.air        = aep.PlexContract?.AirDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    ep.votes      = cae.AniDB_Votes;
                    ep.rating     = aep.PlexContract?.Rating;
                    ep.userrating = aep.PlexContract?.UserRating;
                    double rating;
                    if (double.TryParse(ep.rating, out rating))
                    {
                        // 0.1 should be the absolute lowest rating
                        if (rating > 10)
                        {
                            ep.rating = (rating / 100).ToString().Replace(',', '.');
                        }
                    }

                    ep.view     = cae.IsWatched() ? 1 : 0;
                    ep.epnumber = cae.EpisodeNumber;
                    ep.eptype   = aep.EpisodeTypeEnum.ToString();

                    ep.season = aep.PlexContract?.Season;

                    // until fanart refactor this will be good for start
                    if (aep.PlexContract?.Thumb != null)
                    {
                        ep.art.thumb.Add(new Art()
                        {
                            url   = APIHelper.ConstructImageLinkFromRest(ctx, aep.PlexContract?.Thumb),
                            index = 0
                        });
                    }
                    if (aep.PlexContract?.Art != null)
                    {
                        ep.art.fanart.Add(new Art()
                        {
                            url   = APIHelper.ConstructImageLinkFromRest(ctx, aep.PlexContract?.Art),
                            index = 0
                        });
                    }

                    if (level > 0)
                    {
                        List <SVR_VideoLocal> vls = aep.GetVideoLocals();
                        if (vls.Count > 0)
                        {
                            ep.files = new List <RawFile>();
                            foreach (SVR_VideoLocal vl in vls)
                            {
                                RawFile file = new RawFile(ctx, vl, (level - 1), uid);
                                ep.files.Add(file);
                            }
                        }
                    }
                }
            }

            return(ep);
        }
示例#4
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.aid     = ser.AniDB_ID;
            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);
            sr.votes = contract.AniDBAnime.AniDBAnime.VoteCount.ToString();
            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);
        }
示例#5
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);
        }