예제 #1
0
        public static void SetTvDBInfo(int anidbid, AniDB_Episode ep, ref MetroContract_Anime_Episode contract)
        {
            TvDBSummary tvSummary = new TvDBSummary();
            tvSummary.Populate(anidbid);

            SetTvDBInfo(tvSummary, ep, ref contract);
        }
예제 #2
0
        public Contract_AnimeEpisode ToContract(AniDB_Episode aniEp, List <VideoLocal> epVids, AnimeEpisode_User epuser, AnimeSeries_User seruser)
        {
            Contract_AnimeEpisode contract = new Contract_AnimeEpisode();

            contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
            contract.AnimeEpisodeID  = this.AnimeEpisodeID;
            contract.AnimeSeriesID   = this.AnimeSeriesID;
            contract.DateTimeUpdated = this.DateTimeUpdated;

            if (epuser == null)
            {
                contract.IsWatched    = 0;
                contract.PlayedCount  = 0;
                contract.StoppedCount = 0;
                contract.WatchedCount = 0;
                contract.WatchedDate  = null;
            }
            else
            {
                contract.IsWatched    = epuser.WatchedCount > 0 ? 1 : 0;
                contract.PlayedCount  = epuser.PlayedCount;
                contract.StoppedCount = epuser.StoppedCount;
                contract.WatchedCount = epuser.WatchedCount;
                contract.WatchedDate  = epuser.WatchedDate;
            }

            if (seruser == null)
            {
                contract.UnwatchedEpCountSeries = 0;
            }
            else
            {
                contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;
            }

            contract.AniDB_AirDate       = aniEp.AirDateAsDate;
            contract.AniDB_EnglishName   = aniEp.EnglishName;
            contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
            contract.AniDB_Rating        = aniEp.Rating;
            contract.AniDB_RomajiName    = aniEp.RomajiName;
            contract.AniDB_Votes         = aniEp.Votes;

            contract.EpisodeNumber      = aniEp.EpisodeNumber;
            contract.EpisodeNameRomaji  = aniEp.RomajiName;
            contract.EpisodeNameEnglish = aniEp.EnglishName;
            contract.EpisodeType        = aniEp.EpisodeType;


            // find the number of files we actually have for this episode
            //contract.LocalFileCount = VideoLocals.Count;
            contract.LocalFileCount = epVids.Count;

            contract.ReleaseGroups = new List <Contract_AniDBReleaseGroup>();



            return(contract);
        }
예제 #3
0
		public Contract_AnimeEpisode ToContract(ISession session, bool getFileCount, int userID, AnimeSeries_User seruser)
		{
			Contract_AnimeEpisode contract = new Contract_AnimeEpisode();
			contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
			contract.AnimeEpisodeID = this.AnimeEpisodeID;
			contract.AnimeSeriesID = this.AnimeSeriesID;
			contract.DateTimeUpdated = this.DateTimeUpdated;

			AnimeEpisode_User epuser = this.GetUserRecord(session, userID);

			if (epuser == null)
			{
				contract.IsWatched = 0;
				contract.PlayedCount = 0;
				contract.StoppedCount = 0;
				contract.WatchedCount = 0;
				contract.WatchedDate = null;
			}
			else
			{
				contract.IsWatched = epuser.WatchedCount > 0 ? 1 : 0;
				contract.PlayedCount = epuser.PlayedCount;
				contract.StoppedCount = epuser.StoppedCount;
				contract.WatchedCount = epuser.WatchedCount;
				contract.WatchedDate = epuser.WatchedDate;
			}

			if (seruser == null)
				contract.UnwatchedEpCountSeries = 0;
			else
				contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;

			AniDB_Episode aniEp = this.AniDB_Episode;
			contract.AniDB_AirDate = aniEp.AirDateAsDate;
			contract.AniDB_EnglishName = aniEp.EnglishName;
			contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
			contract.AniDB_Rating = aniEp.Rating;
			contract.AniDB_RomajiName = aniEp.RomajiName;
			contract.AniDB_Votes = aniEp.Votes;

			contract.EpisodeNumber = aniEp.EpisodeNumber;
			contract.EpisodeNameRomaji = aniEp.RomajiName;
			contract.EpisodeNameEnglish = aniEp.EnglishName;
			contract.EpisodeType = aniEp.EpisodeType;


			// find the number of files we actually have for this episode
			if (getFileCount)
				contract.LocalFileCount = this.GetVideoLocals(session).Count;

			contract.ReleaseGroups = new List<Contract_AniDBReleaseGroup>();



			return contract;
		}
예제 #4
0
		public void Save(AniDB_Episode obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
예제 #5
0
        public Contract_AnimeEpisode ToContractOld(AniDB_Episode aniEp)
        {
            Contract_AnimeEpisode contract = new Contract_AnimeEpisode();

            contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
            contract.AnimeEpisodeID  = this.AnimeEpisodeID;
            contract.AnimeSeriesID   = this.AnimeSeriesID;
            contract.DateTimeUpdated = this.DateTimeUpdated;
            //contract.IsWatched = this.IsWatched;
            //contract.PlayedCount = this.PlayedCount;
            //contract.StoppedCount = this.StoppedCount;
            //contract.WatchedCount = this.WatchedCount;
            //contract.WatchedDate = this.WatchedDate;



            contract.AniDB_AirDate       = aniEp.AirDateAsDate;
            contract.AniDB_EnglishName   = aniEp.EnglishName;
            contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
            contract.AniDB_Rating        = aniEp.Rating;
            contract.AniDB_RomajiName    = aniEp.RomajiName;
            contract.AniDB_Votes         = aniEp.Votes;

            contract.EpisodeNumber      = aniEp.EpisodeNumber;
            contract.EpisodeNameRomaji  = aniEp.RomajiName;
            contract.EpisodeNameEnglish = aniEp.EnglishName;
            contract.EpisodeType        = aniEp.EpisodeType;


            // find the number of files we actually have for this episode
            contract.LocalFileCount = GetVideoLocals().Count;

            contract.ReleaseGroups = new List <Contract_AniDBReleaseGroup>();



            return(contract);
        }
예제 #6
0
        private static int? GetTraktEpisodeIdV2(TraktSummaryContainer traktSummary, AniDB_Anime anime, AniDB_Episode ep, ref string traktID, ref int season, ref int epNumber)
        {
            try
            {
                int? traktEpId = null;

                #region normal episodes
                // now do stuff to improve performance
                if (ep.EpisodeTypeEnum == enEpisodeType.Episode)
                {
                    if (traktSummary != null && traktSummary.CrossRefTraktV2 != null && traktSummary.CrossRefTraktV2.Count > 0)
                    {
                        // find the xref that is right
                        // relies on the xref's being sorted by season number and then episode number (desc)
                        List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                        sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                        List<CrossRef_AniDB_TraktV2> traktCrossRef = Sorting.MultiSort<CrossRef_AniDB_TraktV2>(traktSummary.CrossRefTraktV2, sortCriteria);

                        bool foundStartingPoint = false;
                        CrossRef_AniDB_TraktV2 xrefBase = null;
                        foreach (CrossRef_AniDB_TraktV2 xrefTrakt in traktCrossRef)
                        {
                            if (xrefTrakt.AniDBStartEpisodeType != (int)enEpisodeType.Episode) continue;
                            if (ep.EpisodeNumber >= xrefTrakt.AniDBStartEpisodeNumber)
                            {
                                foundStartingPoint = true;
                                xrefBase = xrefTrakt;
                                break;
                            }
                        }

                        // we have found the starting epiosde numbder from AniDB
                        // now let's check that the Trakt Season and Episode Number exist
                        if (foundStartingPoint)
                        {

                            Dictionary<int, int> dictTraktSeasons = null;
                            Dictionary<int, Trakt_Episode> dictTraktEpisodes = null;
                            foreach (TraktDetailsContainer det in traktSummary.TraktDetails.Values)
                            {
                                if (det.TraktID == xrefBase.TraktID)
                                {
                                    dictTraktSeasons = det.DictTraktSeasons;
                                    dictTraktEpisodes = det.DictTraktEpisodes;
                                    break;
                                }
                            }

                            if (dictTraktSeasons.ContainsKey(xrefBase.TraktSeasonNumber))
                            {
                                int episodeNumber = dictTraktSeasons[xrefBase.TraktSeasonNumber] + (ep.EpisodeNumber + xrefBase.TraktStartEpisodeNumber - 2) -
                                    (xrefBase.AniDBStartEpisodeNumber - 1);
                                if (dictTraktEpisodes.ContainsKey(episodeNumber))
                                {
                                    Trakt_Episode traktep = dictTraktEpisodes[episodeNumber];
                                    traktID = xrefBase.TraktID;
                                    season = traktep.Season;
                                    epNumber = traktep.EpisodeNumber;
                                    traktEpId = traktep.TraktID;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region special episodes
                if (ep.EpisodeTypeEnum == enEpisodeType.Special)
                {
                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                    List<CrossRef_AniDB_TraktV2> traktCrossRef = Sorting.MultiSort<CrossRef_AniDB_TraktV2>(traktSummary.CrossRefTraktV2, sortCriteria);

                    bool foundStartingPoint = false;
                    CrossRef_AniDB_TraktV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TraktV2 xrefTrakt in traktCrossRef)
                    {
                        if (xrefTrakt.AniDBStartEpisodeType != (int)enEpisodeType.Special) continue;
                        if (ep.EpisodeNumber >= xrefTrakt.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase = xrefTrakt;
                            break;
                        }
                    }

                    if (traktSummary != null && traktSummary.CrossRefTraktV2 != null && traktSummary.CrossRefTraktV2.Count > 0)
                    {
                        // we have found the starting epiosde numbder from AniDB
                        // now let's check that the Trakt Season and Episode Number exist
                        if (foundStartingPoint)
                        {

                            Dictionary<int, int> dictTraktSeasons = null;
                            Dictionary<int, Trakt_Episode> dictTraktEpisodes = null;
                            foreach (TraktDetailsContainer det in traktSummary.TraktDetails.Values)
                            {
                                if (det.TraktID == xrefBase.TraktID)
                                {
                                    dictTraktSeasons = det.DictTraktSeasons;
                                    dictTraktEpisodes = det.DictTraktEpisodes;
                                    break;
                                }
                            }

                            if (dictTraktSeasons.ContainsKey(xrefBase.TraktSeasonNumber))
                            {
                                int episodeNumber = dictTraktSeasons[xrefBase.TraktSeasonNumber] + (ep.EpisodeNumber + xrefBase.TraktStartEpisodeNumber - 2) -
                                    (xrefBase.AniDBStartEpisodeNumber - 1);
                                if (dictTraktEpisodes.ContainsKey(episodeNumber))
                                {
                                    Trakt_Episode traktep = dictTraktEpisodes[episodeNumber];
                                    traktID = xrefBase.TraktID;
                                    season = traktep.Season;
                                    epNumber = traktep.EpisodeNumber;
                                    traktEpId = traktep.TraktID;
                                }
                            }
                        }
                    }
                }
                #endregion

                return traktEpId;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return null;
            }
        }
예제 #7
0
        private static int? GetTraktEpisodeIdV2(AniDB_Anime anime, AniDB_Episode ep, ref string traktID, ref int season, ref int epNumber)
        {
            TraktSummaryContainer traktSummary = new TraktSummaryContainer();
            traktSummary.Populate(anime.AnimeID);

            return GetTraktEpisodeIdV2(traktSummary, anime, ep, ref traktID, ref season, ref epNumber);
        }
예제 #8
0
 public void Populate(AniDB_Episode anidbEp)
 {
     this.AniDB_EpisodeID = anidbEp.EpisodeID;
     this.DateTimeUpdated = DateTime.Now;
     this.DateTimeCreated = DateTime.Now;
 }
        public static void SetTvDBInfo(TvDBSummary tvSummary,	AniDB_Episode ep, ref MetroContract_Anime_Episode contract)
		{
            #region episode override
            // check if this episode has a direct tvdb over-ride
            if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(ep.EpisodeID))
            {
                foreach (TvDB_Episode tvep in tvSummary.DictTvDBEpisodes.Values)
                {
                    if (tvSummary.DictTvDBCrossRefEpisodes[ep.EpisodeID] == tvep.Id)
                    {
                        if (string.IsNullOrEmpty(tvep.Overview))
                            contract.EpisodeOverview = "Episode Overview Not Available";
                        else
                            contract.EpisodeOverview = tvep.Overview;

                        if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                        {
                            contract.ImageType = 0;
                            contract.ImageID = 0;
                        }
                        else
                        {
                            contract.ImageType = (int)JMMImageType.TvDB_Episode;
                            contract.ImageID = tvep.TvDB_EpisodeID;
                        }

                        if (ServerSettings.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                            contract.EpisodeName = tvep.EpisodeName;

                        return;
                    }
                }
            }
            #endregion

            #region normal episodes
            // now do stuff to improve performance
            if (ep.EpisodeTypeEnum == enEpisodeType.Episode)
            {
                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // find the xref that is right
                    // relies on the xref's being sorted by season number and then episode number (desc)
                    List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                    List<CrossRef_AniDB_TvDBV2> tvDBCrossRef = Sorting.MultiSort<CrossRef_AniDB_TvDBV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                    bool foundStartingPoint = false;
                    CrossRef_AniDB_TvDBV2 xrefBase = null;
                    foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef)
                    {
                        if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Episode) continue;
                        if (ep.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                        {
                            foundStartingPoint = true;
                            xrefBase = xrefTV;
                            break;
                        }
                    }

                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {

                        Dictionary<int, int> dictTvDBSeasons = null;
                        Dictionary<int, TvDB_Episode> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (ep.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {

                                TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber];
                                if (string.IsNullOrEmpty(tvep.Overview))
                                    contract.EpisodeOverview = "Episode Overview Not Available";
                                else
                                    contract.EpisodeOverview = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    contract.ImageType = 0;
                                    contract.ImageID = 0;
                                }
                                else
                                {
                                    contract.ImageType = (int)JMMImageType.TvDB_Episode;
                                    contract.ImageID = tvep.TvDB_EpisodeID;
                                }

                                if (ServerSettings.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    contract.EpisodeName = tvep.EpisodeName;
                            }
                        }
                    }
                }
            }
            #endregion

            #region special episodes
            if (ep.EpisodeTypeEnum == enEpisodeType.Special)
            {
                // find the xref that is right
                // relies on the xref's being sorted by season number and then episode number (desc)
                List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                sortCriteria.Add(new SortPropOrFieldAndDirection("AniDBStartEpisodeNumber", true, SortType.eInteger));
                List<CrossRef_AniDB_TvDBV2> tvDBCrossRef = Sorting.MultiSort<CrossRef_AniDB_TvDBV2>(tvSummary.CrossRefTvDBV2, sortCriteria);

                bool foundStartingPoint = false;
                CrossRef_AniDB_TvDBV2 xrefBase = null;
                foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef)
                {
                    if (xrefTV.AniDBStartEpisodeType != (int)enEpisodeType.Special) continue;
                    if (ep.EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber)
                    {
                        foundStartingPoint = true;
                        xrefBase = xrefTV;
                        break;
                    }
                }

                if (tvSummary != null && tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0)
                {
                    // we have found the starting epiosde numbder from AniDB
                    // now let's check that the TvDB Season and Episode Number exist
                    if (foundStartingPoint)
                    {

                        Dictionary<int, int> dictTvDBSeasons = null;
                        Dictionary<int, TvDB_Episode> dictTvDBEpisodes = null;
                        foreach (TvDBDetails det in tvSummary.TvDetails.Values)
                        {
                            if (det.TvDBID == xrefBase.TvDBID)
                            {
                                dictTvDBSeasons = det.DictTvDBSeasons;
                                dictTvDBEpisodes = det.DictTvDBEpisodes;
                                break;
                            }
                        }

                        if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber))
                        {
                            int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (ep.EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1);
                            if (dictTvDBEpisodes.ContainsKey(episodeNumber))
                            {
                                TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber];
                                contract.EpisodeOverview = tvep.Overview;

                                if (string.IsNullOrEmpty(tvep.FullImagePath) || !File.Exists(tvep.FullImagePath))
                                {
                                    contract.ImageType = 0;
                                    contract.ImageID = 0;
                                }
                                else
                                {
                                    contract.ImageType = (int)JMMImageType.TvDB_Episode;
                                    contract.ImageID = tvep.TvDB_EpisodeID;
                                }

                                if (ServerSettings.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName))
                                    contract.EpisodeName = tvep.EpisodeName;
                            }
                        }
                    }
                }
            }
            #endregion




		}
예제 #10
0
        public void UpdateStats(bool watchedStats, bool missingEpsStats, bool updateAllGroupsAbove)
        {
            DateTime start        = DateTime.Now;
            DateTime startOverall = DateTime.Now;

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

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

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

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

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

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

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

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

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

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

            TimeSpan tsVids = DateTime.Now - startVids;

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


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

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

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

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

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

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

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

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

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

            TimeSpan ts = DateTime.Now - start;

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



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

                MissingEpisodeCount       = 0;
                MissingEpisodeCountGroups = 0;

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

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

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

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

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

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

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



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

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

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


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

                this.LatestLocalEpisodeNumber = latestLocalEpNumber;
            }

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

            AnimeSeriesRepository rep = new AnimeSeriesRepository();

            rep.Save(this);

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

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

            TimeSpan tsOverall = DateTime.Now - startOverall;

            logger.Info("Finished Updating STATS for SERIES {0} in {1}ms ({2} - {3} - {4})", this.ToString(), tsOverall.TotalMilliseconds,
                        watchedStats, missingEpsStats, updateAllGroupsAbove);
        }
예제 #11
0
            public void Add(AnimeEpisode ep, bool available)
            {
                if ((AnimeType == enAnimeType.OVA) || (AnimeType == enAnimeType.Movie))
                {
                    AniDB_Episode aniEp = ep.AniDB_Episode;
                    string        ename = aniEp.EnglishName.ToLower();
                    System.Text.RegularExpressions.Match m = partmatch.Match(ename);
                    StatEpisodes.StatEpisode             s = new StatEpisodes.StatEpisode();
                    s.Available = available;
                    if (m.Success)
                    {
                        int part_number = 0;
                        int part_count  = 0;
                        int.TryParse(m.Groups[1].Value, out part_number);
                        int.TryParse(m.Groups[2].Value, out part_count);
                        string rname = partmatch.Replace(ename, string.Empty);
                        rname = remsymbols.Replace(rname, string.Empty);
                        rname = remmultispace.Replace(rname, " ");


                        s.EpisodeType = StatEpisodes.StatEpisode.EpType.Part;
                        s.PartCount   = part_count;
                        s.Match       = rname.Trim();
                        if ((s.Match == "complete movie") || (s.Match == "movie") || (s.Match == "ova"))
                        {
                            s.Match = string.Empty;
                        }
                    }
                    else
                    {
                        if ((ename == "complete movie") || (ename == "movie") || (ename == "ova"))
                        {
                            s.Match = string.Empty;
                        }
                        else
                        {
                            string rname = partmatch.Replace(aniEp.EnglishName.ToLower(), string.Empty);
                            rname   = remsymbols.Replace(rname, string.Empty);
                            rname   = remmultispace.Replace(rname, " ");
                            s.Match = rname.Trim();
                        }
                        s.EpisodeType = StatEpisodes.StatEpisode.EpType.Complete;
                        s.PartCount   = 0;
                    }
                    StatEpisodes fnd = null;
                    foreach (StatEpisodes k in this)
                    {
                        foreach (StatEpisodes.StatEpisode ss in k)
                        {
                            if (ss.Match == s.Match)
                            {
                                fnd = k;
                                break;
                            }
                        }
                        if (fnd != null)
                        {
                            break;
                        }
                    }
                    if (fnd == null)
                    {
                        StatEpisodes eps = new StatEpisodes();
                        eps.Add(s);
                        Add(eps);
                    }
                    else
                    {
                        fnd.Add(s);
                    }
                }
                else
                {
                    StatEpisodes             eps = new StatEpisodes();
                    StatEpisodes.StatEpisode es  = new StatEpisodes.StatEpisode();
                    es.Match       = string.Empty;
                    es.EpisodeType = StatEpisodes.StatEpisode.EpType.Complete;
                    es.PartCount   = 0;
                    es.Available   = available;
                    eps.Add(es);
                    this.Add(eps);
                }
            }
예제 #12
0
		public void Populate(AniDB_Episode anidbEp)
		{
			this.AniDB_EpisodeID = anidbEp.EpisodeID;
			this.DateTimeUpdated = DateTime.Now;
			this.DateTimeCreated = DateTime.Now;
		}
예제 #13
0
		public Contract_AnimeEpisode ToContractOld(AniDB_Episode aniEp)
		{
			Contract_AnimeEpisode contract = new Contract_AnimeEpisode();
			contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
			contract.AnimeEpisodeID = this.AnimeEpisodeID;
			contract.AnimeSeriesID = this.AnimeSeriesID;
			contract.DateTimeUpdated = this.DateTimeUpdated;
			//contract.IsWatched = this.IsWatched;
			//contract.PlayedCount = this.PlayedCount;
			//contract.StoppedCount = this.StoppedCount;
			//contract.WatchedCount = this.WatchedCount;
			//contract.WatchedDate = this.WatchedDate;



			contract.AniDB_AirDate = aniEp.AirDateAsDate;
			contract.AniDB_EnglishName = aniEp.EnglishName;
			contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
			contract.AniDB_Rating = aniEp.Rating;
			contract.AniDB_RomajiName = aniEp.RomajiName;
			contract.AniDB_Votes = aniEp.Votes;

			contract.EpisodeNumber = aniEp.EpisodeNumber;
			contract.EpisodeNameRomaji = aniEp.RomajiName;
			contract.EpisodeNameEnglish = aniEp.EnglishName;
			contract.EpisodeType = aniEp.EpisodeType;


			// find the number of files we actually have for this episode
			contract.LocalFileCount = GetVideoLocals().Count;

			contract.ReleaseGroups = new List<Contract_AniDBReleaseGroup>();



			return contract;
		}
예제 #14
0
		public Contract_AnimeEpisode ToContract(AniDB_Episode aniEp, List<VideoLocal> epVids, AnimeEpisode_User epuser, AnimeSeries_User seruser)
		{
			Contract_AnimeEpisode contract = new Contract_AnimeEpisode();
			contract.AniDB_EpisodeID = this.AniDB_EpisodeID;
			contract.AnimeEpisodeID = this.AnimeEpisodeID;
			contract.AnimeSeriesID = this.AnimeSeriesID;
			contract.DateTimeUpdated = this.DateTimeUpdated;

			if (epuser == null)
			{
				contract.IsWatched = 0;
				contract.PlayedCount = 0;
				contract.StoppedCount = 0;
				contract.WatchedCount = 0;
				contract.WatchedDate = null;
			}
			else
			{
				contract.IsWatched = epuser.WatchedCount > 0 ? 1 : 0;
				contract.PlayedCount = epuser.PlayedCount;
				contract.StoppedCount = epuser.StoppedCount;
				contract.WatchedCount = epuser.WatchedCount;
				contract.WatchedDate = epuser.WatchedDate;
			}

			if (seruser == null)
				contract.UnwatchedEpCountSeries = 0;
			else
				contract.UnwatchedEpCountSeries = seruser.UnwatchedEpisodeCount;
			
			contract.AniDB_AirDate = aniEp.AirDateAsDate;
			contract.AniDB_EnglishName = aniEp.EnglishName;
			contract.AniDB_LengthSeconds = aniEp.LengthSeconds;
			contract.AniDB_Rating = aniEp.Rating;
			contract.AniDB_RomajiName = aniEp.RomajiName;
			contract.AniDB_Votes = aniEp.Votes;

			contract.EpisodeNumber = aniEp.EpisodeNumber;
			contract.EpisodeNameRomaji = aniEp.RomajiName;
			contract.EpisodeNameEnglish = aniEp.EnglishName;
			contract.EpisodeType = aniEp.EpisodeType;


			// find the number of files we actually have for this episode
			//contract.LocalFileCount = VideoLocals.Count;
			contract.LocalFileCount = epVids.Count;

			contract.ReleaseGroups = new List<Contract_AniDBReleaseGroup>(); 



			return contract;
		}
예제 #15
0
        private void CreateEpisodes(ISession session, List<Raw_AniDB_Episode> eps)
        {
            if (eps == null) return;

            AniDB_EpisodeRepository repEps = new AniDB_EpisodeRepository();

            this.EpisodeCountSpecial = 0;
            this.EpisodeCountNormal = 0;

            List<AnimeEpisode> animeEpsToDelete = new List<AnimeEpisode>();
            List<AniDB_Episode> aniDBEpsToDelete = new List<AniDB_Episode>();

            foreach (Raw_AniDB_Episode epraw in eps)
            {
                //List<AniDB_Episode> existingEps = repEps.GetByAnimeIDAndEpisodeTypeNumber(epraw.AnimeID, (enEpisodeType)epraw.EpisodeType, epraw.EpisodeNumber);
                // we need to do this check because some times AniDB will replace an existing episode with a new episode

                var tempEps = session
                    .CreateCriteria(typeof(AniDB_Episode))
                    .Add(Restrictions.Eq("AnimeID", epraw.AnimeID))
                    .Add(Restrictions.Eq("EpisodeNumber", epraw.EpisodeNumber))
                    .Add(Restrictions.Eq("EpisodeType", epraw.EpisodeType))
                    .List<AniDB_Episode>();

                List<AniDB_Episode> existingEps = new List<AniDB_Episode>(tempEps);

                // delete any old records
                foreach (AniDB_Episode epOld in existingEps)
                {
                    if (epOld.EpisodeID != epraw.EpisodeID)
                    {
                        // first delete any AnimeEpisode records that point to the new anidb episode
                        AnimeEpisodeRepository repAnimeEps = new AnimeEpisodeRepository();
                        AnimeEpisode aniep = repAnimeEps.GetByAniDBEpisodeID(session, epOld.EpisodeID);
                        if (aniep != null)
                        {
                            //repAnimeEps.Delete(aniep.AnimeEpisodeID);
                            animeEpsToDelete.Add(aniep);
                        }

                        //repEps.Delete(epOld.AniDB_EpisodeID);
                        aniDBEpsToDelete.Add(epOld);
                    }
                }
            }
            using (var transaction = session.BeginTransaction())
            {
                foreach (AnimeEpisode ep in animeEpsToDelete)
                    session.Delete(ep);

                transaction.Commit();
            }

            using (var transaction = session.BeginTransaction())
            {
                foreach (AniDB_Episode ep in aniDBEpsToDelete)
                    session.Delete(ep);

                transaction.Commit();
            }

            List<AniDB_Episode> epsToSave = new List<AniDB_Episode>();
            foreach (Raw_AniDB_Episode epraw in eps)
            {
                AniDB_Episode epNew = session
                    .CreateCriteria(typeof(AniDB_Episode))
                    .Add(Restrictions.Eq("EpisodeID", epraw.EpisodeID))
                    .UniqueResult<AniDB_Episode>();

                if (epNew == null) epNew = new AniDB_Episode();

                epNew.Populate(epraw);
                epsToSave.Add(epNew);

                // since the HTTP api doesn't return a count of the number of specials, we will calculate it here
                if (epNew.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Episode)
                    this.EpisodeCountNormal++;

                if (epNew.EpisodeTypeEnum == AniDBAPI.enEpisodeType.Special)
                    this.EpisodeCountSpecial++;
            }
            using (var transaction = session.BeginTransaction())
            {
                foreach (AniDB_Episode rec in epsToSave)
                    session.SaveOrUpdate(rec);

                transaction.Commit();
            }

            this.EpisodeCount = EpisodeCountSpecial + EpisodeCountNormal;
        }
예제 #16
0
        private void CreateEpisodes(List<Raw_AniDB_Episode> eps)
        {
            if (eps == null) return;

            this.EpisodeCountSpecial = 0;
            this.EpisodeCountNormal = 0;

            List<AnimeEpisode> animeEpsToDelete = new List<AnimeEpisode>();
            List<AniDB_Episode> aniDBEpsToDelete = new List<AniDB_Episode>();

            foreach (Raw_AniDB_Episode epraw in eps)
            {
                //
                // we need to do this check because some times AniDB will replace an existing episode with a new episode
                List<AniDB_Episode> existingEps = RepoFactory.AniDB_Episode.GetByAnimeIDAndEpisodeTypeNumber(epraw.AnimeID, (enEpisodeType)epraw.EpisodeType, epraw.EpisodeNumber);

                // delete any old records
                foreach (AniDB_Episode epOld in existingEps)
                {
                    if (epOld.EpisodeID != epraw.EpisodeID)
                    {
                        // first delete any AnimeEpisode records that point to the new anidb episode
                        AnimeEpisode aniep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(epOld.EpisodeID);
                        if (aniep != null)
                            animeEpsToDelete.Add(aniep);
                        aniDBEpsToDelete.Add(epOld);
                    }
                }
            }
            RepoFactory.AnimeEpisode.Delete(animeEpsToDelete);
            RepoFactory.AniDB_Episode.Delete(aniDBEpsToDelete);

            List<AniDB_Episode> epsToSave = new List<AniDB_Episode>();
            foreach (Raw_AniDB_Episode epraw in eps)
            {
                AniDB_Episode epNew = RepoFactory.AniDB_Episode.GetByEpisodeID(epraw.EpisodeID);
                if (epNew == null) epNew = new AniDB_Episode();

                epNew.Populate(epraw);
                epsToSave.Add(epNew);

                // since the HTTP api doesn't return a count of the number of specials, we will calculate it here
                if (epNew.EpisodeTypeEnum == enEpisodeType.Episode)
                    this.EpisodeCountNormal++;

                if (epNew.EpisodeTypeEnum == enEpisodeType.Special)
                    this.EpisodeCountSpecial++;
            }
            RepoFactory.AniDB_Episode.Save(epsToSave);

            this.EpisodeCount = EpisodeCountSpecial + EpisodeCountNormal;
        }