Ejemplo n.º 1
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");

            try
            {
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();

                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.AniDB_Username, ServerSettings.AniDB_Password);
                enHelperActivityType ev = cmd.Process();
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = repVotes.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == enAniDBVoteType.Anime || myVote.VoteType == enAniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)enAniDBVoteType.Anime || dbVote.VoteType == (int)enAniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        if (thisVote == null)
                        {
                            thisVote          = new AniDB_Vote();
                            thisVote.EntityID = myVote.EntityID;
                        }
                        thisVote.VoteType  = (int)myVote.VoteType;
                        thisVote.VoteValue = myVote.VoteValue;

                        repVotes.Save(thisVote);

                        if (myVote.VoteType == enAniDBVoteType.Anime || myVote.VoteType == enAniDBVoteType.AnimeTemp)
                        {
                            // download the anime info if the user doesn't already have it
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(thisVote.EntityID, false, false);
                            cmdAnime.Save();
                        }
                    }

                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_SyncMyVotes: {0} ", ex.ToString());
                return;
            }
        }
Ejemplo n.º 2
0
        public void Delete(int id)
        {
            int?animeID = null;

            using (var session = JMMService.SessionFactory.OpenSession())
            {
                // populate the database
                using (var transaction = session.BeginTransaction())
                {
                    AniDB_Vote cr = GetByID(id);
                    if (cr != null)
                    {
                        if (cr.VoteType == (int)AniDBVoteType.Anime || cr.VoteType == (int)AniDBVoteType.AnimeTemp)
                        {
                            animeID = cr.EntityID;
                        }

                        session.Delete(cr);
                        transaction.Commit();
                    }
                }
            }
            if (animeID.HasValue)
            {
                AniDB_Anime.UpdateStatsByAnimeID(animeID.Value);
            }
        }
Ejemplo n.º 3
0
        public static void AddSeriesVote(HttpContext context, SVR_AnimeSeries ser, int userID, Vote vote)
        {
            int voteType = (vote.Type?.ToLowerInvariant() ?? "") switch
            {
                "temporary" => (int)AniDBVoteType.AnimeTemp,
                "permanent" => (int)AniDBVoteType.Anime,
                _ => ser.GetAnime()?.GetFinishedAiring() ?? false ? (int)AniDBVoteType.Anime : (int)AniDBVoteType.AnimeTemp,
            };

            AniDB_Vote dbVote = RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.AnimeTemp) ?? RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.Anime);

            if (dbVote == null)
            {
                dbVote = new AniDB_Vote
                {
                    EntityID = ser.AniDB_ID,
                };
            }

            dbVote.VoteValue = (int)Math.Floor(vote.GetRating(1000));
            dbVote.VoteType  = voteType;

            RepoFactory.AniDB_Vote.Save(dbVote);

            var cmdVote = new CommandRequest_VoteAnime(ser.AniDB_ID, voteType, vote.GetRating());

            cmdVote.Save();
        }
Ejemplo n.º 4
0
        protected override void OnShowContextMenu()
        {
            try
            {
                AniDB_Vote userVote = MainAnime.UserVote;

                ContextMenu cmenu = new ContextMenu(MainAnime.FormattedTitle);

                cmenu.AddAction(Translation.UpdateSeriesInfo, () =>
                {
                    MainWindow.ServerHelper.UpdateAnime(MainAnime.AnimeID);
                    SetGUIProperty(GuiProperty.AnimeInfo_DownloadStatus, Translation.WaitingOnServer + "...");
                });


                if (userVote == null && VM_ShokoServer.Instance.CurrentUser.IsAniDBUserBool())
                {
                    cmenu.AddAction(Translation.PermanentVote, () =>
                    {
                        decimal rating = Utils.PromptAniDBRating(MainAnime.FormattedTitle);
                        if (rating > 0)
                        {
                            VM_ShokoServer.Instance.ShokoServices.VoteAnime(MainAnime.AnimeID, rating, (int)AniDBVoteType.Anime);
                            LoadInfo();
                            SetSkinProperties();
                            InfoPage();
                        }
                    });
                    cmenu.AddAction(Translation.TemporaryVote, () =>
                    {
                        decimal rating = Utils.PromptAniDBRating(MainAnime.FormattedTitle);
                        if (rating > 0)
                        {
                            VM_ShokoServer.Instance.ShokoServices.VoteAnime(MainAnime.AnimeID, rating, (int)AniDBVoteType.AnimeTemp);
                            LoadInfo();
                            SetSkinProperties();
                            InfoPage();
                        }
                    });
                }

                if (userVote != null && Commons.Extensions.Models.IsAniDBUserBool(VM_ShokoServer.Instance.CurrentUser))
                {
                    cmenu.AddAction(Translation.RevokeVote, () =>
                    {
                        VM_ShokoServer.Instance.ShokoServices.VoteAnimeRevoke(MainAnime.AnimeID);
                        LoadInfo();
                        SetSkinProperties();
                        InfoPage();
                    });
                }
                cmenu.Show();
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in menu: {0}", ex);
            }
        }
Ejemplo n.º 5
0
        public bool VoteAnime(int animeID, decimal voteValue, enAniDBVoteType voteType)
        {
            if (!Login())
            {
                return(false);
            }

            enHelperActivityType ev      = enHelperActivityType.NoSuchVote;
            AniDBCommand_Vote    cmdVote = null;

            AniDB_VoteRepository repVotes = new AniDB_VoteRepository();

            lock (lockAniDBConnections)
            {
                Pause();

                cmdVote = new AniDBCommand_Vote();
                cmdVote.Init(animeID, voteValue, voteType);
                SetWaitingOnResponse(true);
                ev = cmdVote.Process(ref soUdp, ref remoteIpEndPoint, curSessionID, new UnicodeEncoding(true, false));
                SetWaitingOnResponse(false);
                if (ev == enHelperActivityType.Voted || ev == enHelperActivityType.VoteUpdated)
                {
                    List <AniDB_Vote> dbVotes  = repVotes.GetByEntity(cmdVote.EntityID);
                    AniDB_Vote        thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        // we can only have anime permanent or anime temp but not both
                        if (cmdVote.VoteType == enAniDBVoteType.Anime || cmdVote.VoteType == enAniDBVoteType.AnimeTemp)
                        {
                            if (dbVote.VoteType == (int)enAniDBVoteType.Anime || dbVote.VoteType == (int)enAniDBVoteType.AnimeTemp)
                            {
                                thisVote = dbVote;
                            }
                        }
                        else
                        {
                            thisVote = dbVote;
                        }
                    }

                    if (thisVote == null)
                    {
                        thisVote          = new AniDB_Vote();
                        thisVote.EntityID = cmdVote.EntityID;
                    }
                    thisVote.VoteType  = (int)cmdVote.VoteType;
                    thisVote.VoteValue = cmdVote.VoteValue;
                    repVotes.Save(thisVote);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public AniDB_Vote GetByEntityAndType(int entID, AniDBVoteType voteType)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                AniDB_Vote cr = session
                                .CreateCriteria(typeof(AniDB_Vote))
                                .Add(Restrictions.Eq("EntityID", entID))
                                .Add(Restrictions.Eq("VoteType", (int)voteType))
                                .UniqueResult <AniDB_Vote>();

                return(cr);
            }
        }
Ejemplo n.º 7
0
 public void Save(AniDB_Vote obj)
 {
     using (var session = JMMService.SessionFactory.OpenSession())
     {
         // populate the database
         using (var transaction = session.BeginTransaction())
         {
             session.SaveOrUpdate(obj);
             transaction.Commit();
         }
     }
     if (obj.VoteType == (int)AniDBVoteType.Anime || obj.VoteType == (int)AniDBVoteType.AnimeTemp)
     {
         AniDB_Anime.UpdateStatsByAnimeID(obj.EntityID);
     }
 }
Ejemplo n.º 8
0
        public static void PromptToRateSeriesOnCompletion(VM_AnimeSeries_User ser)
        {
            try
            {
                if (!BaseConfig.Settings.DisplayRatingDialogOnCompletion)
                {
                    return;
                }

                // if the user doesn't have all the episodes return
                if (ser.MissingEpisodeCount > 0)
                {
                    return;
                }

                // if we have no anidb info return
                if (ser.Anime == null || ser.AniDB_ID == 0)
                {
                    return;
                }

                // only prompt the user if the series has finished airing
                // and the user has watched all the episodes
                if (!ser.Anime.FinishedAiring || ser.UnwatchedEpisodeCount > 0)
                {
                    return;
                }

                // don't prompt if the user has already rated this
                AniDB_Vote UserVote = ser.Anime.UserVote;
                if (UserVote != null)
                {
                    return;
                }

                decimal rating = Utils.PromptAniDBRating(ser.Anime.FormattedTitle);
                if (rating > 0)
                {
                    VM_ShokoServer.Instance.ShokoServices.VoteAnime(ser.AniDB_ID, rating, (int)AniDBVoteType.Anime);
                }
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        private void AddBasicAniDBInfo(HttpContext ctx, SVR_AnimeSeries ser)
        {
            var anime = ser.GetAnime();

            if (anime == null)
            {
                return;
            }
            AniDB_Vote vote = RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.Anime) ??
                              RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                string voteType = (AniDBVoteType)vote.VoteType == AniDBVoteType.Anime ? "Permanent" : "Temporary";
                UserRating = new Rating
                {
                    Value  = (decimal)Math.Round(vote.VoteValue / 100D, 1), MaxValue = 10, Type = voteType,
                    Source = "User"
                };
            }
        }
Ejemplo n.º 11
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");
            try
            {
                ReportInit(progress);
                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.Instance.AniDb.Username, ServerSettings.Instance.AniDb.Password);
                ReportUpdate(progress, 30);
                enHelperActivityType ev = cmd.Process();
                ReportUpdate(progress, 60);
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    List <ICommand> cmdstoAdd = new List <ICommand>();
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = Repo.Instance.AniDB_Vote.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)AniDBVoteType.Anime || dbVote.VoteType == (int)AniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        using (var upd = Repo.Instance.AniDB_Vote.BeginAddOrUpdate(thisVote, () => new AniDB_Vote {
                            EntityID = myVote.EntityID
                        }))
                        {
                            upd.Entity.VoteType  = (int)myVote.VoteType;
                            upd.Entity.VoteValue = myVote.VoteValue;

                            upd.Commit();
                        }

                        if ((myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp) && (thisVote != null))
                        {
                            cmdstoAdd.Add(new CmdAniDBGetAnimeHTTP(thisVote.EntityID, false, false));
                        }
                    }
                    if (cmdstoAdd.Count > 0)
                    {
                        Queue.Instance.AddRange(cmdstoAdd);
                    }
                    ReportUpdate(progress, 90);
                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing AniDb.SyncMyVotes: {ex}", ex);
            }
        }
        public System.IO.Stream VoteAnime(string userid, string objectid, string votevalue, string votetype)
        {
            Respond rsp = new Respond();

            rsp.code = 500;

            int    objid  = 0;
            int    usid   = 0;
            int    vt     = 0;
            double vvalue = 0;

            if (!int.TryParse(objectid, out objid))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!int.TryParse(userid, out usid))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!int.TryParse(votetype, out vt))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            if (!double.TryParse(votevalue, NumberStyles.Any, CultureInfo.InvariantCulture, out vvalue))
            {
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                if (vt == (int)enAniDBVoteType.Episode)
                {
                    AnimeEpisodeRepository repEpisodes = new AnimeEpisodeRepository();
                    AnimeEpisode           ep          = repEpisodes.GetByID(session, objid);
                    AniDB_Anime            anime       = ep.GetAnimeSeries().GetAnime();
                    if (anime == null)
                    {
                        rsp.code = 404;
                        return(KodiHelper.GetStreamFromXmlObject(rsp));
                    }
                    string msg = string.Format("Voting for anime episode: {0} - Value: {1}", ep.AnimeEpisodeID, vvalue);
                    logger.Info(msg);

                    // lets save to the database and assume it will work
                    AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                    List <AniDB_Vote>    dbVotes  = repVotes.GetByEntity(ep.AnimeEpisodeID);
                    AniDB_Vote           thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        if (dbVote.VoteType == (int)enAniDBVoteType.Episode)
                        {
                            thisVote = dbVote;
                        }
                    }

                    if (thisVote == null)
                    {
                        thisVote          = new AniDB_Vote();
                        thisVote.EntityID = ep.AnimeEpisodeID;
                    }
                    thisVote.VoteType = vt;

                    int iVoteValue = 0;
                    if (vvalue > 0)
                    {
                        iVoteValue = (int)(vvalue * 100);
                    }
                    else
                    {
                        iVoteValue = (int)vvalue;
                    }

                    msg = string.Format("Voting for anime episode Formatted: {0} - Value: {1}", ep.AnimeEpisodeID, iVoteValue);
                    logger.Info(msg);
                    thisVote.VoteValue = iVoteValue;
                    repVotes.Save(thisVote);
                    CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt, Convert.ToDecimal(vvalue));
                    cmdVote.Save();
                }

                if (vt == (int)enAniDBVoteType.Anime)
                {
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    AnimeSeries           ser       = repSeries.GetByID(session, objid);
                    AniDB_Anime           anime     = ser.GetAnime();
                    if (anime == null)
                    {
                        rsp.code = 404;
                        return(KodiHelper.GetStreamFromXmlObject(rsp));
                    }
                    string msg = string.Format("Voting for anime: {0} - Value: {1}", anime.AnimeID, vvalue);
                    logger.Info(msg);

                    // lets save to the database and assume it will work
                    AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                    List <AniDB_Vote>    dbVotes  = repVotes.GetByEntity(anime.AnimeID);
                    AniDB_Vote           thisVote = null;
                    foreach (AniDB_Vote dbVote in dbVotes)
                    {
                        // we can only have anime permanent or anime temp but not both
                        if (vt == (int)enAniDBVoteType.Anime || vt == (int)enAniDBVoteType.AnimeTemp)
                        {
                            if (dbVote.VoteType == (int)enAniDBVoteType.Anime ||
                                dbVote.VoteType == (int)enAniDBVoteType.AnimeTemp)
                            {
                                thisVote = dbVote;
                            }
                        }
                        else
                        {
                            thisVote = dbVote;
                        }
                    }

                    if (thisVote == null)
                    {
                        thisVote          = new AniDB_Vote();
                        thisVote.EntityID = anime.AnimeID;
                    }
                    thisVote.VoteType = vt;

                    int iVoteValue = 0;
                    if (vvalue > 0)
                    {
                        iVoteValue = (int)(vvalue * 100);
                    }
                    else
                    {
                        iVoteValue = (int)vvalue;
                    }

                    msg = string.Format("Voting for anime Formatted: {0} - Value: {1}", anime.AnimeID, iVoteValue);
                    logger.Info(msg);
                    thisVote.VoteValue = iVoteValue;
                    repVotes.Save(thisVote);
                    CommandRequest_VoteAnime cmdVote = new CommandRequest_VoteAnime(anime.AnimeID, vt, Convert.ToDecimal(vvalue));
                    cmdVote.Save();
                }
                rsp.code = 200;
                return(KodiHelper.GetStreamFromXmlObject(rsp));
            }
        }
Ejemplo n.º 13
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)
        {
            using (ISession session = DatabaseFactory.SessionFactory.OpenSession())
            {
                ISessionWrapper sessionWrapper = session.Wrap();
                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 = RepoFactory.AniDB_Vote.GetByEntityAndType(anidb.AnimeID, AniDBVoteType.Anime) ??
                                  RepoFactory.AniDB_Vote.GetByEntityAndType(anidb.AnimeID, AniDBVoteType.AnimeTemp);
                if (vote != null)
                {
                    p.UserRating = (int)(vote.VoteValue / 100D);
                }

                List <CrossRef_AniDB_TvDBV2> ls = ser.CrossRefAniDBTvDBV2;
                if (ls != null && ls.Count > 0)
                {
                    foreach (CrossRef_AniDB_TvDBV2 c in ls)
                    {
                        if (c.TvDBSeasonNumber == 0)
                        {
                            continue;
                        }
                        p.Season = c.TvDBSeasonNumber.ToString();
                        p.Index  = c.TvDBSeasonNumber;
                    }
                }
                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.AniDB_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
                    });
                }
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public static Serie GenerateFromAniDB_Anime(NancyContext ctx, SVR_AniDB_Anime anime, bool nocast, bool notag, bool allpics, int pic, TagFilter.Filter tagfilter)
        {
            Serie sr = new Serie
            {
                // 0 will load all
                id      = -1,
                aid     = anime.AnimeID,
                summary = anime.Description,
                rating  = Math.Round(anime.Rating / 100D, 1)
                          .ToString(CultureInfo.InvariantCulture),
                votes   = anime.VoteCount.ToString(),
                name    = anime.MainTitle,
                ismovie = anime.AnimeType == (int)AnimeType.Movie ? 1 : 0
            };

            if (anime.AirDate != null)
            {
                sr.year = anime.AirDate.Value.Year.ToString();
                var airdate = anime.AirDate.Value;
                if (airdate != DateTime.MinValue)
                {
                    sr.air = airdate.ToPlexDate();
                }
            }

            AniDB_Vote vote = RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.Anime) ??
                              RepoFactory.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                sr.userrating = Math.Round(vote.VoteValue / 100D, 1).ToString(CultureInfo.InvariantCulture);
            }
            sr.titles = anime.GetTitles().Select(title =>
                                                 new AnimeTitle {
                Language = title.Language, Title = title.Title, Type = title.TitleType
            }).ToList();

            PopulateArtFromAniDBAnime(ctx, anime, sr, allpics, pic);

            if (!nocast)
            {
                var xref_animestaff = RepoFactory.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(anime.AnimeID,
                                                                                               StaffRoleType.Seiyuu);
                foreach (var xref in xref_animestaff)
                {
                    if (xref.RoleID == null)
                    {
                        continue;
                    }
                    var character = RepoFactory.AnimeCharacter.GetByID(xref.RoleID.Value);
                    if (character == null)
                    {
                        continue;
                    }
                    var staff = RepoFactory.AnimeStaff.GetByID(xref.StaffID);
                    if (staff == null)
                    {
                        continue;
                    }
                    var role = new Role
                    {
                        character       = character.Name,
                        character_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Character,
                                                                                    xref.RoleID.Value),
                        staff       = staff.Name,
                        staff_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Staff,
                                                                                xref.StaffID),
                        role = xref.Role,
                        type = ((StaffRoleType)xref.RoleType).ToString()
                    };
                    if (sr.roles == null)
                    {
                        sr.roles = new List <Role>();
                    }
                    sr.roles.Add(role);
                }
            }

            if (!notag)
            {
                var tags = anime.GetAllTags();
                if (tags != null)
                {
                    sr.tags = TagFilter.ProcessTags(tagfilter, tags.ToList());
                }
            }

            return(sr);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level, bool all, bool allpics, int pic, TagFilter.Filter tagfilter)
        {
            Serie sr = new Serie();

            List <SVR_AnimeEpisode> ael = ser.GetAnimeEpisodes();
            var contract = ser.Contract;

            if (contract == null)
            {
                ser.UpdateContract();
            }

            sr.id      = ser.AnimeSeriesID;
            sr.summary = contract.AniDBAnime.AniDBAnime.Description;
            sr.year    = contract.AniDBAnime.AniDBAnime.BeginYear.ToString();
            var airdate = ser.AirDate;

            if (airdate != DateTime.MinValue)
            {
                sr.air = airdate.ToPlexDate();
            }

            GenerateSizes(sr, ael, uid);

            sr.rating = Math.Round(contract.AniDBAnime.AniDBAnime.Rating / 100D, 1)
                        .ToString(CultureInfo.InvariantCulture);
            AniDB_Vote vote = RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.Anime) ??
                              RepoFactory.AniDB_Vote.GetByEntityAndType(ser.AniDB_ID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                sr.userrating = Math.Round(vote.VoteValue / 100D, 1).ToString(CultureInfo.InvariantCulture);
            }
            sr.titles = ser.GetAnime().GetTitles().Select(title =>
                                                          new AnimeTitle {
                Language = title.Language, Title = title.Title, Type = title.TitleType
            }).ToList();
            sr.name = ser.GetSeriesNameFromContract(contract);

            var ls = contract.CrossRefAniDBTvDBV2?.OrderBy(a => a.TvDBSeasonNumber).FirstOrDefault();

            if ((ls?.TvDBSeasonNumber ?? 0) != 0)
            {
                sr.season = ls.TvDBSeasonNumber.ToString();
            }

            if (contract.AniDBAnime.AniDBAnime.AnimeType == (int)AnimeType.Movie)
            {
                sr.ismovie = 1;
            }

            #region Images

            var anime = ser.GetAnime();
            if (anime != null)
            {
                Random rand = new Random();
                if (allpics || pic > 1)
                {
                    if (allpics)
                    {
                        pic = 999;
                    }
                    int pic_index = 0;
                    if (anime.AllPosters != null)
                    {
                        foreach (var cont_image in anime.AllPosters)
                        {
                            if (pic_index < pic)
                            {
                                sr.art.thumb.Add(new Art()
                                {
                                    url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                    cont_image.AniDB_Anime_DefaultImageID),
                                    index = pic_index
                                });
                                pic_index++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    pic_index = 0;
                    if (anime.Contract.AniDBAnime.Fanarts != null)
                    {
                        foreach (var cont_image in anime.Contract.AniDBAnime.Fanarts)
                        {
                            if (pic_index < pic)
                            {
                                sr.art.fanart.Add(new Art()
                                {
                                    url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                    cont_image.AniDB_Anime_DefaultImageID),
                                    index = pic_index
                                });
                                pic_index++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    pic_index = 0;
                    if (anime.Contract.AniDBAnime.Banners != null)
                    {
                        foreach (var cont_image in anime.Contract.AniDBAnime.Banners)
                        {
                            if (pic_index < pic)
                            {
                                sr.art.banner.Add(new Art()
                                {
                                    url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType,
                                                                                    cont_image.AniDB_Anime_DefaultImageID),
                                    index = pic_index
                                });
                                pic_index++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    sr.art.thumb.Add(new Art()
                    {
                        url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.AniDB_Cover,
                                                                        anime.AnimeID),
                        index = 0
                    });

                    var fanarts = anime.Contract.AniDBAnime.Fanarts;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        sr.art.fanart.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }

                    fanarts = anime.Contract.AniDBAnime.Banners;
                    if (fanarts != null && fanarts.Count > 0)
                    {
                        var art = fanarts[rand.Next(fanarts.Count)];
                        sr.art.banner.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType,
                                                                            art.AniDB_Anime_DefaultImageID),
                            index = 0
                        });
                    }
                }
            }

            #endregion

            if (!nocast)
            {
                var xref_animestaff = RepoFactory.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(ser.AniDB_ID,
                                                                                               StaffRoleType.Seiyuu);
                foreach (var xref in xref_animestaff)
                {
                    if (xref.RoleID == null)
                    {
                        continue;
                    }
                    var character = RepoFactory.AnimeCharacter.GetByID(xref.RoleID.Value);
                    if (character == null)
                    {
                        continue;
                    }
                    var staff = RepoFactory.AnimeStaff.GetByID(xref.StaffID);
                    if (staff == null)
                    {
                        continue;
                    }
                    var role = new Role
                    {
                        character       = character.Name,
                        character_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Character,
                                                                                    xref.RoleID.Value),
                        staff       = staff.Name,
                        staff_image = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.Staff,
                                                                                xref.StaffID),
                        role = xref.Role,
                        type = ((StaffRoleType)xref.RoleType).ToString()
                    };
                    if (sr.roles == null)
                    {
                        sr.roles = new List <Role>();
                    }
                    sr.roles.Add(role);
                }
            }

            if (!notag)
            {
                var tags = ser.Contract.AniDBAnime.AniDBAnime.GetAllTags();
                if (tags != null)
                {
                    sr.tags = TagFilter.ProcessTags(tagfilter, tags.ToList());
                }
            }

            if (level > 0)
            {
                if (ael.Count > 0)
                {
                    sr.eps = new List <Episode>();
                    foreach (SVR_AnimeEpisode ae in ael)
                    {
                        if (!all && (ae?.GetVideoLocals()?.Count ?? 0) == 0)
                        {
                            continue;
                        }
                        Episode new_ep = Episode.GenerateFromAnimeEpisode(ctx, ae, uid, (level - 1));
                        if (new_ep != null)
                        {
                            sr.eps.Add(new_ep);
                        }
                        if (level - 1 > 0)
                        {
                            foreach (RawFile file in new_ep.files)
                            {
                                sr.filesize += file.size;
                            }
                        }
                    }
                    sr.eps = sr.eps.OrderBy(a => a.epnumber).ToList();
                }
            }

            return(sr);
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_SyncMyVotes");

            try
            {
                AniDBHTTPCommand_GetVotes cmd = new AniDBHTTPCommand_GetVotes();
                cmd.Init(ServerSettings.Instance.AniDb.Username, ServerSettings.Instance.AniDb.Password);
                enHelperActivityType ev = cmd.Process();
                if (ev == enHelperActivityType.GotVotesHTTP)
                {
                    foreach (Raw_AniDB_Vote_HTTP myVote in cmd.MyVotes)
                    {
                        List <AniDB_Vote> dbVotes  = Repo.Instance.AniDB_Vote.GetByEntity(myVote.EntityID);
                        AniDB_Vote        thisVote = null;
                        foreach (AniDB_Vote dbVote in dbVotes)
                        {
                            // we can only have anime permanent or anime temp but not both
                            if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                            {
                                if (dbVote.VoteType == (int)AniDBVoteType.Anime || dbVote.VoteType == (int)AniDBVoteType.AnimeTemp)
                                {
                                    thisVote = dbVote;
                                }
                            }
                            else
                            {
                                thisVote = dbVote;
                            }
                        }

                        using (var upd = Repo.Instance.AniDB_Vote.BeginAddOrUpdate(
                                   () => thisVote,
                                   () => new AniDB_Vote {
                            EntityID = myVote.EntityID
                        }
                                   ))
                        {
                            upd.Entity.VoteType  = (int)myVote.VoteType;
                            upd.Entity.VoteValue = myVote.VoteValue;

                            upd.Commit();
                        }

                        if (myVote.VoteType == AniDBVoteType.Anime || myVote.VoteType == AniDBVoteType.AnimeTemp)
                        {
                            // download the anime info if the user doesn't already have it
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(thisVote.EntityID,
                                                                                                   false, false);
                            cmdAnime.Save();
                        }
                    }

                    logger.Info("Processed Votes: {0} Items", cmd.MyVotes.Count);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_SyncMyVotes: {0} ", ex);
            }
        }
Ejemplo n.º 19
0
        public void GenerateFromAniDB_Anime(HttpContext ctx, SVR_AniDB_Anime anime)
        {
            anidb_id   = anime.AnimeID;
            restricted = anime.Restricted == 1;
            if (ctx.Items.ContainsKey("description"))
            {
                description = new List <Description>
                {
                    new Description {
                        source = "AniDB", language = "en", description = anime.Description
                    }
                };
            }

            ratings = new List <Rating>
            {
                new Rating
                {
                    source     = "AniDB",
                    rating     = (decimal)anime.Rating / 10,
                    max_rating = 100,
                    votes      = anime.VoteCount
                }
            };
            name        = anime.MainTitle;
            series_type = anime.AnimeType.ToString();

            if (anime.AirDate != null)
            {
                var airdate = anime.AirDate.Value;
                if (airdate != DateTime.MinValue)
                {
                    air_date = airdate.ToString("yyyy-MM-dd");
                }
            }
            if (anime.EndDate != null)
            {
                var enddate = anime.EndDate.Value;
                if (enddate != DateTime.MinValue)
                {
                    end_date = enddate.ToString("yyyy-MM-dd");
                }
            }

            AniDB_Vote vote = Repo.Instance.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.Anime) ??
                              Repo.Instance.AniDB_Vote.GetByEntityAndType(anime.AnimeID, AniDBVoteType.AnimeTemp);

            if (vote != null)
            {
                string voteType = (AniDBVoteType)vote.VoteType == AniDBVoteType.Anime ? "Permanent" : "Temporary";
                user_rating = new Rating
                {
                    rating = (decimal)Math.Round(vote.VoteValue / 100D, 1), max_rating = 10, type = voteType,
                    source = "User"
                };
            }

            if (ctx.Items.ContainsKey("titles"))
            {
                titles = anime.GetTitles().Select(title => new Title
                {
                    language = title.Language, title = title.Title, type = title.TitleType
                }).ToList();
            }

            PopulateArtFromAniDBAnime(ctx, anime);

            if (ctx.Items.ContainsKey("cast"))
            {
                var xref_animestaff = Repo.Instance.CrossRef_Anime_Staff.GetByAnimeIDAndRoleType(anime.AnimeID,
                                                                                                 StaffRoleType.Seiyuu);
                foreach (var xref in xref_animestaff)
                {
                    if (xref.RoleID == null)
                    {
                        continue;
                    }
                    AnimeCharacter character = Repo.Instance.AnimeCharacter.GetByID(xref.RoleID.Value);
                    if (character == null)
                    {
                        continue;
                    }
                    AnimeStaff staff = Repo.Instance.AnimeStaff.GetByID(xref.StaffID);
                    if (staff == null)
                    {
                        continue;
                    }
                    Role role = new Role
                    {
                        character = new Role.Person
                        {
                            name        = character.Name, alternate_name = character.AlternateName,
                            image       = new Image(ctx, xref.RoleID.Value, ImageEntityType.Character),
                            description = character.Description
                        },
                        staff = new Role.Person
                        {
                            name           = staff.Name,
                            alternate_name = staff.AlternateName,
                            description    = staff.Description,
                            image          = new Image(ctx, xref.StaffID, ImageEntityType.Staff),
                        },
                        role         = ((StaffRoleType)xref.RoleType).ToString(),
                        role_details = xref.Role
                    };
                    if (cast == null)
                    {
                        cast = new List <Role>();
                    }
                    cast.Add(role);
                }
            }

            if (ctx.Items.ContainsKey("tags"))
            {
                var animeTags = anime.GetAllTags();
                if (animeTags != null)
                {
                    if (!ctx.Items.TryGetValue("tagfilter", out object tagfilter))
                    {
                        tagfilter = 0;
                    }
                    tags = TagFilter.ProcessTags((TagFilter.Filter)tagfilter, animeTags.ToList());
                }
            }
        }
Ejemplo n.º 20
0
        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);
        }