//private void FilterExtras(IProvider provider, List<Video> videos)
        //{
        //    //foreach (Video v in videos)
        //    //{
        //    //    if (!provider.EnableAnimeTitlesInLists)
        //    //        v.Titles = null;
        //    //    if (!provider.EnableGenresInLists)
        //    //        v.Genres = null;
        //    //    if (!provider.EnableRolesInLists)
        //    //        v.Roles = null;
        //    //}
        //}
        public MediaContainer GetItemsFromSerie(IProvider prov, int userid, string SerieId, BreadCrumbs info, bool nocast)
        {
            BaseObject ret = null;
            enEpisodeType? eptype = null;
            int serieID;
            if (SerieId.Contains("_"))
            {
                int ept;
                string[] ndata = SerieId.Split('_');
                if (!int.TryParse(ndata[0], out ept))
                    return new MediaContainer() {ErrorString = "Invalid Serie Id"};
                eptype = (enEpisodeType) ept;
                if (!int.TryParse(ndata[1], out serieID))
                    return new MediaContainer() { ErrorString = "Invalid Serie Id" };
            }
            else
            {
                if (!int.TryParse(SerieId, out serieID))
                    return new MediaContainer() { ErrorString = "Invalid Serie Id" };
            }

            using (var session = DatabaseFactory.SessionFactory.OpenSession())
            {
                if (serieID == -1)
                    return new MediaContainer() { ErrorString = "Invalid Serie Id" };
                ISessionWrapper sessionWrapper = session.Wrap();
                AnimeSeries ser = RepoFactory.AnimeSeries.GetByID(serieID);
                if (ser == null)
                    return new MediaContainer() {ErrorString = "Invalid Series"};
                Contract_AnimeSeries cseries = ser.GetUserContract(userid);
                if (cseries == null)
                    return new MediaContainer() {ErrorString = "Invalid Series, Contract Not Found"};
                Video nv = ser.GetPlexContract(userid);

                Dictionary<AnimeEpisode, Contract_AnimeEpisode> episodes = ser.GetAnimeEpisodes()
                    .ToDictionary(a => a, a => a.GetUserContract(userid));
                episodes = episodes.Where(a => a.Value == null || a.Value.LocalFileCount > 0)
                    .ToDictionary(a => a.Key, a => a.Value);
                if (eptype.HasValue)
                {
                    ret =
                        new BaseObject(prov.NewMediaContainer(MediaContainerTypes.Episode, ser.GetSeriesName(), true,
                            true, info));
                    if (!ret.Init())
                        return new MediaContainer();
                    ret.MediaContainer.Art = cseries.AniDBAnime?.AniDBAnime?.DefaultImageFanart.GenArt();
                    ret.MediaContainer.LeafCount =
                        (cseries.WatchedEpisodeCount + cseries.UnwatchedEpisodeCount).ToString();
                    ret.MediaContainer.ViewedLeafCount = cseries.WatchedEpisodeCount.ToString();
                    episodes = episodes.Where(a => a.Key.EpisodeTypeEnum == eptype.Value)
                        .ToDictionary(a => a.Key, a => a.Value);
                }
                else
                {
                    ret = new BaseObject(prov.NewMediaContainer(MediaContainerTypes.Show, "Types", false, true, info));
                    if (!ret.Init())
                        return new MediaContainer();
                    ret.MediaContainer.Art = cseries.AniDBAnime?.AniDBAnime?.DefaultImageFanart.GenArt();
                    ret.MediaContainer.LeafCount =
                        (cseries.WatchedEpisodeCount + cseries.UnwatchedEpisodeCount).ToString();
                    ret.MediaContainer.ViewedLeafCount = cseries.WatchedEpisodeCount.ToString();
                    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<Video> dirs = new List<Video>();
                        //bool converttoseason = true;

                        foreach (PlexEpisodeType ee in  eps.OrderBy(a=>a.Name))
                        {
                            Video v = new Directory();
                            v.Art = nv.Art;
                            v.Title = ee.Name;
                            v.AnimeType = "AnimeType";
                            v.LeafCount = ee.Count.ToString();
                            v.ChildCount = v.LeafCount;
                            v.ViewedLeafCount = "0";
                            v.Key = prov.ShortUrl(prov.ConstructSerieIdUrl(userid, ee.Type + "_" + ser.AnimeSeriesID));
                            v.Thumb = Helper.ConstructSupportImageLink(ee.Image);
                            if ((ee.AnimeType == AnimeTypes.Movie) || (ee.AnimeType == AnimeTypes.OVA))
                            {
                                v = Helper.MayReplaceVideo(v, ser, cseries, userid, false, nv);
                            }
                            dirs.Add(prov, v, info, false, true);
                        }
                        ret.Childrens = dirs;
                        return ret.GetStream(prov);
                    }
                }
                List<Video> vids = new List<Video>();

                if ((eptype.HasValue) && (info!=null))
                    info.ParentKey = info.GrandParentKey;
                bool hasRoles = false;
                foreach (KeyValuePair<AnimeEpisode, Contract_AnimeEpisode> ep in episodes)
                {
                    try
                    {
                        Video v = Helper.VideoFromAnimeEpisode(prov, cseries.CrossRefAniDBTvDBV2, ep, userid);
                        if (v!=null && v.Medias != null && v.Medias.Count > 0)
                        {
                            if (nocast && !hasRoles) hasRoles = true;
                            Helper.AddInformationFromMasterSeries(v, cseries, nv, hasRoles);
                            v.Type = "episode";
                            vids.Add(prov, v, info);
                            if (prov.ConstructFakeIosParent)
                                v.GrandparentKey =
                                    prov.Proxyfy(prov.ConstructFakeIosThumb(userid, v.ParentThumb,
                                        v.Art ?? v.ParentArt ?? v.GrandparentArt));
                            v.ParentKey = null;
                            if (!hasRoles) hasRoles = true;
                        }
                    }
                    catch (Exception e)
                    {
                        //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null)
                    }
                }
                ret.Childrens = vids.OrderBy(a => int.Parse(a.EpisodeNumber)).ToList();
                //FilterExtras(prov,ret.Childrens);
                return ret.GetStream(prov);
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public static void EpisodeTypeTranslated(PlexEpisodeType tp, enEpisodeType epType, AnimeTypes an, int cnt)
        {
            tp.Type      = (int)epType;
            tp.Count     = cnt;
            tp.AnimeType = an;
            bool plural = cnt > 1;

            switch (epType)
            {
            case enEpisodeType.Credits:
                tp.Name  = plural ? "Credits" : "Credit";
                tp.Image = "plex_credits.png";
                return;

            case enEpisodeType.Episode:
                switch (an)
                {
                case AnimeTypes.Movie:
                    tp.Name  = plural ? "Movies" : "Movie";
                    tp.Image = "plex_movies.png";
                    return;

                case AnimeTypes.OVA:
                    tp.Name  = plural ? "Ovas" : "Ova";
                    tp.Image = "plex_ovas.png";
                    return;

                case AnimeTypes.Other:
                    tp.Name  = plural ? "Others" : "Other";
                    tp.Image = "plex_others.png";
                    return;

                case AnimeTypes.TV_Series:
                    tp.Name  = plural ? "Episodes" : "Episode";
                    tp.Image = "plex_episodes.png";
                    return;

                case AnimeTypes.TV_Special:
                    tp.Name  = plural ? "TV Episodes" : "TV Episode";
                    tp.Image = "plex_tvepisodes.png";
                    return;

                case AnimeTypes.Web:
                    tp.Name  = plural ? "Web Clips" : "Web Clip";
                    tp.Image = "plex_webclips.png";
                    return;
                }
                tp.Name  = plural ? "Episodes" : "Episode";
                tp.Image = "plex_episodes.png";
                return;

            case enEpisodeType.Parody:
                tp.Name  = plural ? "Parodies" : "Parody";
                tp.Image = "plex_parodies.png";
                return;

            case enEpisodeType.Special:
                tp.Name  = plural ? "Specials" : "Special";
                tp.Image = "plex_specials.png";
                return;

            case enEpisodeType.Trailer:
                tp.Name  = plural ? "Trailers" : "Trailer";
                tp.Image = "plex_trailers.png";
                return;

            default:
                tp.Name  = "Misc";
                tp.Image = "plex_misc.png";
                return;
            }
        }
Exemplo n.º 4
0
 public static void EpisodeTypeTranslated(PlexEpisodeType tp, enEpisodeType epType, AnimeTypes an, int cnt)
 {
     tp.Type = (int) epType;
     tp.Count = cnt;
     tp.AnimeType = an;
     bool plural = cnt > 1;
     switch (epType)
     {
         case enEpisodeType.Credits:
             tp.Name = plural ? "Credits" : "Credit";
             tp.Image = "plex_credits.png";
             return;
         case enEpisodeType.Episode:
             switch (an)
             {
                 case AnimeTypes.Movie:
                     tp.Name = plural ? "Movies" : "Movie";
                     tp.Image = "plex_movies.png";
                     return;
                 case AnimeTypes.OVA:
                     tp.Name = plural ? "Ovas" : "Ova";
                     tp.Image = "plex_ovas.png";
                     return;
                 case AnimeTypes.Other:
                     tp.Name = plural ? "Others" : "Other";
                     tp.Image = "plex_others.png";
                     return;
                 case AnimeTypes.TV_Series:
                     tp.Name = plural ? "Episodes" : "Episode";
                     tp.Image = "plex_episodes.png";
                     return;
                 case AnimeTypes.TV_Special:
                     tp.Name = plural ? "TV Episodes" : "TV Episode";
                     tp.Image = "plex_tvepisodes.png";
                     return;
                 case AnimeTypes.Web:
                     tp.Name = plural ? "Web Clips" : "Web Clip";
                     tp.Image = "plex_webclips.png";
                     return;
             }
             tp.Name = plural ? "Episodes" : "Episode";
             tp.Image = "plex_episodes.png";
             return;
         case enEpisodeType.Parody:
             tp.Name = plural ? "Parodies" : "Parody";
             tp.Image = "plex_parodies.png";
             return;
         case enEpisodeType.Special:
             tp.Name = plural ? "Specials" : "Special";
             tp.Image = "plex_specials.png";
             return;
         case enEpisodeType.Trailer:
             tp.Name = plural ? "Trailers" : "Trailer";
             tp.Image = "plex_trailers.png";
             return;
         default:
             tp.Name = "Misc";
             tp.Image = "plex_misc.png";
             return;
     }
 }