예제 #1
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Reading Media Info for File: {0}", VideoLocalID);


            try
            {
                ReportInit(progress);
                SVR_VideoLocal       vlocal = Repo.Instance.VideoLocal.GetByID(VideoLocalID);
                SVR_VideoLocal_Place place  = vlocal?.GetBestVideoLocalPlace(true);
                ReportUpdate(progress, 50);
                if (place == null)
                {
                    ReportError(progress, $"Could not find VideoLocal: {VideoLocalID}");
                    return;
                }
                using (var txn = Repo.Instance.VideoLocal.BeginAddOrUpdate(place.VideoLocalID))
                {
                    if (place.RefreshMediaInfo(txn.Entity))
                    {
                        txn.Commit();
                    }
                }

                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing ServerReadMediaInfo: {VideoLocalID} - {ex}", ex);
            }
        }
        public override void ProcessCommand()
        {
            logger.Info("Reading Media Info for File: {0}", VideoLocalID);


            try
            {
                SVR_VideoLocal       vlocal = Repo.Instance.VideoLocal.GetByID(VideoLocalID);
                SVR_VideoLocal_Place place  = vlocal?.GetBestVideoLocalPlace(true);
                if (place == null)
                {
                    logger.Error("Cound not find Video: {0}", VideoLocalID);
                    return;
                }
                using (var txn = Repo.Instance.VideoLocal.BeginAddOrUpdate(() => place.VideoLocal))
                {
                    if (place.RefreshMediaInfo(txn.Entity))
                    {
                        txn.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_ReadMediaInfo: {0} - {1}", VideoLocalID, ex);
            }
        }
예제 #3
0
        public override void ProcessCommand()
        {
            logger.Info("Reading Media Info for File: {0}", VideoLocalID);


            try
            {
                SVR_VideoLocal       vlocal = RepoFactory.VideoLocal.GetByID(VideoLocalID);
                SVR_VideoLocal_Place place  = vlocal?.GetBestVideoLocalPlace();
                if (place == null)
                {
                    logger.Error("Cound not find Video: {0}", VideoLocalID);
                    return;
                }
                if (place.RefreshMediaInfo())
                {
                    RepoFactory.VideoLocal.Save(place.VideoLocal, true);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_ReadMediaInfo: {0} - {1}", VideoLocalID, ex.ToString());
                return;
            }
        }
예제 #4
0
 private void UpdateMediaContracts(SVR_VideoLocal obj)
 {
     if (obj.Media == null || obj.MediaVersion < SVR_VideoLocal.MEDIA_VERSION || obj.Duration == 0)
     {
         SVR_VideoLocal_Place place = obj.GetBestVideoLocalPlace();
         place?.RefreshMediaInfo();
     }
 }
예제 #5
0
        public static Video VideoFromVideoLocal(IProvider prov, SVR_VideoLocal v, int userid)
        {
            Video l = new Video
            {
                AnimeType             = AnimeTypes.AnimeFile.ToString(),
                Id                    = v.VideoLocalID,
                Type                  = "episode",
                Summary               = "Episode Overview Not Available", //TODO Intenationalization
                Title                 = Path.GetFileNameWithoutExtension(v.Info),
                AddedAt               = v.DateTimeCreated.ToUnixTime(),
                UpdatedAt             = v.DateTimeUpdated.ToUnixTime(),
                OriginallyAvailableAt = v.DateTimeCreated.ToPlexDate(),
                Year                  = v.DateTimeCreated.Year,
                Medias                = new List <Media>()
            };
            VideoLocal_User vlr = v.GetUserRecord(userid);

            if (vlr?.WatchedDate != null)
            {
                l.LastViewedAt = vlr.WatchedDate.Value.ToUnixTime();
            }
            if (vlr?.ResumePosition > 0)
            {
                l.ViewOffset = vlr.ResumePosition;
            }
            Media m = v.Media;

            if (m?.Duration != 0)
            {
                SVR_VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                if (pl != null)
                {
                    using (var upd = Repo.Instance.VideoLocal.BeginAddOrUpdate(v))
                    {
                        if (pl.RefreshMediaInfo(upd.Entity))
                        {
                            upd.Commit(true);
                        }
                    }
                }
                m = v.Media;
            }
            if (m != null)
            {
                l.Medias.Add(m);
                l.Duration = m.Duration;
            }
            AddLinksToAnimeEpisodeVideo(prov, l, userid);
            return(l);
        }
예제 #6
0
        public static Video VideoFromVideoLocal(IProvider prov, SVR_VideoLocal v, int userid)
        {
            Video l = new Video();

            l.AnimeType             = AnimeTypes.AnimeFile.ToString();
            l.Id                    = v.VideoLocalID.ToString();
            l.Type                  = "episode";
            l.Summary               = "Episode Overview Not Available"; //TODO Intenationalization
            l.Title                 = Path.GetFileNameWithoutExtension(v.FileName);
            l.AddedAt               = v.DateTimeCreated.ToUnixTime();
            l.UpdatedAt             = v.DateTimeUpdated.ToUnixTime();
            l.OriginallyAvailableAt = v.DateTimeCreated.ToPlexDate();
            l.Year                  = v.DateTimeCreated.Year.ToString();
            l.Medias                = new List <Media>();
            VideoLocal_User vlr = v.GetUserRecord(userid);

            if (vlr != null)
            {
                if (vlr.WatchedDate.HasValue)
                {
                    l.LastViewedAt = vlr.WatchedDate.Value.ToUnixTime();
                }
                if (vlr.ResumePosition > 0)
                {
                    l.ViewOffset = vlr.ResumePosition.ToString();
                }
            }
            Media m = v.Media;

            if (string.IsNullOrEmpty(m?.Duration))
            {
                SVR_VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                if (pl != null)
                {
                    if (pl.RefreshMediaInfo())
                    {
                        RepoFactory.VideoLocal.Save(v, true);
                    }
                }
                m = v.Media;
            }
            if (m != null)
            {
                l.Medias.Add(m);
                l.Duration = m.Duration;
            }
            AddLinksToAnimeEpisodeVideo(prov, l, userid);
            return(l);
        }
예제 #7
0
        public static Video GenerateVideoFromAnimeEpisode(SVR_AnimeEpisode ep)
        {
            Video l = new Video();
            List <SVR_VideoLocal> vids = ep.GetVideoLocals();

            l.Type      = "episode";
            l.Summary   = "Episode Overview Not Available"; //TODO Intenationalization
            l.Id        = ep.AnimeEpisodeID.ToString();
            l.AnimeType = 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 (SVR_VideoLocal v in vids)
                {
                    if (string.IsNullOrEmpty(v.Media?.Duration))
                    {
                        SVR_VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                        if (pl?.RefreshMediaInfo() == true)
                        {
                            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);
                    AniDB_Vote vote =
                        RepoFactory.AniDB_Vote.GetByEntityAndType(ep.AnimeEpisodeID, AniDBVoteType.Episode);
                    if (vote != null)
                    {
                        l.UserRating = (vote.VoteValue / 100D).ToString(CultureInfo.InvariantCulture);
                    }

                    if (aep.GetAirDateAsDate().HasValue)
                    {
                        l.Year = aep.GetAirDateAsDate()?.Year.ToString();
                        l.OriginallyAvailableAt = aep.GetAirDateAsDate()?.ToPlexDate();
                    }

                    #region TvDB

                    using (var session = DatabaseFactory.SessionFactory.OpenSession())
                    {
                        List <CrossRef_AniDB_TvDBV2> xref_tvdbv2 =
                            RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeIDEpTypeEpNumber(aep.AnimeID, aep.EpisodeType,
                                                                                         aep.EpisodeNumber);
                        if (xref_tvdbv2?.Count > 0)
                        {
                            TvDB_Episode tvep = ep?.TvDBEpisode;

                            if (tvep != null)
                            {
                                l.Thumb   = tvep.GenPoster(null);
                                l.Summary = tvep.Overview;
                                l.Season  = $"{tvep.SeasonNumber}x{tvep.EpisodeNumber:0#}";
                            }
                            else
                            {
                                string          anime = "[Blank]";
                                SVR_AnimeSeries ser   = ep.GetAnimeSeries();
                                if (ser?.GetSeriesName() != null)
                                {
                                    anime = ser.GetSeriesName();
                                }
                                LogManager.GetCurrentClassLogger()
                                .Warn(
                                    $"Episode {aep.EpisodeNumber}: {aep.EnglishName} from {anime} is out of range" +
                                    " for its TvDB Link. Please check the TvDB links for 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(null);
                            l.Summary = tvdb_ep.Overview;
                            l.Season  = $"{tvdb_ep.SeasonNumber}x{tvdb_ep.EpisodeNumber:0#}";
                        }
                    }

                    #endregion
                }
                if (l.Thumb == null || l.Summary == null)
                {
                    l.Thumb   = ((IProvider)null).ConstructSupportImageLink("plex_404.png");
                    l.Summary = "Episode Overview not Available";
                }
            }
            l.Id = ep.AnimeEpisodeID.ToString();
            return(l);
        }
예제 #8
0
        public static Video VideoFromAnimeEpisode(IProvider prov, List <CrossRef_AniDB_TvDBV2> cross,
                                                  KeyValuePair <SVR_AnimeEpisode, CL_AnimeEpisode_User> e, int userid)
        {
            Video v = e.Key.PlexContract?.Clone <Video>(prov);

            if (v?.Thumb != null)
            {
                v.Thumb = prov.ReplaceSchemeHost(v.Thumb);
            }
            if (v != null && (v.Medias == null || v.Medias.Count == 0))
            {
                foreach (SVR_VideoLocal vl2 in e.Key.GetVideoLocals())
                {
                    if (!string.IsNullOrEmpty(vl2.Media?.Duration))
                    {
                        continue;
                    }
                    SVR_VideoLocal_Place pl = vl2.GetBestVideoLocalPlace();
                    if (pl?.RefreshMediaInfo() == true)
                    {
                        RepoFactory.VideoLocal.Save(vl2, true);
                    }
                }
                RepoFactory.AnimeEpisode.Save(e.Key);
                v = e.Key.PlexContract?.Clone <Video>(prov);
            }
            if (v != null)
            {
                if (e.Value != null)
                {
                    v.ViewCount = e.Value.WatchedCount.ToString();
                    if (e.Value.WatchedDate.HasValue)
                    {
                        v.LastViewedAt = e.Value.WatchedDate.Value.ToUnixTime();
                    }
                }
                v.ParentIndex = "1";
                if (e.Key.EpisodeTypeEnum != enEpisodeType.Episode)
                {
                    v.ParentIndex = null;
                }

                if (e.Key.EpisodeTypeEnum == enEpisodeType.Episode)
                {
                    string client = prov.GetPlexClient().Product;
                    if (client == "Plex for Windows" || client == "Plex Home Theater")
                    {
                        v.Title = $"{v.EpisodeNumber}. {v.Title}";
                    }
                }

                if (cross != null && cross.Count > 0)
                {
                    CrossRef_AniDB_TvDBV2 c2 =
                        cross.FirstOrDefault(
                            a =>
                            a.AniDBStartEpisodeType == int.Parse(v.EpisodeType) &&
                            a.AniDBStartEpisodeNumber <= int.Parse(v.EpisodeNumber));
                    if (c2?.TvDBSeasonNumber > 0)
                    {
                        v.ParentIndex = c2.TvDBSeasonNumber.ToString();
                    }
                }
                AddLinksToAnimeEpisodeVideo(prov, v, userid);
            }
            v.AddResumePosition(prov, userid);

            return(v);
        }
예제 #9
0
        public static Video GenerateVideoFromAnimeEpisode(SVR_AnimeEpisode ep)
        {
            Video l = new Video();
            List <SVR_VideoLocal> vids = ep.GetVideoLocals();

            l.Type      = "episode";
            l.Summary   = "Episode Overview Not Available"; //TODO Intenationalization
            l.Id        = ep.AnimeEpisodeID;
            l.AnimeType = AnimeTypes.AnimeEpisode.ToString();
            if (vids.Count > 0)
            {
                //List<string> hashes = vids.Select(a => a.Hash).Distinct().ToList();
                l.Title                 = Path.GetFileNameWithoutExtension(vids[0].Info);
                l.AddedAt               = vids[0].DateTimeCreated.ToUnixTime();
                l.UpdatedAt             = vids[0].DateTimeUpdated.ToUnixTime();
                l.OriginallyAvailableAt = vids[0].DateTimeCreated.ToPlexDate();
                l.Year   = vids[0].DateTimeCreated.Year;
                l.Medias = new List <Media>();
                foreach (SVR_VideoLocal v in vids)
                {
                    if ((v.Media?.Duration ?? 0) == 0)
                    {
                        SVR_VideoLocal_Place pl = v.GetBestVideoLocalPlace();
                        if (pl != null)
                        {
                            using (var upd = Repo.Instance.VideoLocal.BeginAddOrUpdate(v))
                            {
                                if (pl.RefreshMediaInfo(upd.Entity))
                                {
                                    upd.Commit(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);
                    }
                }

                string title = ep.Title;
                if (!string.IsNullOrEmpty(title))
                {
                    l.Title = title;
                }

                string romaji = Repo.Instance.AniDB_Episode_Title.GetByEpisodeIDAndLanguage(ep.AniDB_EpisodeID, "X-JAT")
                                .FirstOrDefault()?.Title;
                if (!string.IsNullOrEmpty(romaji))
                {
                    l.OriginalTitle = romaji;
                }

                AniDB_Episode aep = ep?.AniDB_Episode;
                if (aep != null)
                {
                    l.EpisodeNumber = aep.EpisodeNumber;
                    l.Index         = aep.EpisodeNumber;
                    l.EpisodeType   = aep.EpisodeType;
                    l.Rating        = (int)float.Parse(aep.Rating, CultureInfo.InvariantCulture);
                    AniDB_Vote vote =
                        Repo.Instance.AniDB_Vote.GetByEntityAndType(ep.AnimeEpisodeID, AniDBVoteType.Episode);
                    if (vote != null)
                    {
                        l.UserRating = (int)(vote.VoteValue / 100D);
                    }

                    if (aep.GetAirDateAsDate().HasValue)
                    {
                        l.Year = aep.GetAirDateAsDate()?.Year ?? 0;
                        l.OriginallyAvailableAt = aep.GetAirDateAsDate()?.ToPlexDate();
                    }

                    #region TvDB

                    TvDB_Episode tvep = ep.TvDBEpisode;
                    if (tvep != null)
                    {
                        l.Thumb   = tvep.GenPoster(null);
                        l.Summary = tvep.Overview;
                        l.Season  = $"{tvep.SeasonNumber}x{tvep.EpisodeNumber:0#}";
                    }
                    #endregion
                }
                if (l.Thumb == null || l.Summary == null)
                {
                    l.Thumb   = ((IProvider)null).ConstructSupportImageLink("plex_404.png");
                    l.Summary = "Episode Overview not Available";
                }
            }
            l.Id = ep.AnimeEpisodeID;
            return(l);
        }
예제 #10
0
        public static Video VideoFromAnimeEpisode(IProvider prov, List <CL_CrossRef_AniDB_Provider> cross, KeyValuePair <SVR_AnimeEpisode, CL_AnimeEpisode_User> e, int userid)
        {
            Video v = e.Key.PlexContract?.Clone <Video>(prov);

            if (v?.Thumb != null)
            {
                v.Thumb = prov.ReplaceSchemeHost(v.Thumb);
            }
            if (v != null && (v.Medias == null || v.Medias.Count == 0))
            {
                using (var upd = Repo.Instance.AnimeEpisode.BeginAddOrUpdate(e.Key))
                {
                    foreach (SVR_VideoLocal vl2 in upd.Entity.GetVideoLocals())
                    {
                        if (vl2.Media?.Duration != 0)
                        {
                            continue;
                        }
                        SVR_VideoLocal_Place pl = vl2.GetBestVideoLocalPlace();

                        if (pl != null)
                        {
                            using (var upd2 = Repo.Instance.VideoLocal.BeginAddOrUpdate(vl2))
                            {
                                if (pl.RefreshMediaInfo(upd2.Entity))
                                {
                                    upd2.Commit(true);
                                }
                            }
                        }
                    }
                    upd.Commit();
                }
                v = e.Key.PlexContract?.Clone <Video>(prov);
            }
            if (v != null)
            {
                if (e.Key.AniDB_Episode == null)
                {
                    return(v);
                }
                if (e.Value != null)
                {
                    v.ViewCount = e.Value.WatchedCount;
                    if (e.Value.WatchedDate.HasValue)
                    {
                        v.LastViewedAt = e.Value.WatchedDate.Value.ToUnixTime();
                    }
                }
                v.ParentIndex = 1;
                if (e.Key.EpisodeTypeEnum != EpisodeType.Episode)
                {
                    v.ParentIndex = 0;
                }

                if (e.Key.EpisodeTypeEnum == EpisodeType.Episode)
                {
                    string client = prov.GetPlexClient().Product;
                    if (client == "Plex for Windows" || client == "Plex Home Theater")
                    {
                        v.Title = $"{v.EpisodeNumber}. {v.Title}";
                    }
                }

                if (cross != null && cross.Count > 0)
                {
                    CrossRef_AniDB_ProviderEpisode ep = cross.Select(a => a.GetEpisodesWithOverrides().FirstOrDefault(b => b.AniDBEpisodeID == e.Key.AniDB_EpisodeID)).FirstOrDefault(a => a != null);
                    if (ep != null && ep.Season > 0)
                    {
                        v.ParentIndex = ep.Season;
                    }
                }
                AddLinksToAnimeEpisodeVideo(prov, v, userid);
            }
            v.AddResumePosition(prov, userid);

            return(v);
        }