Exemplo n.º 1
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MALUploadStatusToMAL");

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

                // find the latest eps to update
                IReadOnlyList <SVR_AniDB_Anime> animes = RepoFactory.AniDB_Anime.GetAll();

                foreach (SVR_AniDB_Anime anime in animes)
                {
                    CommandRequest_MALUpdatedWatchedStatus cmd =
                        new CommandRequest_MALUpdatedWatchedStatus(anime.AnimeID);
                    cmd.Save();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_MALUploadStatusToMAL: {0}", ex);
            }
        }
Exemplo n.º 2
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_Vote: {0}", CommandID);


            try
            {
                ShokoService.AnidbProcessor.VoteAnime(AnimeID, VoteValue, (AniDBVoteType)VoteType);

                if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) &&
                    !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                {
                    CommandRequest_MALUpdatedWatchedStatus cmdMAL = new CommandRequest_MALUpdatedWatchedStatus(AnimeID);
                    cmdMAL.Save();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_Vote: {0} - {1}", CommandID, ex);
            }
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_AddFileToMyList: {0}", Hash);


            try
            {
                vid = RepoFactory.VideoLocal.GetByHash(this.Hash);
                List <SVR_AnimeEpisode> animeEpisodes = new List <SVR_AnimeEpisode>();
                if (vid != null)
                {
                    animeEpisodes = vid.GetAnimeEpisodes();
                }

                if (vid != null)
                {
                    // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB
                    // if the file is already on the user's list

                    bool isManualLink = false;
                    List <CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs;
                    if (xrefs.Count > 0)
                    {
                        isManualLink = xrefs[0].CrossRefSource != (int)CrossRefSource.AniDB;
                    }

                    // mark the video file as watched
                    DateTime?watchedDate      = null;
                    bool     newWatchedStatus = false;

                    if (isManualLink)
                    {
                        newWatchedStatus = ShokoService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID,
                                                                                       xrefs[0].GetEpisode().EpisodeNumber,
                                                                                       ref watchedDate);
                    }
                    else
                    {
                        newWatchedStatus = ShokoService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate);
                    }

                    // do for all AniDB users
                    List <SVR_JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers();


                    if (aniDBUsers.Count > 0)
                    {
                        SVR_JMMUser juser = aniDBUsers[0];
                        vid.ToggleWatchedStatus(newWatchedStatus, false, watchedDate, false, false, juser.JMMUserID,
                                                false, true);
                        logger.Info("Adding file to list: {0} - {1}", vid.ToString(), watchedDate);

                        // if the the episode is watched we may want to set the file to watched as well
                        if (ServerSettings.Import_UseExistingFileWatchedStatus && !newWatchedStatus)
                        {
                            if (animeEpisodes.Count > 0)
                            {
                                SVR_AnimeEpisode      ep     = animeEpisodes[0];
                                SVR_AnimeEpisode_User epUser = null;

                                foreach (SVR_JMMUser tempuser in aniDBUsers)
                                {
                                    // only find the first user who watched this
                                    if (epUser == null)
                                    {
                                        epUser = ep.GetUserRecord(tempuser.JMMUserID);
                                    }
                                }

                                if (epUser != null)
                                {
                                    logger.Info(
                                        "Setting file as watched, because episode was already watched: {0} - user: {1}",
                                        vid.ToString(),
                                        juser.Username);
                                    vid.ToggleWatchedStatus(true, true, epUser.WatchedDate, false, false,
                                                            epUser.JMMUserID, false, true);
                                }
                            }
                        }
                    }

                    SVR_AnimeSeries ser = animeEpisodes[0].GetAnimeSeries();
                    // all the eps should belong to the same anime
                    ser.QueueUpdateStats();
                    //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID);

                    // lets also try adding to the users trakt collecion
                    if (ser != null && ServerSettings.Trakt_IsEnabled &&
                        !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                    {
                        foreach (SVR_AnimeEpisode aep in animeEpisodes)
                        {
                            CommandRequest_TraktCollectionEpisode cmdSyncTrakt =
                                new CommandRequest_TraktCollectionEpisode
                                (
                                    aep.AnimeEpisodeID, TraktSyncAction.Add);
                            cmdSyncTrakt.Save();
                        }
                    }

                    // sync the series on MAL
                    if (ser != null && !string.IsNullOrEmpty(ServerSettings.MAL_Username) &&
                        !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                    {
                        CommandRequest_MALUpdatedWatchedStatus cmdMAL =
                            new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                        cmdMAL.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_AddFileToMyList: {0} - {1}", Hash, ex.ToString());
                return;
            }
        }
Exemplo n.º 4
0
        public override void ProcessCommand()
        {
            logger.Info($"Processing CommandRequest_AddFileToMyList: {vid.FileName} - {vid.Hash}");


            try
            {
                if (vid == null)
                {
                    return;
                }

                List <SVR_AnimeEpisode> animeEpisodes = vid.GetAnimeEpisodes();
                // when adding a file via the API, newWatchedStatus will return with current watched status on AniDB
                // if the file is already on the user's list

                bool isManualLink = false;
                List <CrossRef_File_Episode> xrefs = vid.EpisodeCrossRefs;
                if (xrefs.Count > 0)
                {
                    isManualLink = xrefs[0].CrossRefSource != (int)CrossRefSource.AniDB;
                }

                // mark the video file as watched
                DateTime?       watchedDate = null;
                bool?           newWatchedStatus;
                AniDBFile_State?state = null;

                if (isManualLink)
                {
                    newWatchedStatus = ShokoService.AnidbProcessor.AddFileToMyList(xrefs[0].AnimeID,
                                                                                   xrefs[0].GetEpisode().EpisodeNumber,
                                                                                   ref watchedDate);
                }
                else
                {
                    newWatchedStatus = ShokoService.AnidbProcessor.AddFileToMyList(vid, ref watchedDate, ref state);
                }

                // do for all AniDB users
                List <SVR_JMMUser> aniDBUsers = RepoFactory.JMMUser.GetAniDBUsers();


                if (aniDBUsers.Count > 0)
                {
                    string datemessage = watchedDate?.ToShortDateString() ?? "Not Watched";
                    if (watchedDate?.Equals(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime()) ?? false)
                    {
                        datemessage = "No Watch Date Specified";
                    }
                    logger.Info($"Adding file to list: {vid.FileName} - {datemessage}");
                    bool watched = watchedDate != null;
                    if (newWatchedStatus != null)
                    {
                        watched = newWatchedStatus.Value;
                    }

                    SVR_JMMUser juser          = aniDBUsers[0];
                    bool        watchedLocally = vid.GetUserRecord(juser.JMMUserID)?.WatchedDate != null;
                    bool        watchedChanged = watched != watchedLocally;

                    // handle import watched settings. Don't update AniDB in either case, we'll do that with the storage state
                    if (ServerSettings.AniDB_MyList_ReadWatched && watched && !watchedLocally)
                    {
                        vid.ToggleWatchedStatus(true, false, watchedDate, false, juser.JMMUserID,
                                                false, false);
                    }
                    else if (ServerSettings.AniDB_MyList_ReadUnwatched && !watched && watchedLocally)
                    {
                        vid.ToggleWatchedStatus(false, false, watchedDate, false, juser.JMMUserID,
                                                false, false);
                    }

                    if (watchedChanged || state != ServerSettings.AniDB_MyList_StorageState)
                    {
                        int watchedDateSec = Commons.Utils.AniDB.GetAniDBDateAsSeconds(watchedDate);
                        var cmdUpdate      = new CommandRequest_UpdateMyListFileStatus(Hash, watched, false, watchedDateSec);
                        cmdUpdate.Save();
                    }
                }

                SVR_AnimeSeries ser = animeEpisodes[0].GetAnimeSeries();
                // all the eps should belong to the same anime
                ser.QueueUpdateStats();
                //StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID);

                // lets also try adding to the users trakt collecion
                if (ServerSettings.Trakt_IsEnabled &&
                    !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                {
                    foreach (SVR_AnimeEpisode aep in animeEpisodes)
                    {
                        CommandRequest_TraktCollectionEpisode cmdSyncTrakt =
                            new CommandRequest_TraktCollectionEpisode
                            (
                                aep.AnimeEpisodeID, TraktSyncAction.Add);
                        cmdSyncTrakt.Save();
                    }
                }

                // sync the series on MAL
                if (!string.IsNullOrEmpty(ServerSettings.MAL_Username) &&
                    !string.IsNullOrEmpty(ServerSettings.MAL_Password))
                {
                    CommandRequest_MALUpdatedWatchedStatus cmdMAL =
                        new CommandRequest_MALUpdatedWatchedStatus(ser.AniDB_ID);
                    cmdMAL.Save();
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Error processing CommandRequest_AddFileToMyList: {Hash} - {ex}");
            }
        }