Beispiel #1
0
 public void AddOrUpdate(int animeepisodeId, string providerEpisodeId, int season, int episodeNumber, EpisodeType type, MatchRating rating)
 {
     lock (_dict)
     {
         if (_dict.ContainsKey(animeepisodeId))
         {
             CrossRef_AniDB_ProviderEpisode r = _dict[animeepisodeId];
             if (r.ProviderEpisodeID != providerEpisodeId || r.MatchRating != rating || r.Season != season || r.Number != episodeNumber || r.Type != type)
             {
                 _providerDict.Remove(r.ProviderEpisodeID);
                 r.ProviderEpisodeID = providerEpisodeId;
                 r.MatchRating       = rating;
                 r.Season            = season;
                 r.Number            = episodeNumber;
                 r.Type = type;
                 _providerDict.Add(r.ProviderEpisodeID, animeepisodeId);
                 _needPersistance = true;
             }
         }
         else
         {
             CrossRef_AniDB_ProviderEpisode r = new CrossRef_AniDB_ProviderEpisode();
             r.AniDBEpisodeID    = animeepisodeId;
             r.ProviderEpisodeID = providerEpisodeId;
             r.MatchRating       = rating;
             r.Season            = season;
             r.Number            = episodeNumber;
             r.Type = type;
             _dict.Add(animeepisodeId, r);
             _providerDict[providerEpisodeId] = animeepisodeId;
             _needPersistance = true;
         }
     }
 }
Beispiel #2
0
        public static List <CrossRef_AniDB_ProviderEpisode> GetMatchPreviewWithOverrides(int animeID, string crossSeriesID, CrossRefType tp)
        {
            var matches   = GetMatchPreview(animeID, crossSeriesID, tp);
            var overrides = Repo.Instance.CrossRef_AniDB_Provider.GetByAnimeIDAndType(animeID, tp).SelectMany(a => a.EpisodesListOverride.Episodes);
            List <CrossRef_AniDB_ProviderEpisode> result = new List <CrossRef_AniDB_ProviderEpisode>();

            foreach (var match in matches)
            {
                var match_override = overrides.FirstOrDefault(a => a.AniDBEpisodeID == match.AniDBEpisodeID);
                if (match_override == null)
                {
                    result.Add(match);
                }
                else
                {
                    var new_match = new CrossRef_AniDB_ProviderEpisode
                    {
                        AniDBEpisodeID    = match_override.AniDBEpisodeID,
                        ProviderEpisodeID = match_override.ProviderEpisodeID,
                        MatchRating       = MatchRating.UserVerified,
                        Season            = match_override.Season,
                        Type   = match_override.Type,
                        Number = match_override.Number
                    };
                    result.Add(new_match);
                }
            }

            return(result);
        }
Beispiel #3
0
 public void DeleteFromAnimeEpisodeId(int animeEpisodeId)
 {
     lock (_dict)
     {
         if (_dict.ContainsKey(animeEpisodeId))
         {
             CrossRef_AniDB_ProviderEpisode prov = _dict[animeEpisodeId];
             _dict.Remove(animeEpisodeId);
             _providerDict.Remove(prov.ProviderEpisodeID);
             _needPersistance = true;
         }
     }
 }
Beispiel #4
0
        private static void FillSerie(Video p, SVR_AnimeSeries aser,
                                      Dictionary <SVR_AnimeEpisode, CL_AnimeEpisode_User> eps,
                                      SVR_AniDB_Anime anidb, CL_AnimeSeries_User ser, int userid)
        {
            CL_AniDB_Anime anime = ser.AniDBAnime.AniDBAnime;

            p.Id        = ser.AnimeSeriesID;
            p.AnimeType = AnimeTypes.AnimeSerie.ToString();
            if (ser.AniDBAnime.AniDBAnime.Restricted > 0)
            {
                p.ContentRating = "R";
            }
            p.Title   = aser.GetSeriesName();
            p.Summary = SummaryFromAnimeContract(ser);
            p.Type    = "show";
            p.AirDate = DateTime.MinValue;
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            if (anime.GetAllTags().Count > 0)
            {
                p.Genres = new List <Tag>();
                anime.GetAllTags()
                .ToList()
                .ForEach(a => p.Genres.Add(new Tag {
                    Value = textInfo.ToTitleCase(a.Trim())
                }));
            }
            //p.OriginalTitle
            if (anime.AirDate.HasValue)
            {
                p.AirDate = anime.AirDate.Value;
                p.OriginallyAvailableAt = anime.AirDate.Value.ToPlexDate();
                p.Year = anime.AirDate.Value.Year;
            }
            p.LeafCount = anime.EpisodeCount;
            //p.ChildCount = p.LeafCount;
            p.ViewedLeafCount = ser.WatchedEpisodeCount;
            p.Rating          = (int)Math.Round((anime.Rating / 100D), 1);
            AniDB_Vote vote = Repo.Instance.AniDB_Vote.GetByEntityAndType(anidb.AnimeID, AniDBVoteType.Anime) ??
                              Repo.Instance.AniDB_Vote.GetByEntityAndType(anidb.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                p.UserRating = (int)(vote.VoteValue / 100D);
            }

            List <CL_CrossRef_AniDB_Provider> ls = ser.CrossRefAniDBTvDBV2;

            if (ls != null && ls.Count > 0)
            {
                CrossRef_AniDB_ProviderEpisode ep = ls.Select(a => a.GetEpisodesWithOverrides().FirstOrDefault()).FirstOrDefault(a => a != null);
                if (ep != null)
                {
                    p.Season = ep.Season.ToString();
                    p.Index  = ep.Season;
                }
            }
            p.Thumb = p.ParentThumb = anime.DefaultImagePoster.GenPoster(null);
            p.Art   = anime?.DefaultImageFanart?.GenArt(null);
            if (anime?.Fanarts != null)
            {
                p.Fanarts = new List <Contract_ImageDetails>();
                anime.Fanarts.ForEach(
                    a =>
                    p.Fanarts.Add(new Contract_ImageDetails()
                {
                    ImageID   = a.AniDB_Anime_DefaultImageID,
                    ImageType = a.ImageType
                }));
            }
            if (anime?.Banners != null)
            {
                p.Banners = new List <Contract_ImageDetails>();
                anime.Banners.ForEach(
                    a =>
                    p.Banners.Add(new Contract_ImageDetails()
                {
                    ImageID   = a.AniDB_Anime_DefaultImageID,
                    ImageType = a.ImageType
                }));
            }

            if (eps != null)
            {
                List <EpisodeType> types = eps.Keys.Where(a => a.AniDB_Episode != null)
                                           .Select(a => a.EpisodeTypeEnum).Distinct().ToList();
                p.ChildCount = types.Count > 1 ? types.Count : eps.Keys.Count;
            }
            p.Roles = new List <RoleTag>();

            //TODO Character implementation is limited in JMM, One Character, could have more than one Seiyuu
            if (anime.Characters != null)
            {
                foreach (CL_AniDB_Character c in anime.Characters)
                {
                    string       ch     = c?.CharName;
                    AniDB_Seiyuu seiyuu = c?.Seiyuu;
                    if (string.IsNullOrEmpty(ch))
                    {
                        continue;
                    }
                    RoleTag t = new RoleTag
                    {
                        Value = seiyuu?.SeiyuuName
                    };
                    if (seiyuu != null)
                    {
                        t.TagPicture = ConstructSeiyuuImage(null, seiyuu.SeiyuuID);
                    }
                    t.Role            = ch;
                    t.RoleDescription = c?.CharDescription;
                    t.RolePicture     = ConstructCharacterImage(null, c.CharID);
                    p.Roles.Add(t);
                }
            }
            p.Titles = new List <AnimeTitle>();
            foreach (AniDB_Anime_Title title in anidb.GetTitles())
            {
                p.Titles.Add(
                    new AnimeTitle {
                    Language = title.Language, Title = title.Title, Type = title.TitleType
                });
            }
        }
Beispiel #5
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);
        }