コード例 #1
0
        public static void InitCache()
        {
            string t = "Users";

            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, string.Empty);
            JMMUserRepository repo = new JMMUserRepository();

            Cache = new PocoCache <int, JMMUser>(repo.InternalGetAll(), a => a.JMMUserID);
        }
コード例 #2
0
        private static bool GetTraktCollectionInfo(ref List<TraktV2ShowCollectedResult> collected, ref List<TraktV2ShowWatchedResult> watched)
        {
            try
            {
                if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return false;

                // check that we have at least one user nominated for Trakt
                JMMUserRepository repUsers = new JMMUserRepository();
                List<JMMUser> traktUsers = repUsers.GetTraktUsers();
                if (traktUsers.Count == 0) return false;

                int traktCode = TraktStatusCodes.Success;

                // now get the full users collection from Trakt
                collected = TraktTVHelper.GetCollectedShows(ref traktCode);
                if (traktCode != TraktStatusCodes.Success)
                {
                    logger.Error("Could not get users collection: {0}", traktCode);
                    return false;
                }

                // now get all the shows / episodes the user has watched
                watched = TraktTVHelper.GetWatchedShows(ref traktCode);
                if (traktCode != TraktStatusCodes.Success)
                {
                    logger.Error("Could not get users watched history: {0}", traktCode);
                    return false;
                }

                return true;
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.GetTraktCollectionInfo: " + ex.ToString(), ex);
                return false;
            }
        }
コード例 #3
0
        public static void SyncCollectionToTrakt_Series(AnimeSeries series)
        {
            try
            {
                // check that we have at least one user nominated for Trakt
                JMMUserRepository repUsers = new JMMUserRepository();
                List<JMMUser> traktUsers = repUsers.GetTraktUsers();
                if (traktUsers.Count == 0) return;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(series.AniDB_ID);
                if (anime == null) return;

                TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                traktSummary.Populate(series.AniDB_ID);
                if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) return;

                // now get the full users collection from Trakt
                List<TraktV2ShowCollectedResult> collected = new List<TraktV2ShowCollectedResult>();
                List<TraktV2ShowWatchedResult> watched = new List<TraktV2ShowWatchedResult>();

                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                foreach (AnimeEpisode ep in series.GetAnimeEpisodes())
                {
                    if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                    {
                        ReconSyncTraktEpisode(series, ep, traktSummary, traktUsers, collected, watched, true);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.SyncCollectionToTrakt_Series: " + ex.ToString(), ex);
            }
        }
コード例 #4
0
ファイル: AzureWebAPI.cs プロジェクト: maz0r/jmmserver
        public static UserInfo GetUserInfoData(string dashType = "", string vidPlayer = "")
        {
            try
            {
                if (string.IsNullOrEmpty(ServerSettings.AniDB_Username)) return null;

                UserInfo uinfo = new UserInfo();

                uinfo.DateTimeUpdated = DateTime.Now;
                uinfo.DateTimeUpdatedUTC = 0;

                // Optional JMM Desktop data
                uinfo.DashboardType = null;
                uinfo.VideoPlayer = vidPlayer;

                System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
                try
                {
                    if (a != null) uinfo.JMMServerVersion = Utils.GetApplicationVersion(a);
                }
                catch {}

                uinfo.UsernameHash = Utils.GetMd5Hash(ServerSettings.AniDB_Username);
                uinfo.DatabaseType = ServerSettings.DatabaseType;
                uinfo.WindowsVersion = Utils.GetOSInfo();
                uinfo.TraktEnabled = ServerSettings.Trakt_IsEnabled ? 1 : 0;
                uinfo.MALEnabled = string.IsNullOrEmpty(ServerSettings.MAL_Username) ? 0 : 1;

                uinfo.CountryLocation = "";
                
                // this field is not actually used
                uinfo.LastEpisodeWatchedAsDate = DateTime.Now.AddDays(-5);

                JMMUserRepository repUsers = new JMMUserRepository();
                uinfo.LocalUserCount = (int)(repUsers.GetTotalRecordCount());

                VideoLocalRepository repVids = new VideoLocalRepository();
                uinfo.FileCount = repVids.GetTotalRecordCount();

                AnimeEpisode_UserRepository repEps = new AnimeEpisode_UserRepository();
                List<AnimeEpisode_User> recs = repEps.GetLastWatchedEpisode();
                uinfo.LastEpisodeWatched = 0;
                if (recs.Count > 0)
                    uinfo.LastEpisodeWatched = Utils.GetAniDBDateAsSeconds(recs[0].WatchedDate);

                return uinfo;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return null;
            }
        }
コード例 #5
0
        public string SaveUser(Contract_JMMUser user)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                bool existingUser = false;
                bool updateStats = false;
                JMMUser jmmUser = null;
                if (user.JMMUserID.HasValue)
                {
                    jmmUser = repUsers.GetByID(user.JMMUserID.Value);
                    if (jmmUser == null) return "User not found";
                    existingUser = true;
                }
                else
                {
                    jmmUser = new JMMUser();
                    updateStats = true;
                }

                if (existingUser && jmmUser.IsAniDBUser != user.IsAniDBUser)
                    updateStats = true;

                jmmUser.HideCategories = user.HideCategories;
                jmmUser.IsAniDBUser = user.IsAniDBUser;
                jmmUser.IsTraktUser = user.IsTraktUser;
                jmmUser.IsAdmin = user.IsAdmin;
                jmmUser.Username = user.Username;
                jmmUser.CanEditServerSettings = user.CanEditServerSettings;
                jmmUser.PlexUsers = user.PlexUsers;
                if (string.IsNullOrEmpty(user.Password))
                    jmmUser.Password = "";

                // make sure that at least one user is an admin
                if (jmmUser.IsAdmin == 0)
                {
                    bool adminExists = false;
                    List<JMMUser> users = repUsers.GetAll();
                    foreach (JMMUser userOld in users)
                    {
                        if (userOld.IsAdmin == 1)
                        {
                            if (existingUser)
                            {
                                if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true;
                            }
                            else
                                adminExists = true;

                        }
                    }

                    if (!adminExists) return "At least one user must be an administrator";
                }

                repUsers.Save(jmmUser);

                // update stats
                if (updateStats)
                {
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    foreach (AnimeSeries ser in repSeries.GetAll())
                        ser.QueueUpdateStats();
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }

            return "";
        }
コード例 #6
0
        public List<Contract_AniDB_Anime_Similar> GetSimilarAnimeLinks(int animeID, int userID)
        {
            List<Contract_AniDB_Anime_Similar> links = new List<Contract_AniDB_Anime_Similar>();
            try
            {
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return links;

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser juser = repUsers.GetByID(userID);
                if (juser == null) return links;

                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                foreach (AniDB_Anime_Similar link in anime.GetSimilarAnime())
                {
                    AniDB_Anime animeLink = repAnime.GetByAnimeID(link.SimilarAnimeID);
                    if (animeLink != null)
                    {
                        if (!juser.AllowedAnime(animeLink)) continue;
                    }

                    // check if this anime has a series
                    AnimeSeries ser = repSeries.GetByAnimeID(link.SimilarAnimeID);

                    links.Add(link.ToContract(animeLink, ser, userID));
                }

                return links;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return links;
            }
        }
コード例 #7
0
        public List<Contract_AnimeSeries> GetSeriesRecentlyAdded(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeSeries> retSeries = new List<Contract_AnimeSeries>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    JMMUserRepository repUsers = new JMMUserRepository();
                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return retSeries;

                    List<AnimeSeries> series = repSeries.GetMostRecentlyAdded(session, maxRecords);
                    int numSeries = 0;
                    foreach (AnimeSeries ser in series)
                    {

                        if (user.AllowedSeries(ser))
                        {
                            Contract_AnimeSeries serContract = ser.ToContract(ser.GetUserRecord(session, jmmuserID));
                            if (serContract != null)
                            {
                                retSeries.Add(serContract);
                                numSeries++;

                                // Lets only return the specified amount
                                if (retSeries.Count == maxRecords) return retSeries;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retSeries;
        }
コード例 #8
0
        public List<Contract_AniDBAnime> GetMiniCalendar(int jmmuserID, int numberOfDays)
        {
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the series
            List<Contract_AniDBAnime> animeList = new List<Contract_AniDBAnime>();

            try
            {
                JMMUser user = repUsers.GetByID(jmmuserID);
                if (user == null) return animeList;

                List<AniDB_Anime> animes = repAnime.GetForDate(DateTime.Today.AddDays(0 - numberOfDays), DateTime.Today.AddDays(numberOfDays));
                foreach (AniDB_Anime anime in animes)
                {
                    bool useAnime = true;

                    string[] cats = user.HideCategories.ToLower().Split(',');
                    string[] animeCats = anime.AllCategories.ToLower().Split('|');
                    foreach (string cat in cats)
                    {
                        if (!string.IsNullOrEmpty(cat) && animeCats.Contains(cat))
                        {
                            useAnime = false;
                            break;
                        }
                    }

                    if (useAnime)
                        animeList.Add(anime.ToContract());
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return animeList;
        }
コード例 #9
0
        public List<Contract_AnimeEpisode> GetContinueWatchingFilter(int userID, int maxRecords)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    GroupFilterRepository repGF = new GroupFilterRepository();

                    JMMUserRepository repUsers = new JMMUserRepository();
                    JMMUser user = repUsers.GetByID(session, userID);
                    if (user == null) return retEps;

                    // find the locked Continue Watching Filter
                    GroupFilter gf = null;
                    List<GroupFilter> lockedGFs = repGF.GetLockedGroupFilters(session);
                    if (lockedGFs != null)
                    {
                        // if it already exists we can leave
                        foreach (GroupFilter gfTemp in lockedGFs)
                        {
                            if (gfTemp.FilterType == (int)GroupFilterType.ContinueWatching)
                            {
                                gf = gfTemp;
                                break;
                            }
                        }
                    }

                    if (gf == null) return retEps;

                    // Get all the groups
                    // it is more efficient to just get the full list of groups and then filter them later
                    AnimeGroupRepository repGroups = new AnimeGroupRepository();
                    List<AnimeGroup> allGrps = repGroups.GetAll(session);

                    // get all the user records
                    AnimeGroup_UserRepository repUserRecords = new AnimeGroup_UserRepository();
                    List<AnimeGroup_User> userRecords = repUserRecords.GetByUserID(session, userID);
                    Dictionary<int, AnimeGroup_User> dictUserRecords = new Dictionary<int, AnimeGroup_User>();
                    foreach (AnimeGroup_User userRec in userRecords)
                        dictUserRecords[userRec.AnimeGroupID] = userRec;

                    // get all the groups in this filter for this user
                    HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID];

                    List<Contract_AnimeGroup> comboGroups = new List<Contract_AnimeGroup>();
                    foreach (AnimeGroup grp in allGrps)
                    {
                        if (groups.Contains(grp.AnimeGroupID))
                        {
                            AnimeGroup_User userRec = null;
                            if (dictUserRecords.ContainsKey(grp.AnimeGroupID)) userRec = dictUserRecords[grp.AnimeGroupID];

                            Contract_AnimeGroup rec = grp.ToContract(userRec);
                            comboGroups.Add(rec);
                        }
                    }

                    // apply sorting
                    List<SortPropOrFieldAndDirection> sortCriteria = GroupFilterHelper.GetSortDescriptions(gf);
                    comboGroups = Sorting.MultiSort<Contract_AnimeGroup>(comboGroups, sortCriteria);

                    if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[user.JMMUserID].ContainsKey(gf.GroupFilterID)))
                    {
                        AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                        foreach (Contract_AnimeGroup grp in comboGroups)
                        {
                            List<AnimeSeries> sers = repSeries.GetByGroupID(session, grp.AnimeGroupID);

                            // sort the series by air date
                            List<SortPropOrFieldAndDirection> sortCriteria2 = new List<SortPropOrFieldAndDirection>();
                            sortCriteria2.Add(new SortPropOrFieldAndDirection("AirDate", false, SortType.eDateTime));
                            sers = Sorting.MultiSort<AnimeSeries>(sers, sortCriteria2);

                            List<int> seriesWatching = new List<int>();

                            foreach (AnimeSeries ser in sers)
                            {
                                if (!user.AllowedSeries(ser)) continue;
                                bool useSeries = true;

                                if (seriesWatching.Count > 0)
                                {
                                    if (ser.GetAnime().AnimeType == (int)enAnimeType.TVSeries)
                                    {
                                        // make sure this series is not a sequel to an existing series we have already added
                                        foreach (AniDB_Anime_Relation rel in ser.GetAnime().GetRelatedAnime())
                                        {
                                            if (rel.RelationType.ToLower().Trim().Equals("sequel") || rel.RelationType.ToLower().Trim().Equals("prequel"))
                                                useSeries = false;
                                        }
                                    }

                                }

                                if (!useSeries) continue;

                                Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, ser.AnimeSeriesID, userID);
                                if (ep != null)
                                {
                                    retEps.Add(ep);

                                    // Lets only return the specified amount
                                    if (retEps.Count == maxRecords)
                                        return retEps;

                                    if (ser.GetAnime().AnimeType == (int)enAnimeType.TVSeries)
                                        seriesWatching.Add(ser.AniDB_ID);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return retEps;
        }
コード例 #10
0
        public List<Contract_AnimeRating> GetAnimeRatings(int collectionState, int watchedState, int ratingVotedState, int userID)
        {
            List<Contract_AnimeRating> contracts = new List<Contract_AnimeRating>();

            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                List<AnimeSeries> series = repSeries.GetAll();
                Dictionary<int, AnimeSeries> dictSeries = new Dictionary<int, AnimeSeries>();
                foreach (AnimeSeries ser in series)
                    dictSeries[ser.AniDB_ID] = ser;

                RatingCollectionState _collectionState = (RatingCollectionState)collectionState;
                RatingWatchedState _watchedState = (RatingWatchedState)watchedState;
                RatingVotedState _ratingVotedState = (RatingVotedState)ratingVotedState;

                DateTime start = DateTime.Now;

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                /*
                // build a dictionary of categories
                AniDB_CategoryRepository repCats = new AniDB_CategoryRepository();
                AniDB_Anime_CategoryRepository repAnimeCat = new AniDB_Anime_CategoryRepository();

                List<AniDB_Category> allCatgeories = repCats.GetAll();
                Dictionary<int, AniDB_Category> allCatgeoriesDict = new Dictionary<int, AniDB_Category>();
                foreach (AniDB_Category cat in allCatgeories)
                    allCatgeoriesDict[cat.CategoryID] = cat;

                List<AniDB_Anime_Category> allAnimeCatgeories = repAnimeCat.GetAll();
                Dictionary<int, List<AniDB_Anime_Category>> allAnimeCatgeoriesDict = new Dictionary<int, List<AniDB_Anime_Category>>(); //
                foreach (AniDB_Anime_Category aniCat in allAnimeCatgeories)
                {
                    if (!allAnimeCatgeoriesDict.ContainsKey(aniCat.AnimeID))
                        allAnimeCatgeoriesDict[aniCat.AnimeID] = new List<AniDB_Anime_Category>();

                    allAnimeCatgeoriesDict[aniCat.AnimeID].Add(aniCat);
                }

                // build a dictionary of titles
                AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

                List<AniDB_Anime_Title> allTitles = repTitles.GetAll();
                Dictionary<int, List<AniDB_Anime_Title>> allTitlesDict = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title title in allTitles)
                {
                    if (!allTitlesDict.ContainsKey(title.AnimeID))
                        allTitlesDict[title.AnimeID] = new List<AniDB_Anime_Title>();

                    allTitlesDict[title.AnimeID].Add(title);
                }

                // build a dictionary of tags
                AniDB_TagRepository repTags = new AniDB_TagRepository();
                AniDB_Anime_TagRepository repAnimeTag = new AniDB_Anime_TagRepository();

                List<AniDB_Tag> allTags = repTags.GetAll();
                Dictionary<int, AniDB_Tag> allTagsDict = new Dictionary<int, AniDB_Tag>();
                foreach (AniDB_Tag tag in allTags)
                    allTagsDict[tag.TagID] = tag;

                List<AniDB_Anime_Tag> allAnimeTags = repAnimeTag.GetAll();
                Dictionary<int, List<AniDB_Anime_Tag>> allAnimeTagsDict = new Dictionary<int, List<AniDB_Anime_Tag>>(); //
                foreach (AniDB_Anime_Tag aniTag in allAnimeTags)
                {
                    if (!allAnimeTagsDict.ContainsKey(aniTag.AnimeID))
                        allAnimeTagsDict[aniTag.AnimeID] = new List<AniDB_Anime_Tag>();

                    allAnimeTagsDict[aniTag.AnimeID].Add(aniTag);
                }

                // build a dictionary of languages
                AdhocRepository rep = new AdhocRepository();
                Dictionary<int, LanguageStat> dictAudioStats = rep.GetAudioLanguageStatsForAnime();
                Dictionary<int, LanguageStat> dictSubtitleStats = rep.GetSubtitleLanguageStatsForAnime();

                Dictionary<int, string> dictAnimeVideoQualStats = rep.GetAllVideoQualityByAnime();
                Dictionary<int, AnimeVideoQualityStat> dictAnimeEpisodeVideoQualStats = rep.GetEpisodeVideoQualityStatsByAnime();
                 * */

                List<AniDB_Anime> animes = repAnime.GetAll();

                // user votes
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                List<AniDB_Vote> allVotes = repVotes.GetAll();

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser user = repUsers.GetByID(userID);
                if (user == null) return contracts;

                int i = 0;

                foreach (AniDB_Anime anime in animes)
                {
                    i++;

                    // evaluate collection states
                    if (_collectionState == RatingCollectionState.AllEpisodesInMyCollection)
                    {
                        if (!anime.FinishedAiring) continue;
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
                        if (dictSeries[anime.AnimeID].MissingEpisodeCount > 0) continue;
                    }

                    if (_collectionState == RatingCollectionState.InMyCollection)
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;

                    if (_collectionState == RatingCollectionState.NotInMyCollection)
                        if (dictSeries.ContainsKey(anime.AnimeID)) continue;

                    if (!user.AllowedAnime(anime)) continue;

                    // evaluate watched states
                    if (_watchedState == RatingWatchedState.AllEpisodesWatched)
                    {
                        if (!dictSeries.ContainsKey(anime.AnimeID)) continue;
                        AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
                        if (userRec == null) continue;
                        if (userRec.UnwatchedEpisodeCount > 0) continue;
                    }

                    if (_watchedState == RatingWatchedState.NotWatched)
                    {
                        if (dictSeries.ContainsKey(anime.AnimeID))
                        {
                            AnimeSeries_User userRec = dictSeries[anime.AnimeID].GetUserRecord(userID);
                            if (userRec != null)
                            {
                                if (userRec.UnwatchedEpisodeCount == 0) continue;
                            }
                        }
                    }

                    // evaluate voted states
                    if (_ratingVotedState == RatingVotedState.Voted)
                    {
                        bool voted = false;
                        foreach (AniDB_Vote vote in allVotes)
                        {
                            if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                            {
                                voted = true;
                                break;
                            }
                        }

                        if (!voted) continue;
                    }

                    if (_ratingVotedState == RatingVotedState.NotVoted)
                    {
                        bool voted = false;
                        foreach (AniDB_Vote vote in allVotes)
                        {
                            if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                            {
                                voted = true;
                                break;
                            }
                        }

                        if (voted) continue;
                    }

                    Contract_AnimeRating contract = new Contract_AnimeRating();
                    contract.AnimeID = anime.AnimeID;

                    Contract_AniDB_AnimeDetailed contractAnimeDetailed = new Contract_AniDB_AnimeDetailed();

                    contractAnimeDetailed.AnimeTitles = new List<Contract_AnimeTitle>();
                    contractAnimeDetailed.Tags = new List<Contract_AnimeTag>();
                    contractAnimeDetailed.CustomTags = new List<Contract_CustomTag>();
                    contractAnimeDetailed.UserVote = null;

                    contractAnimeDetailed.AniDBAnime = anime.ToContract();

                    // get user vote
                    foreach (AniDB_Vote vote in allVotes)
                    {
                        if (vote.EntityID == anime.AnimeID && (vote.VoteType == (int)AniDBVoteType.Anime || vote.VoteType == (int)AniDBVoteType.AnimeTemp))
                        {
                            contractAnimeDetailed.UserVote = vote.ToContract();
                            break;
                        }
                    }

                    contract.AnimeDetailed = contractAnimeDetailed;

                    if (dictSeries.ContainsKey(anime.AnimeID))
                    {
                        contract.AnimeSeries = dictSeries[anime.AnimeID].ToContract(dictSeries[anime.AnimeID].GetUserRecord(userID));
                    }

                    contracts.Add(contract);

                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
コード例 #11
0
        public List<Contract_AnimeGroup> GetAnimeGroupsForFilter(int groupFilterID, int userID, bool getSingleSeriesGroups)
        {
            List<Contract_AnimeGroup> retGroups = new List<Contract_AnimeGroup>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    DateTime start = DateTime.Now;
                    GroupFilterRepository repGF = new GroupFilterRepository();

                    JMMUserRepository repUsers = new JMMUserRepository();
                    JMMUser user = repUsers.GetByID(session, userID);
                    if (user == null) return retGroups;

                    GroupFilter gf = null;

                    if (groupFilterID == -999)
                    {
                        // all groups
                        gf = new GroupFilter();
                        gf.GroupFilterName = "All";
                    }
                    else
                    {
                        gf = repGF.GetByID(session, groupFilterID);
                        if (gf == null) return retGroups;
                    }

                    //Contract_GroupFilterExtended contract = gf.ToContractExtended(user);

                    AnimeGroupRepository repGroups = new AnimeGroupRepository();
                    List<AnimeGroup> allGrps = repGroups.GetAll(session);

                    AnimeGroup_UserRepository repUserRecords = new AnimeGroup_UserRepository();
                    List<AnimeGroup_User> userRecords = repUserRecords.GetByUserID(session, userID);
                    Dictionary<int, AnimeGroup_User> dictUserRecords = new Dictionary<int, AnimeGroup_User>();
                    foreach (AnimeGroup_User userRec in userRecords)
                        dictUserRecords[userRec.AnimeGroupID] = userRec;

                    TimeSpan ts = DateTime.Now - start;
                    string msg = string.Format("Got groups for filter DB: {0} - {1} in {2} ms", gf.GroupFilterName, allGrps.Count, ts.TotalMilliseconds);
                    logger.Info(msg);
                    start = DateTime.Now;

                    AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                    List<AnimeSeries> allSeries = new List<AnimeSeries>();
                    if (getSingleSeriesGroups)
                        allSeries = repSeries.GetAll(session);
                    if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[user.JMMUserID].ContainsKey(gf.GroupFilterID)))
                    {
                        HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID];

                        foreach (AnimeGroup grp in allGrps)
                        {
                            AnimeGroup_User userRec = null;
                            if (dictUserRecords.ContainsKey(grp.AnimeGroupID))
                                userRec = dictUserRecords[grp.AnimeGroupID];
                            if (groups.Contains(grp.AnimeGroupID))
                            {
                                Contract_AnimeGroup contractGrp = grp.ToContract(userRec);
                                if (getSingleSeriesGroups)
                                {
                                    if (contractGrp.Stat_SeriesCount == 1)
                                    {
                                        AnimeSeries ser = GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                                        if (ser != null)
                                            contractGrp.SeriesForNameOverride = ser.ToContract(ser.GetUserRecord(session, userID));

                                    }
                                }
                                retGroups.Add(contractGrp);
                            }
                        }
                    }
                    ts = DateTime.Now - start;
                    msg = string.Format("Got groups for filter EVAL: {0} - {1} in {2} ms", gf.GroupFilterName, retGroups.Count, ts.TotalMilliseconds);
                    logger.Info(msg);

                    return retGroups;
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return retGroups;
        }
コード例 #12
0
        public List<Contract_AniDBAnime> GetAnimeForMonth(int jmmuserID, int month, int year)
        {
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the series
            List<Contract_AniDBAnime> animeList = new List<Contract_AniDBAnime>();

            try
            {
                JMMUser user = repUsers.GetByID(jmmuserID);
                if (user == null) return animeList;

                DateTime startDate = new DateTime(year, month, 1, 0, 0, 0);
                DateTime endDate = startDate.AddMonths(1);
                endDate = endDate.AddMinutes(-10);

                List<AniDB_Anime> animes = repAnime.GetForDate(startDate, endDate);
                foreach (AniDB_Anime anime in animes)
                {
                    bool useAnime = true;

                    string[] cats = user.HideCategories.ToLower().Split(',');
                    string[] animeCats = anime.AllCategories.ToLower().Split('|');
                    foreach (string cat in cats)
                    {
                        if (!string.IsNullOrEmpty(cat) && animeCats.Contains(cat))
                        {
                            useAnime = false;
                            break;
                        }
                    }

                    if (useAnime)
                        animeList.Add(anime.ToContract());
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return animeList;
        }
コード例 #13
0
        /*public List<Contract_AniDBAnime> GetMiniCalendar(int numberOfDays)
        {
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the series
            List<Contract_AniDBAnime> animeList = new List<Contract_AniDBAnime>();

            try
            {

                List<AniDB_Anime> animes = repAnime.GetForDate(DateTime.Today.AddDays(0 - numberOfDays), DateTime.Today.AddDays(numberOfDays));
                foreach (AniDB_Anime anime in animes)
                {

                        animeList.Add(anime.ToContract());
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return animeList;
        }*/
        public List<Contract_JMMUser> GetAllUsers()
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the users
            List<Contract_JMMUser> userList = new List<Contract_JMMUser>();

            try
            {
                List<JMMUser> users = repUsers.GetAll();
                foreach (JMMUser user in users)
                    userList.Add(user.ToContract());

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return userList;
        }
コード例 #14
0
        public List<Contract_GroupFilterExtended> GetAllGroupFiltersExtended(int userID)
        {
            List<Contract_GroupFilterExtended> gfs = new List<Contract_GroupFilterExtended>();
            try
            {
                DateTime start = DateTime.Now;
                GroupFilterRepository repGF = new GroupFilterRepository();

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser user = repUsers.GetByID(userID);
                if (user == null) return gfs;

                List<GroupFilter> allGfs = repGF.GetAll();
                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetAllGroupFilters (Database) in {0} ms", ts.TotalMilliseconds);
                start = DateTime.Now;

                AnimeGroupRepository repGroups = new AnimeGroupRepository();
                List<AnimeGroup> allGrps = repGroups.GetAllTopLevelGroups();
                ts = DateTime.Now - start;
                logger.Info("GetAllGroups (Database) in {0} ms", ts.TotalMilliseconds);
                start = DateTime.Now;

                foreach (GroupFilter gf in allGfs)
                {
                    Contract_GroupFilter gfContract = gf.ToContract();
                    Contract_GroupFilterExtended gfeContract = new Contract_GroupFilterExtended();
                    gfeContract.GroupFilter = gfContract;
                    gfeContract.GroupCount = 0;
                    gfeContract.SeriesCount = 0;
                    if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[userID].ContainsKey(gf.GroupFilterID)))
                    {
                        HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID];

                        foreach (AnimeGroup grp in allGrps)
                        {
                            if (groups.Contains(grp.AnimeGroupID))
                            {
                                // calculate stats
                                gfeContract.GroupCount++;
                            }
                        }
                    }
                    gfs.Add(gfeContract);
                }

                ts = DateTime.Now - start;
                logger.Info("GetAllGroupFiltersExtended (FILTER) in {0} ms", ts.TotalMilliseconds);

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return gfs;
        }
コード例 #15
0
		public List<MetroContract_Anime_Summary> SearchAnime(int jmmuserID, string queryText, int maxRecords)
		{
			List<MetroContract_Anime_Summary> retAnime = new List<MetroContract_Anime_Summary>();
			try
			{
				using (var session = JMMService.SessionFactory.OpenSession())
				{
					AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
					JMMUserRepository repUsers = new JMMUserRepository();
					AnimeSeriesRepository repSeries = new AnimeSeriesRepository();


					JMMUser user = repUsers.GetByID(session, jmmuserID);
					if (user == null) return retAnime;


					List<AniDB_Anime> animes = repAnime.SearchByName(session, queryText);
					foreach (AniDB_Anime anidb_anime in animes)
					{

						if (!user.AllowedAnime(anidb_anime)) continue;

						AnimeSeries ser = repSeries.GetByAnimeID(anidb_anime.AnimeID);

						MetroContract_Anime_Summary summ = new MetroContract_Anime_Summary();

						summ.AirDateAsSeconds = anidb_anime.AirDateAsSeconds;
						summ.AnimeID = anidb_anime.AnimeID;
						if (ser != null)
						{
							summ.AnimeName = ser.GetSeriesName(session);
							summ.AnimeSeriesID = ser.AnimeSeriesID;
						}
						else
						{
							summ.AnimeName = anidb_anime.MainTitle;
							summ.AnimeSeriesID = 0;
						}
						summ.BeginYear = anidb_anime.BeginYear;
						summ.EndYear = anidb_anime.EndYear;
						summ.PosterName = anidb_anime.GetDefaultPosterPathNoBlanks(session);

						ImageDetails imgDet = anidb_anime.GetDefaultPosterDetailsNoBlanks(session);
						summ.ImageType = (int)imgDet.ImageType;
						summ.ImageID = imgDet.ImageID;

						retAnime.Add(summ);
						if (retAnime.Count == maxRecords) break;
					}
				}
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}

			return retAnime;
		}
コード例 #16
0
        public Contract_AnimeEpisode GetLastWatchedEpisodeForSeries(int animeSeriesID, int jmmuserID)
        {
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                    AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository();
                    JMMUserRepository repUsers = new JMMUserRepository();

                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return null;

                    List<AnimeEpisode_User> userRecords = repEpUser.GetLastWatchedEpisodeForSeries(session, animeSeriesID, jmmuserID);
                    if (userRecords == null || userRecords.Count == 0) return null;

                    AnimeEpisode ep = repEps.GetByID(session, userRecords[0].AnimeEpisodeID);
                    if (ep == null) return null;

                    return ep.ToContract(session, jmmuserID);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return null;
        }
コード例 #17
0
        public Contract_JMMUser AuthenticateUser(string username, string password)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                JMMUser user = repUsers.AuthenticateUser(username, password);
                if (user == null) return null;

                return user.ToContract();

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return null;
            }
        }
コード例 #18
0
        /// <summary>
        /// Returns a list of recommendations based on the users votes
        /// </summary>
        /// <param name="maxResults"></param>
        /// <param name="userID"></param>
        /// <param name="recommendationType">1 = to watch, 2 = to download</param>
        public List<Contract_Recommendation> GetRecommendations(int maxResults, int userID, int recommendationType)
        {
            List<Contract_Recommendation> recs = new List<Contract_Recommendation>();

            try
            {
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_VoteRepository repVotes = new AniDB_VoteRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

                JMMUserRepository repUsers = new JMMUserRepository();
                JMMUser juser = repUsers.GetByID(userID);
                if (juser == null) return recs;

                // get all the anime the user has chosen to ignore
                int ignoreType = 1;
                switch (recommendationType)
                {
                    case 1: ignoreType = 1; break;
                    case 2: ignoreType = 2; break;
                }
                IgnoreAnimeRepository repIgnore = new IgnoreAnimeRepository();
                List<IgnoreAnime> ignored = repIgnore.GetByUserAndType(userID, ignoreType);
                Dictionary<int, IgnoreAnime> dictIgnored = new Dictionary<int, Entities.IgnoreAnime>();
                foreach (IgnoreAnime ign in ignored)
                    dictIgnored[ign.AnimeID] = ign;

                // find all the series which the user has rated
                List<AniDB_Vote> allVotes = repVotes.GetAll();
                if (allVotes.Count == 0) return recs;

                // sort by the highest rated
                List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("VoteValue", true, SortType.eInteger));
                allVotes = Sorting.MultiSort<AniDB_Vote>(allVotes, sortCriteria);

                Dictionary<int, Contract_Recommendation> dictRecs = new Dictionary<int, Contract_Recommendation>();

                List<AniDB_Vote> animeVotes = new List<AniDB_Vote>();
                foreach (AniDB_Vote vote in allVotes)
                {
                    if (vote.VoteType != (int)enAniDBVoteType.Anime && vote.VoteType != (int)enAniDBVoteType.AnimeTemp) continue;

                    if (dictIgnored.ContainsKey(vote.EntityID)) continue;

                    // check if the user has this anime
                    AniDB_Anime anime = repAnime.GetByAnimeID(vote.EntityID);
                    if (anime == null) continue;

                    // get similar anime
                    List<AniDB_Anime_Similar> simAnime = anime.GetSimilarAnime();
                    // sort by the highest approval
                    sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("ApprovalPercentage", true, SortType.eDoubleOrFloat));
                    simAnime = Sorting.MultiSort<AniDB_Anime_Similar>(simAnime, sortCriteria);

                    foreach (AniDB_Anime_Similar link in simAnime)
                    {
                        if (dictIgnored.ContainsKey(link.SimilarAnimeID)) continue;

                        AniDB_Anime animeLink = repAnime.GetByAnimeID(link.SimilarAnimeID);
                        if (animeLink != null)
                            if (!juser.AllowedAnime(animeLink)) continue;

                        // don't recommend to watch anime that the user doesn't have
                        if (animeLink == null && recommendationType == 1) continue;

                        // don't recommend to watch series that the user doesn't have
                        AnimeSeries ser = repSeries.GetByAnimeID(link.SimilarAnimeID);
                        if (ser == null && recommendationType == 1) continue;

                        if (ser != null)
                        {
                            // don't recommend to watch series that the user has already started watching
                            AnimeSeries_User userRecord = ser.GetUserRecord(userID);
                            if (userRecord != null)
                            {
                                if (userRecord.WatchedEpisodeCount > 0 && recommendationType == 1) continue;
                            }

                            // don't recommend to download anime that the user has files for
                            if (ser.LatestLocalEpisodeNumber > 0 && recommendationType == 2) continue;
                        }

                        Contract_Recommendation rec = new Contract_Recommendation();
                        rec.BasedOnAnimeID = anime.AnimeID;
                        rec.RecommendedAnimeID = link.SimilarAnimeID;

                        // if we don't have the anime locally. lets assume the anime has a high rating
                        decimal animeRating = 850;
                        if (animeLink != null) animeRating = animeLink.AniDBRating;

                        rec.Score = CalculateRecommendationScore(vote.VoteValue, link.ApprovalPercentage, animeRating);
                        rec.BasedOnVoteValue = vote.VoteValue;
                        rec.RecommendedApproval = link.ApprovalPercentage;

                        // check if we have added this recommendation before
                        // this might happen where animes are recommended based on different votes
                        // and could end up with different scores
                        if (dictRecs.ContainsKey(rec.RecommendedAnimeID))
                        {
                            if (rec.Score < dictRecs[rec.RecommendedAnimeID].Score) continue;
                        }

                        rec.Recommended_AniDB_Anime = null;
                        if (animeLink != null)
                            rec.Recommended_AniDB_Anime = animeLink.ToContract();

                        rec.BasedOn_AniDB_Anime = anime.ToContract();

                        rec.Recommended_AnimeSeries = null;
                        if (ser != null)
                            rec.Recommended_AnimeSeries = ser.ToContract(ser.GetUserRecord(userID));

                        AnimeSeries serBasedOn = repSeries.GetByAnimeID(anime.AnimeID);
                        if (serBasedOn == null) continue;

                        rec.BasedOn_AnimeSeries = serBasedOn.ToContract(serBasedOn.GetUserRecord(userID));

                        dictRecs[rec.RecommendedAnimeID] = rec;
                    }
                }

                List<Contract_Recommendation> tempRecs = new List<Contract_Recommendation>();
                foreach (Contract_Recommendation rec in dictRecs.Values)
                    tempRecs.Add(rec);

                // sort by the highest score
                sortCriteria = new List<SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("Score", true, SortType.eDoubleOrFloat));
                tempRecs = Sorting.MultiSort<Contract_Recommendation>(tempRecs, sortCriteria);

                int numRecs = 0;
                foreach (Contract_Recommendation rec in tempRecs)
                {
                    if (numRecs == maxResults) break;
                    recs.Add(rec);
                    numRecs++;
                }

                if (recs.Count == 0) return recs;

                return recs;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return recs;
            }
        }
コード例 #19
0
        public List<Contract_AnimeEpisode> GetEpisodesRecentlyAdded(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                    AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository();
                    JMMUserRepository repUsers = new JMMUserRepository();
                    VideoLocalRepository repVids = new VideoLocalRepository();

                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return retEps;

                    List<VideoLocal> vids = repVids.GetMostRecentlyAdded(session, maxRecords);
                    int numEps = 0;
                    foreach (VideoLocal vid in vids)
                    {
                        foreach (AnimeEpisode ep in vid.GetAnimeEpisodes(session))
                        {
                            if (user.AllowedSeries(ep.GetAnimeSeries(session)))
                            {
                                Contract_AnimeEpisode epContract = ep.ToContract(session, jmmuserID);
                                if (epContract != null)
                                {
                                    retEps.Add(epContract);
                                    numEps++;

                                    // Lets only return the specified amount
                                    if (retEps.Count == maxRecords) return retEps;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retEps;
        }
コード例 #20
0
        public List<Contract_AnimeSeries> GetSeriesWithMissingEpisodes(int maxRecords, int jmmuserID)
        {
            DateTime start = DateTime.Now;
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            JMMUserRepository repUsers = new JMMUserRepository();

            // get all the series
            List<Contract_AnimeSeries> seriesContractList = new List<Contract_AnimeSeries>();

            try
            {
                JMMUser user = repUsers.GetByID(jmmuserID);
                if (user == null) return seriesContractList;

                List<AnimeSeries> series = repSeries.GetWithMissingEpisodes();

                List<AniDB_Anime> animes = repAnime.GetAll();
                Dictionary<int, AniDB_Anime> dictAnimes = new Dictionary<int, AniDB_Anime>();
                foreach (AniDB_Anime anime in animes)
                    dictAnimes[anime.AnimeID] = anime;

                // tvdb
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_TvDBV2>> dictCrossRefsV2 = new Dictionary<int, List<CrossRef_AniDB_TvDBV2>>();
                foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
                {
                    if (!dictCrossRefsV2.ContainsKey(xref.AnimeID))
                        dictCrossRefsV2[xref.AnimeID] = new List<CrossRef_AniDB_TvDBV2>();
                    dictCrossRefsV2[xref.AnimeID].Add(xref);
                }

                // moviedb
                CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
                List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
                Dictionary<int, CrossRef_AniDB_Other> dictMovieCrossRefs = new Dictionary<int, CrossRef_AniDB_Other>();
                foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
                {
                    if (xref.CrossRefType == (int)CrossRefType.MovieDB)
                        dictMovieCrossRefs[xref.AnimeID] = xref;
                }

                // MAL
                CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
                List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_MAL>> dictMALCrossRefs = new Dictionary<int, List<CrossRef_AniDB_MAL>>();
                foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
                {
                    if (!dictMALCrossRefs.ContainsKey(xref.AnimeID))
                        dictMALCrossRefs[xref.AnimeID] = new List<CrossRef_AniDB_MAL>();
                    dictMALCrossRefs[xref.AnimeID].Add(xref);
                }

                // user records
                AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                List<AnimeSeries_User> userRecordList = repSeriesUser.GetByUserID(jmmuserID);
                Dictionary<int, AnimeSeries_User> dictUserRecords = new Dictionary<int, AnimeSeries_User>();
                foreach (AnimeSeries_User serUser in userRecordList)
                    dictUserRecords[serUser.AnimeSeriesID] = serUser;

                int i = 1;
                foreach (AnimeSeries aser in series)
                {
                    if (!dictAnimes.ContainsKey(aser.AniDB_ID)) continue;

                    AniDB_Anime anime = dictAnimes[aser.AniDB_ID];
                    if (!user.AllowedAnime(anime)) continue;

                    List<CrossRef_AniDB_TvDBV2> xrefs = new List<CrossRef_AniDB_TvDBV2>();
                    if (dictCrossRefsV2.ContainsKey(aser.AniDB_ID)) xrefs = dictCrossRefsV2[aser.AniDB_ID];

                    CrossRef_AniDB_Other xrefMovie = null;
                    if (dictMovieCrossRefs.ContainsKey(aser.AniDB_ID)) xrefMovie = dictMovieCrossRefs[aser.AniDB_ID];

                    AnimeSeries_User userRec = null;
                    if (dictUserRecords.ContainsKey(aser.AnimeSeriesID))
                        userRec = dictUserRecords[aser.AnimeSeriesID];

                    List<CrossRef_AniDB_MAL> xrefMAL = null;
                    if (dictMALCrossRefs.ContainsKey(aser.AniDB_ID))
                        xrefMAL = dictMALCrossRefs[aser.AniDB_ID];

                    List<TvDB_Series> sers = new List<TvDB_Series>();
                    foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                        sers.Add(xref.GetTvDBSeries());
                    MovieDB_Movie movie = null;
                    if (xrefMovie != null)
                        movie = xrefMovie.GetMovieDB_Movie();
                    seriesContractList.Add(aser.ToContract(dictAnimes[aser.AniDB_ID], xrefs, xrefMovie, userRec,
                        sers, xrefMAL, false, null, null, null, null,movie));

                    if (i == maxRecords) break;

                    i++;
                }

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetSeriesWithMissingEpisodes in {0} ms", ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return seriesContractList;
        }
コード例 #21
0
        public string ChangePassword(int userID, string newPassword)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                JMMUser jmmUser = repUsers.GetByID(userID);
                if (jmmUser == null) return "User not found";

                jmmUser.Password = Digest.Hash(newPassword);
                repUsers.Save(jmmUser);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }

            return "";
        }
コード例 #22
0
        public void IgnoreAnime(int animeID, int ignoreType, int userID)
        {
            try
            {
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return;

                JMMUserRepository repUser = new JMMUserRepository();
                JMMUser user = repUser.GetByID(userID);
                if (user == null) return;

                IgnoreAnimeRepository repIgnore = new IgnoreAnimeRepository();
                IgnoreAnime ignore = repIgnore.GetByAnimeUserType(animeID, userID, ignoreType);
                if (ignore != null) return;// record already exists

                ignore = new IgnoreAnime();
                ignore.AnimeID = animeID;
                ignore.IgnoreType = ignoreType;
                ignore.JMMUserID = userID;

                repIgnore.Save(ignore);

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }
コード例 #23
0
        public List<Contract_AnimeEpisode> GetEpisodesRecentlyAddedSummary(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            try
            {
                AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository();
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                JMMUserRepository repUsers = new JMMUserRepository();
                VideoLocalRepository repVids = new VideoLocalRepository();

                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return retEps;

                    DateTime start = DateTime.Now;

                    string sql = "Select ae.AnimeSeriesID, max(vl.DateTimeCreated) as MaxDate " +
                            "From VideoLocal vl " +
                            "INNER JOIN CrossRef_File_Episode xref ON vl.Hash = xref.Hash " +
                            "INNER JOIN AnimeEpisode ae ON ae.AniDB_EpisodeID = xref.EpisodeID " +
                            "GROUP BY ae.AnimeSeriesID " +
                            "ORDER BY MaxDate desc ";
                    ArrayList results = DatabaseHelper.GetData(sql);

                    TimeSpan ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:RawData in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now;

                    int numEps = 0;
                    foreach (object[] res in results)
                    {
                        int animeSeriesID = int.Parse(res[0].ToString());

                        AnimeSeries ser = repSeries.GetByID(session, animeSeriesID);
                        if (ser == null) continue;

                        if (!user.AllowedSeries(ser)) continue;

                        List<VideoLocal> vids = repVids.GetMostRecentlyAddedForAnime(session, 1, ser.AniDB_ID);
                        if (vids.Count == 0) continue;

                        List<AnimeEpisode> eps = vids[0].GetAnimeEpisodes(session);
                        if (eps.Count == 0) continue;

                        Contract_AnimeEpisode epContract = eps[0].ToContract(session, jmmuserID);
                        if (epContract != null)
                        {
                            retEps.Add(epContract);
                            numEps++;

                            // Lets only return the specified amount
                            if (retEps.Count == maxRecords)
                            {
                                ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:Episodes in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now;
                                return retEps;
                            }
                        }

                    }
                    ts2 = DateTime.Now - start; logger.Info("GetEpisodesRecentlyAddedSummary:Episodes in {0} ms", ts2.TotalMilliseconds); start = DateTime.Now;
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retEps;
        }
コード例 #24
0
        public string DeleteUser(int userID)
        {
            JMMUserRepository repUsers = new JMMUserRepository();

            try
            {
                JMMUser jmmUser = repUsers.GetByID(userID);
                if (jmmUser == null) return "User not found";

                // make sure that at least one user is an admin
                if (jmmUser.IsAdmin == 1)
                {
                    bool adminExists = false;
                    List<JMMUser> users = repUsers.GetAll();
                    foreach (JMMUser userOld in users)
                    {
                        if (userOld.IsAdmin == 1)
                        {
                            if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true;
                        }
                    }

                    if (!adminExists) return "At least one user must be an administrator";
                }

                repUsers.Delete(userID);

                // delete all user records
                AnimeSeries_UserRepository repSeries = new AnimeSeries_UserRepository();
                foreach (AnimeSeries_User ser in repSeries.GetByUserID(userID))
                    repSeries.Delete(ser.AnimeSeries_UserID);

                AnimeGroup_UserRepository repGroup = new AnimeGroup_UserRepository();
                foreach (AnimeGroup_User grp in repGroup.GetByUserID(userID))
                    repGroup.Delete(grp.AnimeGroup_UserID);

                AnimeEpisode_UserRepository repEpisode = new AnimeEpisode_UserRepository();
                foreach (AnimeEpisode_User ep in repEpisode.GetByUserID(userID))
                    repEpisode.Delete(ep.AnimeEpisode_UserID);

                VideoLocal_UserRepository repVids = new VideoLocal_UserRepository();
                foreach (VideoLocal_User vid in repVids.GetByUserID(userID))
                    repVids.Delete(vid.VideoLocal_UserID);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }

            return "";
        }
コード例 #25
0
        public List<Contract_AnimeEpisode> GetEpisodesRecentlyWatched(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                    AnimeEpisode_UserRepository repEpUser = new AnimeEpisode_UserRepository();
                    JMMUserRepository repUsers = new JMMUserRepository();

                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return retEps;

                    // get a list of series that is applicable
                    List<AnimeEpisode_User> allEpUserRecs = repEpUser.GetMostRecentlyWatched(session, jmmuserID);
                    foreach (AnimeEpisode_User userRecord in allEpUserRecs)
                    {
                        AnimeEpisode ep = repEps.GetByID(session, userRecord.AnimeEpisodeID);
                        if (ep == null) continue;

                        Contract_AnimeEpisode epContract = ep.ToContract(session, jmmuserID);
                        if (epContract != null)
                        {
                            retEps.Add(epContract);

                            // Lets only return the specified amount
                            if (retEps.Count == maxRecords) return retEps;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retEps;
        }
コード例 #26
0
        public static void SyncCollectionToTrakt()
        {
            try
            {
                if (!ServerSettings.Trakt_IsEnabled || string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) return;

                // check that we have at least one user nominated for Trakt
                JMMUserRepository repUsers = new JMMUserRepository();
                List<JMMUser> traktUsers = repUsers.GetTraktUsers();
                if (traktUsers.Count == 0) return;

                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                List<AnimeSeries> allSeries = repSeries.GetAll();

                // now get the full users collection from Trakt
                List<TraktV2ShowCollectedResult> collected = new List<TraktV2ShowCollectedResult>();
                List<TraktV2ShowWatchedResult> watched = new List<TraktV2ShowWatchedResult>();

                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                TraktV2SyncCollectionEpisodesByNumber syncCollectionAdd = new TraktV2SyncCollectionEpisodesByNumber();
                TraktV2SyncCollectionEpisodesByNumber syncCollectionRemove = new TraktV2SyncCollectionEpisodesByNumber();
                TraktV2SyncWatchedEpisodesByNumber syncHistoryAdd = new TraktV2SyncWatchedEpisodesByNumber();
                TraktV2SyncWatchedEpisodesByNumber syncHistoryRemove = new TraktV2SyncWatchedEpisodesByNumber();

                #region Local Collection Sync

                ///////////////////////////////////////////////////////////////////////////////////////
                // First take a look at our local collection and update on Trakt
                ///////////////////////////////////////////////////////////////////////////////////////

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                int counter = 0;
                foreach (AnimeSeries series in allSeries)
                {
                    counter++;
                    logger.Trace("Syncing check -  local collection: {0} / {1} - {2}", counter, allSeries.Count, series.GetSeriesName());

                    AniDB_Anime anime = repAnime.GetByAnimeID(series.AniDB_ID);
                    if (anime == null) continue;

                    //if (anime.AnimeID != 3427) continue;

                    TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                    traktSummary.Populate(series.AniDB_ID);
                    if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                    // get the current watched records for this series on Trakt

                    foreach (AnimeEpisode ep in series.GetAnimeEpisodes())
                    {
                        if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                        {
                            EpisodeSyncDetails epsync = ReconSyncTraktEpisode(series, ep, traktSummary, traktUsers, collected, watched, false);
                            if (epsync != null)
                            {
                                switch (epsync.SyncType)
                                {
                                    case TraktSyncType.CollectionAdd:
                                        syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.CollectionRemove:
                                        syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.HistoryAdd:
                                        syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                    case TraktSyncType.HistoryRemove:
                                        syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                }
                            }
                        }
                    }
                }
                #endregion

                // refresh online info, just in case it was chnaged by the last operations
                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                #region Online Collection Sync
                ///////////////////////////////////////////////////////////////////////////////////////
                // Now look at the collection according to Trakt, and remove it if we don't have it locally
                ///////////////////////////////////////////////////////////////////////////////////////

                CrossRef_AniDB_TraktV2Repository repCrossRef = new CrossRef_AniDB_TraktV2Repository();

                counter = 0;
                foreach (TraktV2ShowCollectedResult col in collected)
                {
                    counter++;
                    logger.Trace("Syncing check - Online collection: {0} / {1} - {2}", counter, collected.Count, col.show.Title);
                    //continue;

                    // check if we have this series locally
                    List<CrossRef_AniDB_TraktV2> xrefs = repCrossRef.GetByTraktID(col.show.ids.slug);

                    if (xrefs.Count > 0)
                    {
                        foreach (CrossRef_AniDB_TraktV2 xref in xrefs)
                        {
                            AnimeSeries locSeries = repSeries.GetByAnimeID(xref.AnimeID);
                            if (locSeries == null) continue;

                            TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                            traktSummary.Populate(locSeries.AniDB_ID);
                            if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                            // if we have this series locSeries, let's sync the whole series
                            foreach (AnimeEpisode ep in locSeries.GetAnimeEpisodes())
                            {
                                if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                                {
                                    EpisodeSyncDetails epsync = ReconSyncTraktEpisode(locSeries, ep, traktSummary, traktUsers, collected, watched, false);
                                    if (epsync != null)
                                    {
                                        switch (epsync.SyncType)
                                        {
                                            case TraktSyncType.CollectionAdd:
                                                syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.CollectionRemove:
                                                syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryAdd:
                                                syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryRemove:
                                                syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                    else
                    {
                        // Actually we can't do this, because the user may have other non Anime series and Movies
                        /*
                        // series doesn't exist locally at all, so let's completely remove it from Trakt
                        foreach (TraktV2CollectedSeason colSeason in col.seasons)
                        {
                            foreach (TraktV2CollectedEpisode colEp in colSeason.episodes)
                            {
                                string msg = string.Format("SYNC ONLINE: Removing from Trakt Collection:  Slug: {0} - S:{1} - EP:{2}", col.show.ids.slug, colSeason.number, colEp.number);
                                logger.Trace(msg);

                                SyncEpisodeToTrakt(TraktSyncType.CollectionRemove, col.show.ids.slug, colSeason.number, colEp.number, DateTime.Now, false);
                            }
                        }*/
                    }

                }

                #endregion

                // refresh online info, just in case it was chnaged by the last operations
                if (!GetTraktCollectionInfo(ref collected, ref watched)) return;

                #region Online History (Watched/Unwatched) Sync
                ///////////////////////////////////////////////////////////////////////////////////////
                // Now look at the history according to Trakt, and remove it if we don't have it locally
                ///////////////////////////////////////////////////////////////////////////////////////

                counter = 0;

                foreach (TraktV2ShowWatchedResult wtch in watched)
                {
                    counter++;
                    logger.Trace("Syncing check - Online History: {0} / {1} - {2}", counter, watched.Count, wtch.show.Title);
                    //continue;

                    // check if we have this series locally
                    List<CrossRef_AniDB_TraktV2> xrefs = repCrossRef.GetByTraktID(wtch.show.ids.slug);

                    if (xrefs.Count > 0)
                    {
                        foreach (CrossRef_AniDB_TraktV2 xref in xrefs)
                        {
                            AnimeSeries locSeries = repSeries.GetByAnimeID(xref.AnimeID);
                            if (locSeries == null) continue;

                            TraktSummaryContainer traktSummary = new TraktSummaryContainer();
                            traktSummary.Populate(locSeries.AniDB_ID);
                            if (traktSummary.CrossRefTraktV2 == null || traktSummary.CrossRefTraktV2.Count == 0) continue;

                            // if we have this series locSeries, let's sync the whole series
                            foreach (AnimeEpisode ep in locSeries.GetAnimeEpisodes())
                            {
                                if (ep.EpisodeTypeEnum == enEpisodeType.Episode || ep.EpisodeTypeEnum == enEpisodeType.Special)
                                {
                                    EpisodeSyncDetails epsync = ReconSyncTraktEpisode(locSeries, ep, traktSummary, traktUsers, collected, watched, false);
                                    if (epsync != null)
                                    {
                                        switch (epsync.SyncType)
                                        {
                                            case TraktSyncType.CollectionAdd:
                                                syncCollectionAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.CollectionRemove:
                                                syncCollectionRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryAdd:
                                                syncHistoryAdd.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                            case TraktSyncType.HistoryRemove:
                                                syncHistoryRemove.AddEpisode(epsync.Slug, epsync.Season, epsync.EpNumber, epsync.EpDate); break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                    else
                    {
                        // Actually we can't do this, because the user may have other non Anime series and Movies
                        /*
                        // series doesn't exist locally at all, so let's completely remove it from Trakt
                        foreach (TraktV2WatchedSeason wtchSeason in wtch.seasons)
                        {
                            foreach (TraktV2WatchedEpisode wtchEp in wtchSeason.episodes)
                            {
                                string msg = string.Format("SYNC ONLINE: Removing from Trakt History:  Slug: {0} - S:{1} - EP:{2}", wtch.show.ids.slug, wtchSeason.number, wtchEp.number);
                                logger.Trace(msg);

                                SyncEpisodeToTrakt(TraktSyncType.HistoryRemove, wtch.show.ids.slug, wtchSeason.number, wtchEp.number, DateTime.Now, false);
                            }
                        }*/
                    }

                }

                #endregion

                // send the data to Trakt
                string json = string.Empty;
                string url = TraktURIs.SyncCollectionAdd;
                string retData = string.Empty;

                if (syncCollectionAdd.shows != null && syncCollectionAdd.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodesByNumber>(syncCollectionAdd);
                    url = TraktURIs.SyncCollectionAdd;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncCollectionRemove.shows != null && syncCollectionRemove.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncCollectionEpisodesByNumber>(syncCollectionRemove);
                    url = TraktURIs.SyncCollectionRemove;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncHistoryAdd.shows != null && syncHistoryAdd.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncWatchedEpisodesByNumber>(syncHistoryAdd);
                    url = TraktURIs.SyncHistoryAdd;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                if (syncHistoryRemove.shows != null && syncHistoryRemove.shows.Count > 0)
                {
                    json = JSONHelper.Serialize<TraktV2SyncWatchedEpisodesByNumber>(syncHistoryRemove);
                    url = TraktURIs.SyncHistoryRemove;
                    retData = string.Empty;
                    SendData(url, json, "POST", BuildRequestHeaders(), ref retData);
                }

                logger.Trace("Test");

            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.SyncCollectionToTrakt: " + ex.ToString(), ex);
            }
        }
コード例 #27
0
        /// <summary>
        /// Gets a list of episodes watched based on the most recently watched series
        /// It will return the next episode to watch in the most recent 10 series
        /// </summary>
        /// <returns></returns>
        public List<Contract_AnimeEpisode> GetEpisodesToWatch_RecentlyWatched(int maxRecords, int jmmuserID)
        {
            List<Contract_AnimeEpisode> retEps = new List<Contract_AnimeEpisode>();
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                    AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository();
                    AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                    JMMUserRepository repUsers = new JMMUserRepository();

                    DateTime start = DateTime.Now;

                    JMMUser user = repUsers.GetByID(session, jmmuserID);
                    if (user == null) return retEps;

                    // get a list of series that is applicable
                    List<AnimeSeries_User> allSeriesUser = repSeriesUser.GetMostRecentlyWatched(session, jmmuserID);

                    TimeSpan ts = DateTime.Now - start;
                    logger.Info(string.Format("GetEpisodesToWatch_RecentlyWatched:Series: {0}", ts.TotalMilliseconds));
                    start = DateTime.Now;

                    foreach (AnimeSeries_User userRecord in allSeriesUser)
                    {
                        AnimeSeries series = repAnimeSer.GetByID(session, userRecord.AnimeSeriesID);
                        if (series == null) continue;

                        if (!user.AllowedSeries(series)) continue;

                        Contract_AnimeEpisode ep = GetNextUnwatchedEpisode(session, userRecord.AnimeSeriesID, jmmuserID);
                        if (ep != null)
                        {
                            retEps.Add(ep);

                            // Lets only return the specified amount
                            if (retEps.Count == maxRecords)
                            {
                                ts = DateTime.Now - start;
                                logger.Info(string.Format("GetEpisodesToWatch_RecentlyWatched:Episodes: {0}", ts.TotalMilliseconds));
                                return retEps;
                            }
                        }
                    }
                    ts = DateTime.Now - start;
                    logger.Info(string.Format("GetEpisodesToWatch_RecentlyWatched:Episodes: {0}", ts.TotalMilliseconds));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retEps;
        }
コード例 #28
0
        private static DateTime GetEpisodeDateForSync(AnimeEpisode ep, TraktSyncType syncType)
        {
            DateTime epDate = DateTime.Now;

            if (syncType == TraktSyncType.CollectionAdd || syncType == TraktSyncType.CollectionRemove)
            {
                epDate = DateTime.Now; // not relevant for a remove
                if (syncType == TraktSyncType.CollectionAdd)
                {
                    // get the the first file that was added to this episode
                    DateTime? thisDate = null;
                    foreach (VideoLocal vid in ep.GetVideoLocals())
                    {
                        if (!thisDate.HasValue)
                            thisDate = vid.DateTimeCreated;

                        if (vid.DateTimeCreated < thisDate)
                            thisDate = vid.DateTimeCreated;
                    }
                    if (thisDate.HasValue)
                        epDate = thisDate.Value;
                }
            }
            else
            {
                epDate = DateTime.Now; // not relevant for a remove
                if (syncType == TraktSyncType.HistoryAdd)
                {
                    // get the latest user record and find the latest date this episode was watched
                    DateTime? thisDate = null;
                    JMMUserRepository repUsers = new JMMUserRepository();
                    List<JMMUser> traktUsers = repUsers.GetTraktUsers();
                    if (traktUsers.Count > 0)
                    {
                        AnimeEpisode_User userRecord = null;
                        foreach (JMMUser juser in traktUsers)
                        {
                            userRecord = ep.GetUserRecord(juser.JMMUserID);
                            if (userRecord != null)
                            {
                                if (!thisDate.HasValue && userRecord.WatchedDate.HasValue)
                                    thisDate = userRecord.WatchedDate;
                                if (userRecord.WatchedDate.HasValue && thisDate.HasValue && userRecord.WatchedDate > thisDate)
                                    thisDate = userRecord.WatchedDate;

                            }
                        }
                        if (thisDate.HasValue)
                            epDate = thisDate.Value;
                    }
                }
            }

            return epDate;
        }
コード例 #29
0
        public Contract_GroupFilterExtended GetGroupFilterExtended(int groupFilterID, int userID)
        {
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    GroupFilterRepository repGF = new GroupFilterRepository();
                    GroupFilter gf = repGF.GetByID(session, groupFilterID);
                    if (gf == null) return null;

                    JMMUserRepository repUsers = new JMMUserRepository();
                    JMMUser user = repUsers.GetByID(session, userID);
                    if (user == null) return null;

                    Contract_GroupFilterExtended contract = gf.ToContractExtended(session, user);

                    return contract;
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return null;
        }
コード例 #30
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MALDownloadStatusFromMAL");

            try
            {
                if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password))
                    return;

                // find the latest eps to update
                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

                myanimelist mal = MALHelper.GetMALAnimeList();
                if (mal == null) return;
                if (mal.anime == null) return;

                CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();
                AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository();
                AnimeEpisodeRepository repEp = new AnimeEpisodeRepository();

                // find the anidb user
                JMMUserRepository repUsers = new JMMUserRepository();
                List<JMMUser> aniDBUsers = repUsers.GetAniDBUsers();
                if (aniDBUsers.Count == 0) return;

                JMMUser user = aniDBUsers[0];

                foreach (myanimelistAnime malAnime in mal.anime)
                {
                    // look up the anime
                    CrossRef_AniDB_MAL xref = repCrossRef.GetByMALID(malAnime.series_animedb_id);
                    if (xref == null) continue;

                    if (malAnime.series_animedb_id == 8107 || malAnime.series_animedb_id == 10737)
                    {
                        Console.Write("");
                    }

                    // check if this anime has any other links
                    List<CrossRef_AniDB_MAL> allXrefs = repCrossRef.GetByAnimeID(xref.AnimeID);
                    if (allXrefs.Count == 0) continue;

                    // find the range of watched episodes that this applies to
                    int startEpNumber = xref.StartEpisodeNumber;
                    int endEpNumber = GetUpperEpisodeLimit(allXrefs, xref);

                    List<AniDB_Episode> aniEps = repAniEps.GetByAnimeID(xref.AnimeID);
                    foreach (AniDB_Episode aniep in aniEps)
                    {
                        if (aniep.EpisodeType != xref.StartEpisodeType) continue;

                        AnimeEpisode ep = repEp.GetByAniDBEpisodeID(aniep.EpisodeID);
                        if (ep == null) continue;

                        int adjustedWatchedEps = malAnime.my_watched_episodes + xref.StartEpisodeNumber - 1;
                        int epNum = aniep.EpisodeNumber;

                        if (epNum < startEpNumber || epNum > endEpNumber) continue;

                        AnimeEpisode_User usrRec = ep.GetUserRecord(user.JMMUserID);

                        if (epNum <= adjustedWatchedEps)
                        {
                            // update if the user doesn't have a record (means not watched)
                            // or it is currently un-watched
                            bool update = false;
                            if (usrRec == null) update = true;
                            else
                            {
                                if (!usrRec.WatchedDate.HasValue) update = true;
                            }

                            if (update) ep.ToggleWatchedStatus(true, true, DateTime.Now, user.JMMUserID, false);
                        }
                        else
                        {
                            bool update = false;
                            if (usrRec != null)
                            {
                                if (usrRec.WatchedDate.HasValue) update = true;
                            }

                            if (update) ep.ToggleWatchedStatus(false, true, DateTime.Now, user.JMMUserID, false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_MALDownloadStatusFromMAL: {0}", ex.ToString());
                return;
            }
        }
コード例 #31
0
        public List<Contract_IgnoreAnime> GetIgnoredAnime(int userID)
        {
            List<Contract_IgnoreAnime> retAnime = new List<Contract_IgnoreAnime>();
            try
            {
                JMMUserRepository repUser = new JMMUserRepository();
                JMMUser user = repUser.GetByID(userID);
                if (user == null) return retAnime;

                IgnoreAnimeRepository repIgnore = new IgnoreAnimeRepository();
                List<IgnoreAnime> ignoredAnime = repIgnore.GetByUser(userID);
                foreach (IgnoreAnime ign in ignoredAnime)
                    retAnime.Add(ign.ToContract());

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return retAnime;
        }