Example #1
0
        internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level)
        {
            Episode ep = new Episode();
            CL_AnimeEpisode_User cae = aep?.GetUserContract(uid);

            if (cae != null)
            {
                TvDB_Episode tvep = aep.TvDBEpisode;
                ep.id   = aep.AnimeEpisodeID;
                ep.art  = new ArtCollection();
                ep.name = cae.AniDB_EnglishName;

                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;
                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);
                    }
                }

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

                ep.art = new ArtCollection();

                if (tvep != null)
                {
                    ep.name = tvep.EpisodeName;
                    ep.art.thumb.Add(new Art {
                        index = 0, url = tvep.GenPoster(null)
                    });
                    ep.art.fanart.Add(new Art {
                        index = 0, url = tvep.GenPoster(null)
                    });
                    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 (ep.art.thumb.Count == 0)
                {
                    ep.art.thumb.Add(
                        new Art {
                        index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png")
                    });
                    ep.art.fanart.Add(new Art
                    {
                        index = 0,
                        url   = APIHelper.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);
                            ep.files.Add(file);
                        }
                    }
                }
            }

            return(ep);
        }
Example #2
0
        internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level)
        {
            Episode ep = new Episode
            {
                id     = aep.AnimeEpisodeID,
                eptype = aep.EpisodeTypeEnum.ToString(),
                art    = new ArtCollection()
            };

            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 (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 (ep.art.thumb.Count == 0)
            {
                ep.art.thumb.Add(
                    new Art {
                    index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png")
                });
                ep.art.fanart.Add(new Art
                {
                    index = 0,
                    url   = APIHelper.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);
                        ep.files.Add(file);
                    }
                }
            }

            return(ep);
        }
Example #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);
        }