Esempio n. 1
0
        private void SaveWatchedStatus(bool watched, int userID, DateTime?watchedDate, bool updateWatchedDate)
        {
            VideoLocal_UserRepository repVidUsers   = new VideoLocal_UserRepository();
            VideoLocal_User           vidUserRecord = this.GetUserRecord(userID);

            if (watched)
            {
                if (vidUserRecord == null)
                {
                    vidUserRecord             = new VideoLocal_User();
                    vidUserRecord.WatchedDate = DateTime.Now;
                }
                vidUserRecord.JMMUserID    = userID;
                vidUserRecord.VideoLocalID = this.VideoLocalID;

                if (watchedDate.HasValue)
                {
                    if (updateWatchedDate)
                    {
                        vidUserRecord.WatchedDate = watchedDate.Value;
                    }
                }

                repVidUsers.Save(vidUserRecord);
            }
            else
            {
                if (vidUserRecord != null)
                {
                    repVidUsers.Delete(vidUserRecord.VideoLocal_UserID);
                }
            }
        }
Esempio n. 2
0
        private void SaveWatchedStatus(bool watched, int userID, DateTime?watchedDate, bool updateWatchedDate)
        {
            VideoLocal_User vidUserRecord = GetUserRecord(userID);

            if (watched)
            {
                if (vidUserRecord == null)
                {
                    vidUserRecord = new VideoLocal_User();
                }
                vidUserRecord.WatchedDate  = DateTime.Now;
                vidUserRecord.JMMUserID    = userID;
                vidUserRecord.VideoLocalID = this.VideoLocalID;

                if (watchedDate.HasValue)
                {
                    if (updateWatchedDate)
                    {
                        vidUserRecord.WatchedDate = watchedDate.Value;
                    }
                }

                RepoFactory.VideoLocalUser.Save(vidUserRecord);
            }
            else
            {
                if (vidUserRecord != null)
                {
                    vidUserRecord.WatchedDate = null;
                    RepoFactory.VideoLocalUser.Save(vidUserRecord);
                }
            }
        }
Esempio n. 3
0
        public Contract_VideoLocalManualLink ToContractManualLink(int userID)
        {
            Contract_VideoLocalManualLink contract = new Contract_VideoLocalManualLink();

            contract.CRC32           = this.CRC32;
            contract.DateTimeUpdated = this.DateTimeUpdated;
            contract.FilePath        = this.FilePath;
            contract.FileSize        = this.FileSize;
            contract.Hash            = this.Hash;
            contract.HashSource      = this.HashSource;
            contract.ImportFolder    = this.ImportFolder.ToContract();
            contract.ImportFolderID  = this.ImportFolderID;
            contract.IsIgnored       = this.IsIgnored;
            contract.IsVariation     = this.IsVariation;
            contract.MD5             = this.MD5;
            contract.SHA1            = this.SHA1;
            contract.VideoLocalID    = this.VideoLocalID;

            VideoLocal_User userRecord = this.GetUserRecord(userID);

            if (userRecord == null)
            {
                contract.IsWatched   = 0;
                contract.WatchedDate = null;
            }
            else
            {
                contract.IsWatched   = 1;
                contract.WatchedDate = userRecord.WatchedDate;
            }

            return(contract);
        }
Esempio n. 4
0
		public void Save(VideoLocal_User obj)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				// populate the database
				using (var transaction = session.BeginTransaction())
				{
					session.SaveOrUpdate(obj);
					transaction.Commit();
				}
			}
		}
Esempio n. 5
0
        public void SetResumePosition(long resumeposition, int userID)
        {
            VideoLocal_User vuser = GetUserRecord(userID);

            if (vuser == null)
            {
                vuser                = new VideoLocal_User();
                vuser.JMMUserID      = userID;
                vuser.VideoLocalID   = VideoLocalID;
                vuser.ResumePosition = resumeposition;
            }
            RepoFactory.VideoLocalUser.Save(vuser);
        }
        public VideoLocal_User GetVideoLocalUserRecord(int userID)
        {
            VideoLocal vid = RepoFactory.VideoLocal.GetByHash(Hash);

            if (vid != null)
            {
                VideoLocal_User vidUser = vid.GetUserRecord(userID);
                if (vidUser != null)
                {
                    return(vidUser);
                }
            }

            return(null);
        }
        public VideoLocal_User GetVideoLocalUserRecord(int userID)
        {
            VideoLocalRepository repVids = new VideoLocalRepository();

            VideoLocal vid = repVids.GetByHash(Hash);

            if (vid != null)
            {
                VideoLocal_User vidUser = vid.GetUserRecord(userID);
                if (vidUser != null)
                {
                    return(vidUser);
                }
            }

            return(null);
        }
Esempio n. 8
0
        public Contract_VideoLocalManualLink ToContractManualLink(int userID)
        {
            Contract_VideoLocalManualLink contract = new Contract_VideoLocalManualLink();

            contract.CRC32           = this.CRC32;
            contract.DateTimeUpdated = this.DateTimeUpdated;
            contract.FileName        = this.FileName;
            contract.FileSize        = this.FileSize;
            contract.Hash            = this.Hash;
            contract.HashSource      = this.HashSource;
            contract.IsIgnored       = this.IsIgnored;
            contract.IsVariation     = this.IsVariation;
            contract.MD5             = this.MD5;
            contract.SHA1            = this.SHA1;
            contract.VideoLocalID    = this.VideoLocalID;
            contract.Places          = Places.Select(a => a.ToContract()).ToList();

            VideoLocal_User userRecord = this.GetUserRecord(userID);

            if (userRecord?.WatchedDate == null)
            {
                contract.IsWatched      = 0;
                contract.WatchedDate    = null;
                contract.ResumePosition = 0;
            }
            else
            {
                contract.IsWatched   = userRecord.WatchedDate.HasValue ? 1 : 0;
                contract.WatchedDate = userRecord.WatchedDate;
            }
            if (userRecord != null)
            {
                contract.ResumePosition = userRecord.ResumePosition;
            }
            return(contract);
        }
Esempio n. 9
0
        public Contract_VideoDetailed ToContractDetailed(int userID)
        {
            Contract_VideoDetailed contract = new Contract_VideoDetailed();

            // get the cross ref episode
            List <CrossRef_File_Episode> xrefs = this.EpisodeCrossRefs;

            if (xrefs.Count == 0)
            {
                return(null);
            }

            contract.Percentage     = xrefs[0].Percentage;
            contract.EpisodeOrder   = xrefs[0].EpisodeOrder;
            contract.CrossRefSource = xrefs[0].CrossRefSource;
            contract.AnimeEpisodeID = xrefs[0].EpisodeID;

            contract.VideoLocal_FileName    = this.FileName;
            contract.VideoLocal_Hash        = this.Hash;
            contract.VideoLocal_FileSize    = this.FileSize;
            contract.VideoLocalID           = this.VideoLocalID;
            contract.VideoLocal_IsIgnored   = this.IsIgnored;
            contract.VideoLocal_IsVariation = this.IsVariation;
            contract.Places = Places.Select(a => a.ToContract()).ToList();

            contract.VideoLocal_MD5        = this.MD5;
            contract.VideoLocal_SHA1       = this.SHA1;
            contract.VideoLocal_CRC32      = this.CRC32;
            contract.VideoLocal_HashSource = this.HashSource;

            VideoLocal_User userRecord = this.GetUserRecord(userID);

            if (userRecord?.WatchedDate == null)
            {
                contract.VideoLocal_IsWatched      = 0;
                contract.VideoLocal_WatchedDate    = null;
                contract.VideoLocal_ResumePosition = 0;
            }
            else
            {
                contract.VideoLocal_IsWatched   = userRecord.WatchedDate.HasValue ? 1 : 0;
                contract.VideoLocal_WatchedDate = userRecord.WatchedDate;
            }
            if (userRecord != null)
            {
                contract.VideoLocal_ResumePosition = userRecord.ResumePosition;
            }
            contract.VideoInfo_AudioBitrate    = AudioBitrate;
            contract.VideoInfo_AudioCodec      = AudioCodec;
            contract.VideoInfo_Duration        = Duration;
            contract.VideoInfo_VideoBitrate    = VideoBitrate;
            contract.VideoInfo_VideoBitDepth   = VideoBitDepth;
            contract.VideoInfo_VideoCodec      = VideoCodec;
            contract.VideoInfo_VideoFrameRate  = VideoFrameRate;
            contract.VideoInfo_VideoResolution = VideoResolution;

            // AniDB File
            AniDB_File anifile = this.GetAniDBFile(); // to prevent multiple db calls

            if (anifile != null)
            {
                contract.AniDB_Anime_GroupName      = anifile.Anime_GroupName;
                contract.AniDB_Anime_GroupNameShort = anifile.Anime_GroupNameShort;
                contract.AniDB_AnimeID              = anifile.AnimeID;
                contract.AniDB_CRC                  = anifile.CRC;
                contract.AniDB_Episode_Rating       = anifile.Episode_Rating;
                contract.AniDB_Episode_Votes        = anifile.Episode_Votes;
                contract.AniDB_File_AudioCodec      = anifile.File_AudioCodec;
                contract.AniDB_File_Description     = anifile.File_Description;
                contract.AniDB_File_FileExtension   = anifile.File_FileExtension;
                contract.AniDB_File_LengthSeconds   = anifile.File_LengthSeconds;
                contract.AniDB_File_ReleaseDate     = anifile.File_ReleaseDate;
                contract.AniDB_File_Source          = anifile.File_Source;
                contract.AniDB_File_VideoCodec      = anifile.File_VideoCodec;
                contract.AniDB_File_VideoResolution = anifile.File_VideoResolution;
                contract.AniDB_FileID               = anifile.FileID;
                contract.AniDB_GroupID              = anifile.GroupID;
                contract.AniDB_MD5                  = anifile.MD5;
                contract.AniDB_SHA1                 = anifile.SHA1;
                contract.AniDB_File_FileVersion     = anifile.FileVersion;

                // languages
                contract.LanguagesAudio    = anifile.LanguagesRAW;
                contract.LanguagesSubtitle = anifile.SubtitlesRAW;
            }
            else
            {
                contract.AniDB_Anime_GroupName      = "";
                contract.AniDB_Anime_GroupNameShort = "";
                contract.AniDB_CRC                  = "";
                contract.AniDB_File_AudioCodec      = "";
                contract.AniDB_File_Description     = "";
                contract.AniDB_File_FileExtension   = "";
                contract.AniDB_File_Source          = "";
                contract.AniDB_File_VideoCodec      = "";
                contract.AniDB_File_VideoResolution = "";
                contract.AniDB_MD5                  = "";
                contract.AniDB_SHA1                 = "";
                contract.AniDB_File_FileVersion     = 1;

                // languages
                contract.LanguagesAudio    = "";
                contract.LanguagesSubtitle = "";
            }


            AniDB_ReleaseGroup relGroup = this.ReleaseGroup; // to prevent multiple db calls

            if (relGroup != null)
            {
                contract.ReleaseGroup = relGroup.ToContract();
            }
            else
            {
                contract.ReleaseGroup = null;
            }
            contract.Media = GetMediaFromUser(userID);
            return(contract);
        }
Esempio n. 10
0
        public void ToggleWatchedStatus(bool watched, bool updateOnline, DateTime?watchedDate, bool updateStats,
                                        bool updateStatsCache, int userID,
                                        bool syncTrakt, bool updateWatchedDate)
        {
            JMMUser user = RepoFactory.JMMUser.GetByID(userID);

            if (user == null)
            {
                return;
            }

            List <JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers();

            // update the video file to watched
            int mywatched = watched ? 1 : 0;

            if (user.IsAniDBUser == 0)
            {
                SaveWatchedStatus(watched, userID, watchedDate, updateWatchedDate);
            }
            else
            {
                // if the user is AniDB user we also want to update any other AniDB
                // users to keep them in sync
                foreach (JMMUser juser in aniDBUsers)
                {
                    if (juser.IsAniDBUser == 1)
                    {
                        SaveWatchedStatus(watched, juser.JMMUserID, watchedDate, updateWatchedDate);
                    }
                }
            }


            // now lets find all the associated AniDB_File record if there is one
            if (user.IsAniDBUser == 1)
            {
                AniDB_File aniFile = RepoFactory.AniDB_File.GetByHash(this.Hash);
                if (aniFile != null)
                {
                    aniFile.IsWatched = mywatched;

                    if (watched)
                    {
                        if (watchedDate.HasValue)
                        {
                            aniFile.WatchedDate = watchedDate;
                        }
                        else
                        {
                            aniFile.WatchedDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        aniFile.WatchedDate = null;
                    }


                    RepoFactory.AniDB_File.Save(aniFile, false);
                }

                if (updateOnline)
                {
                    if ((watched && ServerSettings.AniDB_MyList_SetWatched) ||
                        (!watched && ServerSettings.AniDB_MyList_SetUnwatched))
                    {
                        CommandRequest_UpdateMyListFileStatus cmd = new CommandRequest_UpdateMyListFileStatus(
                            this.Hash, watched, false,
                            watchedDate.HasValue ? Utils.GetAniDBDateAsSeconds(watchedDate) : 0);
                        cmd.Save();
                    }
                }
            }

            // now find all the episode records associated with this video file
            // but we also need to check if theer are any other files attached to this episode with a watched
            // status,


            AnimeSeries ser = null;
            // get all files associated with this episode
            List <CrossRef_File_Episode>  xrefs          = RepoFactory.CrossRef_File_Episode.GetByHash(this.Hash);
            Dictionary <int, AnimeSeries> toUpdateSeries = new Dictionary <int, AnimeSeries>();

            if (watched)
            {
                // find the total watched percentage
                // eg one file can have a % = 100
                // or if 2 files make up one episodes they will each have a % = 50

                foreach (CrossRef_File_Episode xref in xrefs)
                {
                    // get the episodes for this file, may be more than one (One Piece x Toriko)
                    AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(xref.EpisodeID);
                    // get all the files for this episode
                    int epPercentWatched = 0;
                    foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
                    {
                        VideoLocal_User vidUser = filexref.GetVideoLocalUserRecord(userID);
                        if (vidUser != null && vidUser.WatchedDate.HasValue)
                        {
                            // if not null means it is watched
                            epPercentWatched += filexref.Percentage;
                        }

                        if (epPercentWatched > 95)
                        {
                            break;
                        }
                    }

                    if (epPercentWatched > 95)
                    {
                        ser = ep.GetAnimeSeries();
                        if (!toUpdateSeries.ContainsKey(ser.AnimeSeriesID))
                        {
                            toUpdateSeries.Add(ser.AnimeSeriesID, ser);
                        }
                        if (user.IsAniDBUser == 0)
                        {
                            ep.SaveWatchedStatus(true, userID, watchedDate, updateWatchedDate);
                        }
                        else
                        {
                            // if the user is AniDB user we also want to update any other AniDB
                            // users to keep them in sync
                            foreach (JMMUser juser in aniDBUsers)
                            {
                                if (juser.IsAniDBUser == 1)
                                {
                                    ep.SaveWatchedStatus(true, juser.JMMUserID, watchedDate, updateWatchedDate);
                                }
                            }
                        }

                        if (syncTrakt && ServerSettings.Trakt_IsEnabled &&
                            !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                        {
                            CommandRequest_TraktHistoryEpisode cmdSyncTrakt =
                                new CommandRequest_TraktHistoryEpisode(ep.AnimeEpisodeID, TraktSyncAction.Add);
                            cmdSyncTrakt.Save();
                        }

                        if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) &&
                            !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                        {
                            CommandRequest_MALUpdatedWatchedStatus cmdMAL =
                                new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                            cmdMAL.Save();
                        }
                    }
                }
            }
            else
            {
                // if setting a file to unwatched only set the episode unwatched, if ALL the files are unwatched
                foreach (CrossRef_File_Episode xrefEp in xrefs)
                {
                    // get the episodes for this file, may be more than one (One Piece x Toriko)
                    AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(xrefEp.EpisodeID);
                    ser = ep.GetAnimeSeries();
                    if (!toUpdateSeries.ContainsKey(ser.AnimeSeriesID))
                    {
                        toUpdateSeries.Add(ser.AnimeSeriesID, ser);
                    }
                    // get all the files for this episode
                    int epPercentWatched = 0;
                    foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
                    {
                        VideoLocal_User vidUser = filexref.GetVideoLocalUserRecord(userID);
                        if (vidUser != null && vidUser.WatchedDate.HasValue)
                        {
                            epPercentWatched += filexref.Percentage;
                        }

                        if (epPercentWatched > 95)
                        {
                            break;
                        }
                    }

                    if (epPercentWatched < 95)
                    {
                        if (user.IsAniDBUser == 0)
                        {
                            ep.SaveWatchedStatus(false, userID, watchedDate, true);
                        }
                        else
                        {
                            // if the user is AniDB user we also want to update any other AniDB
                            // users to keep them in sync
                            foreach (JMMUser juser in aniDBUsers)
                            {
                                if (juser.IsAniDBUser == 1)
                                {
                                    ep.SaveWatchedStatus(false, juser.JMMUserID, watchedDate, true);
                                }
                            }
                        }

                        if (syncTrakt && ServerSettings.Trakt_IsEnabled &&
                            !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                        {
                            CommandRequest_TraktHistoryEpisode cmdSyncTrakt =
                                new CommandRequest_TraktHistoryEpisode(ep.AnimeEpisodeID, TraktSyncAction.Remove);
                            cmdSyncTrakt.Save();
                        }
                    }
                }
                if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) &&
                    !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                {
                    CommandRequest_MALUpdatedWatchedStatus cmdMAL =
                        new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                    cmdMAL.Save();
                }
            }


            // update stats for groups and series
            if (toUpdateSeries.Count > 0 && updateStats)
            {
                foreach (AnimeSeries s in toUpdateSeries.Values)
                {
                    // update all the groups above this series in the heirarchy
                    s.UpdateStats(true, true, true);
                }
                //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
            }

            //if (ser != null && updateStatsCache)
            //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID);
        }
Esempio n. 11
0
		private void SaveWatchedStatus(bool watched, int userID, DateTime? watchedDate, bool updateWatchedDate)
		{
			VideoLocal_UserRepository repVidUsers = new VideoLocal_UserRepository();
			VideoLocal_User vidUserRecord = this.GetUserRecord(userID);
			if (watched)
			{
				if (vidUserRecord == null)
				{
					vidUserRecord = new VideoLocal_User();
					vidUserRecord.WatchedDate = DateTime.Now;
				}
				vidUserRecord.JMMUserID = userID;
				vidUserRecord.VideoLocalID = this.VideoLocalID;

				if (watchedDate.HasValue)
				{
					if (updateWatchedDate)
						vidUserRecord.WatchedDate = watchedDate.Value;
				}

				repVidUsers.Save(vidUserRecord);
			}
			else
			{
				if (vidUserRecord != null)
					repVidUsers.Delete(vidUserRecord.VideoLocal_UserID);
			}
		}
Esempio n. 12
0
        public Contract_VideoDetailed ToContractDetailed(int userID)
        {
            Contract_VideoDetailed contract = new Contract_VideoDetailed();

            // get the cross ref episode
            List <CrossRef_File_Episode> xrefs = this.EpisodeCrossRefs;

            if (xrefs.Count == 0)
            {
                return(null);
            }

            contract.Percentage     = xrefs[0].Percentage;
            contract.EpisodeOrder   = xrefs[0].EpisodeOrder;
            contract.CrossRefSource = xrefs[0].CrossRefSource;
            contract.AnimeEpisodeID = xrefs[0].EpisodeID;

            contract.VideoLocal_FilePath    = this.FilePath;
            contract.VideoLocal_Hash        = this.Hash;
            contract.VideoLocal_FileSize    = this.FileSize;
            contract.VideoLocalID           = this.VideoLocalID;
            contract.VideoLocal_IsIgnored   = this.IsIgnored;
            contract.VideoLocal_IsVariation = this.IsVariation;

            contract.VideoLocal_MD5        = this.MD5;
            contract.VideoLocal_SHA1       = this.SHA1;
            contract.VideoLocal_CRC32      = this.CRC32;
            contract.VideoLocal_HashSource = this.HashSource;

            VideoLocal_User userRecord = this.GetUserRecord(userID);

            if (userRecord == null)
            {
                contract.VideoLocal_IsWatched = 0;
            }
            else
            {
                contract.VideoLocal_IsWatched = 1;
            }

            // Import Folder
            ImportFolder ns = this.ImportFolder;             // to prevent multiple db calls

            if (ns != null)
            {
                contract.ImportFolderID       = ns.ImportFolderID;
                contract.ImportFolderLocation = ns.ImportFolderLocation;
                contract.ImportFolderName     = ns.ImportFolderName;
            }

            // video info
            VideoInfo vi = this.VideoInfo;             // to prevent multiple db calls

            if (vi != null)
            {
                contract.VideoInfo_AudioBitrate    = vi.AudioBitrate;
                contract.VideoInfo_AudioCodec      = vi.AudioCodec;
                contract.VideoInfo_Duration        = vi.Duration;
                contract.VideoInfo_VideoBitrate    = vi.VideoBitrate;
                contract.VideoInfo_VideoBitDepth   = vi.VideoBitDepth;
                contract.VideoInfo_VideoCodec      = vi.VideoCodec;
                contract.VideoInfo_VideoFrameRate  = vi.VideoFrameRate;
                contract.VideoInfo_VideoResolution = vi.VideoResolution;
                contract.VideoInfo_VideoInfoID     = vi.VideoInfoID;
            }

            // AniDB File
            AniDB_File anifile = this.GetAniDBFile();             // to prevent multiple db calls

            if (anifile != null)
            {
                contract.AniDB_Anime_GroupName      = anifile.Anime_GroupName;
                contract.AniDB_Anime_GroupNameShort = anifile.Anime_GroupNameShort;
                contract.AniDB_AnimeID              = anifile.AnimeID;
                contract.AniDB_CRC                  = anifile.CRC;
                contract.AniDB_Episode_Rating       = anifile.Episode_Rating;
                contract.AniDB_Episode_Votes        = anifile.Episode_Votes;
                contract.AniDB_File_AudioCodec      = anifile.File_AudioCodec;
                contract.AniDB_File_Description     = anifile.File_Description;
                contract.AniDB_File_FileExtension   = anifile.File_FileExtension;
                contract.AniDB_File_LengthSeconds   = anifile.File_LengthSeconds;
                contract.AniDB_File_ReleaseDate     = anifile.File_ReleaseDate;
                contract.AniDB_File_Source          = anifile.File_Source;
                contract.AniDB_File_VideoCodec      = anifile.File_VideoCodec;
                contract.AniDB_File_VideoResolution = anifile.File_VideoResolution;
                contract.AniDB_FileID               = anifile.FileID;
                contract.AniDB_GroupID              = anifile.GroupID;
                contract.AniDB_MD5                  = anifile.MD5;
                contract.AniDB_SHA1                 = anifile.SHA1;
                contract.AniDB_File_FileVersion     = anifile.FileVersion;

                // languages
                contract.LanguagesAudio    = anifile.LanguagesRAW;
                contract.LanguagesSubtitle = anifile.SubtitlesRAW;
            }
            else
            {
                contract.AniDB_Anime_GroupName      = "";
                contract.AniDB_Anime_GroupNameShort = "";
                contract.AniDB_CRC                  = "";
                contract.AniDB_File_AudioCodec      = "";
                contract.AniDB_File_Description     = "";
                contract.AniDB_File_FileExtension   = "";
                contract.AniDB_File_Source          = "";
                contract.AniDB_File_VideoCodec      = "";
                contract.AniDB_File_VideoResolution = "";
                contract.AniDB_MD5                  = "";
                contract.AniDB_SHA1                 = "";
                contract.AniDB_File_FileVersion     = 1;

                // languages
                contract.LanguagesAudio    = "";
                contract.LanguagesSubtitle = "";
            }



            AniDB_ReleaseGroup relGroup = this.ReleaseGroup;             // to prevent multiple db calls

            if (relGroup != null)
            {
                contract.ReleaseGroup = relGroup.ToContract();
            }
            else
            {
                contract.ReleaseGroup = null;
            }

            return(contract);
        }
Esempio n. 13
0
        public void ToggleWatchedStatus(bool watched, bool updateOnline, DateTime?watchedDate, bool updateStats, bool updateStatsCache, int userID,
                                        bool scrobbleTrakt, bool updateWatchedDate)
        {
            VideoLocalRepository            repVids     = new VideoLocalRepository();
            AnimeEpisodeRepository          repEpisodes = new AnimeEpisodeRepository();
            AniDB_FileRepository            repAniFile  = new AniDB_FileRepository();
            CrossRef_File_EpisodeRepository repCross    = new CrossRef_File_EpisodeRepository();
            VideoLocal_UserRepository       repVidUsers = new VideoLocal_UserRepository();
            JMMUserRepository           repUsers        = new JMMUserRepository();
            AnimeEpisode_UserRepository repEpisodeUsers = new AnimeEpisode_UserRepository();

            JMMUser user = repUsers.GetByID(userID);

            if (user == null)
            {
                return;
            }

            List <JMMUser> aniDBUsers = repUsers.GetAniDBUsers();

            // update the video file to watched
            int mywatched = watched ? 1 : 0;

            if (user.IsAniDBUser == 0)
            {
                SaveWatchedStatus(watched, userID, watchedDate, updateWatchedDate);
            }
            else
            {
                // if the user is AniDB user we also want to update any other AniDB
                // users to keep them in sync
                foreach (JMMUser juser in aniDBUsers)
                {
                    if (juser.IsAniDBUser == 1)
                    {
                        SaveWatchedStatus(watched, juser.JMMUserID, watchedDate, updateWatchedDate);
                    }
                }
            }


            // now lets find all the associated AniDB_File record if there is one
            if (user.IsAniDBUser == 1)
            {
                AniDB_File aniFile = repAniFile.GetByHash(this.Hash);
                if (aniFile != null)
                {
                    aniFile.IsWatched = mywatched;

                    if (watched)
                    {
                        if (watchedDate.HasValue)
                        {
                            aniFile.WatchedDate = watchedDate;
                        }
                        else
                        {
                            aniFile.WatchedDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        aniFile.WatchedDate = null;
                    }


                    repAniFile.Save(aniFile, false);
                }

                if (updateOnline)
                {
                    if ((watched && ServerSettings.AniDB_MyList_SetWatched) || (!watched && ServerSettings.AniDB_MyList_SetUnwatched))
                    {
                        CommandRequest_UpdateMyListFileStatus cmd = new CommandRequest_UpdateMyListFileStatus(this.Hash, watched, false,
                                                                                                              watchedDate.HasValue ? Utils.GetAniDBDateAsSeconds(watchedDate) : 0);
                        cmd.Save();
                    }
                }
            }

            // now find all the episode records associated with this video file
            // but we also need to check if theer are any other files attached to this episode with a watched
            // status,


            AnimeSeries ser = null;
            // get all files associated with this episode
            List <CrossRef_File_Episode> xrefs = repCross.GetByHash(this.Hash);

            if (watched)
            {
                // find the total watched percentage
                // eg one file can have a % = 100
                // or if 2 files make up one episodes they will each have a % = 50

                foreach (CrossRef_File_Episode xref in xrefs)
                {
                    // get the episode for this file
                    AnimeEpisode ep = repEpisodes.GetByAniDBEpisodeID(xref.EpisodeID);
                    if (ep == null)
                    {
                        continue;
                    }

                    // get all the files for this episode
                    int epPercentWatched = 0;
                    foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
                    {
                        VideoLocal_User vidUser = filexref.GetVideoLocalUserRecord(userID);
                        if (vidUser != null)
                        {
                            // if not null means it is watched
                            epPercentWatched += filexref.Percentage;
                        }

                        if (epPercentWatched > 95)
                        {
                            break;
                        }
                    }

                    if (epPercentWatched > 95)
                    {
                        ser = ep.GetAnimeSeries();

                        if (user.IsAniDBUser == 0)
                        {
                            ep.SaveWatchedStatus(true, userID, watchedDate, updateWatchedDate);
                        }
                        else
                        {
                            // if the user is AniDB user we also want to update any other AniDB
                            // users to keep them in sync
                            foreach (JMMUser juser in aniDBUsers)
                            {
                                if (juser.IsAniDBUser == 1)
                                {
                                    ep.SaveWatchedStatus(true, juser.JMMUserID, watchedDate, updateWatchedDate);
                                }
                            }
                        }

                        if (scrobbleTrakt && !string.IsNullOrEmpty(ServerSettings.Trakt_Username) && !string.IsNullOrEmpty(ServerSettings.Trakt_Password))
                        {
                            CommandRequest_TraktShowScrobble cmdScrobble = new CommandRequest_TraktShowScrobble(ep.AnimeEpisodeID);
                            cmdScrobble.Save();
                        }

                        if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) && !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                        {
                            CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                            cmdMAL.Save();
                        }
                    }
                }
            }
            else
            {
                // if setting a file to unwatched only set the episode unwatched, if ALL the files are unwatched
                foreach (CrossRef_File_Episode xrefEp in xrefs)
                {
                    AnimeEpisode ep = repEpisodes.GetByAniDBEpisodeID(xrefEp.EpisodeID);
                    if (ep == null)
                    {
                        continue;
                    }
                    ser = ep.GetAnimeSeries();

                    // get all the files for this episode
                    int epPercentWatched = 0;
                    foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
                    {
                        VideoLocal_User vidUser = filexref.GetVideoLocalUserRecord(userID);
                        if (vidUser != null)
                        {
                            epPercentWatched += filexref.Percentage;
                        }

                        if (epPercentWatched > 95)
                        {
                            break;
                        }
                    }

                    if (epPercentWatched < 95)
                    {
                        if (user.IsAniDBUser == 0)
                        {
                            ep.SaveWatchedStatus(false, userID, watchedDate, true);
                        }
                        else
                        {
                            // if the user is AniDB user we also want to update any other AniDB
                            // users to keep them in sync
                            foreach (JMMUser juser in aniDBUsers)
                            {
                                if (juser.IsAniDBUser == 1)
                                {
                                    ep.SaveWatchedStatus(false, juser.JMMUserID, watchedDate, true);
                                }
                            }
                        }

                        CommandRequest_TraktShowEpisodeUnseen cmdUnseen = new CommandRequest_TraktShowEpisodeUnseen(ep.AnimeEpisodeID);
                        cmdUnseen.Save();
                    }
                }

                if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) && !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                {
                    CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                    cmdMAL.Save();
                }
            }


            // update stats for groups and series
            if (ser != null && updateStats)
            {
                // update all the groups above this series in the heirarchy
                ser.UpdateStats(true, true, true);
                //ser.TopLevelAnimeGroup.UpdateStatsFromTopLevel(true, true, true);
            }

            if (ser != null && updateStatsCache)
            {
                StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID);
            }
        }
 public void SetResumePosition(int videolocalid, int jmmuserID, long position)
 {
     try
     {
         VideoLocal_User vlu= RepoFactory.VideoLocalUser.GetByUserIDAndVideoLocalID(jmmuserID, videolocalid);
         if (vlu == null)
         {
             vlu = new VideoLocal_User();
             vlu.JMMUserID = jmmuserID;
             vlu.VideoLocalID = videolocalid;
             vlu.WatchedDate = null;
         }
         vlu.ResumePosition = position;
         RepoFactory.VideoLocalUser.Save(vlu);
     }
     catch (Exception ex)
     {
         logger.Error( ex,ex.ToString());
     }
 }
Esempio n. 15
0
        public List <Contract_VideoDetailed> GetVideoDetailedContracts(int userID)
        {
            VideoLocalRepository          repVids   = new VideoLocalRepository();
            List <Contract_VideoDetailed> contracts = new List <Contract_VideoDetailed>();

            // get all the cross refs
            foreach (CrossRef_File_Episode xref in FileCrossRefs)
            {
                Contract_VideoDetailed contract = new Contract_VideoDetailed();
                contract.Percentage     = xref.Percentage;
                contract.EpisodeOrder   = xref.EpisodeOrder;
                contract.CrossRefSource = xref.CrossRefSource;
                contract.AnimeEpisodeID = this.AnimeEpisodeID;

                // get the video file
                // we will assume that it is unique by hash/episodeid
                VideoLocal vid = repVids.GetByHash(xref.Hash);
                if (vid != null)
                {
                    contract.VideoLocal_FilePath = vid.FilePath;
                    contract.VideoLocal_Hash     = vid.Hash;
                    contract.VideoLocal_FileSize = vid.FileSize;
                    contract.VideoLocalID        = vid.VideoLocalID;

                    contract.VideoLocal_MD5        = vid.MD5;
                    contract.VideoLocal_SHA1       = vid.SHA1;
                    contract.VideoLocal_CRC32      = vid.CRC32;
                    contract.VideoLocal_HashSource = vid.HashSource;

                    VideoLocal_User vidUser = vid.GetUserRecord(userID);
                    //AnimeEpisode_User userRecord = this.GetUserRecord(userID);
                    if (vidUser == null)
                    {
                        contract.VideoLocal_IsWatched   = 0;
                        contract.VideoLocal_WatchedDate = null;
                    }
                    else
                    {
                        contract.VideoLocal_IsWatched   = 1;
                        contract.VideoLocal_WatchedDate = vidUser.WatchedDate;
                    }
                    contract.VideoLocal_IsIgnored   = vid.IsIgnored;
                    contract.VideoLocal_IsVariation = vid.IsVariation;

                    // Import Folder
                    ImportFolder ns = vid.ImportFolder;                     // to prevent multiple db calls
                    contract.ImportFolderID       = ns.ImportFolderID;
                    contract.ImportFolderLocation = ns.ImportFolderLocation;
                    contract.ImportFolderName     = ns.ImportFolderName;

                    // video info
                    VideoInfo vi = vid.VideoInfo;                     // to prevent multiple db calls
                    contract.VideoInfo_AudioBitrate    = vi.AudioBitrate;
                    contract.VideoInfo_AudioCodec      = vi.AudioCodec;
                    contract.VideoInfo_Duration        = vi.Duration;
                    contract.VideoInfo_VideoBitrate    = vi.VideoBitrate;
                    contract.VideoInfo_VideoBitDepth   = vi.VideoBitDepth;
                    contract.VideoInfo_VideoCodec      = vi.VideoCodec;
                    contract.VideoInfo_VideoFrameRate  = vi.VideoFrameRate;
                    contract.VideoInfo_VideoResolution = vi.VideoResolution;
                    contract.VideoInfo_VideoInfoID     = vi.VideoInfoID;

                    // AniDB File
                    AniDB_File anifile = vid.GetAniDBFile();                     // to prevent multiple db calls
                    if (anifile != null)
                    {
                        contract.AniDB_Anime_GroupName      = anifile.Anime_GroupName;
                        contract.AniDB_Anime_GroupNameShort = anifile.Anime_GroupNameShort;
                        contract.AniDB_AnimeID              = anifile.AnimeID;
                        contract.AniDB_CRC                  = anifile.CRC;
                        contract.AniDB_Episode_Rating       = anifile.Episode_Rating;
                        contract.AniDB_Episode_Votes        = anifile.Episode_Votes;
                        contract.AniDB_File_AudioCodec      = anifile.File_AudioCodec;
                        contract.AniDB_File_Description     = anifile.File_Description;
                        contract.AniDB_File_FileExtension   = anifile.File_FileExtension;
                        contract.AniDB_File_LengthSeconds   = anifile.File_LengthSeconds;
                        contract.AniDB_File_ReleaseDate     = anifile.File_ReleaseDate;
                        contract.AniDB_File_Source          = anifile.File_Source;
                        contract.AniDB_File_VideoCodec      = anifile.File_VideoCodec;
                        contract.AniDB_File_VideoResolution = anifile.File_VideoResolution;
                        contract.AniDB_FileID               = anifile.FileID;
                        contract.AniDB_GroupID              = anifile.GroupID;
                        contract.AniDB_MD5                  = anifile.MD5;
                        contract.AniDB_SHA1                 = anifile.SHA1;
                        contract.AniDB_File_FileVersion     = anifile.FileVersion;
                        contract.AniDB_File_IsCensored      = anifile.IsCensored;
                        contract.AniDB_File_IsDeprecated    = anifile.IsDeprecated;
                        contract.AniDB_File_InternalVersion = anifile.InternalVersion;

                        // languages
                        contract.LanguagesAudio    = anifile.LanguagesRAW;
                        contract.LanguagesSubtitle = anifile.SubtitlesRAW;
                    }
                    else
                    {
                        contract.AniDB_Anime_GroupName      = "";
                        contract.AniDB_Anime_GroupNameShort = "";
                        contract.AniDB_CRC                  = "";
                        contract.AniDB_File_AudioCodec      = "";
                        contract.AniDB_File_Description     = "";
                        contract.AniDB_File_FileExtension   = "";
                        contract.AniDB_File_Source          = "";
                        contract.AniDB_File_VideoCodec      = "";
                        contract.AniDB_File_VideoResolution = "";
                        contract.AniDB_MD5                  = "";
                        contract.AniDB_SHA1                 = "";
                        contract.AniDB_File_FileVersion     = 1;

                        // languages
                        contract.LanguagesAudio    = "";
                        contract.LanguagesSubtitle = "";
                    }



                    AniDB_ReleaseGroup relGroup = vid.ReleaseGroup;                     // to prevent multiple db calls
                    if (relGroup != null)
                    {
                        contract.ReleaseGroup = relGroup.ToContract();
                    }
                    else
                    {
                        contract.ReleaseGroup = null;
                    }

                    contracts.Add(contract);
                }
            }


            return(contracts);
        }