예제 #1
0
        public Serie GenerateFromAnimeSeries(AnimeSeries ser, int uid, int nocast, int notag, int level, int all)
        {
            Serie sr = new Serie();

            Video nv = ser.GetPlexContract(uid);

            sr.id = ser.AnimeSeriesID;
            sr.type = nv.Type;
            sr.summary = nv.Summary;
            sr.year = nv.Year;
            sr.air = nv.AirDate.ToString("dd-MM-yyyy");
            sr.size = nv.LeafCount;
            sr.localsize = nv.ChildCount;
            sr.viewed = nv.ViewedLeafCount;
            sr.rating = nv.Rating;
            sr.userrating = nv.UserRating;
            sr.titles = nv.Titles;
            sr.title = nv.Title;
            sr.season = nv.Season;

            // until fanart refactor this will be good for start
            if (!String.IsNullOrEmpty(nv.Thumb)) { sr.art.thumb.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(nv.Thumb), index = 0 }); }
            if (!String.IsNullOrEmpty(nv.Banner)) { sr.art.banner.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(nv.Banner), index = 0 }); }
            if (!String.IsNullOrEmpty(nv.Art)) { sr.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(nv.Art), index = 0 }); }

            if (nocast == 0)
            {
                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(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(rtg.RolePicture); } else { new_role.rolepic = ""; }
                        sr.roles.Add(new_role);
                    }
                }
            }

            if (notag == 0)
            {
                if (nv.Genres != null)
                {
                    foreach (JMMContracts.PlexAndKodi.Tag otg in nv.Genres)
                    {
                        Tag new_tag = new Tag();
                        new_tag.tag = otg.Value;
                        sr.tags.Add(new_tag);
                    }
                }
            }

            if (level != 1)
            {
                List<AnimeEpisode> ael = ser.GetAnimeEpisodes();
                if (ael.Count > 0)
                {
                    sr.eps = new List<Episode>();
                    foreach (AnimeEpisode ae in ael)
                    {
                        Episode new_ep = new Episode().GenerateFromAnimeEpisode(ae, uid, (level - 1), all);
                        if (new_ep != null)
                        {
                            sr.eps.Add(new_ep);
                        }
                    }
                }
            }

            return sr;
        }
예제 #2
0
        public Serie GenerateFromVideoLocal(VideoLocal vl, int uid, int nocast, int notag, int level, int all)
        {
            Serie sr = new Serie();

            if (vl != null)
            {
                foreach (AnimeEpisode ep in vl.GetAnimeEpisodes())
                {
                    sr = GenerateFromAnimeSeries(ep.GetAnimeSeries(), uid, nocast, notag, level, all);
                }
            }

            return sr;
        }
예제 #3
0
 /// <summary>
 /// Internal function returning serie with given ID
 /// </summary>
 /// <param name="series_id">serie id</param>
 /// <param name="nocast">disable cast</param>
 /// <returns></returns>
 internal object GetSerieById(int series_id, int nocast, int notag, int level)
 {
     Request request = this.Request;
     Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
     Serie ser = new Serie().GenerateFromAnimeSeries(RepoFactory.AnimeSeries.GetByID(series_id), user.JMMUserID, nocast, notag, level);
     return ser;
 }
예제 #4
0
        /// <summary>
        /// Handle /api/serie/byfolder
        /// </summary>
        /// <returns>List<Serie></returns>
        private object GetSeriesByFolderId()
        {
            Request request = this.Request;
            Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
            API_Call_Parameters para = this.Bind();

            if (para.id != 0)
            {
                List<object> allseries = new List<object>();
                List<VideoLocal> vlpall = RepoFactory.VideoLocalPlace.GetByImportFolder(para.id).Select(a => a.VideoLocal).ToList();
                if (para.limit == 0) { para.limit = 10; }
                foreach (VideoLocal vl in vlpall)
                {
                    Serie ser = new Serie().GenerateFromVideoLocal(vl, user.JMMUserID, para.nocast, para.notag, para.level);
                    allseries.Add(ser);
                    if (allseries.Count >= para.limit) { break; }
                }

                return allseries;
            }
            else
            {
                return APIStatus.internalError("missing 'id'");
            }
        }
예제 #5
0
        private object GetSerieByFolderId(int folder_id, int max)
        {
            Request request = this.Request;
            Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;

            ObjectList ob = new ObjectList("all series", ObjectList.ListType.SERIE);
            List<object> allseries = new List<object>();

            List<VideoLocal> vlpall = RepoFactory.VideoLocalPlace.GetByImportFolder(folder_id).Select(a => a.VideoLocal).ToList();

            foreach (VideoLocal vl in vlpall)
            {
                Serie ser = new Serie().GenerateFromVideoLocal(vl, user.JMMUserID, 1,0,0);
                allseries.Add(ser);
                if (allseries.Count >= max) { break; }
            }

            ob.Add(allseries);
            return ob;
        }
예제 #6
0
        private object GetItemsFromSerie(int uid, string SerieId, bool nocast = false)
        {
            int serieID;
            enEpisodeType? eptype = null;
            if (SerieId.Contains("_"))
            {
                int ept;
                string[] ndata = SerieId.Split('_');
                if (!int.TryParse(ndata[0], out ept)) { return APIStatus.notFound404("Invalid Serie Id"); }
                if (!int.TryParse(ndata[1], out serieID)) { return APIStatus.notFound404("Invalid Serie Id"); }
                eptype = (enEpisodeType)ept;
            }
            else
            {
                if (!int.TryParse(SerieId, out serieID)) { return APIStatus.notFound404("Invalid Serie Id"); }
            }

            AnimeSeries ser = RepoFactory.AnimeSeries.GetByID(serieID);
            if (ser == null) { return APIStatus.notFound404("Series not found"); }
            Contract_AnimeSeries cseries = ser.GetUserContract(uid);
            if (cseries == null) { return APIStatus.notFound404("Invalid Series, Contract Not Found"); }

            Serie sers = new Serie();

            Video nv = ser.GetPlexContract(uid);

            Dictionary<AnimeEpisode, Contract_AnimeEpisode> episodes = ser.GetAnimeEpisodes().ToDictionary(a => a, a => a.GetUserContract(uid));
            episodes = episodes.Where(a => a.Value == null || a.Value.LocalFileCount > 0).ToDictionary(a => a.Key, a => a.Value);

            sers.size = (cseries.WatchedEpisodeCount + cseries.UnwatchedEpisodeCount).ToString();
            sers.art.fanart.Add(new Art() { url = cseries.AniDBAnime?.AniDBAnime?.DefaultImageFanart?.GenArt(), index = 0 });
            sers.viewed = cseries.WatchedEpisodeCount.ToString();

            if (eptype.HasValue)
            {
                episodes = episodes.Where(a => a.Key.EpisodeTypeEnum == eptype.Value).ToDictionary(a => a.Key, a => a.Value);
            }
            else
            {
                List<enEpisodeType> types = episodes.Keys.Select(a => a.EpisodeTypeEnum).Distinct().ToList();
                if (types.Count > 1)
                {
                    List<PlexEpisodeType> eps = new List<PlexEpisodeType>();
                    foreach (enEpisodeType ee in types)
                    {
                        PlexEpisodeType k2 = new PlexEpisodeType();
                        PlexEpisodeType.EpisodeTypeTranslated(k2, ee, (AnimeTypes)cseries.AniDBAnime.AniDBAnime.AnimeType, episodes.Count(a => a.Key.EpisodeTypeEnum == ee));
                        eps.Add(k2);
                    }

                    List<Serie> dirs = new List<Serie>();

                    foreach (PlexEpisodeType ee in eps.OrderBy(a => a.Name))
                    {
                        Serie ob = new Serie();
                        ob.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(nv.Art), index = 0 });
                        ob.art.thumb.Add(new Art() { url = APIHelper.ConstructSupportImageLink(ee.Image), index = 0 });
                        ob.titles.Add(new AnimeTitle() { Title = ee.Name });
                        ob.type = "AnimeType";
                        ob.size = ee.Count.ToString();
                        ob.viewed = "0";
                        // ob.url = APIHelper.ConstructSerieIdUrl(ee.Type + "_" + ser.AnimeSeriesID);
                        dirs.Add(ob);
                    }

                    return dirs;
                }
            }

            List<Episode> lep = new List<Episode>();

            foreach (KeyValuePair<AnimeEpisode, Contract_AnimeEpisode> epi in episodes)
            {
                try
                {
                    Episode ep = new Episode().GenerateFromAnimeEpisode(epi.Key, uid,0);
                    lep.Add(ep);
                }
                catch (Exception e)
                {
                    //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null)
                }

                sers.eps = lep.OrderBy(a => a.epnumber).ToList();

                return sers;
            }

            return sers;
        }
예제 #7
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;
        }