Exemple #1
0
        public static void Populate(SVR_AniDB_File anidbfile, Raw_AniDB_File fileInfo)
        {
            anidbfile.Anime_GroupName      = fileInfo.Anime_GroupName;
            anidbfile.Anime_GroupNameShort = fileInfo.Anime_GroupNameShort;
            anidbfile.AnimeID              = fileInfo.AnimeID;
            anidbfile.CRC                  = fileInfo.CRC;
            anidbfile.DateTimeUpdated      = DateTime.Now;
            anidbfile.Episode_Rating       = fileInfo.Episode_Rating;
            anidbfile.Episode_Votes        = fileInfo.Episode_Votes;
            anidbfile.File_AudioCodec      = fileInfo.File_AudioCodec;
            anidbfile.File_Description     = fileInfo.File_Description;
            anidbfile.File_FileExtension   = fileInfo.File_FileExtension;
            anidbfile.File_LengthSeconds   = fileInfo.File_LengthSeconds;
            anidbfile.File_ReleaseDate     = fileInfo.File_ReleaseDate;
            anidbfile.File_Source          = fileInfo.File_Source;
            anidbfile.File_VideoCodec      = fileInfo.File_VideoCodec;
            anidbfile.File_VideoResolution = fileInfo.File_VideoResolution;
            anidbfile.FileID               = fileInfo.FileID;
            anidbfile.FileName             = fileInfo.FileName;
            anidbfile.FileSize             = fileInfo.FileSize;
            anidbfile.GroupID              = fileInfo.GroupID;
            anidbfile.Hash                 = fileInfo.ED2KHash;
            anidbfile.IsWatched            = fileInfo.IsWatched;
            anidbfile.MD5                  = fileInfo.MD5;
            anidbfile.SHA1                 = fileInfo.SHA1;
            anidbfile.FileVersion          = fileInfo.FileVersion;
            anidbfile.IsCensored           = fileInfo.IsCensored;
            anidbfile.IsDeprecated         = fileInfo.IsDeprecated;
            anidbfile.InternalVersion      = fileInfo.InternalVersion;

            anidbfile.languagesRAW       = fileInfo.LanguagesRAW;
            anidbfile.subtitlesRAW       = fileInfo.SubtitlesRAW;
            anidbfile.episodesPercentRAW = fileInfo.EpisodesPercentRAW;
            anidbfile.episodesRAW        = fileInfo.EpisodesRAW;
        }
Exemple #2
0
        public CL_VideoDetailed ToClientDetailed(int userID)
        {
            CL_VideoDetailed cl = new CL_VideoDetailed();

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

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

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

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

            cl.VideoLocal_MD5        = MD5;
            cl.VideoLocal_SHA1       = SHA1;
            cl.VideoLocal_CRC32      = CRC32;
            cl.VideoLocal_HashSource = HashSource;

            VideoLocal_User userRecord = GetUserRecord(userID);

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

            // AniDB File
            SVR_AniDB_File anifile = GetAniDBFile(); // to prevent multiple db calls

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

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

                // languages
                cl.LanguagesAudio    = string.Empty;
                cl.LanguagesSubtitle = string.Empty;
            }


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

            if (relGroup != null)
            {
                cl.ReleaseGroup = relGroup;
            }
            else
            {
                cl.ReleaseGroup = null;
            }
            cl.Media = GetMediaFromUser(userID);
            return(cl);
        }
Exemple #3
0
        public void ToggleWatchedStatus(bool watched, bool updateOnline, DateTime?watchedDate, bool updateStats,
                                        bool updateStatsCache, int userID,
                                        bool syncTrakt, bool updateWatchedDate)
        {
            SVR_JMMUser user = RepoFactory.JMMUser.GetByID(userID);

            if (user == null)
            {
                return;
            }

            List <SVR_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 (SVR_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)
            {
                SVR_AniDB_File aniFile = RepoFactory.AniDB_File.GetByHash(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(
                            Hash, watched, false,
                            watchedDate.HasValue ? AniDB.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,


            SVR_AnimeSeries ser = null;
            // get all files associated with this episode
            List <CrossRef_File_Episode>      xrefs          = RepoFactory.CrossRef_File_Episode.GetByHash(Hash);
            Dictionary <int, SVR_AnimeSeries> toUpdateSeries = new Dictionary <int, SVR_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)
                    SVR_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 (SVR_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)
                    SVR_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 (SVR_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 (SVR_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);
        }