Example #1
0
        public static Video VideoFromAnimeGroup(ISession session, AnimeGroup grp, int userid, List <AnimeSeries> allSeries)
        {
            Contract_AnimeGroup cgrp = grp.ToContract(grp.GetUserRecord(session, userid));

            if (StatsCache.Instance.StatGroupSeriesCount[grp.AnimeGroupID] == 1)
            {
                AnimeSeries ser = JMMServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                if (ser != null)
                {
                    Contract_AnimeSeries cserie = ser.ToContract(ser.GetUserRecord(session, userid), true);
                    Video v = FromSerieWithPossibleReplacement(cserie, ser, userid);
                    v.AirDate = ser.AirDate.HasValue ? ser.AirDate.Value : DateTime.MinValue;
                    v.Group   = cgrp;
                    return(v);
                }
            }
            else
            {
                AnimeSeries ser = grp.DefaultAnimeSeriesID.HasValue ? allSeries.FirstOrDefault(a => a.AnimeSeriesID == grp.DefaultAnimeSeriesID.Value) : JMMServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                if (ser != null)
                {
                    Video v = FromGroup(cgrp, ser.ToContract(ser.GetUserRecord(session, userid), true), userid);
                    v.Group   = cgrp;
                    v.AirDate = cgrp.Stat_AirDate_Min.HasValue ? cgrp.Stat_AirDate_Min.Value : DateTime.MinValue;
                    return(v);
                }
            }
            return(null);
        }
        public System.IO.Stream GetItemsFromGroup(int userid, string GroupId)
        {
            KodiObject ret = new KodiObject(KodiHelper.NewMediaContainer("Groups", true));

            if (!ret.Init())
            {
                return(new MemoryStream());
            }
            int groupID;

            int.TryParse(GroupId, out groupID);
            List <Video> retGroups = new List <Video>();

            if (groupID == -1)
            {
                return(new MemoryStream());
            }

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeGroup           grp       = repGroups.GetByID(groupID);
                if (grp != null)
                {
                    Contract_AnimeGroup basegrp = grp.ToContract(grp.GetUserRecord(session, userid));
                    ret.MediaContainer.Title1 = ret.MediaContainer.Title2 = basegrp.GroupName;
                    List <AnimeSeries> sers2 = grp.GetSeries(session);
                    ret.MediaContainer.Art = KodiHelper.GetRandomFanartFromSeries(sers2, session);
                    foreach (AnimeGroup grpChild in grp.GetChildGroups())
                    {
                        Video v = StatsCache.Instance.StatKodiGroupsCache[userid][grpChild.AnimeGroupID];
                        v.Type = "show";
                        if (v != null)
                        {
                            retGroups.Add(v.Clone());
                        }
                    }
                    foreach (AnimeSeries ser in grp.GetSeries())
                    {
                        Contract_AnimeSeries cserie = ser.ToContract(ser.GetUserRecord(session, userid), true);
                        Video v = KodiHelper.FromSerieWithPossibleReplacement(cserie, ser, userid);
                        v.AirDate = ser.AirDate.HasValue ? ser.AirDate.Value : DateTime.MinValue;
                        v.Group   = basegrp;
                        retGroups.Add(v);
                    }
                }
                ret.Childrens = retGroups.OrderBy(a => a.AirDate).ToList();
                return(ret.GetStream());
            }
        }
        public System.IO.Stream GetItemsFromGroup(int userid, string GroupId, HistoryInfo info)
        {
            PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show, info, false));

            if (!ret.Init())
            {
                return(new MemoryStream());
            }
            int groupID;

            int.TryParse(GroupId, out groupID);
            List <Video> retGroups = new List <Video>();

            if (groupID == -1)
            {
                return(new MemoryStream());
            }

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                AnimeGroup           grp       = repGroups.GetByID(groupID);
                if (grp != null)
                {
                    Contract_AnimeGroup basegrp = grp.ToContract(grp.GetUserRecord(session, userid));
                    List <AnimeSeries>  sers2   = grp.GetSeries(session);
                    foreach (AnimeGroup grpChild in grp.GetChildGroups())
                    {
                        Video v = StatsCache.Instance.StatPlexGroupsCache[userid][grpChild.AnimeGroupID];
                        if (v != null)
                        {
                            retGroups.Add(v.Clone(), info);
                        }
                    }
                    foreach (AnimeSeries ser in grp.GetSeries())
                    {
                        Contract_AnimeSeries cserie = ser.ToContract(ser.GetUserRecord(session, userid), true);
                        Video v = PlexHelper.FromSerieWithPossibleReplacement(cserie, ser, ser.GetAnime(), userid);
                        v.AirDate = ser.AirDate.HasValue ? ser.AirDate.Value : DateTime.MinValue;
                        v.Group   = basegrp;
                        retGroups.Add(v, info);
                    }
                }
                ret.Childrens = PlexHelper.ConvertToDirectoryIfNotUnique(retGroups.OrderBy(a => a.AirDate).ToList());
                return(ret.GetStream());
            }
        }