コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();

                StreamReader reader  = new StreamReader(this.Request.InputStream);
                String       xmlData = reader.ReadToEnd();

                XmlDocument docXRef = new XmlDocument();
                docXRef.LoadXml(xmlData);

                string uname = Utils.TryGetProperty("DeleteCrossRef_AniDB_MALRequest", docXRef, "Username");

                string aid     = Utils.TryGetProperty("DeleteCrossRef_AniDB_MALRequest", docXRef, "AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                string sepType = Utils.TryGetProperty("DeleteCrossRef_AniDB_MALRequest", docXRef, "StartEpisodeType");
                int    epType  = 0;
                int.TryParse(sepType, out epType);

                string sepNumber = Utils.TryGetProperty("DeleteCrossRef_AniDB_MALRequest", docXRef, "StartEpisodeNumber");
                int    epNumber  = 0;
                int.TryParse(sepNumber, out epNumber);

                if (string.IsNullOrEmpty(uname) || animeid <= 0 || epType <= 0 || epNumber <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                List <CrossRef_AniDB_MAL> recs = repCrossRef.GetByAnimeIDUser(animeid, uname, epType, epNumber);
                foreach (CrossRef_AniDB_MAL xref in recs)
                {
                    repCrossRef.Delete(xref.CrossRef_AniDB_MALID);
                }

                // now send to mirror
                string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_MAL.aspx", Constants.MirrorWAIX);
                XMLService.SendData(uri, xmlData);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }
コード例 #2
0
        public static void LinkAniDBMAL(int animeID, int malID, string malTitle, int epType, int epNumber,
                                        bool fromWebCache)
        {
            CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();
            CrossRef_AniDB_MAL           xrefTemp    = repCrossRef.GetByMALID(malID);

            if (xrefTemp != null)
            {
                string msg = string.Format("Not using MAL link as this MAL ID ({0}) is already in use by {1}", malID,
                                           xrefTemp.AnimeID);
                logger.Warn(msg);
                return;
            }

            CrossRef_AniDB_MAL xref = new CrossRef_AniDB_MAL();

            xref.AnimeID            = animeID;
            xref.MALID              = malID;
            xref.MALTitle           = malTitle;
            xref.StartEpisodeType   = epType;
            xref.StartEpisodeNumber = epNumber;
            if (fromWebCache)
            {
                xref.CrossRefSource = (int)CrossRefSource.WebCache;
            }
            else
            {
                xref.CrossRefSource = (int)CrossRefSource.User;
            }

            repCrossRef.Save(xref);
            AniDB_Anime.UpdateStatsByAnimeID(animeID);


            logger.Trace("Changed MAL association: {0}", animeID);

            CommandRequest_MALUpdatedWatchedStatus cmd = new CommandRequest_MALUpdatedWatchedStatus(animeID);

            cmd.Save();

            CommandRequest_WebCacheSendXRefAniDBMAL req =
                new CommandRequest_WebCacheSendXRefAniDBMAL(xref.CrossRef_AniDB_MALID);

            req.Save();
        }
コード例 #3
0
ファイル: MALHelper.cs プロジェクト: alimbada/jmmserver
        public static void RemoveLinkAniDBMAL(int animeID, int epType, int epNumber)
        {
            CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();
            CrossRef_AniDB_MAL           xref        = repCrossRef.GetByAnimeConstraint(animeID, epType, epNumber);

            if (xref == null)
            {
                return;
            }

            repCrossRef.Delete(xref.CrossRef_AniDB_MALID);

            StatsCache.Instance.UpdateUsingAnime(animeID);

            CommandRequest_WebCacheDeleteXRefAniDBMAL req = new CommandRequest_WebCacheDeleteXRefAniDBMAL(animeID, epType, epNumber);

            req.Save();
        }
コード例 #4
0
        public override void ProcessCommand()
        {
            try
            {
                CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();
                CrossRef_AniDB_MAL           xref        = repCrossRef.GetByID(CrossRef_AniDB_MALID);
                if (xref == null)
                {
                    return;
                }


                XMLService.Send_CrossRef_AniDB_MAL(xref);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error processing CommandRequest_WebCacheSendXRefAniDBMAL: {0}" + ex.ToString(), ex);
                return;
            }
        }
コード例 #5
0
        public static void ScanForMatches()
        {
            if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password))
            {
                logger.Warn("Won't SCAN MAL, MAL credentials not provided");
                return;
            }

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

            CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();

            foreach (AnimeSeries ser in allSeries)
            {
                AniDB_Anime anime = ser.GetAnime();
                if (anime == null)
                {
                    continue;
                }

                if (anime.IsMALLinkDisabled)
                {
                    continue;
                }

                // don't scan if it is associated on the TvDB
                List <CrossRef_AniDB_MAL> xrefs = anime.GetCrossRefMAL();
                if (xrefs == null || xrefs.Count == 0)
                {
                    logger.Trace(string.Format("Found anime without MAL association: {0} ({1})", anime.AnimeID,
                                               anime.MainTitle));

                    CommandRequest_MALSearchAnime cmd = new CommandRequest_MALSearchAnime(ser.AniDB_ID, false);
                    cmd.Save();
                }
            }
        }
コード例 #6
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MALDownloadStatusFromMAL");

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

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

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

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

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

                JMMUser user = aniDBUsers[0];


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

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

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

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

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

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

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

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

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

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

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

                            if (update)
                            {
                                ep.ToggleWatchedStatus(false, true, DateTime.Now, user.JMMUserID, false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_MALDownloadStatusFromMAL: {0}", ex.ToString());
                return;
            }
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                string aid     = Utils.GetParam("AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                if (animeid <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                string uname = Utils.GetParam("uname");
                if (uname.Trim().Length == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();

                List <CrossRef_AniDB_MALResult> results = new List <CrossRef_AniDB_MALResult>();

                // check for user specific
                List <CrossRef_AniDB_MAL> recs = repCrossRef.GetByAnimeIDUser(animeid, uname);
                // check for other users
                if (recs.Count == 0)
                {
                    // try user lwerndly
                    recs = repCrossRef.GetByAnimeIDUser(animeid, "jonbaby");
                    if (recs.Count == 0)
                    {
                        // try user jmediamanager
                        recs = repCrossRef.GetByAnimeIDUser(animeid, "jmediamanager");
                    }
                }

                if (recs.Count == 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }
                else
                {
                    foreach (CrossRef_AniDB_MAL rec in recs)
                    {
                        CrossRef_AniDB_MALResult result = new CrossRef_AniDB_MALResult(rec);
                        results.Add(result);
                    }
                    string ret = Utils.ConvertToXML(results, typeof(List <CrossRef_AniDB_MALResult>));
                    Response.Write(ret);
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                return;
            }
        }
コード例 #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            try
            {
                CrossRef_AniDB_MALRepository repCrossRef = new CrossRef_AniDB_MALRepository();

                StreamReader reader  = new StreamReader(this.Request.InputStream);
                String       xmlData = reader.ReadToEnd();

                XmlDocument docXRef = new XmlDocument();
                docXRef.LoadXml(xmlData);

                string uname    = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "Username");
                string malTitle = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "MALTitle");

                string aid     = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "AnimeID");
                int    animeid = 0;
                int.TryParse(aid, out animeid);

                string mID   = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "MALID");
                int    malID = 0;
                int.TryParse(mID, out malID);

                string sepType = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "StartEpisodeType");
                int    epType  = 0;
                int.TryParse(sepType, out epType);

                string sepNumber = Utils.TryGetProperty("AddCrossRef_AniDB_MAL_Request", docXRef, "StartEpisodeNumber");
                int    epNumber  = 0;
                int.TryParse(sepNumber, out epNumber);


                if (string.IsNullOrEmpty(uname) || animeid <= 0 || malID <= 0 || epType <= 0 || epNumber <= 0)
                {
                    Response.Write(Constants.ERROR_XML);
                    return;
                }

                CrossRef_AniDB_MAL        xref = null;
                List <CrossRef_AniDB_MAL> recs = repCrossRef.GetByAnimeIDUser(animeid, uname, epType, epNumber);
                if (recs.Count == 1)
                {
                    xref = recs[0];
                }

                if (recs.Count == 0)
                {
                    xref = new CrossRef_AniDB_MAL();
                }
                else
                {
                    xref = recs[0];
                }

                xref.AnimeID            = animeid;
                xref.CrossRefSource     = 1;
                xref.MALID              = malID;
                xref.MALTitle           = malTitle;
                xref.Username           = uname;
                xref.StartEpisodeType   = epType;
                xref.StartEpisodeNumber = epNumber;
                repCrossRef.Save(xref);

                // now send to mirror
                string uri = string.Format("http://{0}/AddCrossRef_AniDB_MAL.aspx", Constants.MirrorWAIX);
                XMLService.SendData(uri, xmlData);
            }
            catch (Exception ex)
            {
                Response.Write(Constants.ERROR_XML);
            }
        }