示例#1
0
        private static void GetValidVideoRecursive(IProvider prov, SVR_GroupFilter f, int userid, Directory pp)
        {
            List <SVR_GroupFilter> gfs = RepoFactory.GroupFilter.GetByParentID(f.GroupFilterID)
                                         .Where(a => a.GroupsIds.ContainsKey(userid) && a.GroupsIds[userid].Count > 0)
                                         .ToList();

            foreach (SVR_GroupFilter gg in gfs.Where(a => (a.FilterType & (int)GroupFilterType.Directory) == 0))
            {
                if (gg.GroupsIds.ContainsKey(userid))
                {
                    HashSet <int> groups = gg.GroupsIds[userid];
                    if (groups.Count != 0)
                    {
                        foreach (int grp in groups.Randomize(f.GroupFilterID))
                        {
                            SVR_AnimeGroup ag = RepoFactory.AnimeGroup.GetByID(grp);
                            Video          v  = ag.GetPlexContract(userid);
                            if (v?.Art == null || v.Thumb == null)
                            {
                                continue;
                            }
                            pp.Art   = prov.ReplaceSchemeHost(v.Art);
                            pp.Thumb = prov.ReplaceSchemeHost(v.Thumb);
                            break;
                        }
                    }
                }
                if (pp.Art != null)
                {
                    break;
                }
            }
            if (pp.Art == null)
            {
                foreach (SVR_GroupFilter gg in gfs
                         .Where(a => (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory &&
                                a.InvisibleInClients == 0)
                         .Randomize(f.GroupFilterID))
                {
                    GetValidVideoRecursive(prov, gg, userid, pp);
                    if (pp.Art != null)
                    {
                        break;
                    }
                }
            }
            pp.LeafCount       = gfs.Count;
            pp.ViewedLeafCount = 0;
        }
示例#2
0
        public static Directory DirectoryFromFilter(IProvider prov, SVR_GroupFilter gg,
                                                    int userid)
        {
            Directory pp = new Directory {
                Type = "show"
            };

            pp.Key       = prov.ConstructFilterIdUrl(userid, gg.GroupFilterID);
            pp.Title     = gg.GroupFilterName;
            pp.Id        = gg.GroupFilterID;
            pp.AnimeType = AnimeTypes.AnimeGroupFilter.ToString();
            if ((gg.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory)
            {
                GetValidVideoRecursive(prov, gg, userid, pp);
            }
            else if (gg.GroupsIds.ContainsKey(userid))
            {
                HashSet <int> groups = gg.GroupsIds[userid];
                if (groups.Count == 0)
                {
                    return(pp);
                }
                pp.LeafCount       = groups.Count;
                pp.ViewedLeafCount = 0;
                foreach (int grp in groups.Randomize())
                {
                    SVR_AnimeGroup ag = RepoFactory.AnimeGroup.GetByID(grp);
                    Video          v  = ag.GetPlexContract(userid);
                    if (v?.Art == null || v.Thumb == null)
                    {
                        continue;
                    }
                    pp.Art   = prov.ReplaceSchemeHost(v.Art);
                    pp.Thumb = prov.ReplaceSchemeHost(v.Thumb);
                    break;
                }
                return(pp);
            }
            return(pp);
        }
示例#3
0
        public static Filter FilterFromGroupFilter(HttpContext ctx, SVR_GroupFilter gg, int uid)
        {
            Filter ob = new Filter
            {
                name = gg.GroupFilterName,
                id   = gg.GroupFilterID,
                url  = APIHelper.ConstructFilterIdUrl(ctx, gg.GroupFilterID)
            };

            if (gg.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groups = gg.GroupsIds[uid];
                if (groups.Count != 0)
                {
                    ob.size   = groups.Count;
                    ob.viewed = 0;

                    foreach (int grp in groups)
                    {
                        SVR_AnimeGroup ag = Repo.Instance.AnimeGroup.GetByID(grp);
                        Video          v  = ag.GetPlexContract(uid);
                        if (v?.Art != null && v.Thumb != null)
                        {
                            ob.art.fanart.Add(new Art()
                            {
                                url = APIHelper.ConstructImageLinkFromRest(ctx, v.Art), index = 0
                            });
                            ob.art.thumb.Add(new Art()
                            {
                                url   = APIHelper.ConstructImageLinkFromRest(ctx, v.Thumb),
                                index = 0
                            });
                            break;
                        }
                    }
                }
            }
            return(ob);
        }
示例#4
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, byte 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
                {
                    if (anime != null)
                    {
                        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())
                             .Select(value => new Tag {
                        tag = value
                    }).ToList();
                }
            }

            if (!nocast)
            {
                Video vag = ag.GetPlexContract(uid);
                if (vag?.Roles != null)
                {
                    g.roles = vag.Roles?.Select(rtg => new Role
                    {
                        name    = !string.IsNullOrEmpty(rtg.Value) ? rtg.Value : string.Empty,
                        namepic = !string.IsNullOrEmpty(rtg.TagPicture)
                            ? APIHelper.ConstructImageLinkFromRest(ctx, rtg.TagPicture)
                            : string.Empty,
                        role     = !string.IsNullOrEmpty(rtg.Role) ? rtg.Role : string.Empty,
                        roledesc = !string.IsNullOrEmpty(rtg.RoleDescription)
                            ? rtg.RoleDescription
                            : string.Empty,
                        rolepic = !string.IsNullOrEmpty(rtg.RolePicture)
                            ? APIHelper.ConstructImageLinkFromRest(ctx, rtg.RolePicture)
                            : string.Empty
                    }).ToList();
                }
            }

            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));
                }
                // This should be faster
                g.series.Sort();
            }

            return(g);
        }
示例#5
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);
        }
示例#6
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);
        }