Example #1
0
        public static Video GenerateVideoFromAnimeEpisode(AnimeEpisode ep)
        {
            Video             l    = new Video();
            List <VideoLocal> vids = ep.GetVideoLocals();

            l.Type      = "episode";
            l.Summary   = "Episode Overview Not Available"; //TODO Intenationalization
            l.Id        = ep.AnimeEpisodeID.ToString();
            l.AnimeType = JMMContracts.PlexAndKodi.AnimeTypes.AnimeEpisode.ToString();
            VideoLocalRepository repo = new VideoLocalRepository();

            if (vids.Count > 0)
            {
                l.Title                 = Path.GetFileNameWithoutExtension(vids[0].FilePath);
                l.AddedAt               = vids[0].DateTimeCreated.ToUnixTime();
                l.UpdatedAt             = vids[0].DateTimeUpdated.ToUnixTime();
                l.OriginallyAvailableAt = vids[0].DateTimeCreated.ToPlexDate();
                l.Year   = vids[0].DateTimeCreated.Year.ToString();
                l.Medias = new List <Media>();
                foreach (VideoLocal v in vids)
                {
                    Media m = v.Media;
                    if (m == null)
                    {
                        if (File.Exists(v.FullServerPath))
                        {
                            repo.Save(v, false);
                        }
                    }
                    if (m != null)
                    {
                        l.Medias.Add(m);
                        l.Duration = m.Duration;
                    }
                }
            }
            AniDB_Episode aep = ep?.AniDB_Episode;

            if (aep != null)
            {
                l.EpisodeNumber = aep.EpisodeNumber.ToString();
                l.Index         = aep.EpisodeNumber.ToString();
                l.Title         = aep.EnglishName;
                l.OriginalTitle = aep.RomajiName;
                l.EpisodeType   = aep.EpisodeType.ToString();
                l.Rating        = float.Parse(aep.Rating, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture);
                if (aep.AirDateAsDate.HasValue)
                {
                    l.Year = aep.AirDateAsDate.Value.Year.ToString();
                    l.OriginallyAvailableAt = aep.AirDateAsDate.Value.ToPlexDate();
                }

                //FIX THIS
                MetroContract_Anime_Episode contract = new MetroContract_Anime_Episode();
                JMMServiceImplementationMetro.SetTvDBInfo(aep.AnimeID, aep, ref contract);
                l.Thumb   = contract.GenPoster();
                l.Summary = contract.EpisodeOverview;
            }
            l.Id = ep.AnimeEpisodeID.ToString();
            return(l);
        }
Example #2
0
        public static Video GenerateVideoFromAnimeEpisode(AnimeEpisode ep)
        {
            Video             l    = new Video();
            List <VideoLocal> vids = ep.GetVideoLocals();

            l.Type      = "episode";
            l.Summary   = "Episode Overview Not Available"; //TODO Intenationalization
            l.Id        = ep.AnimeEpisodeID.ToString();
            l.AnimeType = JMMContracts.PlexAndKodi.AnimeTypes.AnimeEpisode.ToString();
            if (vids.Count > 0)
            {
                //List<string> hashes = vids.Select(a => a.Hash).Distinct().ToList();
                l.Title                 = Path.GetFileNameWithoutExtension(vids[0].FileName);
                l.AddedAt               = vids[0].DateTimeCreated.ToUnixTime();
                l.UpdatedAt             = vids[0].DateTimeUpdated.ToUnixTime();
                l.OriginallyAvailableAt = vids[0].DateTimeCreated.ToPlexDate();
                l.Year   = vids[0].DateTimeCreated.Year.ToString();
                l.Medias = new List <Media>();
                foreach (VideoLocal v in vids)
                {
                    if (string.IsNullOrEmpty(v.Media?.Duration))
                    {
                        VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                        if (pl != null)
                        {
                            if (pl.RefreshMediaInfo())
                            {
                                RepoFactory.VideoLocal.Save(v, true);
                            }
                        }
                    }
                    if (v.Media != null)
                    {
                        l.Medias.Add(v.Media);
                    }
                }
            }
            AniDB_Episode aep = ep?.AniDB_Episode;

            if (aep != null)
            {
                l.EpisodeNumber = aep.EpisodeNumber.ToString();
                l.Index         = aep.EpisodeNumber.ToString();
                l.Title         = aep.EnglishName;
                l.OriginalTitle = aep.RomajiName;
                l.EpisodeType   = aep.EpisodeType.ToString();
                l.Rating        = float.Parse(aep.Rating, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture);
                if (aep.AirDateAsDate.HasValue)
                {
                    l.Year = aep.AirDateAsDate.Value.Year.ToString();
                    l.OriginallyAvailableAt = aep.AirDateAsDate.Value.ToPlexDate();
                }

                //FIX THIS
                MetroContract_Anime_Episode contract = new MetroContract_Anime_Episode();
                JMMServiceImplementationMetro.SetTvDBInfo(aep.AnimeID, aep, ref contract);
                l.Thumb   = contract.GenPoster();
                l.Summary = contract.EpisodeOverview;
            }
            l.Id = ep.AnimeEpisodeID.ToString();
            return(l);
        }
Example #3
0
        internal Episode GenerateFromAnimeEpisode(AnimeEpisode aep, int uid, int level)
        {
            Episode ep = new Episode();

            if (aep != null)
            {
                JMMContracts.Contract_AnimeEpisode cae = aep.GetUserContract(uid);
                if (cae != null)
                {
                    ep.id      = aep.AniDB_EpisodeID;
                    ep.art     = new ArtCollection();
                    ep.id      = aep.AnimeEpisodeID;
                    ep.type    = aep.EpisodeTypeEnum.ToString();
                    ep.title   = aep.PlexContract?.Title;
                    ep.summary = aep.PlexContract?.Summary;
                    ep.year    = aep.PlexContract?.Year;
                    ep.air     = aep.PlexContract?.AirDate.ToString();
                    ep.rating  = aep.PlexContract?.Rating;
                    double rating;
                    if (double.TryParse(ep.rating, out rating))
                    {
                        ep.rating = (rating / 100).ToString().Replace(',', '.');
                    }

                    ep.view     = cae.IsWatched;
                    ep.epnumber = cae.EpisodeNumber;
                    ep.eptype   = cae.EpisodeType;

                    // until fanart refactor this will be good for start
                    if (aep.PlexContract?.Thumb != null)
                    {
                        ep.art.thumb.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromRest(aep.PlexContract?.Thumb), index = 0
                        });
                    }
                    if (aep.PlexContract?.Art != null)
                    {
                        ep.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromRest(aep.PlexContract?.Art), index = 0
                        });
                    }

                    if (level != 1)
                    {
                        List <VideoLocal> vls = aep.GetVideoLocals();
                        if (vls.Count > 0)
                        {
                            ep.files = new List <RawFile>();
                            foreach (VideoLocal vl in vls)
                            {
                                ep.files.Add(new RawFile(vl, (level - 1), uid));
                            }
                        }
                    }
                }
            }

            return(ep);
        }
Example #4
0
        public static Video GenerateVideoFromAnimeEpisode(AnimeEpisode ep)
        {
            Video             l    = new Video();
            List <VideoLocal> vids = ep.GetVideoLocals();

            l.Type      = "episode";
            l.Summary   = "Episode Overview Not Available"; //TODO Intenationalization
            l.Id        = ep.AnimeEpisodeID.ToString();
            l.AnimeType = JMMContracts.PlexAndKodi.AnimeTypes.AnimeEpisode.ToString();
            if (vids.Count > 0)
            {
                //List<string> hashes = vids.Select(a => a.Hash).Distinct().ToList();
                l.Title                 = Path.GetFileNameWithoutExtension(vids[0].FileName);
                l.AddedAt               = vids[0].DateTimeCreated.ToUnixTime();
                l.UpdatedAt             = vids[0].DateTimeUpdated.ToUnixTime();
                l.OriginallyAvailableAt = vids[0].DateTimeCreated.ToPlexDate();
                l.Year   = vids[0].DateTimeCreated.Year.ToString();
                l.Medias = new List <Media>();
                foreach (VideoLocal v in vids)
                {
                    if (string.IsNullOrEmpty(v.Media?.Duration))
                    {
                        VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                        if (pl != null)
                        {
                            if (pl.RefreshMediaInfo())
                            {
                                RepoFactory.VideoLocal.Save(v, true);
                            }
                        }
                    }
                    v.Media?.Parts?.Where(a => a != null)?.ToList()?.ForEach(a =>
                    {
                        if (String.IsNullOrEmpty(a.LocalKey))
                        {
                            a.LocalKey = v?.GetBestVideoLocalPlace()?.FullServerPath ?? null;
                        }
                    });
                    if (v.Media != null)
                    {
                        l.Medias.Add(v.Media);
                    }
                }

                AniDB_Episode aep = ep?.AniDB_Episode;
                if (aep != null)
                {
                    l.EpisodeNumber = aep.EpisodeNumber.ToString();
                    l.Index         = aep.EpisodeNumber.ToString();
                    l.Title         = aep.EnglishName;
                    l.OriginalTitle = aep.RomajiName;
                    l.EpisodeType   = aep.EpisodeType.ToString();
                    l.Rating        = float.Parse(aep.Rating, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture);
                    if (aep.AirDateAsDate.HasValue)
                    {
                        l.Year = aep.AirDateAsDate.Value.Year.ToString();
                        l.OriginallyAvailableAt = aep.AirDateAsDate.Value.ToPlexDate();
                    }

                    #region TvDB

                    using (var session = DatabaseFactory.SessionFactory.OpenSession())
                    {
                        List <CrossRef_AniDB_TvDBV2> xref_tvdb2 =
                            RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeIDEpTypeEpNumber(session, aep.AnimeID,
                                                                                         aep.EpisodeType, aep.EpisodeNumber);
                        if (xref_tvdb2 != null && xref_tvdb2.Count > 0)
                        {
                            TvDB_Episode tvep = GetTvDBEpisodeFromAniDB(session, aep, xref_tvdb2[0]);

                            if (tvep != null)
                            {
                                l.Thumb   = tvep.GenPoster();
                                l.Summary = tvep.Overview;
                            }
                            else
                            {
                                string      anime = "[Blank]";
                                AnimeSeries ser   = ep.GetAnimeSeries();
                                if (ser != null && ser.GetSeriesName() != null)
                                {
                                    anime = ser.GetSeriesName();
                                }
                                LogManager.GetCurrentClassLogger().Error("Episode " + aep.EpisodeNumber + ": " + aep.EnglishName + " from " + anime + " is out of range for its TvDB Link. Please relink it.");
                            }
                        }
                    }

                    #endregion

                    #region TvDB Overrides

                    CrossRef_AniDB_TvDB_Episode xref_tvdb =
                        RepoFactory.CrossRef_AniDB_TvDB_Episode.GetByAniDBEpisodeID(aep.AniDB_EpisodeID);
                    if (xref_tvdb != null)
                    {
                        TvDB_Episode tvdb_ep = RepoFactory.TvDB_Episode.GetByTvDBID(xref_tvdb.TvDBEpisodeID);
                        if (tvdb_ep != null)
                        {
                            l.Thumb   = tvdb_ep.GenPoster();
                            l.Summary = tvdb_ep.Overview;
                        }
                    }

                    #endregion
                }
                if (l.Thumb == null || l.Summary == null)
                {
                    l.Thumb   = ConstructSupportImageLink("plex_404.png");
                    l.Summary = "Episode Overview not Available";
                }
            }
            l.Id = ep.AnimeEpisodeID.ToString();
            return(l);
        }