Esempio n. 1
0
        public MalReturn GetMALTitle(string title)
        {
            try
            {
                MalReturn ret = new MalReturn();

                title = title.ToLower();
                var request = new RestRequest("anime/search.xml", Method.GET);
                if (title.Contains("episode"))
                {
                    title = title.Remove(title.IndexOf(" episode"));
                }
                request.AddParameter("q", title);
                request.RootElement = "anime";

                var resp = client.Execute(request);

                if (string.IsNullOrEmpty(resp.Content))
                {
                    return(null);
                }

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(resp.Content);

                byte[] bytes = dlClient.DownloadData(new Uri(xml.SelectSingleNode("anime/entry/image").InnerText));

                using (MemoryStream memstream = new MemoryStream(bytes))
                {
                    ret.Cover = new Bitmap(memstream);
                }

                ret.id = xml.SelectSingleNode("anime/entry/id").InnerText;

                return(ret);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Main timer loop
        /// </summary>
        /// <param name="client">Discord.DiscordClient, used to assign the status</param>
        internal void TimerCheck()
        {
            var BrowserProcesses = GetBrowserProcesses();

            if (BrowserProcesses == null)
            {
                return;
            }

            var rightProcess = GetKeywordProcess(BrowserProcesses);

            if (rightProcess == null)
            {
                if (_retryInt >= 3)
                {
                    if (lastTitle != null)
                    {
                        ChangeGame(null);
                        lastTitle = null;

                        lastTitleRet = null;
                        pCover.Image = Properties.Resources.noAni;

                        pCover.MouseHover -= pCover_MouseHover;
                    }

                    _retryInt = 3;
                }

                _retryInt++;
                return;
            }
            else
            {
                _retryInt = 0;
            }

            var title = RemoveWebString(rightProcess.Item2.MainWindowTitle, rightProcess.Item1, rightProcess.Item3);

            if (title == null)
            {
                return;
            }

            if (title != lastTitle)
            {
                ChangeGame(title);

                var apiReturn = wrapper.GetMALTitle(title);

                if (apiReturn != null)
                {
                    pCover.Image       = apiReturn.Cover;
                    lastTitleRet       = apiReturn;
                    pCover.MouseHover += pCover_MouseHover;
                }
                else
                {
                    pCover.Image       = Properties.Resources.noAni;
                    lastTitleRet       = null;
                    pCover.MouseHover -= pCover_MouseHover;
                }
            }

            lastTitle = title;
        }