Exemplo n.º 1
0
        private static void CreateInitialUsers()
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            if (repUsers.GetAll().Count() > 0)
            {
                return;
            }

            JMMUser defaultUser = new JMMUser();

            defaultUser.CanEditServerSettings = 1;
            defaultUser.HideCategories        = "";
            defaultUser.IsAdmin     = 1;
            defaultUser.IsAniDBUser = 1;
            defaultUser.IsTraktUser = 1;
            defaultUser.Password    = "";
            defaultUser.Username    = "******";
            repUsers.Save(defaultUser);

            JMMUser familyUser = new JMMUser();

            familyUser.CanEditServerSettings = 1;
            familyUser.HideCategories        = "Ecchi,Nudity,Sex,Sexual Abuse,Horror,Erotic Game,Incest,18 Restricted";
            familyUser.IsAdmin     = 1;
            familyUser.IsAniDBUser = 1;
            familyUser.IsTraktUser = 1;
            familyUser.Password    = "";
            familyUser.Username    = "******";
            repUsers.Save(familyUser);
        }
Exemplo n.º 2
0
        private static void CreateInitialUsers()
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            if (repUsers.GetAll().Count() > 0)
            {
                return;
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

            JMMUser defaultUser = new JMMUser();

            defaultUser.CanEditServerSettings = 1;
            defaultUser.HideCategories        = "";
            defaultUser.IsAdmin     = 1;
            defaultUser.IsAniDBUser = 1;
            defaultUser.IsTraktUser = 1;
            defaultUser.Password    = "";
            defaultUser.Username    = JMMServer.Properties.Resources.Users_Default;
            repUsers.Save(defaultUser, true);

            JMMUser familyUser = new JMMUser();

            familyUser.CanEditServerSettings = 1;
            familyUser.HideCategories        = "ecchi,nudity,sex,sexual abuse,horror,erotic game,incest,18 restricted";
            familyUser.IsAdmin     = 1;
            familyUser.IsAniDBUser = 1;
            familyUser.IsTraktUser = 1;
            familyUser.Password    = "";
            familyUser.Username    = JMMServer.Properties.Resources.Users_FamilyFriendly;
            repUsers.Save(familyUser, true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates all Group Filters. This should be done as the last step.
        /// </summary>
        /// <remarks>
        /// Assumes that all caches are up to date.
        /// </remarks>
        private void UpdateGroupFilters(ISessionWrapper session)
        {
            _log.Info("Updating Group Filters");

            IReadOnlyList <GroupFilter> grpFilters = _groupFilterRepo.GetAll(session);
            ILookup <int, int>          groupsForTagGroupFilter = _groupFilterRepo.CalculateAnimeGroupsPerTagGroupFilter(session);
            IReadOnlyList <JMMUser>     users = _userRepo.GetAll();

            // The main reason for doing this in parallel is because UpdateEntityReferenceStrings does JSON encoding
            // and is enough work that it can benefit from running in parallel
            Parallel.ForEach(grpFilters.Where(f => ((GroupFilterType)f.FilterType & GroupFilterType.Directory) != GroupFilterType.Directory), filter =>
            {
                var userGroupIds = filter.GroupsIds;

                userGroupIds.Clear();

                if (filter.FilterType == (int)GroupFilterType.Tag)
                {
                    foreach (var user in users)
                    {
                        userGroupIds[user.JMMUserID] = groupsForTagGroupFilter[filter.GroupFilterID].ToHashSet();
                    }
                }
                else     // All other group filters are to be handled normally
                {
                    filter.EvaluateAnimeGroups();
                }

                filter.UpdateEntityReferenceStrings(updateGroups: true, updateSeries: false);
            });

            _groupFilterRepo.BatchUpdate(session, grpFilters);
            _log.Info("Group Filters updated");
        }
Exemplo n.º 4
0
        public static JMMUser GetJMMUser(string userid)
        {
            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allusers = repUsers.GetAll();
            int id = 0;

            int.TryParse(userid, out id);
            return(allusers.FirstOrDefault(a => a.JMMUserID == id) ??
                   allusers.FirstOrDefault(a => a.IsAdmin == 1) ??
                   allusers.FirstOrDefault(a => a.Username == "Default") ?? allusers.First());
        }
Exemplo n.º 5
0
        public static JMMUser GetUser(string UserId)
        {
            int userId = -1;

            if (!string.IsNullOrEmpty(UserId))
            {
                int.TryParse(UserId, out userId);
            }
            JMMUserRepository repUsers = new JMMUserRepository();

            return(userId != 0
                ? repUsers.GetByID(userId)
                : repUsers.GetAll().FirstOrDefault(a => a.Username == "Default"));
        }
Exemplo n.º 6
0
        public static JMMUser GetUser(string userid)
        {
            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allusers = repUsers.GetAll();

            foreach (JMMUser n in allusers)
            {
                if (userid.FindIn(n?.Contract?.PlexUsers))
                {
                    return(n);
                }
            }
            return(allusers.FirstOrDefault(a => a.IsAdmin == 1) ??
                   allusers.FirstOrDefault(a => a.Username == "Default") ?? allusers.First());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates all Group Filters. This should be done as the last step.
        /// </summary>
        /// <remarks>
        /// Assumes that all caches are up to date.
        /// </remarks>
        private void UpdateGroupFilters(ISessionWrapper session)
        {
            _log.Info("Updating Group Filters");

            IReadOnlyList <SVR_GroupFilter> grpFilters          = _groupFilterRepo.GetAll(session);
            ILookup <int, int>          seriesForTagGroupFilter = _groupFilterRepo.CalculateAnimeSeriesPerTagGroupFilter(session);
            IReadOnlyList <SVR_JMMUser> users = _userRepo.GetAll();

            // The main reason for doing this in parallel is because UpdateEntityReferenceStrings does JSON encoding
            // and is enough work that it can benefit from running in parallel
            Parallel.ForEach(
                grpFilters.Where(f => ((GroupFilterType)f.FilterType & GroupFilterType.Directory) !=
                                 GroupFilterType.Directory), filter =>
            {
                filter.SeriesIds.Clear();

                if (filter.FilterType == (int)GroupFilterType.Tag)
                {
                    filter.SeriesIds[0] = seriesForTagGroupFilter[filter.GroupFilterID].ToHashSet();
                    filter.GroupsIds[0] = filter.SeriesIds[0]
                                          .Select(id => RepoFactory.AnimeSeries.GetByID(id).TopLevelAnimeGroup?.AnimeGroupID ?? -1)
                                          .Where(id => id != -1).ToHashSet();
                    foreach (var user in users)
                    {
                        filter.SeriesIds[user.JMMUserID] = seriesForTagGroupFilter[filter.GroupFilterID]
                                                           .Select(id => RepoFactory.AnimeSeries.GetByID(id))
                                                           .Where(ser =>
                                                                  !(ser.GetAnime()?.GetAllTags()?.FindInEnumerable(user.GetHideCategories()) ??
                                                                    false)).Select(a => a.AnimeSeriesID).ToHashSet();
                        filter.GroupsIds[user.JMMUserID] = filter.SeriesIds[user.JMMUserID]
                                                           .Select(id => RepoFactory.AnimeSeries.GetByID(id).TopLevelAnimeGroup?.AnimeGroupID ?? -1)
                                                           .Where(id => id != -1).ToHashSet();
                    }
                }
                else     // All other group filters are to be handled normally
                {
                    filter.CalculateGroupsAndSeries();
                }

                filter.UpdateEntityReferenceStrings();
            });

            _groupFilterRepo.BatchUpdate(session, grpFilters);
            _log.Info("Group Filters updated");
        }
Exemplo n.º 8
0
        public static JMMUser GetUser(string UserId)
        {
            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allusers = repUsers.GetAll();

            foreach (JMMUser n in allusers)
            {
                if (!string.IsNullOrEmpty(n.PlexUsers))
                {
                    string[] users = n.PlexUsers.Split(',');
                    foreach (string m in users)
                    {
                        if (m.Trim().ToLower() == UserId.ToLower())
                        {
                            return(n);
                        }
                    }
                }
            }
            return(allusers.FirstOrDefault(a => a.IsAdmin == 1) ?? allusers.FirstOrDefault(a => a.Username == "Default") ?? allusers.First());
        }
        public System.IO.Stream GetUsers()
        {
            KodiContract_Users gfs = new KodiContract_Users();

            try
            {
                gfs.Users = new List <KodiContract_User>();
                JMMUserRepository repUsers = new JMMUserRepository();
                foreach (JMMUser us in repUsers.GetAll())
                {
                    KodiContract_User p = new KodiContract_User();
                    p.id   = us.JMMUserID.ToString();
                    p.name = us.Username;
                    gfs.Users.Add(p);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return(KodiHelper.GetStreamFromXmlObject(gfs));
        }
Exemplo n.º 10
0
        public void UpdateStats(bool watchedStats, bool missingEpsStats, bool updateAllGroupsAbove)
        {
            DateTime start        = DateTime.Now;
            DateTime startOverall = DateTime.Now;

            logger.Info("Starting Updating STATS for SERIES {0} ({1} - {2} - {3})", this.ToString(), watchedStats, missingEpsStats, updateAllGroupsAbove);

            AnimeSeries_UserRepository      repSeriesUser  = new AnimeSeries_UserRepository();
            AnimeEpisode_UserRepository     repEpisodeUser = new AnimeEpisode_UserRepository();
            VideoLocalRepository            repVids        = new VideoLocalRepository();
            CrossRef_File_EpisodeRepository repXrefs       = new CrossRef_File_EpisodeRepository();

            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allUsers = repUsers.GetAll();

            DateTime            startEps = DateTime.Now;
            List <AnimeEpisode> eps      = GetAnimeEpisodes();
            TimeSpan            tsEps    = DateTime.Now - startEps;

            logger.Trace("Got episodes for SERIES {0} in {1}ms", this.ToString(), tsEps.TotalMilliseconds);

            DateTime                     startVids = DateTime.Now;
            List <VideoLocal>            vidsTemp  = repVids.GetByAniDBAnimeID(this.AniDB_ID);
            List <CrossRef_File_Episode> crossRefs = repXrefs.GetByAnimeID(this.AniDB_ID);

            Dictionary <int, List <CrossRef_File_Episode> > dictCrossRefs = new Dictionary <int, List <CrossRef_File_Episode> >();

            foreach (CrossRef_File_Episode xref in crossRefs)
            {
                if (!dictCrossRefs.ContainsKey(xref.EpisodeID))
                {
                    dictCrossRefs[xref.EpisodeID] = new List <CrossRef_File_Episode>();
                }
                dictCrossRefs[xref.EpisodeID].Add(xref);
            }

            Dictionary <string, VideoLocal> dictVids = new Dictionary <string, VideoLocal>();

            foreach (VideoLocal vid in vidsTemp)
            {
                dictVids[vid.Hash] = vid;
            }

            TimeSpan tsVids = DateTime.Now - startVids;

            logger.Trace("Got video locals for SERIES {0} in {1}ms", this.ToString(), tsVids.TotalMilliseconds);


            if (watchedStats)
            {
                foreach (JMMUser juser in allUsers)
                {
                    //this.WatchedCount = 0;
                    AnimeSeries_User userRecord = GetUserRecord(juser.JMMUserID);
                    if (userRecord == null)
                    {
                        userRecord = new AnimeSeries_User(juser.JMMUserID, this.AnimeSeriesID);
                    }

                    // reset stats
                    userRecord.UnwatchedEpisodeCount = 0;
                    userRecord.WatchedEpisodeCount   = 0;
                    userRecord.WatchedCount          = 0;
                    userRecord.WatchedDate           = null;

                    DateTime startUser = DateTime.Now;
                    List <AnimeEpisode_User>            epUserRecords   = repEpisodeUser.GetByUserID(juser.JMMUserID);
                    Dictionary <int, AnimeEpisode_User> dictUserRecords = new Dictionary <int, AnimeEpisode_User>();
                    foreach (AnimeEpisode_User usrec in epUserRecords)
                    {
                        dictUserRecords[usrec.AnimeEpisodeID] = usrec;
                    }
                    TimeSpan tsUser = DateTime.Now - startUser;
                    logger.Trace("Got user records for SERIES {0}/{1} in {2}ms", this.ToString(), juser.Username, tsUser.TotalMilliseconds);

                    foreach (AnimeEpisode ep in eps)
                    {
                        // if the episode doesn't have any files then it won't count towards watched/unwatched counts
                        List <VideoLocal> epVids = new List <VideoLocal>();

                        if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                        {
                            foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                            {
                                if (xref.EpisodeID == ep.AniDB_EpisodeID)
                                {
                                    if (dictVids.ContainsKey(xref.Hash))
                                    {
                                        epVids.Add(dictVids[xref.Hash]);
                                    }
                                }
                            }
                        }
                        if (epVids.Count == 0)
                        {
                            continue;
                        }

                        if (ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Episode || ep.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Special)
                        {
                            AnimeEpisode_User epUserRecord = null;
                            if (dictUserRecords.ContainsKey(ep.AnimeEpisodeID))
                            {
                                epUserRecord = dictUserRecords[ep.AnimeEpisodeID];
                            }

                            if (epUserRecord != null && epUserRecord.WatchedDate.HasValue)
                            {
                                userRecord.WatchedEpisodeCount++;
                            }
                            else
                            {
                                userRecord.UnwatchedEpisodeCount++;
                            }

                            if (epUserRecord != null)
                            {
                                if (userRecord.WatchedDate.HasValue)
                                {
                                    if (epUserRecord.WatchedDate > userRecord.WatchedDate)
                                    {
                                        userRecord.WatchedDate = epUserRecord.WatchedDate;
                                    }
                                }
                                else
                                {
                                    userRecord.WatchedDate = epUserRecord.WatchedDate;
                                }

                                userRecord.WatchedCount += epUserRecord.WatchedCount;
                            }
                        }
                    }
                    repSeriesUser.Save(userRecord);
                }
            }

            TimeSpan ts = DateTime.Now - start;

            logger.Trace("Updated WATCHED stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;



            if (missingEpsStats)
            {
                enAnimeType animeType   = enAnimeType.TVSeries;
                AniDB_Anime aniDB_Anime = this.GetAnime();
                if (aniDB_Anime != null)
                {
                    animeType = aniDB_Anime.AnimeTypeEnum;
                }

                MissingEpisodeCount       = 0;
                MissingEpisodeCountGroups = 0;

                // get all the group status records
                AniDB_GroupStatusRepository repGrpStat  = new AniDB_GroupStatusRepository();
                List <AniDB_GroupStatus>    grpStatuses = repGrpStat.GetByAnimeID(this.AniDB_ID);

                // find all the episodes for which the user has a file
                // from this we can determine what their latest episode number is
                // find out which groups the user is collecting

                List <int> userReleaseGroups = new List <int>();
                foreach (AnimeEpisode ep in eps)
                {
                    List <VideoLocal> vids = new List <VideoLocal>();
                    if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                    {
                        foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                        {
                            if (xref.EpisodeID == ep.AniDB_EpisodeID)
                            {
                                if (dictVids.ContainsKey(xref.Hash))
                                {
                                    vids.Add(dictVids[xref.Hash]);
                                }
                            }
                        }
                    }

                    //List<VideoLocal> vids = ep.VideoLocals;
                    foreach (VideoLocal vid in vids)
                    {
                        AniDB_File anifile = vid.GetAniDBFile();
                        if (anifile != null)
                        {
                            if (!userReleaseGroups.Contains(anifile.GroupID))
                            {
                                userReleaseGroups.Add(anifile.GroupID);
                            }
                        }
                    }
                }

                int         latestLocalEpNumber = 0;
                EpisodeList epReleasedList      = new EpisodeList(animeType);
                EpisodeList epGroupReleasedList = new EpisodeList(animeType);

                foreach (AnimeEpisode ep in eps)
                {
                    //List<VideoLocal> vids = ep.VideoLocals;
                    if (ep.EpisodeTypeEnum != AniDBAPI.enEpisodeType.Episode)
                    {
                        continue;
                    }

                    List <VideoLocal> vids = new List <VideoLocal>();
                    if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
                    {
                        foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
                        {
                            if (xref.EpisodeID == ep.AniDB_EpisodeID)
                            {
                                if (dictVids.ContainsKey(xref.Hash))
                                {
                                    vids.Add(dictVids[xref.Hash]);
                                }
                            }
                        }
                    }



                    AniDB_Episode aniEp     = ep.AniDB_Episode;
                    int           thisEpNum = aniEp.EpisodeNumber;

                    if (thisEpNum > latestLocalEpNumber && vids.Count > 0)
                    {
                        latestLocalEpNumber = thisEpNum;
                    }

                    // does this episode have a file released
                    // does this episode have a file released by the group the user is collecting
                    bool epReleased      = false;
                    bool epReleasedGroup = false;
                    foreach (AniDB_GroupStatus gs in grpStatuses)
                    {
                        if (gs.LastEpisodeNumber >= thisEpNum)
                        {
                            epReleased = true;
                        }
                        if (userReleaseGroups.Contains(gs.GroupID) && gs.HasGroupReleasedEpisode(thisEpNum))
                        {
                            epReleasedGroup = true;
                        }
                    }


                    try
                    {
                        epReleasedList.Add(ep, (!epReleased || vids.Count != 0));
                        epGroupReleasedList.Add(ep, (!epReleasedGroup || vids.Count != 0));
                    }
                    catch (Exception e)
                    {
                        logger.Trace("Error {0}", e.ToString());
                        throw;
                    }
                }
                foreach (EpisodeList.StatEpisodes eplst in epReleasedList)
                {
                    if (!eplst.Available)
                    {
                        MissingEpisodeCount++;
                    }
                }
                foreach (EpisodeList.StatEpisodes eplst in epGroupReleasedList)
                {
                    if (!eplst.Available)
                    {
                        MissingEpisodeCountGroups++;
                    }
                }

                this.LatestLocalEpisodeNumber = latestLocalEpNumber;
            }

            ts = DateTime.Now - start;
            logger.Trace("Updated MISSING EPS stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;

            AnimeSeriesRepository rep = new AnimeSeriesRepository();

            rep.Save(this);

            if (updateAllGroupsAbove)
            {
                foreach (AnimeGroup grp in AllGroupsAbove)
                {
                    grp.UpdateStats(watchedStats, missingEpsStats);
                }
            }

            ts = DateTime.Now - start;
            logger.Trace("Updated GROUPS ABOVE stats for SERIES {0} in {1}ms", this.ToString(), ts.TotalMilliseconds);
            start = DateTime.Now;

            TimeSpan tsOverall = DateTime.Now - startOverall;

            logger.Info("Finished Updating STATS for SERIES {0} in {1}ms ({2} - {3} - {4})", this.ToString(), tsOverall.TotalMilliseconds,
                        watchedStats, missingEpsStats, updateAllGroupsAbove);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Update the stats for this group based on the child series
        /// Assumes that all the AnimeSeries have had their stats updated already
        /// </summary>
        public void UpdateStats(bool watchedStats, bool missingEpsStats)
        {
            List <AnimeSeries> seriesList = GetAllSeries();

            JMMUserRepository repUsers = new JMMUserRepository();
            List <JMMUser>    allUsers = repUsers.GetAll();

            if (watchedStats)
            {
                foreach (JMMUser juser in allUsers)
                {
                    AnimeGroup_User userRecord = GetUserRecord(juser.JMMUserID);
                    if (userRecord == null)
                    {
                        userRecord = new AnimeGroup_User(juser.JMMUserID, this.AnimeGroupID);
                    }

                    // reset stats
                    userRecord.WatchedCount          = 0;
                    userRecord.UnwatchedEpisodeCount = 0;
                    userRecord.PlayedCount           = 0;
                    userRecord.StoppedCount          = 0;
                    userRecord.WatchedEpisodeCount   = 0;
                    userRecord.WatchedDate           = null;

                    foreach (AnimeSeries ser in seriesList)
                    {
                        AnimeSeries_User serUserRecord = ser.GetUserRecord(juser.JMMUserID);
                        if (serUserRecord != null)
                        {
                            userRecord.WatchedCount          += serUserRecord.WatchedCount;
                            userRecord.UnwatchedEpisodeCount += serUserRecord.UnwatchedEpisodeCount;
                            userRecord.PlayedCount           += serUserRecord.PlayedCount;
                            userRecord.StoppedCount          += serUserRecord.StoppedCount;
                            userRecord.WatchedEpisodeCount   += serUserRecord.WatchedEpisodeCount;

                            if (serUserRecord.WatchedDate.HasValue)
                            {
                                if (userRecord.WatchedDate.HasValue)
                                {
                                    if (serUserRecord.WatchedDate > userRecord.WatchedDate)
                                    {
                                        userRecord.WatchedDate = serUserRecord.WatchedDate;
                                    }
                                }
                                else
                                {
                                    userRecord.WatchedDate = serUserRecord.WatchedDate;
                                }
                            }
                        }
                    }

                    // now update the stats for the groups
                    logger.Trace("Updating stats for {0}", this.ToString());
                    AnimeGroup_UserRepository rep = new AnimeGroup_UserRepository();
                    rep.Save(userRecord);
                }
            }

            if (missingEpsStats)
            {
                this.MissingEpisodeCount       = 0;
                this.MissingEpisodeCountGroups = 0;

                foreach (AnimeSeries ser in seriesList)
                {
                    this.MissingEpisodeCount       += ser.MissingEpisodeCount;
                    this.MissingEpisodeCountGroups += ser.MissingEpisodeCountGroups;
                }

                AnimeGroupRepository repGrp = new AnimeGroupRepository();
                repGrp.Save(this);
            }
        }