public void Populate(CL_AnimeEpisode_User contract) { try { AniDB_EpisodeID = contract.AniDB_EpisodeID; AnimeEpisodeID = contract.AnimeEpisodeID; AnimeSeriesID = contract.AnimeSeriesID; DateTimeUpdated = contract.DateTimeUpdated; EpisodeNumber = contract.EpisodeNumber; EpisodeType = contract.EpisodeType; UnwatchedEpCountSeries = contract.UnwatchedEpCountSeries; AniDB_LengthSeconds = contract.AniDB_LengthSeconds; AniDB_Rating = contract.AniDB_Rating; AniDB_Votes = contract.AniDB_Votes; AniDB_RomajiName = contract.AniDB_RomajiName; AniDB_EnglishName = contract.AniDB_EnglishName; AniDB_AirDate = contract.AniDB_AirDate; LocalFileCount = contract.LocalFileCount; PlayedCount = contract.PlayedCount; StoppedCount = contract.StoppedCount; WatchedCount = contract.WatchedCount; WatchedDate = contract.WatchedDate; } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }
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 TraktScrobble(ScrobblePlayingStatus scrobblePlayingStatus, VideoInfo info, int position, int duration, bool logOutput = false) { try { VM_VideoDetailed vd = (VM_VideoDetailed)VM_ShokoServer.Instance.ShokoServices.GetVideoDetailed(info.VideoLocalId, VM_ShokoServer.Instance.CurrentUser.JMMUserID); if (vd == null) { if (logOutput) { logger.Debug("Trakt scrobbling video detail = null"); } return; } CL_AnimeEpisode_User ep = VM_ShokoServer.Instance.ShokoServices.GetEpisodeByAniDBEpisodeID(vd.AnimeEpisodeID, VM_ShokoServer.Instance.CurrentUser.JMMUserID); if (ep != null) { double percentagePlayed = (int)Math.Round((double)(100 * position) / duration); if (logOutput) { logger.Debug("Trakt is scrobbling for anime episode id: " + ep.AnimeEpisodeID); logger.Debug("Trakt is scrobbling with played percentage: " + (int)percentagePlayed); } VM_ShokoServer.Instance.ShokoServices.TraktScrobble(ep.AnimeEpisodeID, (int)ScrobblePlayingType.episode, (int)percentagePlayed, (int)scrobblePlayingStatus); } if (logOutput) { logger.Debug("Trakt scrobbling has finished scrobbling"); } } catch (Exception e) { if (logOutput) { logger.Debug("Error in VideoHandler.TraktScrobble: {0}", e.ToString()); } } }
void btnTvDBLinkAdd_Click(object sender, RoutedEventArgs e) { try { // get the current tvdb link VM_AnimeEpisode_User ep = DataContext as VM_AnimeEpisode_User; ep.RefreshAnime(); if (ep.AniDB_Anime == null || ep.AniDB_Anime.TvSummary == null || ep.AniDB_Anime.TvSummary.CrossRefTvDBV2 == null || ep.AniDB_Anime.TvSummary.CrossRefTvDBV2.Count == 0) { Utils.ShowErrorMessage(Shoko.Commons.Properties.Resources.EpisodeDetail_TvDBLink); return; } Window wdw = Window.GetWindow(this); Cursor = Cursors.Wait; SelectTvDBEpisodeForm frm = new SelectTvDBEpisodeForm(); frm.Owner = wdw; frm.Init(ep, ep.AniDB_Anime); bool?result = frm.ShowDialog(); if (result.Value) { // update info CL_AnimeEpisode_User contract = VM_ShokoServer.Instance.ShokoServices.GetEpisode( ep.AnimeEpisodeID, VM_ShokoServer.Instance.CurrentUser.JMMUserID); if (contract != null) { ep.RefreshAnime(true); ep.Populate(contract); ep.SetTvDBInfo(); } } Cursor = Cursors.Arrow; } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }
internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level) { Episode ep = new Episode { id = aep.AnimeEpisodeID, eptype = aep.EpisodeTypeEnum.ToString(), art = new ArtCollection() }; var userrating = aep.UserRating; if (userrating > 0) { ep.userrating = userrating.ToString(CultureInfo.InvariantCulture); } if (double.TryParse(ep.rating, out double rating)) { // 0.1 should be the absolute lowest rating if (rating > 10) { ep.rating = (rating / 100).ToString(CultureInfo.InvariantCulture); } } CL_AnimeEpisode_User cae = aep.GetUserContract(uid); if (cae != null) { ep.name = cae.AniDB_EnglishName; ep.summary = cae.Description; ep.year = cae.AniDB_AirDate?.Year.ToString(CultureInfo.InvariantCulture); ep.air = cae.AniDB_AirDate?.ToPlexDate(); ep.votes = cae.AniDB_Votes; ep.rating = cae.AniDB_Rating; ep.view = cae.IsWatched() ? 1 : 0; ep.epnumber = cae.EpisodeNumber; } TvDB_Episode tvep = aep.TvDBEpisode; if (tvep != null) { if (!string.IsNullOrEmpty(tvep.EpisodeName)) { ep.name = tvep.EpisodeName; } if (Misc.IsImageValid(tvep.GetFullImagePath())) { ep.art.thumb.Add(new Art { index = 0, url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode, tvep.TvDB_EpisodeID) }); } var fanarts = aep.GetAnimeSeries()?.GetAnime()?.Contract?.AniDBAnime?.Fanarts; if (fanarts != null && fanarts.Count > 0) { var cont_image = fanarts[new Random().Next(fanarts.Count)]; ep.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType, cont_image.AniDB_Anime_DefaultImageID), index = 0 }); } else { ep.art.fanart.Add(new Art { index = 0, url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode, tvep.TvDB_EpisodeID) }); } if (!string.IsNullOrEmpty(tvep.Overview)) { ep.summary = tvep.Overview; } int zeroPadding = tvep.EpisodeNumber.ToString().Length; string episodeNumber = tvep.EpisodeNumber.ToString().PadLeft(zeroPadding, '0'); zeroPadding = tvep.SeasonNumber.ToString().Length; string seasonNumber = tvep.SeasonNumber.ToString().PadLeft(zeroPadding, '0'); ep.season = $"{seasonNumber}x{episodeNumber}"; var airdate = tvep.AirDate; if (airdate != null) { ep.air = airdate.Value.ToPlexDate(); ep.year = airdate.Value.Year.ToString(CultureInfo.InvariantCulture); } } if (string.IsNullOrEmpty(ep.summary)) { ep.summary = string.Intern("Episode Overview not Available"); } if (ep.art.thumb.Count == 0) { ep.art.thumb.Add( new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); ep.art.fanart.Add(new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); } if (string.IsNullOrEmpty(ep.year)) { ep.year = aep.GetAnimeSeries().AirDate.Year.ToString(CultureInfo.InvariantCulture); } if (level > 0) { List <SVR_VideoLocal> vls = aep.GetVideoLocals(); if (vls.Count > 0) { ep.files = new List <RawFile>(); foreach (SVR_VideoLocal vl in vls) { RawFile file = new RawFile(ctx, vl, (level - 1), uid); ep.files.Add(file); } } } return(ep); }
public void CollectContractMemory() { _contract = null; }
internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level) { Episode ep = new Episode(); CL_AnimeEpisode_User cae = aep?.GetUserContract(uid); if (cae != null) { TvDB_Episode tvep = aep.TvDBEpisode; ep.id = aep.AnimeEpisodeID; ep.art = new ArtCollection(); ep.name = cae.AniDB_EnglishName; ep.year = cae.AniDB_AirDate?.Year.ToString(CultureInfo.InvariantCulture); ep.air = cae.AniDB_AirDate?.ToPlexDate(); ep.votes = cae.AniDB_Votes; ep.rating = cae.AniDB_Rating; var userrating = aep.UserRating; if (userrating > 0) { ep.userrating = userrating.ToString(CultureInfo.InvariantCulture); } if (double.TryParse(ep.rating, out double rating)) { // 0.1 should be the absolute lowest rating if (rating > 10) { ep.rating = (rating / 100).ToString(CultureInfo.InvariantCulture); } } ep.view = cae.IsWatched() ? 1 : 0; ep.epnumber = cae.EpisodeNumber; ep.eptype = aep.EpisodeTypeEnum.ToString(); ep.art = new ArtCollection(); if (tvep != null) { ep.name = tvep.EpisodeName; ep.art.thumb.Add(new Art { index = 0, url = tvep.GenPoster(null) }); ep.art.fanart.Add(new Art { index = 0, url = tvep.GenPoster(null) }); ep.summary = tvep.Overview; int zeroPadding = tvep.EpisodeNumber.ToString().Length; string episodeNumber = tvep.EpisodeNumber.ToString().PadLeft(zeroPadding, '0'); zeroPadding = tvep.SeasonNumber.ToString().Length; string seasonNumber = tvep.SeasonNumber.ToString().PadLeft(zeroPadding, '0'); ep.season = $"{seasonNumber}x{episodeNumber}"; var airdate = tvep.AirDate; if (airdate != null) { ep.air = airdate.Value.ToPlexDate(); ep.year = airdate.Value.Year.ToString(CultureInfo.InvariantCulture); } } if (string.IsNullOrEmpty(ep.summary)) { ep.summary = string.Intern("Episode Overview not Available"); } if (ep.art.thumb.Count == 0) { ep.art.thumb.Add( new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); ep.art.fanart.Add(new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); } if (string.IsNullOrEmpty(ep.year)) { ep.year = aep.GetAnimeSeries().AirDate.Year.ToString(CultureInfo.InvariantCulture); } if (level > 0) { List <SVR_VideoLocal> vls = aep.GetVideoLocals(); if (vls.Count > 0) { ep.files = new List <RawFile>(); foreach (SVR_VideoLocal vl in vls) { RawFile file = new RawFile(ctx, vl, (level - 1), uid); ep.files.Add(file); } } } } return(ep); }
internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level) { Episode ep = new Episode(); if (aep != null) { CL_AnimeEpisode_User cae = aep.GetUserContract(uid); if (cae != null) { ep.id = aep.AnimeEpisodeID; ep.art = new ArtCollection(); ep.name = aep.PlexContract?.Title; ep.summary = aep.PlexContract?.Summary; ep.year = aep.PlexContract?.Year; ep.air = aep.PlexContract?.AirDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); ep.votes = cae.AniDB_Votes; ep.rating = aep.PlexContract?.Rating; ep.userrating = aep.PlexContract?.UserRating; double rating; if (double.TryParse(ep.rating, out rating)) { // 0.1 should be the absolute lowest rating if (rating > 10) { ep.rating = (rating / 100).ToString().Replace(',', '.'); } } ep.view = cae.IsWatched() ? 1 : 0; ep.epnumber = cae.EpisodeNumber; ep.eptype = aep.EpisodeTypeEnum.ToString(); ep.season = aep.PlexContract?.Season; // until fanart refactor this will be good for start if (aep.PlexContract?.Thumb != null) { ep.art.thumb.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(ctx, aep.PlexContract?.Thumb), index = 0 }); } if (aep.PlexContract?.Art != null) { ep.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromRest(ctx, aep.PlexContract?.Art), index = 0 }); } if (level > 0) { List <SVR_VideoLocal> vls = aep.GetVideoLocals(); if (vls.Count > 0) { ep.files = new List <RawFile>(); foreach (SVR_VideoLocal vl in vls) { RawFile file = new RawFile(ctx, vl, (level - 1), uid); ep.files.Add(file); } } } } } return(ep); }