Exemplo n.º 1
0
        public override void DownloadEmoticons(string url)
        {
            //image: ssl.gstatic.com/chat/emoji/emoji20png-61089cf406d77f75e149071e74d8f714.png
            lock (iconParseLock)
            {
                if (IsFallbackEmoticons && IsWebEmoticons)
                {
                    return;
                }

                var list = new List <Emoticon>();
                if (Emoticons == null)
                {
                    Emoticons = new List <Emoticon>();
                }


                var content = webClient.Download(url);
                if (String.IsNullOrWhiteSpace(content))
                {
                    return;
                }
                MatchCollection matches = Regex.Matches(content, @"yt-emoji-icon.yt-emoji-([0-9,a-z]+)\s*{(.*?)}", RegexOptions.IgnoreCase);

                if (matches.Count <= 0)
                {
                    Log.WriteError("Unable to get Youtube emoticons!");
                }
                else
                {
                    string originalUrl = null;
                    foreach (Match match in matches)
                    {
                        if (match.Groups.Count >= 2)
                        {
                            var smileName          = match.Groups[1].Value;
                            var cssClassDefinition = match.Groups[2].Value;

                            var background = Css.GetBackground(cssClassDefinition);

                            if (background != null && !String.IsNullOrWhiteSpace(background.url) && background.width > 0 && background.height > 0)
                            {
                                originalUrl = String.Format("http://{0}", background.url.Replace("//", ""));
                                var modifiedUrl = String.Format(@"/ubiquitous/cache?ubx={0}&uby={1}&ubw={2}&ubh={3}&uburl={4}",
                                                                background.x, background.y, background.width, background.height, HttpUtility.UrlEncode(originalUrl));

                                list.Add(new Emoticon(String.Format(@"\u{0}", smileName),
                                                      modifiedUrl,
                                                      background.width,
                                                      background.height
                                                      ));
                            }
                        }
                    }
                    if (list.Count > 0)
                    {
                        Uri uri;
                        if (!String.IsNullOrWhiteSpace(originalUrl) && Uri.TryCreate(originalUrl, UriKind.Absolute, out uri))
                        {
                            var imageDataService = SimpleIoc.Default.GetInstance <IImageDataSource>();

                            using (var memoryStream = webClient.DownloadToMemoryStream(originalUrl))
                            {
                                if (memoryStream == null)
                                {
                                    Log.WriteError("Web Youtube emoticons aren't available!");
                                    using (var memStream = webClient.DownloadToMemoryStream(@"Content\youtubeemoji.png"))
                                    {
                                        if (memStream != null)
                                        {
                                            imageDataService.AddImage(uri, memStream);
                                        }
                                    }
                                }
                            }
                        }
                        Emoticons = list;
                        if (IsFallbackEmoticons)
                        {
                            IsWebEmoticons = true;
                        }

                        IsFallbackEmoticons = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void DownloadEmoticons(string url)
        {
            lock (iconParseLock)
            {
                if (IsFallbackEmoticons && IsWebEmoticons)
                {
                    return;
                }

                var list = new List <Emoticon>();
                if (Emoticons == null)
                {
                    Emoticons = new List <Emoticon>();
                }


                var content = GoodgameGet(url);
                if (content == null)
                {
                    return;
                }

                MatchCollection matches = Regex.Matches(content, @"\.smiles\.([^-|\s]*)\s*{(.*?)}", RegexOptions.IgnoreCase);

                if (matches.Count <= 0)
                {
                    Log.WriteError("Unable to get Goodgame.ru emoticons!");
                }
                else
                {
                    string originalUrl = null;
                    foreach (Match match in matches)
                    {
                        if (match.Groups.Count >= 2)
                        {
                            var smileName          = match.Groups[1].Value;
                            var cssClassDefinition = match.Groups[2].Value;

                            var background = Css.GetBackground(cssClassDefinition);

                            if (background != null && !String.IsNullOrWhiteSpace(background.url) && background.width > 0 && background.height > 0)
                            {
                                originalUrl = String.Format("http://goodgame.ru/{0}", background.url.Replace("../../", ""));
                                var modifiedUrl = String.Format(@"/ubiquitous/cache?ubx={0}&uby={1}&ubw={2}&ubh={3}&uburl={4}",
                                                                background.x, background.y, background.width, background.height, HttpUtility.UrlEncode(originalUrl));

                                list.Add(new Emoticon(String.Format(":{0}:", smileName),
                                                      modifiedUrl,
                                                      background.width,
                                                      background.height
                                                      ));
                            }
                        }
                    }
                    if (list.Count > 0)
                    {
                        Uri uri;
                        if (!String.IsNullOrWhiteSpace(originalUrl) && Uri.TryCreate(originalUrl, UriKind.Absolute, out uri))
                        {
                            var ddosCookieGet = GoodgameGet("http://goodgame.ru");
                            if (ddosCookieGet != null)
                            {
                                var imageDataService = SimpleIoc.Default.GetInstance <IImageDataSource>();
                                using (var memoryStream = webClient.DownloadToMemoryStream(originalUrl))
                                {
                                    imageDataService.AddImage(uri, memoryStream);
                                }
                            }
                            else
                            {
                                //get local image
                            }
                        }
                        Emoticons = list;
                        if (IsFallbackEmoticons)
                        {
                            IsWebEmoticons = true;
                        }

                        IsFallbackEmoticons = true;
                    }
                }
            }
        }