Exemple #1
0
        internal Filter GenerateFromGroupFilter(Entities.GroupFilter gf, int uid, int nocast, int notag, int level)
        {
            Filter filter = new Filter();
            filter.name = gf.GroupFilterName;
            filter.id = gf.GroupFilterID;
            filter.size = 0;
            filter.type = gf.FilterType.ToString();

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet<int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;
                    if (level != 1)
                    {
                        foreach (int gp in groupsh)
                        {
                            Entities.AnimeGroup ag = Repositories.RepoFactory.AnimeGroup.GetByID(groupsh.First<int>());
                            groups.Add(new Group().GenerateFromAnimeGroup(ag, uid, nocast, notag, (level - 1)));
                            if (ag != null)
                            {
                                JMMContracts.PlexAndKodi.Video v = ag.GetPlexContract(uid);
                                if (v.Banner != null)
                                {
                                    filter.art.banner.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Banner), index = filter.art.banner.Count });
                                }

                                // we want to have same fanart and thumb
                                if (v.Art != null & v.Thumb != null)
                                {
                                    filter.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Art), index = filter.art.fanart.Count });
                                    filter.art.thumb.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Thumb), index = filter.art.thumb.Count });
                                }

                                if (filter.art.fanart.Count > 0 && filter.art.thumb.Count > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

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

            return filter;
        }
Exemple #2
0
        /// <summary>
        /// Internal function that return information about given filter
        /// </summary>
        /// <param name="id">filter id</param>
        /// <param name="uid">user id</param>
        /// <param name="nocast">disable cast</param>
        /// <param name="notag">disable tag/genre</param>
        /// <param name="level">deep level</param>
        /// <returns>Filter</returns>
        internal object GetFilter(int id, int uid, int nocast, int notag, int level)
        {
            GroupFilter gf = RepoFactory.GroupFilter.GetByID(id);
            Filter filter = new Filter().GenerateFromGroupFilter(gf, uid, nocast, notag, level);

            return filter;
        }
Exemple #3
0
        /// <summary>
        /// Internal function that return all filter for given user
        /// </summary>
        /// <param name="uid">user id</param>
        /// <param name="nocast">disable cast</param>
        /// <param name="notag">disable tag/genre</param>
        /// <param name="level">deep level</param>
        /// <returns>List<Filter></returns>
        internal object GetAllFilters(int uid, int nocast, int notag, int level)
        {
            List<GroupFilter> allGfs = RepoFactory.GroupFilter.GetTopLevel().Where(a => a.InvisibleInClients == 0 && ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) || (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory)).ToList();
            List<Filter> filters = new List<Filter>();

            foreach (GroupFilter gf in allGfs)
            {
                Filter filter = new Filter().GenerateFromGroupFilter(gf, uid, nocast, notag, level);
                filters.Add(filter);
            }

            // Unsort
            List<VideoLocal> vids = RepoFactory.VideoLocal.GetVideosWithoutEpisode();
            if (vids.Count > 0)
            {
                Filter filter = new Filter();

                filter.url = APIHelper.ConstructUnsortUrl();
                filter.name = "Unsort";
                filter.art.fanart.Add(new Art() { url = APIHelper.ConstructSupportImageLink("plex_unsort.png"), index = 0 });
                filter.art.thumb.Add(new Art() { url = APIHelper.ConstructSupportImageLink("plex_unsort.png"), index = 0 });
                filter.size = vids.Count;
                filter.viewed = 0;

                filters.Add(filter);
            }

            return filters;
        }
Exemple #4
0
        private object GetItemsFromGroup(int uid, string GroupId, bool nocast = false)
        {
            int gid;
            int.TryParse(GroupId, out gid);
            if (gid == -1) { return APIStatus.internalError("Invalid Group Id"); }

            ObjectList obl = new ObjectList();

            List<Video> retGroups = new List<Video>();
            AnimeGroup grp = RepoFactory.AnimeGroup.GetByID(gid);
            if (grp == null) { return APIStatus.notFound404("Group not found"); }

            Contract_AnimeGroup basegrp = grp?.GetUserContract(uid);
            if (basegrp != null)
            {
                List<AnimeSeries> seriesList = grp.GetSeries();

                foreach (AnimeGroup grpChild in grp.GetChildGroups())
                {
                    Filter fr = new Filter();

                    var v = grpChild.GetPlexContract(uid);
                    if (v != null)
                    {
                        fr.type = "show";
                        fr.url = APIHelper.ConstructGroupIdUrl(gid.ToString());

                        fr.art.fanart.Add(new Art() { url = Helper.GetRandomFanartFromVideo(v) ?? v.Art, index = 0 });
                        fr.art.banner.Add(new Art() { url = v.Banner = Helper.GetRandomBannerFromVideo(v) ?? v.Banner, index = 0 });

                        obl.list.Add(fr);
                    }
                }
                foreach (AnimeSeries ser in seriesList)
                {
                    Serie seri = new Serie().GenerateFromAnimeSeries(ser, uid, 0,0,0);
                    obl.list.Add(seri);
                }
            }

            return obl;
        }
        internal Filter GenerateFromGroupFilter(Entities.GroupFilter gf, int uid, int nocast, int notag, int level, int all)
        {
            Filter filter = new Filter();
            filter.name = gf.GroupFilterName;
            filter.id = gf.GroupFilterID;
            filter.size = 0;
            filter.type = gf.FilterType.ToString();

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

                    foreach (int gp in groupsh)
                    {
                        Entities.AnimeGroup ag = Repositories.RepoFactory.AnimeGroup.GetByID(gp);

                        if (ag != null)
                        {
                            JMMContracts.PlexAndKodi.Video v = ag.GetPlexContract(uid);

                            if (v.Art != null && !image_found)
                            {
                                filter.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Art), index = filter.art.fanart.Count });

                                if (v.Banner != null)
                                {
                                    filter.art.banner.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Banner), index = filter.art.banner.Count });
                                }

                                if (v.Thumb != null)
                                {
                                    filter.art.thumb.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(v.Thumb), index = filter.art.thumb.Count });
                                }

                                if (filter.art.fanart.Count > 0)
                                {
                                    image_found = true;
                                }
                            }

                            // only scan deeper if the level is correct
                            if (level > 1)
                            {
                                groups.Add(new Group().GenerateFromAnimeGroup(ag, uid, nocast, notag, (level - 1), all));
                            }
                            else
                            {
                                // if we have image for filter and we dont wan't include series inside filter then break
                                if (image_found)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    // save groups
                    if (groups.Count > 0)
                    {
                        filter.groups = groups;
                    }
                }
            }

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

            return filter;
        }