Example #1
0
        public string ParseGfycatCajaxResponse(string result, GfycatTypes gfycatType)
        {
            XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(result),
                                                                                      new XmlDictionaryReaderQuotas());
            XElement root = XElement.Load(jsonReader);
            string   url;

            switch (gfycatType)
            {
            case GfycatTypes.Gif:
                url = root.Element("gfyItem").Element("gifUrl").Value;
                break;

            case GfycatTypes.Max5mbGif:
                url = root.Element("gfyItem").Element("max5mbGif").Value;
                break;

            case GfycatTypes.Max2mbGif:
                url = root.Element("gfyItem").Element("max2mbGif").Value;
                break;

            case GfycatTypes.Mjpg:
                url = root.Element("gfyItem").Element("mjpgUrl").Value;
                break;

            case GfycatTypes.Mp4:
                url = root.Element("gfyItem").Element("mp4Url").Value;
                break;

            case GfycatTypes.Poster:
                url = root.Element("gfyItem").Element("posterUrl").Value;
                break;

            case GfycatTypes.Webm:
                url = root.Element("gfyItem").Element("webmUrl").Value;
                break;

            case GfycatTypes.Webp:
                url = root.Element("gfyItem").Element("webpUrl").Value;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(url);
        }
Example #2
0
        public async Task <IEnumerable <string> > SearchForGfycatUrlAsync(string searchableText, GfycatTypes gfycatType)
        {
            var   urlList = new List <string>();
            Regex regex   = GetGfycatUrlRegex();

            foreach (Match match in regex.Matches(searchableText))
            {
                string gfyId = match.Groups[2].Value;
                urlList.Add(ParseGfycatCajaxResponse(await RequestGfycatCajax(gfyId), gfycatType));
            }

            return(urlList);
        }