Exemplo n.º 1
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.º 2
0
        public System.IO.Stream GetItemsFromSerie(int userid, string SerieId,HistoryInfo info)
        {
            PlexObject 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 MemoryStream();
                eptype = (enEpisodeType) ept;
                if (!int.TryParse(ndata[1], out serieID))
                    return new MemoryStream();
            }
            else
            {
                if (!int.TryParse(SerieId, out serieID))
                    return new MemoryStream();
            }

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                if (serieID == -1)
                    return new MemoryStream();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByID(session, serieID);
                if (ser == null)
                    return new MemoryStream();
                AniDB_Anime anime = ser.GetAnime();
                if (anime == null)
                    return new MemoryStream();
                Contract_AnimeSeries cseries = ser.ToContract(ser.GetUserRecord(userid), true);
                ImageDetails fanart = anime.GetDefaultFanartDetailsNoBlanks(session);

                //iOS Hack, since it uses the previous thumb, as overlay image on the episodes
                bool iosHack = false;
                if (WebOperationContext.Current != null && WebOperationContext.Current.IncomingRequest.Headers.AllKeys.Contains("X-Plex-Product"))
                {
                    string kh = WebOperationContext.Current.IncomingRequest.Headers.Get("X-Plex-Product").ToUpper();
                    if (kh.Contains(" IOS"))
                        iosHack = true;
                }

                List<AnimeEpisode> episodes = ser.GetAnimeEpisodes(session).Where(a => a.GetVideoLocals(session).Count > 0).ToList();
                if (eptype.HasValue)
                {
                    ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Episode, info, true));
                    if (!ret.Init())
                        return new MemoryStream();
                    ret.MediaContainer.LeafCount = (cseries.WatchedEpisodeCount + cseries.UnwatchedEpisodeCount).ToString();
                    ret.MediaContainer.ViewedLeafCount = cseries.WatchedEpisodeCount.ToString();
                    episodes = episodes.Where(a => a.EpisodeTypeEnum == eptype.Value).ToList();
                }
                else
                {
                    ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show, info, true));
                    if (!ret.Init())
                        return new MemoryStream();

                    ret.MediaContainer.LeafCount = (cseries.WatchedEpisodeCount + cseries.UnwatchedEpisodeCount).ToString();
                    ret.MediaContainer.ViewedLeafCount = cseries.WatchedEpisodeCount.ToString();
                    List<enEpisodeType> types = episodes.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)anime.AnimeType, episodes.Count(a => a.EpisodeTypeEnum == ee));
                            eps.Add(k2);
                        }
                        List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                        sortCriteria.Add(new SortPropOrFieldAndDirection("Name", SortType.eString));
                        eps = Sorting.MultiSort(eps, sortCriteria);
                        List<Video> dirs= new List<Video>();
                        bool converttoseason = true;

                        foreach (PlexEpisodeType ee in  eps)
                        {
                            Video v = new Directory();
                            if (fanart != null)
                                v.Art = fanart.GenArt();
                            v.Title = ee.Name;
                            v.LeafCount = ee.Count.ToString();
                            v.ChildCount = v.LeafCount;
                            v.ViewedLeafCount = "0";
                            v.Key = PlexHelper.ConstructSerieIdUrl(userid, ee.Type + "_" + ser.AnimeSeriesID);
                            v.Thumb = PlexHelper.ConstructSupportImageLink(ee.Image);
                            if ((ee.AnimeType==AnimeTypes.Movie) || (ee.AnimeType==AnimeTypes.OVA))
                            {
                                v = PlexHelper.MayReplaceVideo(v, ser, cseries, anime,  JMMType.File, userid, false);
                            }
                            dirs.Add(v,info);
                            if (iosHack)
                            {
                                v.Thumb = ret.MediaContainer.ParentThumb;
                                v.ParentThumb = ret.MediaContainer.GrandparentThumb;
                                v.GrandparentThumb = ret.MediaContainer.GrandparentThumb;
                                v.ParentKey = v.GrandparentKey;
                            }
                        }
                        ret.Childrens = dirs;
                        return ret.GetStream();
                    }
                }
                List<Video> vids=new List<Video>();
                Video nv = new Video();
                PlexHelper.FillSerie(nv,ser,anime, cseries, userid);
                foreach (AnimeEpisode ep in episodes)
                {

                    Video v = new Video();
                    List<VideoLocal> locals = ep.GetVideoLocals(session);
                    if ((locals == null) || (locals.Count == 0))
                        continue;
                    AniDB_Episode aep = ep.AniDB_Episode;
                    if (aep == null)
                        continue;
                    VideoLocal current = locals[0];
                    try
                    {
                        PlexHelper.PopulateVideo(v, current, ep, ser, cseries, anime, nv, JMMType.File, userid);
                        vids.Add(v, info);
                        if (iosHack)
                        {
                            v.Art = v.Thumb;
                            v.Thumb = ret.MediaContainer.ParentThumb;
                        }
                    }
                    catch (Exception e)
                    {
                        //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null)
                    }
                }

                List<SortPropOrFieldAndDirection> sortCriteria2 = new List<SortPropOrFieldAndDirection>();
                sortCriteria2.Add(new SortPropOrFieldAndDirection("EpNumber", SortType.eInteger));
                vids= Sorting.MultiSort(vids, sortCriteria2);
                ret.Childrens = vids;

                return ret.GetStream();
            }
        }
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;
     }
 }
        public System.IO.Stream GetItemsFromSerie(int userid, string SerieId)
        {
            PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer("Series", true));
            if (!ret.Init())
                return new MemoryStream();
            enEpisodeType? eptype = null;
            int serieID ;
            if (SerieId.Contains("_"))
            {
                int ept ;
                string[] ndata = SerieId.Split('_');
                if (!int.TryParse(ndata[0], out ept))
                    return new MemoryStream();
                eptype = (enEpisodeType) ept;
                if (!int.TryParse(ndata[1], out serieID))
                    return new MemoryStream();
            }
            else
            {
                if (!int.TryParse(SerieId, out serieID))
                    return new MemoryStream();
            }

            
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                if (serieID == -1)
                    return new MemoryStream();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByID(session, serieID);
                if (ser == null)
                    return new MemoryStream();
                AniDB_Anime anime = ser.GetAnime();
                if (anime == null)
                    return new MemoryStream();

                ImageDetails fanart = anime.GetDefaultFanartDetailsNoBlanks(session);
                if (fanart != null)
                    ret.MediaContainer.Art = fanart.GenArt();
                ret.MediaContainer.Title2 = ret.MediaContainer.Title1 = anime.MainTitle;
                List<AnimeEpisode> episodes = ser.GetAnimeEpisodes(session).Where(a => a.GetVideoLocals(session).Count > 0).ToList();
                if (eptype.HasValue)
                {
                    episodes = episodes.Where(a => a.EpisodeTypeEnum == eptype.Value).ToList();
                }
                else
                {
                    List<enEpisodeType> types = episodes.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)anime.AnimeType, episodes.Count(a => a.EpisodeTypeEnum == ee));
                            eps.Add(k2);
                        }
                        List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                        sortCriteria.Add(new SortPropOrFieldAndDirection("Name", SortType.eString));
                        eps = Sorting.MultiSort(eps, sortCriteria);
                        List<Video> dirs= new List<Video>();

                        foreach (PlexEpisodeType ee in  eps)
                        {
                            Video v = new Directory();
                            v.Title = ee.Name;
                            v.Type = "season";
                            v.LeafCount = ee.Count.ToString();
                            v.ViewedLeafCount = "0";
                            v.Key = PlexHelper.PlexProxy(PlexHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressPlex + "/GetMetadata/" + userid + "/" + (int)JMMType.Serie + "/" + ee.Type + "_" + ser.AnimeSeriesID));
                            v.Thumb = PlexHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort),
                                MainWindow.PathAddressPlex + "/GetSupportImage/" + ee.Image);
                            if ((ee.AnimeType==AnimeTypes.Movie) || (ee.AnimeType==AnimeTypes.OVA))
                            {
                                v = PlexHelper.MayReplaceVideo((Directory)v, ser,anime,  JMMType.File, userid, false);
                            }

                            dirs.Add(v);
                        }
                        ret.Childrens = dirs;
                        return ret.GetStream();
                    }
                }
                List<Video> vids=new List<Video>();
                Contract_AnimeSeries cseries = ser.ToContract(ser.GetUserRecord(userid), true);
                Video nv = PlexHelper.FromSerie(cseries, userid);
                PlexEpisodeType k = new PlexEpisodeType();
                if (eptype.HasValue)
                {
                    PlexEpisodeType.EpisodeTypeTranslated(k, (enEpisodeType) eptype.Value, (AnimeTypes) anime.AnimeType,
                        episodes.Count);
                }
                foreach (AnimeEpisode ep in episodes)
                {
                    Video v = new Video();
                    List<VideoLocal> locals = ep.GetVideoLocals(session);
                    if ((locals == null) || (locals.Count == 0))
                        continue;
                    AniDB_Episode aep = ep.AniDB_Episode;
                    if (aep == null)
                        continue;
                    VideoLocal current = locals[0];
                    try
                    {
                        PlexHelper.PopulateVideo(v, current, ep, ser, anime, nv, JMMType.File, userid);
                        if (eptype.HasValue)
                        {
                            v.ParentTitle = k.Name;
                        }
                        vids.Add(v);
                    }
                    catch (Exception e)
                    {
                        //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null)
                    }
                }

                List<SortPropOrFieldAndDirection> sortCriteria2 = new List<SortPropOrFieldAndDirection>();
                sortCriteria2.Add(new SortPropOrFieldAndDirection("EpNumber", SortType.eInteger));
                vids= Sorting.MultiSort(vids, sortCriteria2);
                ret.Childrens = vids;
                return ret.GetStream();
            }
        }