public static void PopulateManually(this CrossRef_File_Episode cross, SVR_VideoLocal vid, SVR_AnimeEpisode ep) { cross.Hash = vid.ED2KHash; cross.FileName = vid.FileName; cross.FileSize = vid.FileSize; cross.CrossRefSource = (int)CrossRefSource.User; cross.AnimeID = ep.GetAnimeSeries().AniDB_ID; cross.EpisodeID = ep.AniDB_EpisodeID; cross.Percentage = 100; cross.EpisodeOrder = 1; }
private void ScrobbleToTrakt(SVR_VideoLocal file, SVR_AnimeEpisode episode, long position, ScrobblePlayingStatus status) { if (User.IsTraktUser == 0) { return; } float percentage = 100 * (position / file.Duration); ScrobblePlayingType scrobbleType = episode.GetAnimeSeries()?.GetAnime()?.AnimeType == (int)AnimeType.Movie ? ScrobblePlayingType.movie : ScrobblePlayingType.episode; TraktTVHelper.Scrobble(scrobbleType, episode.AnimeEpisodeID.ToString(), status, percentage); }
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 override void ProcessCommand() { CrossRef_File_Episode xref = new CrossRef_File_Episode(); try { xref.PopulateManually(vlocal, episode); if (Percentage > 0 && Percentage <= 100) { xref.Percentage = Percentage; } } catch (Exception ex) { logger.Error(ex, "Error populating XREF: {0}", vlocal.ToStringDetailed()); throw; } RepoFactory.CrossRef_File_Episode.Save(xref); CommandRequest_WebCacheSendXRefFileEpisode cr = new CommandRequest_WebCacheSendXRefFileEpisode(xref.CrossRef_File_EpisodeID); cr.Save(); if (ServerSettings.FileQualityFilterEnabled) { List <SVR_VideoLocal> videoLocals = episode.GetVideoLocals(); if (videoLocals != null) { videoLocals.Sort(FileQualityFilter.CompareTo); List <SVR_VideoLocal> keep = videoLocals.Take(FileQualityFilter.Settings.MaxNumberOfFilesToKeep) .ToList(); foreach (SVR_VideoLocal vl2 in keep) { videoLocals.Remove(vl2); } if (videoLocals.Contains(vlocal)) { videoLocals.Remove(vlocal); } videoLocals = videoLocals.Where(FileQualityFilter.CheckFileKeep).ToList(); foreach (SVR_VideoLocal toDelete in videoLocals) { toDelete.Places.ForEach(a => a.RemoveAndDeleteFile()); } } } vlocal.Places.ForEach(a => { a.RenameAndMoveAsRequired(); }); SVR_AnimeSeries ser = episode.GetAnimeSeries(); ser.EpisodeAddedDate = DateTime.Now; RepoFactory.AnimeSeries.Save(ser, false, true); //Update will re-save ser.QueueUpdateStats(); foreach (SVR_AnimeGroup grp in ser.AllGroupsAbove) { grp.EpisodeAddedDate = DateTime.Now; RepoFactory.AnimeGroup.Save(grp, false, false); } if (ServerSettings.AniDB_MyList_AddFiles) { CommandRequest_AddFileToMyList cmdAddFile = new CommandRequest_AddFileToMyList(vlocal.Hash); cmdAddFile.Save(); } }
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); }
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); }
public override void Run(IProgress <ICommand> progress = null) { try { ReportInit(progress); CrossRef_File_Episode xref = new CrossRef_File_Episode(); try { xref.PopulateManually_RA(vlocal, episode); if (Percentage > 0 && Percentage <= 100) { xref.Percentage = Percentage; } } catch (Exception ex) { ReportError(progress, $"Error populating XREF: {vlocal.ToStringDetailed()}", ex); return; } ReportUpdate(progress, 20); List <ICommand> cmds = new List <ICommand>(); Repo.Instance.CrossRef_File_Episode.BeginAdd(xref).Commit(); Queue.Instance.Add(new CmdWebCacheSendXRefFileEpisode(xref.CrossRef_File_EpisodeID)); ReportUpdate(progress, 40); if (ServerSettings.Instance.FileQualityFilterEnabled) { List <SVR_VideoLocal> videoLocals = episode.GetVideoLocals(); if (videoLocals != null) { videoLocals.Sort(FileQualityFilter.CompareTo); List <SVR_VideoLocal> keep = videoLocals.Take(FileQualityFilter.Settings.MaxNumberOfFilesToKeep) .ToList(); foreach (SVR_VideoLocal vl2 in keep) { videoLocals.Remove(vl2); } if (videoLocals.Contains(vlocal)) { videoLocals.Remove(vlocal); } videoLocals = videoLocals.Where(FileQualityFilter.CheckFileKeep).ToList(); foreach (SVR_VideoLocal toDelete in videoLocals) { toDelete.Places.ForEach(a => a.RemoveAndDeleteFile()); } } } ReportUpdate(progress, 60); vlocal.Places.ForEach(a => { a.RenameAndMoveAsRequired(); }); SVR_AnimeSeries ser; using (var upd = Repo.Instance.AnimeSeries.BeginAddOrUpdate(() => episode.GetAnimeSeries())) { upd.Entity.EpisodeAddedDate = DateTime.Now; ser = upd.Commit((false, true, false, false)); } //Update will re-save ser.QueueUpdateStats(); ReportUpdate(progress, 80); Repo.Instance.AnimeGroup.BatchAction(ser.AllGroupsAbove, ser.AllGroupsAbove.Count, (grp, _) => grp.EpisodeAddedDate = DateTime.Now); if (ServerSettings.Instance.AniDb.MyList_AddFiles) { cmds.Add(new CmdAniDBAddFileToMyList(vlocal.Hash)); } if (cmds.Count > 0) { Queue.Instance.AddRange(cmds); } ReportFinish(progress); } catch (Exception e) { ReportError(progress, $"Error processing ServerLinkFileManually: {VideoLocalID} - {EpisodeID} - {e}", e); } }