public override void Run(IProgress <ICommand> progress = null) { logger.Info("Processing CommandRequest_TraktHistoryEpisode: {0}-{1}", AnimeEpisodeID, Action); try { ReportInit(progress); if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { ReportFinish(progress); return; } SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByID(AnimeEpisodeID); ReportUpdate(progress, 50); if (ep != null) { TraktSyncType syncType = TraktSyncType.HistoryAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.HistoryRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } ReportFinish(progress); } catch (Exception ex) { ReportError(progress, $"Error processing CommandRequest_TraktHistoryEpisode: {AnimeEpisodeID} - {Action} - {ex}", ex); } }
public Episode(HttpContext ctx, SVR_AnimeEpisode ep) { var tvdb = ep.TvDBEpisodes; IDs = new EpisodeIDs { ID = ep.AnimeEpisodeID, AniDB = ep.AniDB_EpisodeID, TvDB = tvdb.Select(a => a.Id).ToList() }; var anidb = ep.AniDB_Episode; if (anidb != null) { Duration = new TimeSpan(0, 0, anidb.LengthSeconds); } var uid = ctx.GetUser()?.JMMUserID ?? 0; Watched = ep.GetVideoLocals().Select(v => v.GetUserRecord(uid)?.WatchedDate).Where(v => v.HasValue).OrderByDescending(v => v).FirstOrDefault(); Name = GetEpisodeTitle(ep.AniDB_EpisodeID); Size = ep.GetVideoLocals().Count; }
public Episode(HttpContext ctx, SVR_AnimeEpisode ep) { var tvdb = ep.TvDBEpisodes; IDs = new EpisodeIDs { ID = ep.AnimeEpisodeID, AniDB = ep.AniDB_EpisodeID, TvDB = tvdb.Select(a => a.Id).ToList() }; var anidb = ep.AniDB_Episode; if (anidb != null) { Duration = new TimeSpan(0, 0, anidb.LengthSeconds); } var uid = ctx.GetUser()?.JMMUserID ?? 0; Watched = ep.GetUserRecord(uid)?.WatchedDate; Name = ep.Title; Size = ep.GetVideoLocals().Count; }
public override bool LoadFromDBCommand(CommandRequest cq) { CommandID = cq.CommandID; CommandRequestID = cq.CommandRequestID; Priority = cq.Priority; CommandDetails = cq.CommandDetails; DateTimeUpdated = cq.DateTimeUpdated; // read xml to get parameters if (CommandDetails.Trim().Length > 0) { XmlDocument docCreator = new XmlDocument(); docCreator.LoadXml(CommandDetails); // populate the fields VideoLocalID = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "VideoLocalID")); EpisodeID = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "EpisodeID")); Percentage = int.Parse(TryGetProperty(docCreator, "CommandRequest_LinkFileManually", "Percentage")); vlocal = RepoFactory.VideoLocal.GetByID(VideoLocalID); if (null == vlocal) { logger.Info("videolocal object {0} not found", VideoLocalID); return(false); } episode = RepoFactory.AnimeEpisode.GetByID(EpisodeID); } return(true); }
public AniDB_VoteRepository() { EndSaveCallback = cr => { switch (cr.VoteType) { case (int)AniDBVoteType.Anime: case (int)AniDBVoteType.AnimeTemp: SVR_AniDB_Anime.UpdateStatsByAnimeID(cr.EntityID); break; case (int)AniDBVoteType.Episode: SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(cr.EntityID); RepoFactory.AnimeEpisode.Save(ep); break; } }; EndDeleteCallback = cr => { switch (cr.VoteType) { case (int)AniDBVoteType.Anime: case (int)AniDBVoteType.AnimeTemp: SVR_AniDB_Anime.UpdateStatsByAnimeID(cr.EntityID); break; case (int)AniDBVoteType.Episode: SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(cr.EntityID); RepoFactory.AnimeEpisode.Save(ep); break; } }; }
private AniDB_VoteRepository() { EndSaveCallback = (cr) => { if (cr.VoteType == (int)AniDBVoteType.Anime || cr.VoteType == (int)AniDBVoteType.AnimeTemp) { SVR_AniDB_Anime.UpdateStatsByAnimeID(cr.EntityID); } else if (cr.VoteType == (int)AniDBVoteType.Episode) { SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(cr.EntityID); RepoFactory.AnimeEpisode.Save(ep); } } ; EndDeleteCallback = (cr) => { if (cr.VoteType == (int)AniDBVoteType.Anime || cr.VoteType == (int)AniDBVoteType.AnimeTemp) { SVR_AniDB_Anime.UpdateStatsByAnimeID(cr.EntityID); } else if (cr.VoteType == (int)AniDBVoteType.Episode) { SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(cr.EntityID); RepoFactory.AnimeEpisode.Save(ep); } } ; }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktHistoryEpisode: {0}-{1}", AnimeEpisodeID, Action); try { if (!ServerSettings.Instance.TraktTv.Enabled || string.IsNullOrEmpty(ServerSettings.Instance.TraktTv.AuthToken)) { return; } SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByID(AnimeEpisodeID); if (ep != null) { TraktSyncType syncType = TraktSyncType.HistoryAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.HistoryRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktHistoryEpisode: {0} - {1}", AnimeEpisodeID, ex); } }
public static void CreateAnimeEpisode(this AniDB_Episode episode, ISession session, int animeSeriesID) { // check if there is an existing episode for this EpisodeID SVR_AnimeEpisode existingEp = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(episode.EpisodeID); if (existingEp == null) { SVR_AnimeEpisode animeEp = new SVR_AnimeEpisode(); animeEp.Populate(episode); animeEp.AnimeSeriesID = animeSeriesID; RepoFactory.AnimeEpisode.Save(animeEp); } else { if (existingEp.AnimeSeriesID != animeSeriesID) { existingEp.AnimeSeriesID = animeSeriesID; } existingEp.PlexContract = null; RepoFactory.AnimeEpisode.Save(existingEp); foreach (var episodeUser in RepoFactory.AnimeEpisode_User.GetByEpisodeID(existingEp.AnimeEpisodeID)) { RepoFactory.AnimeEpisode_User.SaveWithOpenTransaction(session, episodeUser); } } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_TraktCollectionEpisode: {0}-{1}", AnimeEpisodeID, Action); try { logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG01"); if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { return; } logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG02"); SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByID(AnimeEpisodeID); if (ep != null) { logger.Info("CommandRequest_TraktCollectionEpisode - DEBUG03"); TraktSyncType syncType = TraktSyncType.CollectionAdd; if (ActionEnum == TraktSyncAction.Remove) { syncType = TraktSyncType.CollectionRemove; } TraktTVHelper.SyncEpisodeToTrakt(ep, syncType); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_TraktCollectionEpisode: {0} - {1} - {2}", AnimeEpisodeID, Action, ex); } }
internal void OnEpisodeUpdated(DataSourceEnum source, SVR_AniDB_Anime anime, SVR_AnimeEpisode episode) { EpisodeUpdated?.Invoke(null, new EpisodeInfoUpdatedEventArgs { Type = source, AnimeInfo = anime, EpisodeInfo = episode, }); }
public CmdServerLinkFileManually(string str) : base(str) { vlocal = Repo.Instance.VideoLocal.GetByID(VideoLocalID); if (null == vlocal) { throw new Exception($"Videolocal object {VideoLocalID} not found"); } episode = Repo.Instance.AnimeEpisode.GetByID(EpisodeID); }
public CmdServerLinkFileManually(SVR_VideoLocal vl, SVR_AnimeEpisode ep) { VideoLocalID = vl.VideoLocalID; vlocal = vl; episode = ep; if (ep != null) { EpisodeID = ep.AnimeEpisodeID; } }
public CmdServerLinkFileManually(int vidLocalID, int episodeID) { VideoLocalID = vidLocalID; EpisodeID = episodeID; vlocal = Repo.Instance.VideoLocal.GetByID(VideoLocalID); if (null == vlocal) { throw new Exception($"Videolocal object {VideoLocalID} not found"); } episode = Repo.Instance.AnimeEpisode.GetByID(EpisodeID); }
public static void CreateAnimeEpisode(this AniDB_Episode episode, ISession session, int animeSeriesID) { // check if there is an existing episode for this EpisodeID SVR_AnimeEpisode existingEp = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(episode.EpisodeID) ?? new SVR_AnimeEpisode(); existingEp.Populate(episode); existingEp.AnimeSeriesID = animeSeriesID; RepoFactory.AnimeEpisode.Save(existingEp); // We might have removed our AnimeEpisode_User records when wiping out AnimeEpisodes, recreate them if there's watched files var vlUsers = existingEp?.GetVideoLocals() .SelectMany(a => RepoFactory.VideoLocalUser.GetByVideoLocalID(a.VideoLocalID)).ToList(); // get the list of unique users var users = vlUsers.Select(a => a.JMMUserID).Distinct(); if (vlUsers.Count > 0) { // per user. An episode is watched if any file is foreach (int uid in users) { // get the last watched file var vlUser = vlUsers.Where(a => a.JMMUserID == uid && a.WatchedDate != null) .MaxBy(a => a.WatchedDate).FirstOrDefault(); // create or update the record var epUser = RepoFactory.AnimeEpisode_User.GetByUserIDAndEpisodeID(uid, existingEp.AnimeEpisodeID); if (epUser == null) { epUser = new SVR_AnimeEpisode_User { JMMUserID = uid, WatchedDate = vlUser?.WatchedDate, PlayedCount = vlUser != null ? 1 : 0, WatchedCount = vlUser != null ? 1 : 0, AnimeSeriesID = animeSeriesID, AnimeEpisodeID = existingEp.AnimeEpisodeID }; RepoFactory.AnimeEpisode_User.Save(epUser); } } } else { // since these are created with VideoLocal_User, // these will probably never exist, but if they do, cover our bases foreach (var episodeUser in RepoFactory.AnimeEpisode_User.GetByEpisodeID(existingEp.AnimeEpisodeID)) { RepoFactory.AnimeEpisode_User.Save(episodeUser); } } }
public static void CreateAnimeEpisode(this AniDB_Episode episode, ISession session, int animeSeriesID) { // check if there is an existing episode for this EpisodeID SVR_AnimeEpisode existingEp = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(episode.EpisodeID); if (existingEp == null) { SVR_AnimeEpisode animeEp = new SVR_AnimeEpisode(); animeEp.Populate(episode); animeEp.AnimeSeriesID = animeSeriesID; RepoFactory.AnimeEpisode.Save(animeEp); } }
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); }
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 static void LinkAniDBTvDBEpisode(int aniDBID, int tvDBID) { CrossRef_AniDB_TvDB_Episode_Override xref = RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.GetByAniDBAndTvDBEpisodeIDs(aniDBID, tvDBID) ?? new CrossRef_AniDB_TvDB_Episode_Override(); xref.AniDBEpisodeID = aniDBID; xref.TvDBEpisodeID = tvDBID; RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.Save(xref); SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(aniDBID); SVR_AniDB_Anime.UpdateStatsByAnimeID(ep.AniDB_Episode.AnimeID); RepoFactory.AnimeEpisode.Save(ep); logger.Trace($"Changed tvdb episode association: {aniDBID}"); }
public static void LinkAniDBTvDBEpisode(int aniDBID, int tvDBID) { using (var upd = Repo.Instance.CrossRef_AniDB_TvDB_Episode_Override.BeginAddOrUpdate(() => Repo.Instance.CrossRef_AniDB_TvDB_Episode_Override.GetByAniDBAndTvDBEpisodeIDs(aniDBID, tvDBID))) { upd.Entity.AniDBEpisodeID = aniDBID; upd.Entity.TvDBEpisodeID = tvDBID; upd.Commit(); } SVR_AnimeEpisode ep = Repo.Instance.AnimeEpisode.GetByAniDBEpisodeID(aniDBID); using (var upd = Repo.Instance.AnimeEpisode.BeginAddOrUpdate(() => Repo.Instance.AnimeEpisode.GetByAniDBEpisodeID(aniDBID))) { SVR_AniDB_Anime.UpdateStatsByAnimeID(ep.AniDB_Episode.AnimeID); upd.Commit(); } logger.Trace($"Changed tvdb episode association: {aniDBID}"); }
public static void AddEpisodeVote(HttpContext context, SVR_AnimeEpisode ep, int userID, Vote vote) { AniDB_Vote dbVote = RepoFactory.AniDB_Vote.GetByEntityAndType(ep.AnimeEpisodeID, AniDBVoteType.Episode); if (dbVote == null) { dbVote = new AniDB_Vote { EntityID = ep.AnimeEpisodeID, VoteType = (int)AniDBVoteType.Episode, }; } dbVote.VoteValue = (int)Math.Floor(vote.GetRating(1000)); RepoFactory.AniDB_Vote.Save(dbVote); //var cmdVote = new CommandRequest_VoteAnimeEpisode(ep.AniDB_EpisodeID, voteType, vote.GetRating()); //cmdVote.Save(); }
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 void LinkAniDBTvDBEpisode(int aniDBID, int tvDBID, int animeID) { CrossRef_AniDB_TvDB_Episode xref = RepoFactory.CrossRef_AniDB_TvDB_Episode.GetByAniDBEpisodeID(aniDBID); if (xref == null) { xref = new CrossRef_AniDB_TvDB_Episode(); } xref.AnimeID = animeID; xref.AniDBEpisodeID = aniDBID; xref.TvDBEpisodeID = tvDBID; RepoFactory.CrossRef_AniDB_TvDB_Episode.Save(xref); SVR_AniDB_Anime.UpdateStatsByAnimeID(animeID); SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(aniDBID); RepoFactory.AnimeEpisode.Save(ep); logger.Trace("Changed tvdb episode association: {0}", aniDBID); }
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 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 void Populate(this SVR_AnimeEpisode animeep, AniDB_Episode anidbEp) { animeep.AniDB_EpisodeID = anidbEp.EpisodeID; animeep.DateTimeUpdated = DateTime.Now; animeep.DateTimeCreated = DateTime.Now; }
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; }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_MALDownloadStatusFromMAL"); try { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { return; } // find the latest eps to update myanimelist mal = MALHelper.GetMALAnimeList(); if (mal == null || mal.anime == null) { return; } // find the anidb user List <SVR_JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers(); if (aniDBUsers.Count == 0) { return; } SVR_JMMUser user = aniDBUsers[0]; foreach (myanimelistAnime malAnime in mal.anime) { // look up the anime CrossRef_AniDB_MAL xref = RepoFactory.CrossRef_AniDB_MAL.GetByMALID(malAnime.series_animedb_id); if (xref == null) { continue; } if (malAnime.series_animedb_id == 8107 || malAnime.series_animedb_id == 10737) { Console.Write(""); } // check if this anime has any other links List <CrossRef_AniDB_MAL> allXrefs = RepoFactory.CrossRef_AniDB_MAL.GetByAnimeID(xref.AnimeID); if (allXrefs.Count == 0) { continue; } // find the range of watched episodes that this applies to int startEpNumber = xref.StartEpisodeNumber; int endEpNumber = GetUpperEpisodeLimit(allXrefs, xref); List <AniDB_Episode> aniEps = RepoFactory.AniDB_Episode.GetByAnimeID(xref.AnimeID); foreach (AniDB_Episode aniep in aniEps) { if (aniep.EpisodeType != xref.StartEpisodeType) { continue; } SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(aniep.EpisodeID); if (ep == null) { continue; } int adjustedWatchedEps = malAnime.my_watched_episodes + xref.StartEpisodeNumber - 1; int epNum = aniep.EpisodeNumber; if (epNum < startEpNumber || epNum > endEpNumber) { continue; } SVR_AnimeEpisode_User usrRec = ep.GetUserRecord(user.JMMUserID); if (epNum <= adjustedWatchedEps) { // update if the user doesn't have a record (means not watched) // or it is currently un-watched bool update = false; if (usrRec == null) { update = true; } else if (!usrRec.WatchedDate.HasValue) { update = true; } if (update) { ep.ToggleWatchedStatus(true, true, DateTime.Now, user.JMMUserID, false); } } else { if (usrRec != null && usrRec.WatchedDate.HasValue) { ep.ToggleWatchedStatus(false, true, DateTime.Now, user.JMMUserID, false); } } } } } catch (Exception ex) { logger.Error("Error processing CommandRequest_MALDownloadStatusFromMAL: {0}", ex); } }
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 override void ProcessCommand() { vlocal = RepoFactory.VideoLocal.GetByID(VideoLocalID); episode = RepoFactory.AnimeEpisode.GetByID(EpisodeID); CrossRef_File_Episode xref = new CrossRef_File_Episode(); try { xref.PopulateManually(vlocal, episode); if (Percentage > 0 && Percentage <= 100) { xref.Percentage = Percentage; } } catch (Exception ex) { string msg = string.Format("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); } 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); }