Esempio n. 1
0
        public async Task <IEnumerable <Tuple <string, string> > > GetImagesFromUrl(string title, string url)
        {
            try
            {
                var uri = new Uri(url);

                string filename = Path.GetFileName(uri.LocalPath);

                //if (filename.EndsWith(".gif"))
                //    return Enumerable.Empty<Tuple<string, string>>();

                if (filename.EndsWith(".jpg") || filename.EndsWith(".png") || filename.EndsWith(".jpeg") || filename.EndsWith(".gif"))
                {
                    return new Tuple <string, string>[] { Tuple.Create(title, url) }
                }
                ;
                else
                {
                    var targetHost = uri.DnsSafeHost.ToLower(); //make sure we can compare caseless

                    switch (targetHost)
                    {
                    case "imgur.com":
                        return(await Imgur.GetImagesFromUri(title, uri));

                    case "min.us":
                        return(await Minus.GetImagesFromUri(title, uri));

                    case "www.quickmeme.com":
                    case "i.qkme.me":
                    case "quickmeme.com":
                    case "qkme.me":
                        return(Quickmeme.GetImagesFromUri(title, uri));

                    case "memecrunch.com":
                        return(Memecrunch.GetImagesFromUri(title, uri));

                    case "flickr.com":
                        return(await Flickr.GetImagesFromUri(title, uri));

                    default:
                        return(Enumerable.Empty <Tuple <string, string> >());
                    }
                }
            }
            catch
            {
                return(Enumerable.Empty <Tuple <string, string> >());
            }
        }