コード例 #1
0
        public void ProcessFromHTTPResult(XmlNode node, int anid)
        {
            this.AnimeID        = anid;
            this.TagID          = 0;
            this.Spoiler        = 0;
            this.LocalSpoiler   = 0;
            this.GlobalSpoiler  = 0;
            this.TagName        = string.Empty;
            this.TagDescription = string.Empty;
            this.TagCount       = 0;
            this.Approval       = 0;
            this.Weight         = 0;

            this.TagID = int.Parse(AniDBHTTPHelper.TryGetAttribute(node, "id"));

            int.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "weight"), out int tapp);
            this.Weight = tapp;

            this.TagName        = AniDBHTTPHelper.TryGetProperty(node, "name")?.Replace('`', '\'');
            this.TagDescription = AniDBHTTPHelper.TryGetProperty(node, "description")?.Replace('`', '\'');

            bool.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "localspoiler"), out bool lsp);
            this.Spoiler |= lsp ? 1 : 0;

            bool.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "globalspoiler"), out bool gsp);
            this.Spoiler |= gsp ? 1 : 0;
        }
コード例 #2
0
        public void ProcessFromHTTPResult(XmlNode node, int anid)
        {
            InitFields();

            this.AnimeID  = anid;
            this.CharID   = int.Parse(AniDBHTTPHelper.TryGetAttribute(node, "id"));
            this.CharType = AniDBHTTPHelper.TryGetAttribute(node, "type");

            this.CharName        = AniDBHTTPHelper.TryGetProperty(node, "name")?.Replace('`', '\'');
            this.CharDescription = AniDBHTTPHelper.TryGetProperty(node, "description")?.Replace('`', '\'');
            this.EpisodeListRaw  = AniDBHTTPHelper.TryGetProperty(node, "episodes") ?? string.Empty;
            this.PicName         = AniDBHTTPHelper.TryGetProperty(node, "picture");

            CreatorListRaw = string.Empty;
            foreach (XmlNode nodeChild in node.ChildNodes)
            {
                if (nodeChild?.Name == "seiyuu")
                {
                    Raw_AniDB_Seiyuu seiyuu = new Raw_AniDB_Seiyuu();

                    if (nodeChild.Attributes?["id"] != null)
                    {
                        string creatorid = nodeChild.Attributes["id"].Value;
                        seiyuu.SeiyuuID = int.Parse(creatorid);

                        if (CreatorListRaw.Length > 0)
                        {
                            CreatorListRaw += ",";
                        }
                        CreatorListRaw += creatorid.Trim();
                    }

                    if (nodeChild.Attributes?["picture"] != null)
                    {
                        seiyuu.PicName = nodeChild.Attributes["picture"].Value;
                    }

                    seiyuu.SeiyuuName = nodeChild.InnerText.Replace('`', '\'');
                    Seiyuus.Add(seiyuu);
                }
            }
        }
コード例 #3
0
        public void ProcessFromHTTPResult(XmlNode node, int anid)
        {
            this.AnimeID             = anid;
            this.CategoryID          = 0;
            this.ParentID            = 0;
            this.IsHentai            = 0;
            this.CategoryName        = string.Empty;
            this.CategoryDescription = string.Empty;
            this.Weighting           = 0;

            this.CategoryID = int.Parse(AniDBHTTPHelper.TryGetAttribute(node, "id"));
            this.ParentID   = int.Parse(AniDBHTTPHelper.TryGetAttribute(node, "parentid"));

            bool.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "hentai"), out bool hentai);
            this.IsHentai = hentai ? 1 : 0;


            this.CategoryName        = AniDBHTTPHelper.TryGetProperty(node, "name");
            this.CategoryDescription = AniDBHTTPHelper.TryGetProperty(node, "description");

            int.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "weight"), out int weight);
            this.Weighting = weight;
        }
コード例 #4
0
        public static anime SearchAnimesByTitle(string searchTitle)
        {
            if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password))
            {
                logger.Warn("Won't search MAL, MAL credentials not provided");
                return(GetEmptyAnimes());
            }

            searchTitle = HttpUtility.UrlPathEncode(searchTitle);

            string searchResultXML = "";

            try
            {
                searchResultXML =
                    SendMALAuthenticatedRequest("https://myanimelist.net/api/anime/search.xml?q=" + searchTitle);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(GetEmptyAnimes());
            }
            if (searchResultXML.Trim().Length == 0)
            {
                return(GetEmptyAnimes());
            }

            searchResultXML = HttpUtility.HtmlDecode(searchResultXML);
            searchResultXML = HttpUtilityV2.HtmlDecode(searchResultXML);
            searchResultXML = searchResultXML.Replace("&", "&");
            XmlDocument docSearchResult = new XmlDocument();

            docSearchResult.LoadXml(searchResultXML);

            anime             animes  = GetEmptyAnimes();
            List <animeEntry> entries = new List <animeEntry>();

            if (docSearchResult != null && docSearchResult["anime"] != null)
            {
                XmlNodeList searchItems = docSearchResult["anime"].GetElementsByTagName("entry");

                foreach (XmlNode node in searchItems)
                {
                    try
                    {
                        animeEntry entry = new animeEntry();
                        // default values
                        entry.end_date   = string.Empty;
                        entry.english    = string.Empty;
                        entry.episodes   = 0;
                        entry.id         = 0;
                        entry.image      = string.Empty;
                        entry.score      = 0;
                        entry.start_date = string.Empty;
                        entry.status     = string.Empty;
                        entry.synonyms   = string.Empty;
                        entry.synopsis   = string.Empty;
                        entry.title      = string.Empty;
                        entry.type       = string.Empty;

                        entry.end_date = AniDBHTTPHelper.TryGetProperty(node, "end_date");
                        entry.english  = AniDBHTTPHelper.TryGetProperty(node, "english");
                        entry.image    = AniDBHTTPHelper.TryGetProperty(node, "image");

                        int     eps   = 0;
                        int     id    = 0;
                        decimal score = 0;

                        int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "episodes"), out eps);
                        int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "id"), out id);
                        decimal.TryParse(AniDBHTTPHelper.TryGetProperty(node, "score"), out score);

                        entry.episodes = eps;
                        entry.id       = id;
                        entry.score    = score;

                        entry.start_date = AniDBHTTPHelper.TryGetProperty(node, "start_date");
                        entry.status     = AniDBHTTPHelper.TryGetProperty(node, "status");
                        entry.synonyms   = AniDBHTTPHelper.TryGetProperty(node, "synonyms");
                        entry.synopsis   = AniDBHTTPHelper.TryGetProperty(node, "synopsis");
                        entry.title      = AniDBHTTPHelper.TryGetProperty(node, "title");
                        entry.type       = AniDBHTTPHelper.TryGetProperty(node, "type");

                        entries.Add(entry);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, ex.ToString());
                    }
                }
            }

            animes.entry = entries.ToArray();
            return(animes);
        }
コード例 #5
0
        public bool ProcessEpisodeSource(XmlNode node, int anid)
        {
            if (string.IsNullOrEmpty(node?.Attributes?["id"]?.Value))
            {
                return(false);
            }
            if (!int.TryParse(node?.Attributes?["id"]?.Value, out int id))
            {
                return(false);
            }
            EpisodeID = id;
            // default values
            LengthSeconds   = 0;
            Rating          = 0;
            Votes           = 0;
            EpisodeNumber   = 0;
            EpisodeType     = 1;
            AirDate         = 0;
            DateTimeUpdated = DateTime.Now;

            AnimeID = anid;

            string epno = AniDBHTTPHelper.TryGetProperty(node, "epno");

            EpisodeType     = GetEpisodeType(epno);
            EpisodeNumber   = GetEpisodeNumber(epno);
            IsDoubleEpisode = GetIsDoubleEpisode(epno);

            string length = AniDBHTTPHelper.TryGetProperty(node, "length");

            int.TryParse(length, out int lMinutes);
            int secs = lMinutes * 60;

            LengthSeconds = secs;

            NumberStyles style   = NumberStyles.Number;
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-GB");

            if (decimal.TryParse(AniDBHTTPHelper.TryGetProperty(node, "rating"), style, culture, out decimal rating))
            {
                Rating = rating;
            }
            if (int.TryParse(AniDBHTTPHelper.TryGetAttribute(node, "rating", "votes"), out int votes))
            {
                Votes = votes;
            }

            // Titles
            foreach (XmlNode nodeChild in node.ChildNodes)
            {
                // Make sure that it's a title and has data
                if (!(nodeChild?.Name.Equals("title") ?? false) ||
                    string.IsNullOrEmpty(nodeChild.InnerText))
                {
                    continue;
                }

                // get language
                string language = nodeChild.Attributes?["xml:lang"]?.Value?.Trim().ToUpperInvariant();
                if (string.IsNullOrEmpty(language))
                {
                    continue;
                }
                string title = nodeChild.InnerText.Trim().Replace('`', '\'');

                using (var upd = Repo.Instance.AniDB_Episode_Title.BeginAddOrUpdate(() => Repo.Instance.AniDB_Episode_Title.GetByEpisodeIDAndLanguage(id, language).FirstOrDefault()))
                {
                    upd.Entity.AniDB_EpisodeID = id;
                    upd.Entity.Language        = language;
                    upd.Entity.Title           = title;
                    upd.Commit();
                }
            }

            string adate = AniDBHTTPHelper.TryGetProperty(node, "airdate");

            AirDate = Commons.Utils.AniDB.GetAniDBDateAsSeconds(adate, true);

            Description = AniDBHTTPHelper.TryGetProperty(node, "summary")?.Replace('`', '\'');
            IsValid     = true;
            return(true);
        }
コード例 #6
0
        public void ProcessHTTPSource(XmlNode node)
        {
            if (node == null)
            {
                logger.Warn("MyList item had a corrupted XML");
                return;
            }
            if (string.IsNullOrEmpty(node.Attributes?["id"]?.Value))
            {
                logger.Warn("MyList item has no ID" + "\n" + node);
                return;
            }
            ListID    = int.Parse(node.Attributes["id"].Value);
            AnimeID   = int.Parse(node.Attributes["aid"].Value);
            EpisodeID = int.Parse(node.Attributes["eid"].Value);
            FileID    = int.Parse(node.Attributes["fid"].Value);

            ViewDateHTTP = AniDBHTTPHelper.TryGetAttribute(node, "viewdate");

            // calculate the watched date
            if (!string.IsNullOrEmpty(ViewDateHTTP) && ViewDateHTTP.Length > 17)
            {
                try
                {
                    // eg "2011-02-23T20:49:18+0000"

                    /*int year = int.Parse(ViewDateHTTP.Trim().Substring(0, 4));
                     * int month = int.Parse(ViewDateHTTP.Trim().Substring(5, 2));
                     * int day = int.Parse(ViewDateHTTP.Trim().Substring(8, 2));
                     *
                     * int hour = int.Parse(ViewDateHTTP.Trim().Substring(11, 2));
                     * int minute = int.Parse(ViewDateHTTP.Trim().Substring(14, 2));
                     * int second = int.Parse(ViewDateHTTP.Trim().Substring(17, 2));
                     *
                     * DateTime utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
                     */
                    if (!DateTime.TryParse(ViewDateHTTP, out DateTime utcDate))
                    {
                        logger.Error("Error processing View Date HTTP: " + ViewDateHTTP);
                    }
                    utcDate = utcDate.AddSeconds(ViewDateUDP);

                    WatchedDate = utcDate.ToLocalTime();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error processing View Date HTTP: " + ex.ToString());
                }
            }

            string tempstate = AniDBHTTPHelper.TryGetProperty(node, "state");
            bool   state     = int.TryParse(tempstate, out int istate);

            if (state)
            {
                State = istate;
            }

            string fstate    = AniDBHTTPHelper.TryGetProperty(node, "filestate");
            bool   filestate = int.TryParse(fstate, out int ifilestate);

            if (filestate)
            {
                FileState = ifilestate;
            }

            if (!state && !filestate)
            {
                logger.Warn($"AniDB Sync_MyList - MyListItem with fid {FileID} has no 'State' or 'FileState'");
            }

            Source = AniDBHTTPHelper.TryGetProperty(node, "storage");
        }