Exemple #1
0
 public static Contract_ImageDetails CopyTo(this Contract_ImageDetails v, Contract_ImageDetails o)
 {
     o.ImageID   = v.ImageID;
     o.ImageType = v.ImageType;
     return(o);
 }
Exemple #2
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);
        }
Exemple #3
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)
        {
            Group g = new Group
            {
                name = ag.GroupName,
                id   = ag.AnimeGroupID,

                //g.videoqualities = ag.VideoQualities; <-- deadly trap
                added  = ag.DateTimeCreated,
                edited = ag.DateTimeUpdated
            };
            Video vag = ag.GetPlexContract(uid);

            if (vag != null)
            {
                g.air = vag.OriginallyAvailableAt;

                List <SVR_AnimeEpisode> ael = ag.GetAllSeries().SelectMany(a => a.GetAnimeEpisodes()).ToList();

                GenerateSizes(g, ael, uid);

                g.rating     = vag.Rating;
                g.userrating = vag.UserRating;

                g.summary = vag.Summary;
                g.titles  = vag.Titles;
                g.year    = vag.Year;

                Random rand = new Random();
                Contract_ImageDetails art = new Contract_ImageDetails();
                // vag.Fanarts can be null even if contract isn't
                if (vag.Fanarts != null && vag.Fanarts.Count > 0)
                {
                    art = vag.Fanarts[rand.Next(vag.Fanarts.Count)];
                    g.art.fanart.Add(new Art()
                    {
                        url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                        index = 0
                    });
                }

                if (vag.Banners != null && vag.Banners.Count > 0)
                {
                    art = vag.Banners[rand.Next(vag.Banners.Count)];
                    g.art.banner.Add(new Art()
                    {
                        url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                        index = 0
                    });
                    if (!string.IsNullOrEmpty(vag.Thumb))
                    {
                        g.art.thumb.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromRest(ctx, vag.Thumb), index = 0
                        });
                    }
                }

                if (!nocast)
                {
                    if (vag.Roles != null)
                    {
                        g.roles = new List <Role>();
                        foreach (RoleTag rtg in vag.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 = "";
                            }
                            g.roles.Add(new_role);
                        }
                    }
                }

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

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

            return(g);
        }
Exemple #4
0
        internal static Filter GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                       bool all)
        {
            List <Group> groups = new List <Group>();
            Filter       filter = new Filter();

            filter.name = gf.GroupFilterName;
            filter.id   = gf.GroupFilterID;
            filter.size = 0;

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;

                    int rand_art_iteration = 0;

                    // Populate Random Art
                    while (rand_art_iteration < 3)
                    {
                        int            index    = new Random().Next(groupsh.Count);
                        SVR_AnimeGroup randGrp  = Repositories.RepoFactory.AnimeGroup.GetByID(groupsh.ToList()[index]);
                        Video          contract = randGrp?.GetPlexContract(uid);
                        if (contract != null)
                        {
                            Random rand = new Random();
                            Contract_ImageDetails art = new Contract_ImageDetails();
                            // contract.Fanarts can be null even if contract isn't
                            if (contract.Fanarts != null && contract.Fanarts.Count > 0)
                            {
                                art = contract.Fanarts[rand.Next(contract.Fanarts.Count)];
                                filter.art.fanart.Add(new Art()
                                {
                                    url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                                    index = 0
                                });
                                rand_art_iteration = 3;

                                // we only want banner if we have fanart, other way will desync images
                                if (contract.Banners != null && contract.Banners.Count > 0)
                                {
                                    art = contract.Banners[rand.Next(contract.Banners.Count)];
                                    filter.art.banner.Add(new Art()
                                    {
                                        url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                                        index = 0
                                    });
                                    if (!string.IsNullOrEmpty(contract.Thumb))
                                    {
                                        filter.art.thumb.Add(new Art()
                                        {
                                            url   = APIHelper.ConstructImageLinkFromRest(ctx, contract.Thumb),
                                            index = 0
                                        });
                                    }
                                }
                            }
                        }
                        rand_art_iteration++;
                    }

                    Dictionary <CL_AnimeGroup_User, Group> order = new Dictionary <CL_AnimeGroup_User, Group>();
                    if (level > 0)
                    {
                        foreach (int gp in groupsh)
                        {
                            SVR_AnimeGroup ag = Repositories.RepoFactory.AnimeGroup.GetByID(gp);
                            if (ag == null)
                            {
                                continue;
                            }
                            Group group =
                                Group.GenerateFromAnimeGroup(ctx, ag, uid, nocast, notag, (level - 1), all,
                                                             filter.id);
                            groups.Add(group);
                            order.Add(ag.GetUserContract(uid), group);
                        }
                    }

                    if (groups.Count > 0)
                    {
                        // Proper Sorting!
                        IEnumerable <CL_AnimeGroup_User> grps = order.Keys;
                        grps = gf.SortCriteriaList.Count != 0
                            ? GroupFilterHelper.Sort(grps, gf)
                            : grps.OrderBy(a => a.GroupName);
                        groups        = grps.Select(a => order[a]).ToList();
                        filter.groups = groups;
                    }
                }
            }

            filter.viewed = 0;
            filter.url    = APIHelper.ConstructFilterIdUrl(ctx, filter.id);

            return(filter);
        }