public AniDB(AniDB_Episode ep) { if (!decimal.TryParse(ep.Rating, out var rating)) { rating = 0; } if (!int.TryParse(ep.Votes, out var votes)) { votes = 0; } var titles = RepoFactory.AniDB_Episode_Title.GetByEpisodeID(ep.EpisodeID); ID = ep.EpisodeID; Type = MapAniDBEpisodeType(ep.GetEpisodeTypeEnum()); EpisodeNumber = ep.EpisodeNumber; AirDate = ep.GetAirDateAsDate(); Description = ep.Description; Rating = new Rating { MaxValue = 10, Value = rating, Votes = votes, Source = "AniDB", }; Titles = titles.Select(a => new Title { Name = a.Title, Language = a.Language.ToLower(), Default = false, Source = "AniDB", } ).ToList(); }
public EpisodeDetails(AniDB_Episode episode, SVR_AniDB_Anime anime, SVR_AnimeSeries series = null) { ID = episode.EpisodeID; Title = Episode.GetEpisodeTitle(episode.EpisodeID); Number = episode.EpisodeNumber; Type = Episode.MapAniDBEpisodeType(episode.GetEpisodeTypeEnum()); AirDate = (DateTime)episode.GetAirDateAsDate(); InCollection = series != null; SeriesID = anime.AnimeID; SeriesTitle = series?.GetSeriesName() ?? anime.PreferredTitle; SeriesPoster = Series.GetDefaultImage(anime.AnimeID, ImageSizeType.Poster) ?? Series.GetAniDBPoster(anime.AnimeID); }
public void UpdateContract(SVR_AnimeEpisode_User aeu) { CL_AnimeEpisode_User caep = aeu.Contract ?? new CL_AnimeEpisode_User(); SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByID(aeu.AnimeEpisodeID); if (ep == null) { return; } AniDB_Episode aniEp = ep.AniDB_Episode; caep.AniDB_EpisodeID = ep.AniDB_EpisodeID; caep.AnimeEpisodeID = ep.AnimeEpisodeID; caep.AnimeSeriesID = ep.AnimeSeriesID; caep.DateTimeUpdated = ep.DateTimeUpdated; caep.PlayedCount = aeu.PlayedCount; caep.StoppedCount = aeu.StoppedCount; caep.WatchedCount = aeu.WatchedCount; caep.WatchedDate = aeu.WatchedDate; var englishTitle = Repo.Instance.AniDB_Episode_Title.GetByEpisodeIDAndLanguage(ep.AniDB_EpisodeID, "EN") .FirstOrDefault()?.Title; var romajiTitle = Repo.Instance.AniDB_Episode_Title.GetByEpisodeIDAndLanguage(ep.AniDB_EpisodeID, "X-JAT") .FirstOrDefault()?.Title; caep.AniDB_EnglishName = englishTitle; caep.AniDB_RomajiName = romajiTitle; caep.EpisodeNameEnglish = englishTitle; caep.EpisodeNameRomaji = romajiTitle; if (aniEp != null) { caep.AniDB_AirDate = aniEp.GetAirDateAsDate(); caep.AniDB_LengthSeconds = aniEp.LengthSeconds; caep.AniDB_Rating = aniEp.Rating; caep.AniDB_Votes = aniEp.Votes; caep.EpisodeNumber = aniEp.EpisodeNumber; caep.Description = aniEp.Description; caep.EpisodeType = aniEp.EpisodeType; } /* * //TODO if this is needed, calculating it in here will not affect performance * caep.ReleaseGroups = new List<CL_AniDB_GroupStatus>(); */ aeu.Contract = caep; }
public void UpdateContract(SVR_AnimeEpisode_User aeu) { Shoko.Models.Client.CL_AnimeEpisode_User caep = aeu.Contract ?? new CL_AnimeEpisode_User(); SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(aeu.AnimeEpisodeID); if (ep == null) { return; } AniDB_Episode aniEp = ep.AniDB_Episode; caep.AniDB_EpisodeID = ep.AniDB_EpisodeID; caep.AnimeEpisodeID = ep.AnimeEpisodeID; caep.AnimeSeriesID = ep.AnimeSeriesID; caep.DateTimeUpdated = ep.DateTimeUpdated; caep.PlayedCount = aeu.PlayedCount; caep.StoppedCount = aeu.StoppedCount; caep.WatchedCount = aeu.WatchedCount; caep.WatchedDate = aeu.WatchedDate; if (aniEp != null) { caep.AniDB_AirDate = aniEp.GetAirDateAsDate(); caep.AniDB_EnglishName = aniEp.EnglishName; caep.AniDB_LengthSeconds = aniEp.LengthSeconds; caep.AniDB_Rating = aniEp.Rating; caep.AniDB_RomajiName = aniEp.RomajiName; caep.AniDB_Votes = aniEp.Votes; caep.EpisodeNumber = aniEp.EpisodeNumber; caep.EpisodeNameRomaji = aniEp.RomajiName; caep.EpisodeNameEnglish = aniEp.EnglishName; caep.EpisodeType = aniEp.EpisodeType; } /* * //TODO if this is needed, calculating it in here will not affect performance * caep.ReleaseGroups = new List<CL_AniDB_GroupStatus>(); */ aeu.Contract = caep; }
public static AniDB GetAniDBInfo(AniDB_Episode ep) { decimal rating = 0; int votes = 0; try { rating = decimal.Parse(ep.Rating); votes = int.Parse(ep.Votes); } catch {} var titles = RepoFactory.AniDB_Episode_Title.GetByEpisodeID(ep.EpisodeID); return(new AniDB { ID = ep.EpisodeID, Type = (EpisodeType)ep.EpisodeType, EpisodeNumber = ep.EpisodeNumber, AirDate = ep.GetAirDateAsDate(), Description = ep.Description, Rating = new Rating { Source = "AniDB", Value = rating, MaxValue = 10, Votes = votes }, Titles = titles.Select(a => new Title { Source = "AniDB", Name = a.Title, Language = a.Language }).ToList() }); }
public static Video GenerateVideoFromAnimeEpisode(SVR_AnimeEpisode ep, int userID) { 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].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; l.Medias = new List <Media>(); foreach (SVR_VideoLocal v in vids) { if (v?.Media == null) { continue; } var legacy = new Media(v.VideoLocalID, v.Media); var place = v.GetBestVideoLocalPlace(); legacy.Parts.ForEach(p => { if (string.IsNullOrEmpty(p.LocalKey)) { p.LocalKey = place.FullServerPath; } string name = UrlSafe.Replace(Path.GetFileName(place.FilePath), " ").CompactWhitespaces() .Trim(); name = UrlSafe2.Replace(name, string.Empty) .Trim() .CompactCharacters('.') .Replace(" ", "_") .CompactCharacters('_') .Replace("_.", "."); while (name.StartsWith("_")) { name = name.Substring(1); } while (name.StartsWith(".")) { name = name.Substring(1); } p.Key = ((IProvider)null).ReplaceSchemeHost( ((IProvider)null).ConstructVideoLocalStream(userID, v.VideoLocalID, name, false)); if (p.Streams == null) { return; } foreach (Stream s in p.Streams.Where(a => a.File != null && a.StreamType == 3).ToList()) { s.Key = ((IProvider)null).ReplaceSchemeHost( ((IProvider)null).ConstructFileStream(userID, s.File, false)); } }); l.Medias.Add(legacy); } string title = ep.Title; if (!String.IsNullOrEmpty(title)) { l.Title = title; } string romaji = RepoFactory.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)Single.Parse(aep.Rating, CultureInfo.InvariantCulture); AniDB_Vote vote = RepoFactory.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); }
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].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; l.Medias = new List <Media>(); foreach (SVR_VideoLocal v in vids) { if (v.Media == null) { continue; } var legacy = new Media(v.VideoLocalID, v.Media); legacy.Parts.ForEach(a => { if (string.IsNullOrEmpty(a.LocalKey)) { a.LocalKey = v?.GetBestVideoLocalPlace()?.FullServerPath ?? null; } }); l.Medias.Add(legacy); } string title = ep.Title; if (!string.IsNullOrEmpty(title)) { l.Title = title; } string romaji = RepoFactory.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 = RepoFactory.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); }
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); }